List of usage examples for io.netty.channel ChannelHandlerContext channel
Channel channel();
From source file:be.yildizgames.module.network.netty.server.SessionMessageHandler.java
License:MIT License
@Override public void channelActive(final ChannelHandlerContext ctx) { this.setSession(NettySessionFactory.createAnonymousText(ctx.channel())); }
From source file:be.yildizgames.module.network.netty.server.SessionWebSocketMessageHandler.java
License:MIT License
@Override public void channelActive(final ChannelHandlerContext ctx) throws Exception { this.setSession(NettySessionFactory.createAnonymousWebSocket(ctx.channel())); }
From source file:bean.lee.demo.netty.learn.http.file.HttpStaticFileServerHandler.java
License:Apache License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { cause.printStackTrace();/*from www . j a va2 s.c om*/ if (ctx.channel().isActive()) { sendError(ctx, INTERNAL_SERVER_ERROR); } }
From source file:bftsmart.communication.client.netty.NettyClientServerCommunicationSystemClientSide.java
License:Apache License
@Override public void channelRead0(ChannelHandlerContext ctx, TOMMessage sm) throws Exception { logger.debug("channelRead0(ChannelHandlerContext ctx, TOMMessage sm)."); if (closed) { closeChannelAndEventLoop(ctx.channel()); return;// ww w . j a v a 2 s .c om } trr.replyReceived(sm); }
From source file:bftsmart.communication.client.netty.NettyClientServerCommunicationSystemClientSide.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { if (closed) { closeChannelAndEventLoop(ctx.channel()); return;/* w ww . j av a 2 s .c o m*/ } logger.debug("Channel active"); }
From source file:bftsmart.communication.client.netty.NettyClientServerCommunicationSystemClientSide.java
License:Apache License
public void reconnect(final ChannelHandlerContext ctx) { rl.writeLock().lock();/*from ww w. j ava 2s .c o m*/ ArrayList<NettyClientServerSession> sessions = new ArrayList<NettyClientServerSession>( sessionClientToReplica.values()); for (NettyClientServerSession ncss : sessions) { if (ncss.getChannel() == ctx.channel()) { int replicaId = ncss.getReplicaId(); try { if (controller.getRemoteAddress(replicaId) != null) { ChannelFuture future; try { future = connectToReplica(replicaId, secretKeyFactory); } catch (InvalidKeyException | InvalidKeySpecException e) { // TODO Auto-generated catch block logger.error("Error in key.", e); } logger.info("ClientID {}, re-connection to replica {}, at address: {}", clientId, replicaId, controller.getRemoteAddress(replicaId)); } else { // This cleans an old server from the session table removeClient(replicaId); } } catch (NoSuchAlgorithmException ex) { logger.error("Failed to reconnect to replica", ex); } } } rl.writeLock().unlock(); }
From source file:bftsmart.communication.client.netty.NettyClientServerCommunicationSystemClientSide.java
License:Apache License
private void scheduleReconnect(final ChannelHandlerContext ctx, int time) { if (closed) { closeChannelAndEventLoop(ctx.channel()); return;//from w ww. j ava2s.c o m } final EventLoop loop = ctx.channel().eventLoop(); loop.schedule(new Runnable() { @Override public void run() { reconnect(ctx); } }, time, TimeUnit.SECONDS); }
From source file:bftsmart.communication.client.netty.NettyClientServerCommunicationSystemServerSide.java
License:Apache License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (this.closed) { closeChannelAndEventLoop(ctx.channel()); return;/* w w w . j a va2 s . com*/ } if (cause instanceof ClosedChannelException) logger.info("Client connection closed."); else if (cause instanceof IOException) { logger.error("Impossible to connect to client. (Connection reset by peer)"); } else { logger.error("Connection problem. Cause:{}", cause); } }
From source file:bftsmart.communication.client.netty.NettyClientServerCommunicationSystemServerSide.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, TOMMessage sm) throws Exception { if (this.closed) { closeChannelAndEventLoop(ctx.channel()); return;/*from ww w . ja v a 2 s .co m*/ } // delivers message to TOMLayer if (requestReceiver == null) logger.warn("Request receiver is still null!"); else requestReceiver.requestReceived(sm); }
From source file:bftsmart.communication.client.netty.NettyClientServerCommunicationSystemServerSide.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { if (this.closed) { closeChannelAndEventLoop(ctx.channel()); return;//from ww w . j a v a 2 s . c o m } logger.info("Session Created, active clients=" + sessionReplicaToClient.size()); }