1 22 package org.jboss.mq.il.uil2; 23 24 import java.lang.reflect.UndeclaredThrowableException ; 25 import java.util.Properties ; 26 27 import org.jboss.logging.Logger; 28 import org.jboss.mq.Connection; 29 import org.jboss.mq.ReceiveRequest; 30 import org.jboss.mq.SpyDestination; 31 import org.jboss.mq.il.ClientILService; 32 import org.jboss.mq.il.ClientIL; 33 import org.jboss.mq.il.uil2.msgs.MsgTypes; 34 import org.jboss.mq.il.uil2.msgs.BaseMsg; 35 import org.jboss.mq.il.uil2.msgs.ReceiveRequestMsg; 36 import org.jboss.mq.il.uil2.msgs.DeleteTemporaryDestMsg; 37 import org.jboss.mq.il.uil2.msgs.PingMsg; 38 39 46 public class UILClientILService 47 implements ClientILService, MsgTypes, SocketManagerHandler 48 { 49 static Logger log = Logger.getLogger(UILClientILService.class); 50 51 53 private UILClientIL clientIL; 55 private SocketManager socketMgr; 57 private Connection connection; 59 private boolean sendReceiveReplies = true; 61 62 68 public ClientIL getClientIL() 69 throws Exception 70 { 71 return clientIL; 72 } 73 74 81 public void init(Connection connection, Properties props) 82 throws Exception 83 { 84 this.connection = connection; 85 clientIL = new UILClientIL(); 86 UILServerIL serverIL = (UILServerIL) connection.getServerIL(); 87 socketMgr = serverIL.getSocketMgr(); 88 String t = props.getProperty(UILServerILFactory.UIL_BUFFERSIZE_KEY); 89 if (t != null) 90 socketMgr.setBufferSize(Integer.parseInt(t)); 91 t = props.getProperty(UILServerILFactory.UIL_CHUNKSIZE_KEY); 92 if (t != null) 93 socketMgr.setChunkSize(Integer.parseInt(t)); 94 t = props.getProperty(UILServerILFactory.UIL_RECEIVE_REPLIES_KEY); 96 if (t != null) 97 sendReceiveReplies = false; 98 socketMgr.setHandler(this); 99 } 100 101 103 public void handleMsg(BaseMsg msg) 104 throws Exception 105 { 106 boolean trace = log.isTraceEnabled(); 107 int msgType = msg.getMsgType(); 108 if (trace) 109 log.trace("Begin handleMsg, msgType: " + msgType); 110 switch( msgType ) 111 { 112 case m_acknowledge: 113 break; 115 case m_receiveRequest: 116 ReceiveRequestMsg rmsg = (ReceiveRequestMsg) msg; 117 ReceiveRequest[] messages = rmsg.getMessages(); 118 connection.asynchDeliver(messages); 119 if (sendReceiveReplies) 121 { 122 rmsg.trimTheMessages(); 123 socketMgr.sendReply(msg); 124 } 125 break; 126 case m_deleteTemporaryDestination: 127 DeleteTemporaryDestMsg dmsg = (DeleteTemporaryDestMsg) msg; 128 SpyDestination dest = dmsg.getDest(); 129 connection.asynchDeleteTemporaryDestination(dest); 130 socketMgr.sendReply(msg); 131 break; 132 case m_close: 133 connection.asynchClose(); 134 socketMgr.sendReply(msg); 135 break; 136 case m_pong: 137 PingMsg pmsg = (PingMsg) msg; 138 long time = pmsg.getTime(); 139 connection.asynchPong(time); 140 break; 141 default: 142 connection.asynchFailure("UILClientILService received bad msg: "+msg, null); 143 } 144 if (trace) 145 log.trace("End handleMsg"); 146 } 147 148 152 public void start() throws Exception 153 { 154 log.debug("Starting"); 155 } 156 157 160 public void stop() throws Exception 161 { 162 log.debug("Stopping"); 163 socketMgr.stop(); 164 } 165 166 public void onStreamNotification(Object stream, int size) 167 { 168 connection.asynchPong(System.currentTimeMillis()); 169 } 170 171 public void asynchFailure(String error, Throwable e) 172 { 173 if (e instanceof Exception ) 174 connection.asynchFailure(error, e); 175 else 176 connection.asynchFailure(error, new UndeclaredThrowableException (e)); 177 } 178 179 public void close() 180 { 181 } 182 } 183 | Popular Tags |