1 20 package org.apache.mina.handler.multiton; 21 22 import org.apache.mina.common.IdleStatus; 23 import org.apache.mina.common.IoHandler; 24 import org.apache.mina.common.IoSession; 25 26 35 public class SingleSessionIoHandlerDelegate implements IoHandler { 36 40 public static final String HANDLER = SingleSessionIoHandlerDelegate.class 41 .getName() 42 + ".handler"; 43 44 48 private final SingleSessionIoHandlerFactory factory; 49 50 57 public SingleSessionIoHandlerDelegate(SingleSessionIoHandlerFactory factory) { 58 if (factory == null) { 59 throw new NullPointerException ("factory"); 60 } 61 this.factory = factory; 62 } 63 64 71 public void sessionCreated(IoSession session) throws Exception { 72 SingleSessionIoHandler handler = factory.getHandler(session); 73 session.setAttribute(HANDLER, handler); 74 handler.sessionCreated(); 75 } 76 77 82 public void sessionOpened(IoSession session) throws Exception { 83 SingleSessionIoHandler handler = (SingleSessionIoHandler) session 84 .getAttribute(HANDLER); 85 handler.sessionOpened(); 86 } 87 88 93 public void sessionClosed(IoSession session) throws Exception { 94 SingleSessionIoHandler handler = (SingleSessionIoHandler) session 95 .getAttribute(HANDLER); 96 handler.sessionClosed(); 97 } 98 99 104 public void sessionIdle(IoSession session, IdleStatus status) 105 throws Exception { 106 SingleSessionIoHandler handler = (SingleSessionIoHandler) session 107 .getAttribute(HANDLER); 108 handler.sessionIdle(status); 109 } 110 111 116 public void exceptionCaught(IoSession session, Throwable cause) 117 throws Exception { 118 SingleSessionIoHandler handler = (SingleSessionIoHandler) session 119 .getAttribute(HANDLER); 120 handler.exceptionCaught(cause); 121 } 122 123 128 public void messageReceived(IoSession session, Object message) 129 throws Exception { 130 SingleSessionIoHandler handler = (SingleSessionIoHandler) session 131 .getAttribute(HANDLER); 132 handler.messageReceived(message); 133 } 134 135 140 public void messageSent(IoSession session, Object message) throws Exception { 141 SingleSessionIoHandler handler = (SingleSessionIoHandler) session 142 .getAttribute(HANDLER); 143 handler.messageSent(message); 144 } 145 } 146 | Popular Tags |