Skip to content

Commit

Permalink
Expose nettyRemotingServer (#153)
Browse files Browse the repository at this point in the history
* add constructor, expose nettyRemotingServer

* code review
  • Loading branch information
hzh0425 authored Jun 3, 2022
1 parent bc9a820 commit 32be3da
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.rocketmq.remoting.ChannelEventListener;
import org.apache.rocketmq.remoting.netty.NettyClientConfig;
import org.apache.rocketmq.remoting.netty.NettyRemotingClient;
import org.apache.rocketmq.remoting.netty.NettyRemotingServer;
Expand Down Expand Up @@ -96,6 +97,14 @@ public Thread newThread(Runnable r) {
});

public DLedgerRpcNettyService(DLedgerServer dLedgerServer) {
this(dLedgerServer, null, null, null);
}

public DLedgerRpcNettyService(DLedgerServer dLedgerServer, NettyServerConfig nettyServerConfig, NettyClientConfig nettyClientConfig) {
this(dLedgerServer, nettyServerConfig, nettyClientConfig, null);
}

public DLedgerRpcNettyService(DLedgerServer dLedgerServer, NettyServerConfig nettyServerConfig, NettyClientConfig nettyClientConfig, ChannelEventListener channelEventListener) {
this.dLedgerServer = dLedgerServer;
this.memberState = dLedgerServer.getMemberState();
NettyRequestProcessor protocolProcessor = new NettyRequestProcessor() {
Expand All @@ -110,9 +119,11 @@ public boolean rejectRequest() {
}
};
//start the remoting server
NettyServerConfig nettyServerConfig = new NettyServerConfig();
nettyServerConfig.setListenPort(Integer.valueOf(memberState.getSelfAddr().split(":")[1]));
this.remotingServer = new NettyRemotingServer(nettyServerConfig, null);
if (nettyServerConfig == null) {
nettyServerConfig = new NettyServerConfig();
}
nettyServerConfig.setListenPort(Integer.parseInt(memberState.getSelfAddr().split(":")[1]));
this.remotingServer = new NettyRemotingServer(nettyServerConfig, channelEventListener);
this.remotingServer.registerProcessor(DLedgerRequestCode.METADATA.getCode(), protocolProcessor, null);
this.remotingServer.registerProcessor(DLedgerRequestCode.APPEND.getCode(), protocolProcessor, null);
this.remotingServer.registerProcessor(DLedgerRequestCode.GET.getCode(), protocolProcessor, null);
Expand All @@ -123,8 +134,10 @@ public boolean rejectRequest() {
this.remotingServer.registerProcessor(DLedgerRequestCode.LEADERSHIP_TRANSFER.getCode(), protocolProcessor, null);

//start the remoting client
this.remotingClient = new NettyRemotingClient(new NettyClientConfig(), null);

if (nettyClientConfig == null) {
nettyClientConfig = new NettyClientConfig();
}
this.remotingClient = new NettyRemotingClient(nettyClientConfig, null);
}

private String getPeerAddr(RequestOrResponse request) {
Expand Down Expand Up @@ -476,4 +489,8 @@ public DLedgerServer getdLedgerServer() {
public void setdLedgerServer(DLedgerServer dLedgerServer) {
this.dLedgerServer = dLedgerServer;
}

public NettyRemotingServer getRemotingServer() {
return remotingServer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.CompletableFuture;

import org.apache.rocketmq.remoting.ChannelEventListener;
import org.apache.rocketmq.remoting.netty.NettyClientConfig;
import org.apache.rocketmq.remoting.netty.NettyRemotingServer;
import org.apache.rocketmq.remoting.netty.NettyServerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -76,10 +80,18 @@ public class DLedgerServer implements DLedgerProtocolHandler {
private Optional<StateMachineCaller> fsmCaller;

public DLedgerServer(DLedgerConfig dLedgerConfig) {
this(dLedgerConfig, null, null, null);
}

public DLedgerServer(DLedgerConfig dLedgerConfig, NettyServerConfig nettyServerConfig, NettyClientConfig nettyClientConfig) {
this(dLedgerConfig, nettyServerConfig, nettyClientConfig, null);
}

public DLedgerServer(DLedgerConfig dLedgerConfig, NettyServerConfig nettyServerConfig, NettyClientConfig nettyClientConfig, ChannelEventListener channelEventListener) {
this.dLedgerConfig = dLedgerConfig;
this.memberState = new MemberState(dLedgerConfig);
this.dLedgerStore = createDLedgerStore(dLedgerConfig.getStoreType(), this.dLedgerConfig, this.memberState);
dLedgerRpcService = new DLedgerRpcNettyService(this);
dLedgerRpcService = new DLedgerRpcNettyService(this, nettyServerConfig, nettyClientConfig, channelEventListener);
dLedgerEntryPusher = new DLedgerEntryPusher(dLedgerConfig, memberState, dLedgerStore, dLedgerRpcService);
dLedgerLeaderElector = new DLedgerLeaderElector(dLedgerConfig, memberState, dLedgerRpcService);
executorService = Executors.newSingleThreadScheduledExecutor(r -> {
Expand Down Expand Up @@ -433,4 +445,11 @@ public DLedgerLeaderElector getdLedgerLeaderElector() {
public DLedgerConfig getdLedgerConfig() {
return dLedgerConfig;
}

public NettyRemotingServer getRemotingServer() {
if (this.dLedgerRpcService instanceof DLedgerRpcNettyService) {
return ((DLedgerRpcNettyService)this.dLedgerRpcService).getRemotingServer();
}
return null;
}
}

0 comments on commit 32be3da

Please sign in to comment.