mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed format & import
This commit is contained in:
@@ -34,7 +34,10 @@ public class CanalServerWithNetty extends AbstractCanalLifeCycle implements Cana
|
||||
private int port;
|
||||
private Channel serverChannel = null;
|
||||
private ServerBootstrap bootstrap = null;
|
||||
private ChannelGroup childGroups = null; //socket channel container, used to close sockets explicitly.
|
||||
private ChannelGroup childGroups = null; // socket channel
|
||||
// container, used to
|
||||
// close sockets
|
||||
// explicitly.
|
||||
|
||||
private static class SingletonHolder {
|
||||
|
||||
@@ -60,12 +63,10 @@ public class CanalServerWithNetty extends AbstractCanalLifeCycle implements Cana
|
||||
this.bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
|
||||
Executors.newCachedThreadPool()));
|
||||
/*
|
||||
* enable keep-alive mechanism, handle abnormal network connection scenarios on OS level.
|
||||
* the threshold parameters are depended on OS.
|
||||
* e.g. On Linux:
|
||||
* net.ipv4.tcp_keepalive_time = 300
|
||||
* net.ipv4.tcp_keepalive_probes = 2
|
||||
* net.ipv4.tcp_keepalive_intvl = 30
|
||||
* enable keep-alive mechanism, handle abnormal network connection
|
||||
* scenarios on OS level. the threshold parameters are depended on OS.
|
||||
* e.g. On Linux: net.ipv4.tcp_keepalive_time = 300
|
||||
* net.ipv4.tcp_keepalive_probes = 2 net.ipv4.tcp_keepalive_intvl = 30
|
||||
*/
|
||||
bootstrap.setOption("child.keepAlive", true);
|
||||
/*
|
||||
@@ -79,8 +80,9 @@ public class CanalServerWithNetty extends AbstractCanalLifeCycle implements Cana
|
||||
public ChannelPipeline getPipeline() throws Exception {
|
||||
ChannelPipeline pipelines = Channels.pipeline();
|
||||
pipelines.addLast(FixedHeaderFrameDecoder.class.getName(), new FixedHeaderFrameDecoder());
|
||||
//support to maintain child socket channel.
|
||||
pipelines.addLast(HandshakeInitializationHandler.class.getName(), new HandshakeInitializationHandler(childGroups));
|
||||
// support to maintain child socket channel.
|
||||
pipelines.addLast(HandshakeInitializationHandler.class.getName(),
|
||||
new HandshakeInitializationHandler(childGroups));
|
||||
pipelines.addLast(ClientAuthenticationHandler.class.getName(),
|
||||
new ClientAuthenticationHandler(embeddedServer));
|
||||
|
||||
@@ -105,9 +107,10 @@ public class CanalServerWithNetty extends AbstractCanalLifeCycle implements Cana
|
||||
this.serverChannel.close().awaitUninterruptibly(1000);
|
||||
}
|
||||
|
||||
//close sockets explicitly to reduce socket channel hung in complicated network environment.
|
||||
// close sockets explicitly to reduce socket channel hung in complicated
|
||||
// network environment.
|
||||
if (this.childGroups != null) {
|
||||
this.childGroups.close().awaitUninterruptibly(5000);
|
||||
this.childGroups.close().awaitUninterruptibly(5000);
|
||||
}
|
||||
|
||||
if (this.bootstrap != null) {
|
||||
|
||||
@@ -89,11 +89,13 @@ public class ClientAuthenticationHandler extends SimpleChannelHandler {
|
||||
if (clientAuth.getNetWriteTimeout() > 0) {
|
||||
writeTimeout = clientAuth.getNetWriteTimeout();
|
||||
}
|
||||
//fix bug: soTimeout parameter's unit from connector is millseconds.
|
||||
// fix bug: soTimeout parameter's unit from connector is
|
||||
// millseconds.
|
||||
IdleStateHandler idleStateHandler = new IdleStateHandler(NettyUtils.hashedWheelTimer,
|
||||
readTimeout,
|
||||
writeTimeout,
|
||||
0, TimeUnit.MILLISECONDS);
|
||||
0,
|
||||
TimeUnit.MILLISECONDS);
|
||||
ctx.getPipeline().addBefore(SessionHandler.class.getName(),
|
||||
IdleStateHandler.class.getName(),
|
||||
idleStateHandler);
|
||||
|
||||
@@ -19,20 +19,21 @@ import com.alibaba.otter.canal.server.netty.NettyUtils;
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class HandshakeInitializationHandler extends SimpleChannelHandler {
|
||||
//support to maintain socket channel.
|
||||
private ChannelGroup childGroups;
|
||||
|
||||
public HandshakeInitializationHandler(ChannelGroup childGroups) {
|
||||
this.childGroups = childGroups;
|
||||
}
|
||||
// support to maintain socket channel.
|
||||
private ChannelGroup childGroups;
|
||||
|
||||
public HandshakeInitializationHandler(ChannelGroup childGroups){
|
||||
this.childGroups = childGroups;
|
||||
}
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(HandshakeInitializationHandler.class);
|
||||
|
||||
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
//add new socket channel in channel container, used to manage sockets.
|
||||
if(childGroups != null) {
|
||||
childGroups.add(ctx.getChannel());
|
||||
}
|
||||
// add new socket channel in channel container, used to manage sockets.
|
||||
if (childGroups != null) {
|
||||
childGroups.add(ctx.getChannel());
|
||||
}
|
||||
|
||||
byte[] body = Packet.newBuilder()
|
||||
.setType(CanalPacket.PacketType.HANDSHAKE)
|
||||
|
||||
Reference in New Issue
Block a user