📄 jmsserverconnection.java
字号:
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Exoffice Technologies. For written permission,
* please contact info@exolab.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Exoffice Technologies. Exolab is a registered
* trademark of Exoffice Technologies.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.exolab.org/).
*
* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2000-2005 (C) Exoffice Technologies Inc. All Rights Reserved.
*
* $Id: JmsServerConnection.java,v 1.3 2005/05/24 13:09:09 tanderson Exp $
*/
package org.exolab.jms.server;
import java.util.HashSet;
import java.util.Iterator;
import javax.jms.InvalidClientIDException;
import javax.jms.JMSException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Server implementation of the <code>javax.jms.Connection</code> interface
*
* @author <a href="mailto:jima@comware.com.au">Jim Alateras</a>
* @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
* @version $Revision: 1.3 $ $Date: 2005/05/24 13:09:09 $
* @see JmsServerConnectionManager
*/
public class JmsServerConnection implements ServerConnection {
/**
* The connection manager responsible for this.
*/
private final JmsServerConnectionManager _manager;
/**
* The connection identifier.
*/
private final long _connectionId;
/**
* The client identifier. May be <code>null</code>.
*/
private String _clientId;
/**
* The sessions associated with the connection.
*/
private HashSet _sessions = new HashSet();
/**
* Indicates if message delivery has been stopped for this connection.
*/
private boolean _stopped = true;
/**
* The logger.
*/
private static final Log _log =
LogFactory.getLog(JmsServerConnection.class);
/**
* Construct a new <code>JmsServerConnection</code>.
*
* @param manager the connection manager
* @param connectionId the identifier for this connection
* @param clientId the client identifier. May be <code>null</code>
*/
protected JmsServerConnection(JmsServerConnectionManager manager,
long connectionId, String clientId) {
_manager = manager;
_connectionId = connectionId;
_clientId = clientId;
}
/**
* Returns the connection identifier.
*
* @return the connection identifier
*/
public long getConnectionId() {
return _connectionId;
}
/**
* Returns the client identifier.
*
* @return the client identifier
*/
public String getClientID() {
return _clientId;
}
/**
* Sets the client identifier for this connection.
*
* @param clientID the unique client identifier
* @throws JMSException if the JMS provider fails to set the
* client ID for this connection due to
* some internal error.
* @throws InvalidClientIDException if the JMS client specifies an invalid
* or duplicate client ID.
* @throws IllegalStateException if the JMS client attempts to set a
* connection's client ID at the wrong time
* or when it has been administratively
* configured.
*/
public void setClientID(String clientID) throws JMSException {
if (clientID == null) {
throw new InvalidClientIDException("Invalid clientID: " + clientID);
}
_manager.addClientID(clientID);
_clientId = clientID;
}
/**
* Create a new session
*
* @param transacted indicates whether the session is transacted
* @param acknowledgeMode indicates whether the consumer or the client will
* acknowledge any messages it receives; ignored if
* the session is transacted. Legal values are
* <code>Session.AUTO_ACKNOWLEDGE</code>,
* <code>Session.CLIENT_ACKNOWLEDGE</code>, and
* <code>Session.DUPS_OK_ACKNOWLEDGE</code>.
* @return a newly created session
* @throws JMSException for any JMS error
*/
public synchronized ServerSession createSession(int acknowledgeMode,
boolean transacted)
throws JMSException {
JmsServerSession session = new JmsServerSession(this, acknowledgeMode,
transacted);
_sessions.add(session);
if (!_stopped) {
session.start();
}
return session;
}
/**
* Starts (or restarts) a connection's delivery of incoming messages. A call
* to <code>start</code> on a connection that has already been started is
* ignored.
*
* @todo - unused?
*/
public synchronized void start() {
if (_stopped) {
Iterator iterator = _sessions.iterator();
while (iterator.hasNext()) {
JmsServerSession session = (JmsServerSession) iterator.next();
session.start();
}
_stopped = false;
}
}
/**
* Closes the connection.
*/
public synchronized void close() {
Iterator iterator = _sessions.iterator();
while (iterator.hasNext()) {
JmsServerSession session = (JmsServerSession) iterator.next();
try {
session.close();
} catch (JMSException exception) {
_log.debug("Failed to close session", exception);
}
}
_sessions.clear();
_manager.closed(this);
}
/**
* Notify closure of a session
*
* @param session the closed session
*/
public synchronized void closed(JmsServerSession session) {
_sessions.remove(session);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -