1 45 package org.exolab.jms.client.net; 46 47 import java.rmi.RemoteException ; 48 import java.util.List ; 49 import javax.jms.JMSException ; 50 import javax.jms.Message ; 51 import javax.transaction.xa.XAException ; 52 import javax.transaction.xa.Xid ; 53 54 import org.exolab.jms.client.JmsDestination; 55 import org.exolab.jms.client.JmsMessageListener; 56 import org.exolab.jms.client.JmsQueue; 57 import org.exolab.jms.client.JmsTopic; 58 import org.exolab.jms.message.MessageImpl; 59 import org.exolab.jms.net.orb.ORB; 60 import org.exolab.jms.net.proxy.Proxy; 61 import org.exolab.jms.server.ServerSession; 62 63 64 70 public class JmsSessionStubImpl 71 implements ServerSession, JmsMessageListener { 72 73 77 private JmsMessageListener _listener = null; 78 79 82 private ORB _orb; 83 84 87 private ServerSession _session = null; 88 89 90 99 protected JmsSessionStubImpl(ServerSession session, ORB orb, 100 String uri, String principal, 101 String credentials) 102 throws RemoteException { 103 if (session == null) { 104 throw new IllegalArgumentException ("Argument 'session' is null"); 105 } 106 if (orb == null) { 107 throw new IllegalArgumentException ("Argument 'orb' is null"); 108 } 109 _session = session; 110 _orb = orb; 111 Proxy proxy = orb.exportObjectTo(this, uri, principal, credentials); 112 _session.setMessageListener((JmsMessageListener) proxy); 113 } 114 115 120 public void close() throws JMSException { 121 try { 122 _session.close(); 123 _orb.unexportObject(this); 124 _session = null; 125 _listener = null; 126 } catch (RemoteException exception) { 127 rethrow(exception); 128 } 129 } 130 131 138 public void acknowledgeMessage(long consumerId, String messageId) 139 throws JMSException { 140 _session.acknowledgeMessage(consumerId, messageId); 141 } 142 143 149 public void send(MessageImpl message) throws JMSException { 150 _session.send(message); 151 } 152 153 159 public void send(List messages) throws JMSException { 160 _session.send(messages); 161 } 162 163 176 public MessageImpl receive(long consumerId, long wait) 177 throws JMSException { 178 return _session.receive(consumerId, wait); 179 } 180 181 189 public List browse(long consumerId, int count) throws JMSException { 190 return _session.browse(consumerId, count); 191 } 192 193 205 public long createConsumer(JmsDestination destination, String selector, 206 boolean noLocal) throws JMSException { 207 return _session.createConsumer(destination, selector, noLocal); 208 } 209 210 225 public long createDurableConsumer(JmsTopic topic, String name, 226 String selector, boolean noLocal) 227 throws JMSException { 228 return _session.createDurableConsumer(topic, name, selector, noLocal); 229 } 230 231 240 public long createBrowser(JmsQueue queue, String selector) 241 throws JMSException { 242 return _session.createBrowser(queue, selector); 243 } 244 245 251 public void removeConsumer(long consumerId) throws JMSException { 252 _session.removeConsumer(consumerId); 253 } 254 255 261 public void unsubscribe(String name) throws JMSException { 262 _session.unsubscribe(name); 263 } 264 265 270 public void start() throws JMSException { 271 _session.start(); 272 } 273 274 279 public void stop() throws JMSException { 280 _session.stop(); 281 } 282 283 291 public void enableAsynchronousDelivery(long consumerId, boolean enable) 292 throws JMSException { 293 _session.enableAsynchronousDelivery(consumerId, enable); 294 } 295 296 302 public void recover() throws JMSException { 303 _session.recover(); 304 } 305 306 311 public void commit() throws JMSException { 312 _session.commit(); 313 } 314 315 320 public void rollback() throws JMSException { 321 _session.rollback(); 322 } 323 324 333 public void start(Xid xid, int flags) throws XAException { 334 _session.start(xid, flags); 335 } 336 337 345 public int prepare(Xid xid) throws XAException { 346 return _session.prepare(xid); 347 } 348 349 356 public void commit(Xid xid, boolean onePhase) throws XAException { 357 _session.commit(xid, onePhase); 358 } 359 360 370 public void end(Xid xid, int flags) throws XAException { 371 _session.end(xid, flags); 372 } 373 374 381 public void forget(Xid xid) throws XAException { 382 _session.forget(xid); 383 } 384 385 392 public void rollback(Xid xid) throws XAException { 393 _session.rollback(xid); 394 } 395 396 406 public Xid [] recover(int flag) throws XAException { 407 return _session.recover(flag); 408 } 409 410 417 public int getTransactionTimeout() throws XAException { 418 return _session.getTransactionTimeout(); 419 } 420 421 428 public boolean setTransactionTimeout(int seconds) throws XAException { 429 return _session.setTransactionTimeout(seconds); 430 } 431 432 438 public String getResourceManagerId() throws XAException { 439 return _session.getResourceManagerId(); 440 } 441 442 447 public void setMessageListener(JmsMessageListener listener) { 448 _listener = listener; 449 } 450 451 457 public void onMessage(Message message) throws RemoteException { 458 _listener.onMessage(message); 459 } 460 461 468 public void onMessageAvailable(long consumerId) throws RemoteException { 469 _listener.onMessageAvailable(consumerId); 470 } 471 472 478 private void rethrow(RemoteException exception) throws JMSException { 479 JMSException error = new JMSException (exception.getMessage()); 480 error.setLinkedException(exception); 481 throw error; 482 } 483 484 } 485 | Popular Tags |