@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { final ChannelBuffer message = (ChannelBuffer) e.getMessage(); final int size = message.readableBytes(); final byte[] array = new byte[size]; message.readBytes(array); this.nodeName = new String(array, Charsets.UTF_8); LOG.info("Channel {} is node {}.", ctx.getChannel(), nodeName); this.node = cluster.getNodeInfoByName(nodeName); if (node == null) { LOG.error("Node info for {} not found!", ctx.getChannel(), nodeName); throw new RuntimeException("No node info for channel"); } final SocketAddress address = ctx.getChannel().getRemoteAddress(); final InetAddress host = ((InetSocketAddress) address).getAddress(); if (!host.equals((InetAddress) node.get(IpConstants.IP_ADDRESS))) { LOG.error("Channel coming from {} claims to be node {} - host address mismatch!", address, node); throw new RuntimeException("Node identity problem!"); } LOG.info("Channel {} is {}.", ctx.getChannel(), node); ChannelNodeInfo.nodeInfo.set(ctx.getChannel(), node); assert connectEvent != null; ctx.sendUpstream(connectEvent); ctx.getPipeline().remove(this); }
@Override public void channelBound(final ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { try (Closeable closeable = IMAPMDCContext.from(ctx, attributes)) { ImapSession imapsession = new NettyImapSession(ctx.getChannel(), context, enabledCipherSuites, compress, plainAuthDisallowed); attributes.set(ctx.getChannel(), imapsession); super.channelBound(ctx, e); } }
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { try (Closeable closeable = ManageSieveMDCContext.from(ctx, attributes)) { InetSocketAddress address = (InetSocketAddress) ctx.getChannel().getRemoteAddress(); logger.info("Connection established from {}", address.getAddress().getHostAddress()); Session session = new SettableSession(); if (sslServer) { session.setSslEnabled(true); } attributes.set(ctx.getChannel(), session); ctx.setAttachment(new ChannelManageSieveResponseWriter(ctx.getChannel())); super.channelBound(ctx, e); ((ChannelManageSieveResponseWriter) ctx.getAttachment()).write(manageSieveProcessor.getAdvertisedCapabilities()); } }
@Override public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { OdetteFtpSession session = new OdetteFtpSession(entityType); ChannelContext.SESSION.set(e.getChannel(), session); ChannelCallbackHandler channelWriter = new ChannelCallbackHandler(e.getChannel()); session.setChannelCallback(channelWriter); /* create new instance of the Oftplet implementation */ Oftplet oftplet = getOftpletFactory().createProvider(); setSessionOftplet(session, oftplet); /* let the Oftplet implementation adjust the parameters */ oftplet.init(session); // configure channel idle based on configured session timeout int timeoutSeconds = session.getTimeout(); ctx.getPipeline().addFirst("Timeout-HANDLER", new IdleStateHandler(timer, timeoutSeconds, timeoutSeconds, 0)); // Add all accepted channels to the group so that they are closed // properly on shutdown. If the added channel is closed before shutdown, // it will be removed from the group automatically. if (channelGroup != null) { channelGroup.add(e.getChannel()); } super.channelOpen(ctx, e); }