List of usage examples for io.netty.channel ChannelHandlerContext channel
Channel channel();
From source file:com.cloudera.livy.client.local.rpc.SaslHandler.java
License:Apache License
@Override protected final void channelRead0(ChannelHandlerContext ctx, Rpc.SaslMessage msg) throws Exception { LOG.debug("Handling SASL challenge message..."); Rpc.SaslMessage response = update(msg); if (response != null) { LOG.debug("Sending SASL challenge response..."); hasAuthResponse = true;/* www . j a v a 2s.c o m*/ ctx.channel().writeAndFlush(response).sync(); } if (!isComplete()) { return; } // If negotiation is complete, remove this handler from the pipeline, and register it with // the Kryo instance to handle encryption if needed. ctx.channel().pipeline().remove(this); String qop = getNegotiatedProperty(Sasl.QOP); LOG.debug("SASL negotiation finished with QOP {}.", qop); if (Rpc.SASL_AUTH_CONF.equals(qop)) { LOG.info("SASL confidentiality enabled."); kryo.setEncryptionHandler(this); } else { if (requiresEncryption) { throw new SaslException("Encryption required, but SASL negotiation did not set it up."); } dispose(); } onComplete(); }
From source file:com.cloudera.livy.rsc.rpc.RpcDispatcher.java
License:Apache License
@Override public final void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("[%s] Caught exception in channel pipeline.", name()), cause); } else {/*from ww w .j a v a2 s. c o m*/ LOG.info("[{}] Closing channel due to exception in pipeline ({}).", name(), cause.getMessage()); } if (lastHeader != null) { // There's an RPC waiting for a reply. Exception was most probably caught while processing // the RPC, so send an error. ctx.channel().write(new Rpc.MessageHeader(lastHeader.id, Rpc.MessageType.ERROR)); ctx.channel().writeAndFlush(Utils.stackTraceAsString(cause)); lastHeader = null; } ctx.close(); }
From source file:com.cloudhopper.smpp.channel.SmppClientConnector.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { // called every time a new channel connects channels.add(ctx.channel()); super.channelActive(ctx); }
From source file:com.cloudhopper.smpp.channel.SmppClientConnector.java
License:Apache License
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { // called every time a channel disconnects channels.remove(ctx.channel()); super.channelInactive(ctx); }
From source file:com.cloudhopper.smpp.channel.SmppServerConnector.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { // the channel we are going to handle Channel channel = ctx.channel(); // always add it to our channel group channels.add(channel);/*from www . jav a 2s.c o m*/ this.server.getCounters().incrementChannelConnectsAndGet(); // create a default "unbound" thread name for the thread processing the channel // this will create a name of "RemoteIPAddress.RemotePort" String channelName = ChannelUtil.createChannelName(channel); String threadName = server.getConfiguration().getName() + ".UnboundSession." + channelName; // rename the current thread for logging, then rename it back String currentThreadName = Thread.currentThread().getName(); Thread.currentThread().setName(server.getConfiguration().getName()); logger.info("New channel from [{}]", channelName); Thread.currentThread().setName(currentThreadName); // add SSL handler if (server.getConfiguration().isUseSsl()) { SslConfiguration sslConfig = server.getConfiguration().getSslConfiguration(); if (sslConfig == null) throw new IllegalStateException("sslConfiguration must be set"); SslContextFactory factory = new SslContextFactory(sslConfig); SSLEngine sslEngine = factory.newSslEngine(); sslEngine.setUseClientMode(false); channel.pipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_SSL_NAME, new SslHandler(sslEngine)); } // add a new instance of a thread renamer channel.pipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_THREAD_RENAMER_NAME, new SmppSessionThreadRenamer(threadName)); // add a new instance of a decoder (that takes care of handling frames) channel.pipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_PDU_DECODER_NAME, new SmppSessionPduDecoder(server.getTranscoder())); // create a new wrapper around an "unbound" session to pass the pdu up the chain UnboundSmppSession session = new UnboundSmppSession(channelName, channel, server); channel.pipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_WRAPPER_NAME, new SmppSessionWrapper(session)); super.channelActive(ctx); }
From source file:com.cloudhopper.smpp.channel.SmppServerConnector.java
License:Apache License
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { // called every time a channel disconnects channels.remove(ctx.channel()); this.server.getCounters().incrementChannelDisconnectsAndGet(); super.channelInactive(ctx); }
From source file:com.cloudhopper.smpp.simulator.SmppSimulatorServerHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, Pdu msg) throws Exception { logger.info("Read message {} from channel {}", msg.toString(), ctx.channel()); //if (msg instanceof Pdu) { // Pdu pdu = (Pdu)msg; // this.listener.firePduReceived(pdu); //}/*w ww. jav a 2 s. c o m*/ }
From source file:com.cloudhopper.smpp.simulator.SmppSimulatorServerHandler.java
License:Apache License
@Override public void channelRegistered(ChannelHandlerContext ctx) throws Exception { logger.info("childChannelRegistered {}", ctx.channel()); // modify its pipeline PduTranscoderContext context = new DefaultPduTranscoderContext(); PduTranscoder transcoder = new DefaultPduTranscoder(context); // create a new "smsc" session instance (which is just a handler) SmppSimulatorSessionHandler session = new SmppSimulatorSessionHandler(ctx.channel(), transcoder); // add this channel's new processing pipeline ctx.channel().pipeline().addLast(SmppSimulatorServer.PIPELINE_SESSION_NAME, session); session.setPduProcessor(defaultPduProcessor); // store this in our internal queue this.sessionChannels.add(ctx.channel()); this.sessionQueue.add(session); }
From source file:com.cloudhopper.smpp.simulator.SmppSimulatorServerHandler.java
License:Apache License
/** * Invoked when a child {@link io.netty.channel.Channel} was closed. * (e.g. the accepted connection was closed) *///from ww w . j a va 2 s .c o m @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { logger.info("childChannelClosed {}", ctx.channel()); super.channelInactive(ctx); }
From source file:com.cloudhopper.smpp.simulator.SmppSimulatorServerHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { logger.info("childChannelOpened {}", ctx.channel()); super.channelActive(ctx); }