📄 rmijmsserverconnection.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-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
*
* $Id: RmiJmsServerConnection.java,v 1.18 2003/08/17 01:32:26 tanderson Exp $
*
* Date Author Changes
* 04/18/2000 jima Created
*/
package org.exolab.jms.server.rmi;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Enumeration;
import javax.jms.JMSException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.exolab.jms.lease.BaseLease;
import org.exolab.jms.lease.LeaseEventListenerIfc;
import org.exolab.jms.server.JmsServerConnection;
import org.exolab.jms.server.JmsServerConnectionManager;
/**
* This is an implementation of the RemoteJmsServerConnectionIfc interface
* which wraps the JmsConnection class. It basically delegates to an instance
* of JmsConnection.
*
* @version $Revision: 1.18 $ $Date: 2003/08/17 01:32:26 $
* @author <a href="mailto:jima@intalio.com">Jim Alateras</a>
* @see JmsServerConnection
*/
public class RmiJmsServerConnection
extends UnicastRemoteObject
implements RemoteJmsServerConnectionIfc, LeaseEventListenerIfc {
/**
* This is the object that the RMI connection object delegates to. It must
* be non-null and assigned during object construction
*/
protected JmsServerConnection _delegate = null;
/**
* The interval, in milliseconds, between subsequent ping events
*/
protected int _interval = 0;
/**
* This is the lease on this object. This is not used anymore since we
* now use a different approach to determine whether the client is
* active. {@see JmsServerSession#isClientEndpointActive}
*/
protected BaseLease _lease = null;
/**
* The logger
*/
private static final Log _log =
LogFactory.getLog(RmiJmsServerConnection.class);
/**
* Instantiae an instance of this class with a JmsServerConnection instance.
* This class will simply delegate requests to the JmsServerConnection
* object. If a null connection is specified then throw JMSException.
*
* @param connection delegate connection object
* @param interval the interval between ping requests, in seconds
* @throws RemoteException if failed to export object
*/
public RmiJmsServerConnection(JmsServerConnection connection, int interval)
throws RemoteException {
if (connection == null) {
throw new IllegalArgumentException("Argument connection is null");
}
if (interval < 0) {
interval = 0;
}
_interval = interval * 1000;
_delegate = connection;
}
// implementation of RemoteJmsServerConnection.createSession
public RemoteJmsServerSessionIfc createSession(int ackMode,
boolean transacted)
throws JMSException, RemoteException {
return new RmiJmsServerSession(
_delegate.createSession(ackMode, transacted));
}
// implementation of RemoteJmsServerConnection.deleteSession
public void deleteSession(RemoteJmsServerSessionIfc session)
throws JMSException, RemoteException {
// _delegate.deleteSession(???);
}
// implementation of RemoteJmsServerConnection.getSessionCount
public int getSessionCount() throws JMSException, RemoteException {
return _delegate.getSessionCount();
}
// implementation of RemoteJmsServerConnection.getSessions
public Enumeration getSessions() throws JMSException, RemoteException {
throw new RemoteException(
"This function is too expensive to implement");
// this is quite an expensive call since it will create
// RmiJmsServerSession objects for each active session.
// wait until we need it.
}
// implementation of RemoteJmsServerConnection.start
public void start() throws JMSException, RemoteException {
_delegate.start();
}
// implementation of RemoteJmsServerConnection.stop
public void stop() throws JMSException, RemoteException {
_delegate.stop();
}
// implementation of RemoteJmsServerConnection.close
public void close() throws JMSException, RemoteException {
JmsServerConnectionManager.instance().closeConnection(
_delegate.getID());
_delegate.close();
_delegate = null;
}
// implementation of RemoteJmsServerConnection.getConnectionId()
public String getConnectionId() throws RemoteException {
return _delegate.getConnectionId();
}
// implementation of RemoteJmsServerConnection.ping()
public void ping() throws RemoteException {
// do nothing at this stage
//if (_lease == null) {
// _lease = LeaseManager.instance().createLease(
// this, _interval, this);
//} else {
// LeaseManager.instance().renewLease(_lease, _interval);
//}
}
// implementation of LeaseEventListenerIfc.onLeaseExpired
public void onLeaseExpired(Object leasedObject) {
_log.error("onLeaseExpired should never be called");
/**
// the lease has expired. It means that the client has gone. so we need
// to shutdown the connection on this side
try {
this.close();
_lease = null;
} catch (Exception exception) {
// catch all exceptions
_log.error("Error while closing the connection", exception);
}
**/
}
} //-- RmiJmsServerConnection
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -