提交 cf3e06ca 编写于 作者: H huzongtang

[RIP-11]add SEND_BATCH_MESSAGE request code to related processor.

上级 806f36b4
...@@ -82,13 +82,13 @@ public class Http2ClientImpl extends NettyRemotingClientAbstract implements Remo ...@@ -82,13 +82,13 @@ public class Http2ClientImpl extends NettyRemotingClientAbstract implements Remo
public RemotingClient init(ClientConfig clientConfig, ChannelEventListener channelEventListener) { public RemotingClient init(ClientConfig clientConfig, ChannelEventListener channelEventListener) {
this.nettyClientConfig = clientConfig; this.nettyClientConfig = clientConfig;
this.channelEventListener = channelEventListener; this.channelEventListener = channelEventListener;
this.ioGroup = new NioEventLoopGroup(clientConfig.getClientWorkerThreads(), ThreadUtils.newGenericThreadFactory("NettyClientEpollIoThreads", this.ioGroup = new NioEventLoopGroup(clientConfig.getClientWorkerThreads(), ThreadUtils.newGenericThreadFactory("Http2NettyClientEpollIoThreads",
clientConfig.getClientWorkerThreads())); clientConfig.getClientWorkerThreads()));
this.publicExecutor = ThreadUtils.newFixedThreadPool( this.publicExecutor = ThreadUtils.newFixedThreadPool(
clientConfig.getClientCallbackExecutorThreads(), clientConfig.getClientCallbackExecutorThreads(),
10000, "Remoting-PublicExecutor", true); 10000, "Http2Remoting-PublicExecutor", true);
this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(clientConfig.getClientWorkerThreads(), this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(clientConfig.getClientWorkerThreads(),
ThreadUtils.newGenericThreadFactory("NettyClientWorkerThreads", clientConfig.getClientWorkerThreads())); ThreadUtils.newGenericThreadFactory("Http2NettyClientWorkerThreads", clientConfig.getClientWorkerThreads()));
buildHttp2SslClientContext(); buildHttp2SslClientContext();
return this; return this;
} }
......
...@@ -97,23 +97,23 @@ public class Http2ServerImpl extends NettyRemotingServerAbstract implements Remo ...@@ -97,23 +97,23 @@ public class Http2ServerImpl extends NettyRemotingServerAbstract implements Remo
this.channelEventListener = channelEventListener; this.channelEventListener = channelEventListener;
this.publicExecutor = ThreadUtils.newFixedThreadPool( this.publicExecutor = ThreadUtils.newFixedThreadPool(
serverConfig.getServerCallbackExecutorThreads(), serverConfig.getServerCallbackExecutorThreads(),
10000, "Remoting-PublicExecutor", true); 10000, "Http2Remoting-PublicExecutor", true);
if (JvmUtils.isLinux() && this.serverConfig.isUseEpollNativeSelector()) { if (JvmUtils.isLinux() && this.serverConfig.isUseEpollNativeSelector()) {
this.ioGroup = new EpollEventLoopGroup(serverConfig.getServerSelectorThreads(), ThreadUtils.newGenericThreadFactory("NettyEpollIoThreads", this.ioGroup = new EpollEventLoopGroup(serverConfig.getServerSelectorThreads(), ThreadUtils.newGenericThreadFactory("Http2NettyEpollIoThreads",
serverConfig.getServerSelectorThreads())); serverConfig.getServerSelectorThreads()));
this.bossGroup = new EpollEventLoopGroup(serverConfig.getServerAcceptorThreads(), ThreadUtils.newGenericThreadFactory("NettyBossThreads", this.bossGroup = new EpollEventLoopGroup(serverConfig.getServerAcceptorThreads(), ThreadUtils.newGenericThreadFactory("Http2NettyBossThreads",
serverConfig.getServerAcceptorThreads())); serverConfig.getServerAcceptorThreads()));
this.socketChannelClass = EpollServerSocketChannel.class; this.socketChannelClass = EpollServerSocketChannel.class;
} else { } else {
this.bossGroup = new NioEventLoopGroup(serverConfig.getServerAcceptorThreads(), ThreadUtils.newGenericThreadFactory("NettyBossThreads", this.bossGroup = new NioEventLoopGroup(serverConfig.getServerAcceptorThreads(), ThreadUtils.newGenericThreadFactory("Http2NettyBossThreads",
serverConfig.getServerAcceptorThreads())); serverConfig.getServerAcceptorThreads()));
this.ioGroup = new NioEventLoopGroup(serverConfig.getServerSelectorThreads(), ThreadUtils.newGenericThreadFactory("NettyNioIoThreads", this.ioGroup = new NioEventLoopGroup(serverConfig.getServerSelectorThreads(), ThreadUtils.newGenericThreadFactory("Http2NettyNioIoThreads",
serverConfig.getServerSelectorThreads())); serverConfig.getServerSelectorThreads()));
this.socketChannelClass = NioServerSocketChannel.class; this.socketChannelClass = NioServerSocketChannel.class;
} }
this.workerGroup = new DefaultEventExecutorGroup(serverConfig.getServerWorkerThreads(), this.workerGroup = new DefaultEventExecutorGroup(serverConfig.getServerWorkerThreads(),
ThreadUtils.newGenericThreadFactory("NettyWorkerThreads", serverConfig.getServerWorkerThreads())); ThreadUtils.newGenericThreadFactory("Http2NettyWorkerThreads", serverConfig.getServerWorkerThreads()));
this.port = nettyServerConfig.getListenPort(); this.port = nettyServerConfig.getListenPort();
buildHttp2SslServerContext(); buildHttp2SslServerContext();
return this; return this;
......
...@@ -51,13 +51,15 @@ public class SendMessageProcessor implements RequestProcessor { ...@@ -51,13 +51,15 @@ public class SendMessageProcessor implements RequestProcessor {
} }
String enodeName; String enodeName;
SendMessageRequestHeaderV2 sendMessageRequestHeaderV2 = null; SendMessageRequestHeaderV2 sendMessageRequestHeaderV2 = null;
ConsumerSendMsgBackRequestHeader consumerSendMsgBackRequestHeader = null;
boolean isSendBack = false; boolean isSendBack = false;
if (request.getCode() == RequestCode.SEND_MESSAGE_V2) { if (request.getCode() == RequestCode.SEND_MESSAGE_V2 ||
request.getCode() == RequestCode.SEND_BATCH_MESSAGE) {
sendMessageRequestHeaderV2 = (SendMessageRequestHeaderV2) request.decodeCommandCustomHeader(SendMessageRequestHeaderV2.class); sendMessageRequestHeaderV2 = (SendMessageRequestHeaderV2) request.decodeCommandCustomHeader(SendMessageRequestHeaderV2.class);
enodeName = sendMessageRequestHeaderV2.getN(); enodeName = sendMessageRequestHeaderV2.getN();
} else { } else {
isSendBack = true; isSendBack = true;
ConsumerSendMsgBackRequestHeader consumerSendMsgBackRequestHeader = (ConsumerSendMsgBackRequestHeader) request.decodeCommandCustomHeader(ConsumerSendMsgBackRequestHeader.class); consumerSendMsgBackRequestHeader = (ConsumerSendMsgBackRequestHeader) request.decodeCommandCustomHeader(ConsumerSendMsgBackRequestHeader.class);
enodeName = consumerSendMsgBackRequestHeader.getEnodeName(); enodeName = consumerSendMsgBackRequestHeader.getEnodeName();
} }
......
...@@ -71,12 +71,18 @@ public class SendMessageProcessorTest { ...@@ -71,12 +71,18 @@ public class SendMessageProcessorTest {
} }
@Test @Test
public void testProcessRequest() throws RemotingCommandException { public void testSendMessageV2ProcessRequest() throws RemotingCommandException {
CompletableFuture<RemotingCommand> future = new CompletableFuture<>();
RemotingCommand request = createSendMesssageV2Command();
when(this.snodeController.getEnodeService().sendMessage(anyString(), any(RemotingCommand.class))).thenReturn(future);
sendMessageProcessor.processRequest(remotingChannel, request);
}
@Test
public void testSendBatchMessageProcessRequest() throws RemotingCommandException {
snodeController.setEnodeService(enodeService); snodeController.setEnodeService(enodeService);
CompletableFuture<RemotingCommand> future = new CompletableFuture<>(); CompletableFuture<RemotingCommand> future = new CompletableFuture<>();
RemotingCommand request = createSendMesssageCommand(); RemotingCommand request = createSendBatchMesssageCommand();
SendMessageRequestHeaderV2 sendMessageRequestHeaderV2 = (SendMessageRequestHeaderV2) request.decodeCommandCustomHeader(SendMessageRequestHeaderV2.class);
System.out.println("sendMessageRequestHeaderV2: " + sendMessageRequestHeaderV2);
when(this.snodeController.getEnodeService().sendMessage(anyString(), any(RemotingCommand.class))).thenReturn(future); when(this.snodeController.getEnodeService().sendMessage(anyString(), any(RemotingCommand.class))).thenReturn(future);
sendMessageProcessor.processRequest(remotingChannel, request); sendMessageProcessor.processRequest(remotingChannel, request);
} }
...@@ -95,7 +101,7 @@ public class SendMessageProcessorTest { ...@@ -95,7 +101,7 @@ public class SendMessageProcessorTest {
return requestHeader; return requestHeader;
} }
private RemotingCommand createSendMesssageCommand() { private RemotingCommand createSendMesssageV2Command() {
SendMessageRequestHeaderV2 sendMessageRequestHeaderV2 = createSendMsgRequestHeader(); SendMessageRequestHeaderV2 sendMessageRequestHeaderV2 = createSendMsgRequestHeader();
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE_V2, sendMessageRequestHeaderV2); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE_V2, sendMessageRequestHeaderV2);
request.setBody(new byte[] {'a'}); request.setBody(new byte[] {'a'});
...@@ -103,6 +109,14 @@ public class SendMessageProcessorTest { ...@@ -103,6 +109,14 @@ public class SendMessageProcessorTest {
return request; return request;
} }
private RemotingCommand createSendBatchMesssageCommand() {
SendMessageRequestHeaderV2 sendMessageRequestHeaderV2 = createSendMsgRequestHeader();
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.SEND_BATCH_MESSAGE, sendMessageRequestHeaderV2);
request.setBody(new byte[] {'b'});
CodecHelper.makeCustomHeaderToNet(request);
return request;
}
RemotingCommand createSendMessageResponse(int responseCode) { RemotingCommand createSendMessageResponse(int responseCode) {
return RemotingCommand.createResponseCommand(ResponseCode.SUCCESS, null); return RemotingCommand.createResponseCommand(ResponseCode.SUCCESS, null);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册