1 45 package org.exolab.jms.server; 46 47 import java.util.HashSet ; 48 import java.util.Iterator ; 49 import javax.jms.InvalidClientIDException ; 50 import javax.jms.JMSException ; 51 52 import org.apache.commons.logging.Log; 53 import org.apache.commons.logging.LogFactory; 54 55 63 public class JmsServerConnection implements ServerConnection { 64 65 68 private final JmsServerConnectionManager _manager; 69 70 73 private final long _connectionId; 74 75 78 private String _clientId; 79 80 83 private HashSet _sessions = new HashSet (); 84 85 88 private boolean _stopped = true; 89 90 93 private static final Log _log = 94 LogFactory.getLog(JmsServerConnection.class); 95 96 103 protected JmsServerConnection(JmsServerConnectionManager manager, 104 long connectionId, String clientId) { 105 _manager = manager; 106 _connectionId = connectionId; 107 _clientId = clientId; 108 } 109 110 115 public long getConnectionId() { 116 return _connectionId; 117 } 118 119 124 public String getClientID() { 125 return _clientId; 126 } 127 128 142 public void setClientID(String clientID) throws JMSException { 143 if (clientID == null) { 144 throw new InvalidClientIDException ("Invalid clientID: " + clientID); 145 } 146 _manager.addClientID(clientID); 147 _clientId = clientID; 148 } 149 150 163 public synchronized ServerSession createSession(int acknowledgeMode, 164 boolean transacted) 165 throws JMSException { 166 JmsServerSession session = new JmsServerSession(this, acknowledgeMode, 167 transacted); 168 _sessions.add(session); 169 if (!_stopped) { 170 session.start(); 171 } 172 173 return session; 174 } 175 176 183 public synchronized void start() { 184 if (_stopped) { 185 Iterator iterator = _sessions.iterator(); 186 while (iterator.hasNext()) { 187 JmsServerSession session = (JmsServerSession) iterator.next(); 188 session.start(); 189 } 190 _stopped = false; 191 } 192 } 193 194 197 public synchronized void close() { 198 Iterator iterator = _sessions.iterator(); 199 while (iterator.hasNext()) { 200 JmsServerSession session = (JmsServerSession) iterator.next(); 201 try { 202 session.close(); 203 } catch (JMSException exception) { 204 _log.debug("Failed to close session", exception); 205 } 206 } 207 _sessions.clear(); 208 _manager.closed(this); 209 } 210 211 216 public synchronized void closed(JmsServerSession session) { 217 _sessions.remove(session); 218 } 219 220 } 221 | Popular Tags |