001 /*
002 * Copyright (C) The Apache Software Foundation. All rights reserved.
003 *
004 * This software is published under the terms of the Apache Software License
005 * version 1.1, a copy of which has been included with this distribution in
006 * the LICENSE file.
007 *
008 * $Id: DefaultServerSession.java 155459 2005-02-26 13:24:44Z dirkv $
009 */
010 package org.apache.commons.messenger;
011
012 import javax.jms.JMSException;
013 import javax.jms.ServerSession;
014 import javax.jms.Session;
015
016
017 /** <p><code>DefaultServerSession</code> is a default implementation of
018 * the JMS ServerSession interface.</p>
019 *
020 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
021 * @version $Revision: 155459 $
022 */
023 public class DefaultServerSession extends Thread implements ServerSession {
024
025 /** The JMS Session on which this ServerSession is based */
026 private Session session;
027 /** Indicates whether the session has been started */
028 private boolean started = false;
029
030 public DefaultServerSession(Session session) throws JMSException {
031 this.session = session;
032 }
033
034 /**
035 * Return the ServerSession's Session. This must be a Session
036 * created by the same Connection which will be dispatching messages
037 * to it. The provider will assign one or more messages to the Session
038 * and then call start on the ServerSession.
039 *
040 * @return the server session's session.
041 *
042 * @exception JMSException if a JMS error occurs.
043 */
044 public Session getSession() throws JMSException {
045 return session;
046 }
047
048 /**
049 * Cause the session's run method to be called to process messages
050 * that were just assigned to it.
051 *
052 */
053 public synchronized void start() {
054 if ( ! started ) {
055 started = true;
056 super.start();
057 }
058 }
059
060 public void run() {
061 session.run();
062 }
063 }
064