thufir

client

Jul 26th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package net.bounceme.dur.client.netty;
  2.  
  3. import io.netty.channel.ChannelHandlerContext;
  4. import io.netty.channel.ChannelInboundHandlerAdapter;
  5. import java.util.logging.Logger;
  6. import net.bounceme.dur.client.jdbc.Title;
  7.  
  8. public class ClientHandler extends ChannelInboundHandlerAdapter {
  9.  
  10.     private static final Logger log = Logger.getLogger(ClientHandler.class.getName());
  11.  
  12.     public ClientHandler() {
  13.     }
  14.  
  15.     @Override
  16.     public void channelActive(ChannelHandlerContext ctx) {
  17.         Title title = new Title();
  18.         log.info(title.toString());
  19.         ctx.write(title);
  20.     }
  21.  
  22.     @Override
  23.     public void channelRead(ChannelHandlerContext ctx, Object msg) {
  24.         try {
  25.             Title t = (Title) msg;
  26.             log.info(msg.toString());
  27.             ctx.write(t);
  28.         } catch (ClassCastException cce) {  //????
  29.             log.warning(cce.toString());
  30.         }
  31.     }
  32.  
  33.     @Override
  34.     public void channelReadComplete(ChannelHandlerContext ctx
  35.     ) {
  36.         ctx.flush();
  37.     }
  38.  
  39.     @Override
  40.     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause
  41.     ) {
  42.         log.severe(cause.toString());
  43.         ctx.close();
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment