1 22 package org.jboss.mq.il.uil2; 23 24 import java.rmi.RemoteException ; 25 import javax.jms.Destination ; 26 import javax.transaction.xa.Xid ; 27 28 import org.jboss.logging.Logger; 29 import org.jboss.mq.ConnectionToken; 30 import org.jboss.mq.AcknowledgementRequest; 31 import org.jboss.mq.Recoverable; 32 import org.jboss.mq.SpyMessage; 33 import org.jboss.mq.SpyDestination; 34 import org.jboss.mq.TransactionRequest; 35 import org.jboss.mq.DurableSubscriptionID; 36 import org.jboss.mq.il.uil2.msgs.BaseMsg; 37 import org.jboss.mq.il.uil2.msgs.ConnectionTokenMsg; 38 import org.jboss.mq.il.uil2.msgs.AcknowledgementRequestMsg; 39 import org.jboss.mq.il.uil2.msgs.MsgTypes; 40 import org.jboss.mq.il.uil2.msgs.AddMsg; 41 import org.jboss.mq.il.uil2.msgs.BrowseMsg; 42 import org.jboss.mq.il.uil2.msgs.CheckIDMsg; 43 import org.jboss.mq.il.uil2.msgs.CreateDestMsg; 44 import org.jboss.mq.il.uil2.msgs.DeleteTemporaryDestMsg; 45 import org.jboss.mq.il.uil2.msgs.GetIDMsg; 46 import org.jboss.mq.il.uil2.msgs.RecoverMsg; 47 import org.jboss.mq.il.uil2.msgs.TemporaryDestMsg; 48 import org.jboss.mq.il.uil2.msgs.ReceiveMsg; 49 import org.jboss.mq.il.uil2.msgs.EnableConnectionMsg; 50 import org.jboss.mq.il.uil2.msgs.SubscribeMsg; 51 import org.jboss.mq.il.uil2.msgs.TransactMsg; 52 import org.jboss.mq.il.uil2.msgs.UnsubscribeMsg; 53 import org.jboss.mq.il.uil2.msgs.DeleteSubscriptionMsg; 54 import org.jboss.mq.il.uil2.msgs.CheckUserMsg; 55 import org.jboss.mq.il.uil2.msgs.PingMsg; 56 import org.jboss.mq.il.Invoker; 57 58 64 public class ServerSocketManagerHandler implements MsgTypes, SocketManagerHandler 65 { 66 private static Logger log = Logger.getLogger(ServerSocketManagerHandler.class); 67 68 private ConnectionToken connectionToken; 69 private Invoker server; 70 private SocketManager socketMgr; 71 private boolean closed; 72 73 public ServerSocketManagerHandler(Invoker server, SocketManager socketMgr) 74 { 75 this.server = server; 76 this.socketMgr = socketMgr; 77 this.closed = false; 78 } 79 80 83 public void handleMsg(BaseMsg msg) 84 throws Exception 85 { 86 boolean trace = log.isTraceEnabled(); 87 int msgType = msg.getMsgType(); 88 if (trace) 89 log.trace("Begin handleMsg, msgType: " + msgType); 90 91 switch (msgType) 92 { 93 case m_setSpyDistributedConnection: 94 log.debug("Setting up the UILClientIL Connection"); 95 ConnectionTokenMsg cmsg = (ConnectionTokenMsg) msg; 96 connectionToken = cmsg.getToken(); 97 UILClientIL clientIL = (UILClientIL) connectionToken.clientIL; 98 clientIL.setSocketMgr(socketMgr); 99 socketMgr.sendReply(msg); 100 log.debug("The UILClientIL Connection is set up"); 101 break; 102 case m_acknowledge: 103 AcknowledgementRequestMsg ackmsg = (AcknowledgementRequestMsg) msg; 104 AcknowledgementRequest ack = ackmsg.getAck(); 105 server.acknowledge(connectionToken, ack); 106 socketMgr.sendReply(msg); 108 break; 109 case m_addMessage: 110 AddMsg amsg = (AddMsg) msg; 111 server.addMessage(connectionToken, amsg.getMsg()); 112 socketMgr.sendReply(msg); 113 break; 114 case m_browse: 115 BrowseMsg bmsg = (BrowseMsg) msg; 116 SpyMessage[] msgs = server.browse(connectionToken, bmsg.getDest(), bmsg.getSelector()); 117 bmsg.setMessages(msgs); 118 socketMgr.sendReply(msg); 119 break; 120 case m_checkID: 121 CheckIDMsg idmsg = (CheckIDMsg) msg; 122 String ID = idmsg.getID(); 123 server.checkID(ID); 124 if (connectionToken != null) 125 connectionToken.setClientID(ID); 126 socketMgr.sendReply(msg); 127 break; 128 case m_connectionClosing: 129 server.connectionClosing(connectionToken); 130 closed = true; 131 socketMgr.sendReply(msg); 132 socketMgr.stop(); 133 break; 134 case m_createQueue: 135 CreateDestMsg cqmsg = (CreateDestMsg) msg; 136 Destination queue = server.createQueue(connectionToken, cqmsg.getName()); 137 cqmsg.setDest(queue); 138 socketMgr.sendReply(msg); 139 break; 140 case m_createTopic: 141 CreateDestMsg ctmsg = (CreateDestMsg) msg; 142 Destination topic = server.createTopic(connectionToken, ctmsg.getName()); 143 ctmsg.setDest(topic); 144 socketMgr.sendReply(msg); 145 break; 146 case m_deleteTemporaryDestination: 147 DeleteTemporaryDestMsg dtdmsg = (DeleteTemporaryDestMsg) msg; 148 SpyDestination tmpdest = dtdmsg.getDest(); 149 server.deleteTemporaryDestination(connectionToken, tmpdest); 150 socketMgr.sendReply(msg); 151 break; 152 case m_getID: 153 GetIDMsg gidmsg = (GetIDMsg) msg; 154 String gid = server.getID(); 155 if (connectionToken != null) 156 connectionToken.setClientID(gid); 157 gidmsg.setID(gid); 158 socketMgr.sendReply(msg); 159 break; 160 case m_getTemporaryQueue: 161 TemporaryDestMsg tqmsg = (TemporaryDestMsg) msg; 162 Destination tmpQueue = server.getTemporaryQueue(connectionToken); 163 tqmsg.setDest(tmpQueue); 164 socketMgr.sendReply(msg); 165 break; 166 case m_getTemporaryTopic: 167 TemporaryDestMsg ttmsg = (TemporaryDestMsg) msg; 168 Destination tmpTopic = server.getTemporaryTopic(connectionToken); 169 ttmsg.setDest(tmpTopic); 170 socketMgr.sendReply(msg); 171 break; 172 case m_receive: 173 ReceiveMsg rmsg = (ReceiveMsg) msg; 174 SpyMessage reply = server.receive(connectionToken, rmsg.getSubscriberID(), rmsg.getWait()); 175 rmsg.setMessage(reply); 176 socketMgr.sendReply(msg); 177 break; 178 case m_setEnabled: 179 EnableConnectionMsg ecmsg = (EnableConnectionMsg) msg; 180 server.setEnabled(connectionToken, ecmsg.isEnabled()); 181 socketMgr.sendReply(msg); 182 break; 183 case m_subscribe: 184 SubscribeMsg smsg = (SubscribeMsg) msg; 185 server.subscribe(connectionToken, smsg.getSubscription()); 186 socketMgr.sendReply(msg); 187 break; 188 case m_transact: 189 TransactMsg tmsg = (TransactMsg) msg; 190 TransactionRequest trans = tmsg.getRequest(); 191 server.transact(connectionToken, trans); 192 socketMgr.sendReply(msg); 193 break; 194 case m_recover: 195 RecoverMsg recmsg = (RecoverMsg) msg; 196 int flags = recmsg.getFlags(); 197 if (server instanceof Recoverable) 198 { 199 Recoverable recoverable = (Recoverable) server; 200 Xid [] xids = recoverable.recover(connectionToken, flags); 201 recmsg.setXids(xids); 202 socketMgr.sendReply(msg); 203 break; 204 } 205 throw new IllegalStateException ("Invoker does not implement recoverable " + server); 206 case m_unsubscribe: 207 UnsubscribeMsg umsg = (UnsubscribeMsg) msg; 208 server.unsubscribe(connectionToken, umsg.getSubscriptionID()); 209 socketMgr.sendReply(msg); 210 break; 211 case m_destroySubscription: 212 DeleteSubscriptionMsg dsmsg = (DeleteSubscriptionMsg) msg; 213 DurableSubscriptionID dsub = dsmsg.getSubscriptionID(); 214 server.destroySubscription(connectionToken, dsub); 215 socketMgr.sendReply(msg); 216 break; 217 case m_checkUser: 218 CheckUserMsg cumsg = (CheckUserMsg) msg; 219 String uid = server.checkUser(cumsg.getUsername(), cumsg.getPassword()); 220 cumsg.setID(uid); 221 cumsg.clearPassword(); 222 socketMgr.sendReply(msg); 223 break; 224 case m_ping: 225 PingMsg ping = (PingMsg) msg; 226 server.ping(connectionToken, ping.getTime()); 227 break; 228 case m_pong: 229 break; 230 case m_receiveRequest: 232 break; 233 case m_authenticate: 234 CheckUserMsg cumsg2 = (CheckUserMsg) msg; 235 String sessionID = server.authenticate(cumsg2.getUsername(), cumsg2.getPassword()); 236 cumsg2.setID(sessionID); 237 cumsg2.clearPassword(); 238 socketMgr.sendReply(msg); 239 break; 240 default: 241 throw new RemoteException ("Unknown msgType: "+msgType); 242 } 243 if (trace) 244 log.trace("End handleMsg, msgType: " + msgType); 245 } 246 247 public void onStreamNotification(Object stream, int size) 248 { 249 } 250 251 public void asynchFailure(String error, Throwable e) 252 { 253 log.debug(error, e); 254 } 255 256 public void close() 257 { 258 try 259 { 260 if (closed == false) 261 server.connectionClosing(connectionToken); 262 } 263 catch (Exception e) 264 { 265 log.debug("Error closing connection: ", e); 266 } 267 } 268 } 269 | Popular Tags |