List of usage examples for io.netty.channel ChannelHandlerContext channel
Channel channel();
From source file:com.ebay.jetstream.messaging.transport.netty.eventconsumer.EventProducerSessionHandler.java
License:MIT License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { printInfo("Rcvr Session created to host - " + ((InetSocketAddress) ctx.channel().remoteAddress()).getHostName()); printInfo("Rcvr Session config -" + ctx.channel().config().getOptions()); m_eventConsumer.registerChannel(ctx.channel()); super.channelActive(ctx); }
From source file:com.ebay.jetstream.messaging.transport.netty.eventconsumer.EventProducerSessionHandler.java
License:MIT License
/** * Calls {@link ChannelHandlerContext#fireChannelInactive()} to forward * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}. * * Sub-classes may override this method to change behavior. *//*from w ww.j a v a 2s. c om*/ @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { printInfo("EventProducerSessionHandler -> session closed to host - " + ((InetSocketAddress) ctx.channel().remoteAddress()).getHostName()); m_eventConsumer.unregisterChannel(ctx.channel()); super.channelInactive(ctx); }
From source file:com.ebay.jetstream.messaging.transport.netty.eventconsumer.EventProducerSessionHandler.java
License:MIT License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { LOGGER.error(cause.getLocalizedMessage(), cause); m_eventConsumer.unregisterChannel(ctx.channel()); if (ctx.channel().isActive()) ctx.channel().close();/*from www. j av a 2 s.c o m*/ }
From source file:com.ebay.jetstream.messaging.transport.netty.eventproducer.EventConsumerSessionHandler.java
License:MIT License
/** * Calls {@link ChannelHandlerContext#disconnect(ChannelPromise)} to forward * to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}. * * Sub-classes may override this method to change behavior. *///from w w w .j av a 2 s . c om @Override public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { LOGGER.error("Session closed to host - " + ctx.channel().remoteAddress()); m_ep.removeSession(ctx); super.disconnect(ctx, promise); }
From source file:com.ebay.jetstream.messaging.transport.netty.eventproducer.EventConsumerSessionHandler.java
License:MIT License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { printInfo("Send Session created to host - " + ((InetSocketAddress) ctx.channel().remoteAddress()).getHostName()); printInfo("Send Session config -" + ctx.channel().config().getOptions()); super.channelActive(ctx); }
From source file:com.ebay.jetstream.messaging.transport.netty.eventproducer.EventConsumerSessionHandler.java
License:MIT License
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { String message = "Channel Inactive "; message += " - "; message += ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress(); if (ctx.channel().isActive()) ctx.channel().close();/*from w w w . ja va2 s . c o m*/ LOGGER.warn(message); m_ep.removeSession(ctx); ctx.fireChannelInactive(); }
From source file:com.ebay.jetstream.messaging.transport.netty.eventproducer.EventConsumerSessionHandler.java
License:MIT License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { LOGGER.error(cause.getLocalizedMessage(), cause); m_ep.removeSession(ctx);/* ww w. j a v a 2s .co m*/ if (ctx.channel().isActive()) ctx.channel().close(); }
From source file:com.ebay.jetstream.messaging.transport.netty.eventproducer.EventProducer.java
License:MIT License
/** * @param ctx//from w w w . j a v a2 s . co m */ public void removeSession(ChannelHandlerContext ctx) { String host; int port; if (ctx == null) return; try { /* Remove for netty 4.0 as host port does not come back when channel gets disconnected - in fact no notification arrives that I know of. I am * tapping in to the future to tell me is channel is disconnected. For this host and port need to stored in channel context. */ host = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress(); port = ((InetSocketAddress) ctx.channel().remoteAddress()).getPort(); } catch (Throwable t) { return; } if (host == null) return; printInfo("removeSession to host : " + host); String hostAndPort = host + "-" + Integer.toString(port);// this is so // that we // can // lookup in // the // register // using // "host-port" // - SRM Sep // 1,2012 EventConsumerInfo info = m_eventConsumerRegistry.get(hostAndPort); if (info == null) { return; } // Lets close all open connections to this consumer Map<Channel, ConsumerChannelContext> channelMap = info.getConsumerChannelContexts(); Set<Channel> openchannels = channelMap.keySet(); for (Channel channel : openchannels) { channel.close(); info.markChannelAsDisconnected(channel); } m_deadConsumerQueue.offer(info); }
From source file:com.ebay.jetstream.messaging.transport.netty.eventproducer.EventProducer.java
License:MIT License
public EventConsumerInfo findEventConsumer(ChannelHandlerContext ctx) { String host;/*from ww w . j a v a2 s .c o m*/ int port; if (ctx == null) return null; try { /* Remove for netty 4.0 as host port does not come back when channel gets disconnected - in fact no notification arrives that I know of. I am * tapping in to the future to tell me is channel is disconnected. For this host and port need to stored in channel context. */ host = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress(); port = ((InetSocketAddress) ctx.channel().remoteAddress()).getPort(); } catch (Throwable t) { return null; } if (host == null) return null; printInfo("removeSession to host : " + host); String hostAndPort = host + "-" + Integer.toString(port);// this is so // that we // can // lookup in // the // register // using // "host-port" // - SRM Sep // 1,2012 EventConsumerInfo info = m_eventConsumerRegistry.get(hostAndPort); return info; }
From source file:com.ebay.jetstream.messaging.transport.netty.serializer.KryoObjectEncoder.java
License:MIT License
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { Attribute<Boolean> attr = ctx.channel().attr(EventProducer.m_kskey); Boolean enableKryo = attr.get(); if ((enableKryo != null) && (enableKryo == true)) super.write(ctx, msg, promise); else/*from w w w. j a v a 2 s . c o m*/ ctx.write(msg, promise); }