use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project x-pipe by ctripcorp.
the class DefaultRedisKeeperServer method startServer.
protected void startServer() throws InterruptedException {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new LoggingHandler(LogLevel.DEBUG));
p.addLast(new NettySimpleMessageHandler());
p.addLast(new NettyMasterHandler(DefaultRedisKeeperServer.this, new CommandHandlerManager(), keeperConfig.getTrafficReportIntervalMillis()));
}
});
serverSocketChannel = (ServerSocketChannel) b.bind(currentKeeperMeta.getPort()).sync().channel();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project aerospike-client-java by aerospike.
the class NettyCommand method executeCommand.
private void executeCommand(long deadline, int tstate) {
state = AsyncCommand.CHANNEL_INIT;
iteration++;
try {
node = command.getNode(cluster);
node.validateErrorCount();
conn = (NettyConnection) node.getAsyncConnection(eventState.index, null);
if (conn != null) {
setTimeoutTask(deadline, tstate);
InboundHandler handler = (InboundHandler) conn.channel.pipeline().last();
handler.setCommand(this);
writeCommand();
return;
}
connectInProgress = true;
if (command.policy.connectTimeout > 0) {
timeoutState = new TimeoutState(deadline, tstate);
deadline = timeoutState.start + TimeUnit.MILLISECONDS.toNanos(command.policy.connectTimeout);
timeoutTask.cancel();
eventLoop.timer.addTimeout(timeoutTask, deadline);
} else {
setTimeoutTask(deadline, tstate);
}
final InboundHandler handler = new InboundHandler(this);
Bootstrap b = new Bootstrap();
initBootstrap(b, cluster, eventLoop);
b.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) {
if (state != AsyncCommand.CHANNEL_INIT) {
// Timeout occurred. Close channel.
try {
ch.close();
} catch (Throwable e) {
}
connectInProgress = false;
return;
}
state = AsyncCommand.CONNECT;
conn = new NettyConnection(ch);
node.connectionOpened(eventLoop.index);
connectInProgress = false;
ChannelPipeline p = ch.pipeline();
if (cluster.tlsPolicy != null && !cluster.tlsPolicy.forLoginOnly) {
state = AsyncCommand.TLS_HANDSHAKE;
cluster.nettyTlsContext.addHandler(ch, p);
}
p.addLast(handler);
}
});
b.connect(node.getAddress());
eventState.errors = 0;
} catch (AerospikeException.Connection ac) {
eventState.errors++;
onNetworkError(ac);
} catch (AerospikeException.Backoff ab) {
eventState.errors++;
onBackoffError(ab);
} catch (AerospikeException ae) {
// Fail without retry on non-connection errors.
eventState.errors++;
onFatalError(ae);
} catch (Throwable e) {
// Fail without retry on unknown errors.
eventState.errors++;
onFatalError(new AerospikeException(e));
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project aerospike-client-java by aerospike.
the class NettyConnector method finish.
private final void finish() {
try {
// Assign normal InboundHandler to connection.
SocketChannel channel = conn.channel;
channel.config().setAutoRead(false);
ChannelPipeline p = channel.pipeline();
p.removeLast();
if (cluster.keepAlive == null) {
p.addLast(new NettyCommand.InboundHandler());
} else {
AsyncPool pool = node.getAsyncPool(eventState.index);
p.addLast(new NettyCommand.InboundHandler(pool));
}
conn.updateLastUsed();
success();
} catch (Throwable e) {
Log.error("NettyConnector fatal error: " + Util.getStackTrace(e));
throw e;
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project aerospike-client-java by aerospike.
the class NettyRecover method recover.
private final void recover() {
// System.out.println("" + tranId + " connection drained");
if (state == AsyncCommand.COMPLETE) {
return;
}
state = AsyncCommand.COMPLETE;
try {
// Assign normal InboundHandler to connection.
SocketChannel channel = conn.channel;
channel.config().setAutoRead(false);
ChannelPipeline p = channel.pipeline();
p.removeLast();
if (cluster.keepAlive == null) {
p.addLast(new NettyCommand.InboundHandler());
} else {
AsyncPool pool = node.getAsyncPool(eventState.index);
p.addLast(new NettyCommand.InboundHandler(pool));
}
// Put connection into pool.
conn.updateLastUsed();
node.putAsyncConnection(conn, eventLoop.index);
// Close recovery command.
close(true);
} catch (Throwable e) {
if (!eventState.closed) {
Log.error("NettyRecover recover failed: " + Util.getStackTrace(e));
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project rocketmq-externals by apache.
the class MQTTBridge method init.
private void init() {
bossGroup = new NioEventLoopGroup(MQTTBridgeConfiguration.threadNumOfBossGroup());
workerGroup = new NioEventLoopGroup(MQTTBridgeConfiguration.threadNumOfWorkerGroup());
serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup).localAddress(MQTTBridgeConfiguration.port()).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, MQTTBridgeConfiguration.socketBacklog()).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("mqtt-decoder", new MqttDecoder());
pipeline.addLast("mqtt-encoder", MqttEncoder.INSTANCE);
pipeline.addLast("channel-idle-handler", new MqttIdleHandler());
pipeline.addLast("message-dispatcher", messageDispatcher);
pipeline.addLast("connection-manager", connectionHandler);
}
});
subscriptionStore = new InMemorySubscriptionStore();
clientManager = new ClientManagerImpl();
messageDispatcher = new MessageDispatcher(clientManager);
connectionHandler = new MqttConnectionHandler(clientManager, subscriptionStore);
registerMessageHandlers();
}
Aggregations