1 22 package org.jboss.mq.server; 23 24 import java.util.Iterator ; 25 26 import javax.jms.Destination ; 27 import javax.jms.JMSException ; 28 import javax.jms.Queue ; 29 import javax.jms.TemporaryQueue ; 30 import javax.jms.TemporaryTopic ; 31 import javax.jms.Topic ; 32 33 import org.jboss.mq.AcknowledgementRequest; 34 import org.jboss.mq.ConnectionToken; 35 import org.jboss.mq.DurableSubscriptionID; 36 import org.jboss.mq.SpyDestination; 37 import org.jboss.mq.SpyMessage; 38 import org.jboss.mq.Subscription; 39 import org.jboss.mq.TransactionRequest; 40 import org.jboss.mq.il.jvm.JVMClientIL; 41 42 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 43 44 54 public class ClientMonitorInterceptor extends JMSServerInterceptorSupport 55 { 56 ConcurrentReaderHashMap clients = new ConcurrentReaderHashMap(); 58 59 private static class ClientStats 60 { 61 private long lastUsed = System.currentTimeMillis(); 62 63 boolean disconnectIfInactive = true; 64 } 65 66 public void disconnectInactiveClients(long disconnectTime) 67 { 68 log.debug("Checking for timedout clients."); 69 Iterator i = clients.keySet().iterator(); 70 while (i.hasNext()) 71 { 72 ConnectionToken dc = (ConnectionToken) i.next(); 73 ClientStats cs = (ClientStats) clients.get(dc); 74 if (cs.disconnectIfInactive && cs.lastUsed < disconnectTime) 75 { 76 try 77 { 78 log.debug("Disconnecting client due to inactivity timeout: " + dc); 79 connectionClosing(dc); 80 } 81 catch (Throwable e) 82 { 83 } 84 } 85 } 86 } 87 88 94 public ClientStats peekClientStats(ConnectionToken dc) 95 { 96 return (ClientStats) clients.get(dc); 97 } 98 99 public ClientStats getClientStats(ConnectionToken dc) throws JMSException 100 { 101 ClientStats cq = (ClientStats) clients.get(dc); 102 if (cq != null) 103 return cq; 104 105 if (dc.getClientID() != null) 107 { 108 ConnectionToken withoutID = new ConnectionToken(null, dc.clientIL, dc.getSessionId()); 109 clients.remove(withoutID); 110 } 111 112 cq = new ClientStats(); 113 114 if (dc.clientIL instanceof JVMClientIL) 116 cq.disconnectIfInactive = false; 117 118 clients.put(dc, cq); 119 return cq; 120 } 121 122 public TemporaryTopic getTemporaryTopic(ConnectionToken dc) throws JMSException 123 { 124 getClientStats(dc).lastUsed = System.currentTimeMillis(); 125 return getNext().getTemporaryTopic(dc); 126 } 127 128 public TemporaryQueue getTemporaryQueue(ConnectionToken dc) throws JMSException 129 { 130 getClientStats(dc).lastUsed = System.currentTimeMillis(); 131 return getNext().getTemporaryQueue(dc); 132 } 133 134 public void connectionClosing(ConnectionToken dc) throws JMSException 135 { 136 clients.remove(dc); 137 getNext().connectionClosing(dc); 138 } 139 140 public void addMessage(ConnectionToken dc, SpyMessage message) throws JMSException 141 { 142 getClientStats(dc).lastUsed = System.currentTimeMillis(); 143 getNext().addMessage(dc, message); 144 } 145 146 public Queue createQueue(ConnectionToken dc, String dest) throws JMSException 147 { 148 getClientStats(dc).lastUsed = System.currentTimeMillis(); 149 return getNext().createQueue(dc, dest); 150 151 } 152 153 public Topic createTopic(ConnectionToken dc, String dest) throws JMSException 154 { 155 getClientStats(dc).lastUsed = System.currentTimeMillis(); 156 return getNext().createTopic(dc, dest); 157 } 158 159 public void deleteTemporaryDestination(ConnectionToken dc, SpyDestination dest) throws JMSException 160 { 161 getClientStats(dc).lastUsed = System.currentTimeMillis(); 162 getNext().deleteTemporaryDestination(dc, dest); 163 } 164 165 public void transact(ConnectionToken dc, TransactionRequest t) throws JMSException 166 { 167 getClientStats(dc).lastUsed = System.currentTimeMillis(); 168 getNext().transact(dc, t); 169 170 } 171 172 public void acknowledge(ConnectionToken dc, AcknowledgementRequest item) throws JMSException 173 { 174 getClientStats(dc).lastUsed = System.currentTimeMillis(); 175 getNext().acknowledge(dc, item); 176 } 177 178 public SpyMessage[] browse(ConnectionToken dc, Destination dest, String selector) throws JMSException 179 { 180 getClientStats(dc).lastUsed = System.currentTimeMillis(); 181 return getNext().browse(dc, dest, selector); 182 } 183 184 public SpyMessage receive(ConnectionToken dc, int subscriberId, long wait) throws JMSException 185 { 186 getClientStats(dc).lastUsed = System.currentTimeMillis(); 187 return getNext().receive(dc, subscriberId, wait); 188 } 189 190 public void setEnabled(ConnectionToken dc, boolean enabled) throws JMSException 191 { 192 getClientStats(dc).lastUsed = System.currentTimeMillis(); 193 getNext().setEnabled(dc, enabled); 194 } 195 196 public void unsubscribe(ConnectionToken dc, int subscriptionId) throws JMSException 197 { 198 getClientStats(dc).lastUsed = System.currentTimeMillis(); 199 getNext().unsubscribe(dc, subscriptionId); 200 } 201 202 public void destroySubscription(ConnectionToken dc, DurableSubscriptionID id) throws JMSException 203 { 204 getClientStats(dc).lastUsed = System.currentTimeMillis(); 205 getNext().destroySubscription(dc, id); 206 } 207 208 public void subscribe(org.jboss.mq.ConnectionToken dc, org.jboss.mq.Subscription s) throws JMSException 209 { 210 211 getClientStats(dc).lastUsed = System.currentTimeMillis(); 212 getNext().subscribe(dc, s); 213 214 } 215 216 public void ping(ConnectionToken dc, long clientTime) throws JMSException 217 { 218 getClientStats(dc).lastUsed = System.currentTimeMillis(); 219 getNext().ping(dc, clientTime); 220 } 221 222 public Subscription getSubscription(ConnectionToken dc, int subscriberId) throws JMSException 223 { 224 getClientStats(dc).lastUsed = System.currentTimeMillis(); 225 return getNext().getSubscription(dc, subscriberId); 226 227 } 228 } 229 | Popular Tags |