use of org.apache.flink.shaded.netty4.io.netty.handler.codec.LengthFieldBasedFrameDecoder in project angel by Tencent.
the class MatrixTransportClient method init.
private void init() {
Configuration conf = PSAgentContext.get().getConf();
rpcContext.init(conf, PSAgentContext.get().getLocationManager().getPsIds());
// Init response handler
registeHandler();
// Init network parameters
int nettyWorkerNum = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_EVENTGROUP_THREADNUM, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_EVENTGROUP_THREADNUM);
int sendBuffSize = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_SNDBUF, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_SNDBUF);
int recvBuffSize = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_RCVBUF, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_RCVBUF);
final int maxMessageSize = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_MAX_MESSAGE_SIZE, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_MAX_MESSAGE_SIZE);
requestThreadPool = Executors.newFixedThreadPool(conf.getInt(AngelConf.ANGEL_MATRIXTRANSFER_CLIENT_REQUESTER_POOL_SIZE, AngelConf.DEFAULT_ANGEL_MATRIXTRANSFER_CLIENT_REQUESTER_POOL_SIZE), new AngelThreadFactory("RPCRequest"));
responseThreadPool = Executors.newFixedThreadPool(conf.getInt(AngelConf.ANGEL_MATRIXTRANSFER_CLIENT_RESPONSER_POOL_SIZE, AngelConf.DEFAULT_ANGEL_MATRIXTRANSFER_CLIENT_RESPONSER_POOL_SIZE), new AngelThreadFactory("RPCResponser"));
ChannelPoolParam poolParam = new ChannelPoolParam();
poolParam.maxActive = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MAX_CONN_PERSERVER, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MAX_CONN_PERSERVER);
poolParam.minActive = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MIN_CONN_PERSERVER, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MIN_CONN_PERSERVER);
poolParam.maxIdleTimeMs = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MAX_CONN_IDLETIME_MS, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MAX_CONN_IDLETIME_MS);
poolParam.getChannelTimeoutMs = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_GET_CONN_TIMEOUT_MS, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_GET_CONN_TIMEOUT_MS);
int ioRatio = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_IORATIO, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_IORATIO);
String channelType = conf.get(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_CHANNEL_TYPE, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_CHANNEL_TYPE);
hbThreadPool = Executors.newFixedThreadPool(8, new AngelThreadFactory("Heartbeat"));
bootstrap = new Bootstrap();
channelManager = new ChannelManager2(bootstrap, poolParam);
channelManager.initAndStart();
// Use Epoll for linux
Class channelClass;
String os = System.getProperty("os.name");
if (os != null && os.toLowerCase().startsWith("linux") && channelType.equals("epoll")) {
LOG.info("Use epoll channel");
channelClass = EpollSocketChannel.class;
eventGroup = new EpollEventLoopGroup(nettyWorkerNum);
((EpollEventLoopGroup) eventGroup).setIoRatio(ioRatio);
} else {
LOG.info("Use nio channel");
channelClass = NioSocketChannel.class;
eventGroup = new NioEventLoopGroup(nettyWorkerNum);
((NioEventLoopGroup) eventGroup).setIoRatio(ioRatio);
}
MatrixTransportClient client = this;
bootstrap.group(eventGroup).channel(channelClass).option(ChannelOption.SO_SNDBUF, sendBuffSize).option(ChannelOption.SO_RCVBUF, recvBuffSize).option(ChannelOption.SO_KEEPALIVE, true).handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeLine = ch.pipeline();
pipeLine.addLast(new LengthFieldBasedFrameDecoder(maxMessageSize, 0, 4, 0, 4));
pipeLine.addLast(new LengthFieldPrepender(4));
pipeLine.addLast(new MatrixTransportClientHandler(client, dispatchMessageQueue, rpcContext));
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.LengthFieldBasedFrameDecoder in project neo4j by neo4j.
the class CatchUpClientChannelPipeline method initChannel.
static void initChannel(SocketChannel ch, CatchUpResponseHandler handler, LogProvider logProvider, Monitors monitors) throws Exception {
CatchupClientProtocol protocol = new CatchupClientProtocol();
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
pipeline.addLast(new LengthFieldPrepender(4));
pipeline.addLast(new VersionDecoder(logProvider));
pipeline.addLast(new VersionPrepender());
pipeline.addLast(new TxPullRequestEncoder());
pipeline.addLast(new GetStoreRequestEncoder());
pipeline.addLast(new CoreSnapshotRequestEncoder());
pipeline.addLast(new GetStoreIdRequestEncoder());
pipeline.addLast(new ResponseMessageTypeEncoder());
pipeline.addLast(new RequestMessageTypeEncoder());
pipeline.addLast(new ClientMessageTypeHandler(protocol, logProvider));
RequestDecoderDispatcher<CatchupClientProtocol.State> decoderDispatcher = new RequestDecoderDispatcher<>(protocol, logProvider);
decoderDispatcher.register(CatchupClientProtocol.State.STORE_ID, new GetStoreIdResponseDecoder());
decoderDispatcher.register(CatchupClientProtocol.State.TX_PULL_RESPONSE, new TxPullResponseDecoder());
decoderDispatcher.register(CatchupClientProtocol.State.CORE_SNAPSHOT, new CoreSnapshotDecoder());
decoderDispatcher.register(CatchupClientProtocol.State.STORE_COPY_FINISHED, new StoreCopyFinishedResponseDecoder());
decoderDispatcher.register(CatchupClientProtocol.State.TX_STREAM_FINISHED, new TxStreamFinishedResponseDecoder());
decoderDispatcher.register(CatchupClientProtocol.State.FILE_HEADER, new FileHeaderDecoder());
decoderDispatcher.register(CatchupClientProtocol.State.FILE_CONTENTS, new FileChunkDecoder());
pipeline.addLast(decoderDispatcher);
pipeline.addLast(new TxPullResponseHandler(protocol, handler));
pipeline.addLast(new CoreSnapshotResponseHandler(protocol, handler));
pipeline.addLast(new StoreCopyFinishedResponseHandler(protocol, handler));
pipeline.addLast(new TxStreamFinishedResponseHandler(protocol, handler));
pipeline.addLast(new FileHeaderHandler(protocol, handler, logProvider));
pipeline.addLast(new FileChunkHandler(protocol, handler));
pipeline.addLast(new GetStoreIdResponseHandler(protocol, handler));
pipeline.addLast(new ExceptionLoggingHandler(logProvider.getLog(CatchUpClient.class)));
pipeline.addLast(new ExceptionMonitoringHandler(monitors.newMonitor(ExceptionMonitoringHandler.Monitor.class, CatchUpClient.class)));
pipeline.addLast(new ExceptionSwallowingHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.LengthFieldBasedFrameDecoder in project neo4j by neo4j.
the class RaftServer method startNettyServer.
private void startNettyServer() {
workerGroup = new NioEventLoopGroup(0, threadFactory);
log.info("Starting server at: " + listenAddress);
ServerBootstrap bootstrap = new ServerBootstrap().group(workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_REUSEADDR, true).localAddress(listenAddress.socketAddress()).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
pipeline.addLast(new LengthFieldPrepender(4));
pipeline.addLast(new VersionDecoder(logProvider));
pipeline.addLast(new VersionPrepender());
pipeline.addLast(new RaftMessageDecoder(marshal));
pipeline.addLast(new RaftMessageHandler());
pipeline.addLast(new ExceptionLoggingHandler(log));
pipeline.addLast(new ExceptionMonitoringHandler(monitors.newMonitor(ExceptionMonitoringHandler.Monitor.class, RaftServer.class)));
pipeline.addLast(new ExceptionSwallowingHandler());
}
});
try {
channel = bootstrap.bind().syncUninterruptibly().channel();
} catch (Exception e) {
//noinspection ConstantConditions
if (e instanceof BindException) {
userLog.error("Address is already bound for setting: " + setting + " with value: " + listenAddress);
log.error("Address is already bound for setting: " + setting + " with value: " + listenAddress, e);
throw e;
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.LengthFieldBasedFrameDecoder in project neo4j by neo4j.
the class CatchupServer method start.
@Override
public synchronized void start() throws Throwable {
if (channel != null) {
return;
}
workerGroup = new NioEventLoopGroup(0, threadFactory);
ServerBootstrap bootstrap = new ServerBootstrap().group(workerGroup).channel(NioServerSocketChannel.class).localAddress(listenAddress.socketAddress()).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) {
CatchupServerProtocol protocol = new CatchupServerProtocol();
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
pipeline.addLast(new LengthFieldPrepender(4));
pipeline.addLast(new VersionDecoder(logProvider));
pipeline.addLast(new VersionPrepender());
pipeline.addLast(new ResponseMessageTypeEncoder());
pipeline.addLast(new RequestMessageTypeEncoder());
pipeline.addLast(new TxPullResponseEncoder());
pipeline.addLast(new CoreSnapshotEncoder());
pipeline.addLast(new GetStoreIdResponseEncoder());
pipeline.addLast(new StoreCopyFinishedResponseEncoder());
pipeline.addLast(new TxStreamFinishedResponseEncoder());
pipeline.addLast(new FileChunkEncoder());
pipeline.addLast(new FileHeaderEncoder());
pipeline.addLast(new ServerMessageTypeHandler(protocol, logProvider));
pipeline.addLast(decoders(protocol));
pipeline.addLast(new TxPullRequestHandler(protocol, storeIdSupplier, dataSourceAvailabilitySupplier, transactionIdStoreSupplier, logicalTransactionStoreSupplier, txPullBatchSize, monitors, logProvider));
pipeline.addLast(new ChunkedWriteHandler());
pipeline.addLast(new GetStoreRequestHandler(protocol, dataSourceSupplier, checkPointerSupplier, fs, pageCache, logProvider, storeCopyCheckPointMutex));
pipeline.addLast(new GetStoreIdRequestHandler(protocol, storeIdSupplier));
if (coreState != null) {
pipeline.addLast(new CoreSnapshotRequestHandler(protocol, coreState));
}
pipeline.addLast(new ExceptionLoggingHandler(log));
pipeline.addLast(new ExceptionMonitoringHandler(monitors.newMonitor(ExceptionMonitoringHandler.Monitor.class, CatchupServer.class)));
pipeline.addLast(new ExceptionSwallowingHandler());
}
});
try {
channel = bootstrap.bind().syncUninterruptibly().channel();
} catch (Exception e) {
//noinspection ConstantConditions
if (e instanceof BindException) {
userLog.error("Address is already bound for setting: " + CausalClusteringSettings.transaction_listen_address + " with value: " + listenAddress);
log.error("Address is already bound for setting: " + CausalClusteringSettings.transaction_listen_address + " with value: " + listenAddress, e);
throw e;
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.LengthFieldBasedFrameDecoder in project pulsar by yahoo.
the class ServerCnxTest method resetChannel.
private void resetChannel() throws Exception {
int MaxMessageSize = 5 * 1024 * 1024;
if (channel != null && channel.isActive()) {
serverCnx.close();
channel.close().get();
}
serverCnx = new ServerCnx(brokerService);
channel = new EmbeddedChannel(new LengthFieldBasedFrameDecoder(MaxMessageSize, 0, 4, 0, 4), serverCnx);
}
Aggregations