1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2000-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: RmiJmsServerConnection.java,v 1.18 2003/08/17 01:32:26 tanderson Exp $
44 *
45 * Date Author Changes
46 * 04/18/2000 jima Created
47 */
48 package org.exolab.jms.server.rmi;
49
50 import java.rmi.RemoteException;
51 import java.rmi.server.UnicastRemoteObject;
52 import java.util.Enumeration;
53
54 import javax.jms.JMSException;
55
56 import org.apache.commons.logging.Log;
57 import org.apache.commons.logging.LogFactory;
58
59 import org.exolab.jms.lease.BaseLease;
60 import org.exolab.jms.lease.LeaseEventListenerIfc;
61 import org.exolab.jms.server.JmsServerConnection;
62 import org.exolab.jms.server.JmsServerConnectionManager;
63
64
65 /***
66 * This is an implementation of the RemoteJmsServerConnectionIfc interface
67 * which wraps the JmsConnection class. It basically delegates to an instance
68 * of JmsConnection.
69 *
70 * @version $Revision: 1.18 $ $Date: 2003/08/17 01:32:26 $
71 * @author <a href="mailto:jima@intalio.com">Jim Alateras</a>
72 * @see JmsServerConnection
73 */
74 public class RmiJmsServerConnection
75 extends UnicastRemoteObject
76 implements RemoteJmsServerConnectionIfc, LeaseEventListenerIfc {
77
78 /***
79 * This is the object that the RMI connection object delegates to. It must
80 * be non-null and assigned during object construction
81 */
82 protected JmsServerConnection _delegate = null;
83
84 /***
85 * The interval, in milliseconds, between subsequent ping events
86 */
87 protected int _interval = 0;
88
89 /***
90 * This is the lease on this object. This is not used anymore since we
91 * now use a different approach to determine whether the client is
92 * active. {@see JmsServerSession#isClientEndpointActive}
93 */
94 protected BaseLease _lease = null;
95
96 /***
97 * The logger
98 */
99 private static final Log _log =
100 LogFactory.getLog(RmiJmsServerConnection.class);
101
102
103 /***
104 * Instantiae an instance of this class with a JmsServerConnection instance.
105 * This class will simply delegate requests to the JmsServerConnection
106 * object. If a null connection is specified then throw JMSException.
107 *
108 * @param connection delegate connection object
109 * @param interval the interval between ping requests, in seconds
110 * @throws RemoteException if failed to export object
111 */
112 public RmiJmsServerConnection(JmsServerConnection connection, int interval)
113 throws RemoteException {
114
115 if (connection == null) {
116 throw new IllegalArgumentException("Argument connection is null");
117 }
118
119 if (interval < 0) {
120 interval = 0;
121 }
122 _interval = interval * 1000;
123 _delegate = connection;
124 }
125
126 // implementation of RemoteJmsServerConnection.createSession
127 public RemoteJmsServerSessionIfc createSession(int ackMode,
128 boolean transacted)
129 throws JMSException, RemoteException {
130 return new RmiJmsServerSession(
131 _delegate.createSession(ackMode, transacted));
132 }
133
134 // implementation of RemoteJmsServerConnection.deleteSession
135 public void deleteSession(RemoteJmsServerSessionIfc session)
136 throws JMSException, RemoteException {
137 // _delegate.deleteSession(???);
138 }
139
140 // implementation of RemoteJmsServerConnection.getSessionCount
141 public int getSessionCount() throws JMSException, RemoteException {
142 return _delegate.getSessionCount();
143 }
144
145 // implementation of RemoteJmsServerConnection.getSessions
146 public Enumeration getSessions() throws JMSException, RemoteException {
147 throw new RemoteException(
148 "This function is too expensive to implement");
149 // this is quite an expensive call since it will create
150 // RmiJmsServerSession objects for each active session.
151 // wait until we need it.
152 }
153
154 // implementation of RemoteJmsServerConnection.start
155 public void start() throws JMSException, RemoteException {
156 _delegate.start();
157 }
158
159 // implementation of RemoteJmsServerConnection.stop
160 public void stop() throws JMSException, RemoteException {
161 _delegate.stop();
162 }
163
164 // implementation of RemoteJmsServerConnection.close
165 public void close() throws JMSException, RemoteException {
166 JmsServerConnectionManager.instance().closeConnection(
167 _delegate.getID());
168 _delegate.close();
169 _delegate = null;
170 }
171
172 // implementation of RemoteJmsServerConnection.getConnectionId()
173 public String getConnectionId() throws RemoteException {
174 return _delegate.getConnectionId();
175 }
176
177 // implementation of RemoteJmsServerConnection.ping()
178 public void ping() throws RemoteException {
179 // do nothing at this stage
180
181 //if (_lease == null) {
182 // _lease = LeaseManager.instance().createLease(
183 // this, _interval, this);
184 //} else {
185 // LeaseManager.instance().renewLease(_lease, _interval);
186 //}
187 }
188
189 // implementation of LeaseEventListenerIfc.onLeaseExpired
190 public void onLeaseExpired(Object leasedObject) {
191 _log.error("onLeaseExpired should never be called");
192 /***
193 // the lease has expired. It means that the client has gone. so we need
194 // to shutdown the connection on this side
195 try {
196 this.close();
197 _lease = null;
198 } catch (Exception exception) {
199 // catch all exceptions
200 _log.error("Error while closing the connection", exception);
201 }
202 **/
203 }
204
205 } //-- RmiJmsServerConnection
This page was automatically generated by Maven