use of org.jboss.netty.handler.timeout.IdleStateHandler in project hadoop by apache.
the class Portmap method start.
void start(final int idleTimeMilliSeconds, final SocketAddress tcpAddress, final SocketAddress udpAddress) {
tcpServer = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
tcpServer.setPipelineFactory(new ChannelPipelineFactory() {
private final HashedWheelTimer timer = new HashedWheelTimer();
private final IdleStateHandler idleStateHandler = new IdleStateHandler(timer, 0, 0, idleTimeMilliSeconds, TimeUnit.MILLISECONDS);
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(RpcUtil.constructRpcFrameDecoder(), RpcUtil.STAGE_RPC_MESSAGE_PARSER, idleStateHandler, handler, RpcUtil.STAGE_RPC_TCP_RESPONSE);
}
});
tcpServer.setOption("reuseAddress", true);
tcpServer.setOption("child.reuseAddress", true);
udpServer = new ConnectionlessBootstrap(new NioDatagramChannelFactory(Executors.newCachedThreadPool()));
udpServer.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, handler, RpcUtil.STAGE_RPC_UDP_RESPONSE));
udpServer.setOption("reuseAddress", true);
tcpChannel = tcpServer.bind(tcpAddress);
udpChannel = udpServer.bind(udpAddress);
allChannels.add(tcpChannel);
allChannels.add(udpChannel);
LOG.info("Portmap server started at tcp://" + tcpChannel.getLocalAddress() + ", udp://" + udpChannel.getLocalAddress());
}
use of org.jboss.netty.handler.timeout.IdleStateHandler in project canal by alibaba.
the class ClientAuthenticationHandler method messageReceived.
public void messageReceived(final ChannelHandlerContext ctx, MessageEvent e) throws Exception {
ChannelBuffer buffer = (ChannelBuffer) e.getMessage();
final Packet packet = Packet.parseFrom(buffer.readBytes(buffer.readableBytes()).array());
switch(packet.getVersion()) {
case SUPPORTED_VERSION:
default:
final ClientAuth clientAuth = ClientAuth.parseFrom(packet.getBody());
if (seed == null) {
byte[] errorBytes = AdminNettyUtils.errorPacket(300, MessageFormatter.format("auth failed for seed is null", clientAuth.getUsername()).getMessage());
AdminNettyUtils.write(ctx.getChannel(), errorBytes);
}
if (!canalAdmin.auth(clientAuth.getUsername(), clientAuth.getPassword().toStringUtf8(), seed)) {
byte[] errorBytes = AdminNettyUtils.errorPacket(300, MessageFormatter.format("auth failed for user:{}", clientAuth.getUsername()).getMessage());
AdminNettyUtils.write(ctx.getChannel(), errorBytes);
}
byte[] ackBytes = AdminNettyUtils.ackPacket();
AdminNettyUtils.write(ctx.getChannel(), ackBytes, future -> {
logger.info("remove unused channel handlers after authentication is done successfully.");
ctx.getPipeline().remove(HandshakeInitializationHandler.class.getName());
ctx.getPipeline().remove(ClientAuthenticationHandler.class.getName());
int readTimeout = defaultSubscriptorDisconnectIdleTimeout;
int writeTimeout = defaultSubscriptorDisconnectIdleTimeout;
if (clientAuth.getNetReadTimeout() > 0) {
readTimeout = clientAuth.getNetReadTimeout();
}
if (clientAuth.getNetWriteTimeout() > 0) {
writeTimeout = clientAuth.getNetWriteTimeout();
}
// fix bug: soTimeout parameter's unit from connector is
// millseconds.
IdleStateHandler idleStateHandler = new IdleStateHandler(NettyUtils.hashedWheelTimer, readTimeout, writeTimeout, 0, TimeUnit.MILLISECONDS);
ctx.getPipeline().addBefore(SessionHandler.class.getName(), IdleStateHandler.class.getName(), idleStateHandler);
IdleStateAwareChannelHandler idleStateAwareChannelHandler = new IdleStateAwareChannelHandler() {
public void channelIdle(ChannelHandlerContext ctx1, IdleStateEvent e1) throws Exception {
logger.warn("channel:{} idle timeout exceeds, close channel to save server resources...", ctx1.getChannel());
ctx1.getChannel().close();
}
};
ctx.getPipeline().addBefore(SessionHandler.class.getName(), IdleStateAwareChannelHandler.class.getName(), idleStateAwareChannelHandler);
});
break;
}
}
use of org.jboss.netty.handler.timeout.IdleStateHandler in project traccar by tananaev.
the class BasePipelineFactory method getPipeline.
@Override
public ChannelPipeline getPipeline() {
ChannelPipeline pipeline = Channels.pipeline();
if (timeout > 0 && !server.isConnectionless()) {
pipeline.addLast("idleHandler", new IdleStateHandler(GlobalTimer.getTimer(), timeout, 0, 0));
}
pipeline.addLast("openHandler", new OpenChannelHandler(server));
if (Context.isLoggerEnabled()) {
pipeline.addLast("logger", new StandardLoggingHandler());
}
addSpecificHandlers(pipeline);
if (geolocationHandler != null) {
pipeline.addLast("location", geolocationHandler);
}
if (hemisphereHandler != null) {
pipeline.addLast("hemisphere", hemisphereHandler);
}
if (distanceHandler != null) {
pipeline.addLast("distance", distanceHandler);
}
if (remoteAddressHandler != null) {
pipeline.addLast("remoteAddress", remoteAddressHandler);
}
addDynamicHandlers(pipeline);
if (filterHandler != null) {
pipeline.addLast("filter", filterHandler);
}
if (geocoderHandler != null) {
pipeline.addLast("geocoder", geocoderHandler);
}
if (motionHandler != null) {
pipeline.addLast("motion", motionHandler);
}
if (copyAttributesHandler != null) {
pipeline.addLast("copyAttributes", copyAttributesHandler);
}
if (computedAttributesHandler != null) {
pipeline.addLast("computedAttributes", computedAttributesHandler);
}
if (Context.getDataManager() != null) {
pipeline.addLast("dataHandler", new DefaultDataHandler());
}
if (Context.getConfig().getBoolean("forward.enable")) {
pipeline.addLast("webHandler", new WebDataHandler(Context.getConfig().getString("forward.url"), Context.getConfig().getBoolean("forward.json")));
}
if (commandResultEventHandler != null) {
pipeline.addLast("CommandResultEventHandler", commandResultEventHandler);
}
if (overspeedEventHandler != null) {
pipeline.addLast("OverspeedEventHandler", overspeedEventHandler);
}
if (fuelDropEventHandler != null) {
pipeline.addLast("FuelDropEventHandler", fuelDropEventHandler);
}
if (motionEventHandler != null) {
pipeline.addLast("MotionEventHandler", motionEventHandler);
}
if (geofenceEventHandler != null) {
pipeline.addLast("GeofenceEventHandler", geofenceEventHandler);
}
if (alertEventHandler != null) {
pipeline.addLast("AlertEventHandler", alertEventHandler);
}
if (ignitionEventHandler != null) {
pipeline.addLast("IgnitionEventHandler", ignitionEventHandler);
}
if (maintenanceEventHandler != null) {
pipeline.addLast("MaintenanceEventHandler", maintenanceEventHandler);
}
if (driverEventHandler != null) {
pipeline.addLast("DriverEventHandler", driverEventHandler);
}
pipeline.addLast("mainHandler", new MainEventHandler());
return pipeline;
}
use of org.jboss.netty.handler.timeout.IdleStateHandler in project cdap by caskdata.
the class ClientChannelPipelineFactory method getPipeline.
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("tracker", connectionTracker);
pipeline.addLast("request-encoder", new HttpRequestEncoder());
// outbound handler gets dynamically added here (after 'request-encoder')
pipeline.addLast("response-decoder", new HttpResponseDecoder());
// disable the read-specific and write-specific timeouts; we only utilize IdleState#ALL_IDLE
pipeline.addLast("idle-event-generator", new IdleStateHandler(timer, 0, 0, connectionTimeout));
pipeline.addLast("idle-event-processor", new IdleEventProcessor());
return pipeline;
}
use of org.jboss.netty.handler.timeout.IdleStateHandler in project traccar by traccar.
the class BasePipelineFactory method getPipeline.
@Override
public ChannelPipeline getPipeline() {
ChannelPipeline pipeline = Channels.pipeline();
if (timeout > 0 && !server.isConnectionless()) {
pipeline.addLast("idleHandler", new IdleStateHandler(GlobalTimer.getTimer(), timeout, 0, 0));
}
pipeline.addLast("openHandler", new OpenChannelHandler(server));
if (Context.isLoggerEnabled()) {
pipeline.addLast("logger", new StandardLoggingHandler());
}
addSpecificHandlers(pipeline);
if (geolocationHandler != null) {
pipeline.addLast("location", geolocationHandler);
}
if (hemisphereHandler != null) {
pipeline.addLast("hemisphere", hemisphereHandler);
}
if (distanceHandler != null) {
pipeline.addLast("distance", distanceHandler);
}
if (remoteAddressHandler != null) {
pipeline.addLast("remoteAddress", remoteAddressHandler);
}
addDynamicHandlers(pipeline);
if (filterHandler != null) {
pipeline.addLast("filter", filterHandler);
}
if (geocoderHandler != null) {
pipeline.addLast("geocoder", geocoderHandler);
}
if (motionHandler != null) {
pipeline.addLast("motion", motionHandler);
}
if (copyAttributesHandler != null) {
pipeline.addLast("copyAttributes", copyAttributesHandler);
}
if (computedAttributesHandler != null) {
pipeline.addLast("computedAttributes", computedAttributesHandler);
}
if (Context.getDataManager() != null) {
pipeline.addLast("dataHandler", new DefaultDataHandler());
}
if (Context.getConfig().getBoolean("forward.enable")) {
pipeline.addLast("webHandler", new WebDataHandler(Context.getConfig().getString("forward.url"), Context.getConfig().getBoolean("forward.json")));
}
if (commandResultEventHandler != null) {
pipeline.addLast("CommandResultEventHandler", commandResultEventHandler);
}
if (overspeedEventHandler != null) {
pipeline.addLast("OverspeedEventHandler", overspeedEventHandler);
}
if (fuelDropEventHandler != null) {
pipeline.addLast("FuelDropEventHandler", fuelDropEventHandler);
}
if (motionEventHandler != null) {
pipeline.addLast("MotionEventHandler", motionEventHandler);
}
if (geofenceEventHandler != null) {
pipeline.addLast("GeofenceEventHandler", geofenceEventHandler);
}
if (alertEventHandler != null) {
pipeline.addLast("AlertEventHandler", alertEventHandler);
}
if (ignitionEventHandler != null) {
pipeline.addLast("IgnitionEventHandler", ignitionEventHandler);
}
if (maintenanceEventHandler != null) {
pipeline.addLast("MaintenanceEventHandler", maintenanceEventHandler);
}
if (driverEventHandler != null) {
pipeline.addLast("DriverEventHandler", driverEventHandler);
}
pipeline.addLast("mainHandler", new MainEventHandler());
return pipeline;
}
Aggregations