From dfd9669797d859cc8a2e5791a89d1c1533fefc69 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 4 Mar 2009 14:17:35 +0000 Subject: [PATCH] Code cleanup --- .../securechat/SecureChatServerHandler.java | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/jboss/netty/example/securechat/SecureChatServerHandler.java b/src/main/java/org/jboss/netty/example/securechat/SecureChatServerHandler.java index 890a41608b..fe5cdb6feb 100644 --- a/src/main/java/org/jboss/netty/example/securechat/SecureChatServerHandler.java +++ b/src/main/java/org/jboss/netty/example/securechat/SecureChatServerHandler.java @@ -77,26 +77,7 @@ public class SecureChatServerHandler extends SimpleChannelHandler { // Get notified when SSL handshake is done. ChannelFuture handshakeFuture = sslHandler.handshake(e.getChannel()); - handshakeFuture.addListener(new ChannelFutureListener() { - public void operationComplete(ChannelFuture future) throws Exception { - if (future.isSuccess()) { - // Once session is secured, send a greeting. - future.getChannel().write( - "Welcome to " + InetAddress.getLocalHost().getHostName() + - " secure chat service!\n"); - future.getChannel().write( - "Your session is protected by " + - sslHandler.getEngine().getSession().getCipherSuite() + - " cipher suite.\n"); - - // Register the channel to the global channel list - // so the channel received the messages from others. - channels.add(future.getChannel()); - } else { - future.getChannel().close(); - } - } - }); + handshakeFuture.addListener(new Greeter(sslHandler)); } @Override @@ -137,4 +118,37 @@ public class SecureChatServerHandler extends SimpleChannelHandler { e.getCause()); e.getChannel().close(); } + + /** + * @author The Netty Project (netty-dev@lists.jboss.org) + * @author Trustin Lee (tlee@redhat.com) + * @version $Rev$, $Date$ + */ + private static final class Greeter implements ChannelFutureListener { + + private final SslHandler sslHandler; + + Greeter(SslHandler sslHandler) { + this.sslHandler = sslHandler; + } + + public void operationComplete(ChannelFuture future) throws Exception { + if (future.isSuccess()) { + // Once session is secured, send a greeting. + future.getChannel().write( + "Welcome to " + InetAddress.getLocalHost().getHostName() + + " secure chat service!\n"); + future.getChannel().write( + "Your session is protected by " + + sslHandler.getEngine().getSession().getCipherSuite() + + " cipher suite.\n"); + + // Register the channel to the global channel list + // so the channel received the messages from others. + channels.add(future.getChannel()); + } else { + future.getChannel().close(); + } + } + } }