List of usage examples for io.netty.channel ChannelHandlerContext name
String name();
From source file:sailfish.remoting.handler.NegotiateChannelHandler.java
License:Apache License
private void negotiateIdle(ChannelHandlerContext ctx, byte idleTimeout, byte maxIdleTimeout) { byte serverSideIdleTimeout = ctx.channel().attr(OneTime.idleTimeout).get(); byte serverSideMaxIdleTimeout = ctx.channel().attr(ChannelAttrKeys.maxIdleTimeout).get(); if (idleTimeout != serverSideIdleTimeout) { ChannelHandlerContext idleHandlerContext = ctx.pipeline().context(IdleStateHandler.class); ctx.pipeline().replace(IdleStateHandler.class, idleHandlerContext.name(), new IdleStateHandler(idleTimeout, 0, 0)); }//from ww w .j a va 2s .c o m if (maxIdleTimeout != serverSideMaxIdleTimeout) { ctx.channel().attr(ChannelAttrKeys.maxIdleTimeout).set(maxIdleTimeout); } }
From source file:sg.atom.managex.api.net.telnet.TelnetServerHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { users.put(ctx.name(), new TelnetUser(ctx.name(), new DateTime())); // Send greeting for a new connection. ctx.write("Welcome to " + InetAddress.getLocalHost().getHostName() + "!\r\n"); ctx.write("It is " + new Date() + " now.\r\n"); ctx.write("There are " + users.values().size() + " here!\r\n"); for (TelnetUser user : users.values()) { ctx.write(user.name + " .\r\n"); }// w w w. j av a2s.co m ctx.flush(); }
From source file:sg.atom.managex.api.net.telnet.TelnetServerHandler.java
License:Apache License
@Override public void messageReceived(ChannelHandlerContext ctx, String request) throws Exception { // Generate and write a response. String response;/*from www . jav a 2 s.c o m*/ boolean close = false; if (request.isEmpty()) { response = "Please type something.\r\n"; } else if ("bye".equals(request.toLowerCase())) { response = "Have a good day!\r\n"; close = true; } else { TelnetUser thisUser = users.get(ctx.name()); DateTime thisTime = new DateTime(); addMessage(request, thisUser, thisTime); //response = "Did you say '" + request + "'?\r\n"; response = getMessages(thisUser.lastActive, thisTime); thisUser.lastActive = thisTime; } // We do not need to write a ChannelBuffer here. // We know the encoder inserted at TelnetPipelineFactory will do the conversion. ChannelFuture future = ctx.write(response); // Close the connection after sending 'Have a good day!' // if the client has sent 'bye'. if (close) { future.addListener(ChannelFutureListener.CLOSE); } }
From source file:ws.wamp.jawampa.transport.netty.WampClientWebsocketHandler.java
License:Apache License
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) { // Handshake is completed String actualProtocol = handshaker.actualSubprotocol(); serialization = WampSerialization.fromString(actualProtocol); if (serialization == WampSerialization.Invalid) { throw new WampError("Invalid Websocket Protocol"); }/*from w w w . ja v a 2s .c o m*/ // Install the serializer and deserializer ctx.pipeline().addAfter(ctx.name(), "wamp-deserializer", new WampDeserializationHandler(serialization)); ctx.pipeline().addAfter(ctx.name(), "wamp-serializer", new WampSerializationHandler(serialization)); // Fire the connection established event ctx.fireUserEventTriggered(new ConnectionEstablishedEvent(serialization)); } else { ctx.fireUserEventTriggered(evt); } }
From source file:ws.wamp.jawampa.transport.WampClientWebsocketHandler.java
License:Apache License
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) { // Handshake is completed String actualProtocol = handshaker.actualSubprotocol(); if (actualProtocol.equals("wamp.2.json")) { serialization = Serialization.Json; }//from w w w .ja v a2s.c om // else if (actualProtocol.equals("wamp.2.msgpack")) { // serialization = Serialization.MessagePack; // } else { // We don't want that protocol throw new WampError("Invalid Websocket Protocol"); } // Install the serializer and deserializer ctx.pipeline().addAfter(ctx.name(), "wamp-deserializer", new WampDeserializationHandler(serialization, objectMapper)); ctx.pipeline().addAfter(ctx.name(), "wamp-serializer", new WampSerializationHandler(serialization, objectMapper)); // Fire the connection established event ctx.fireUserEventTriggered(WampChannelEvents.WEBSOCKET_CONN_ESTABLISHED); } else { ctx.fireUserEventTriggered(evt); } }