01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.mq.server.jmx;
23:
24: import org.jboss.mq.server.JMSServerInterceptor;
25:
26: /**
27: * JMX MBean implementation DelayInterceptor.
28: *
29: * @jmx:mbean extends="org.jboss.mq.server.jmx.InterceptorMBean"
30: * @author <a href="hiram.chirino@jboss.org">Hiram Chirino</a>
31: * @version $Revision: 57198 $
32: */
33: public class ClientMonitorInterceptor extends InterceptorMBeanSupport
34: implements ClientMonitorInterceptorMBean {
35:
36: private org.jboss.mq.server.ClientMonitorInterceptor interceptor = new org.jboss.mq.server.ClientMonitorInterceptor();
37:
38: long clientTimeout = 1000 * 60;
39: Thread serviceThread;
40:
41: public JMSServerInterceptor getInterceptor() {
42: return interceptor;
43: }
44:
45: /**
46: * Returns the clientTimeout.
47: * @return long
48: * @jmx:managed-attribute
49: */
50: public long getClientTimeout() {
51: return clientTimeout;
52: }
53:
54: /**
55: * Sets the clientTimeout.
56: * @param clientTimeout The clientTimeout to set
57: * @jmx:managed-attribute
58: */
59: public void setClientTimeout(long clientTimeout) {
60: this .clientTimeout = clientTimeout;
61: }
62:
63: /**
64: * @see org.jboss.system.ServiceMBeanSupport#startService()
65: */
66: protected void startService() throws Exception {
67: super .startService();
68: if (serviceThread != null)
69: return;
70:
71: serviceThread = new Thread(new Runnable() {
72: public void run() {
73: try {
74: while (true) {
75: Thread.sleep(clientTimeout);
76: interceptor.disconnectInactiveClients(System
77: .currentTimeMillis()
78: - clientTimeout);
79: }
80: } catch (InterruptedException e) {
81: }
82: }
83: }, "ClientMonitor Service Thread");
84: serviceThread.setDaemon(true);
85: serviceThread.start();
86: }
87:
88: /**
89: * @see org.jboss.system.ServiceMBeanSupport#stopService()
90: */
91: protected void stopService() throws Exception {
92: if (serviceThread != null) {
93: serviceThread.interrupt();
94: serviceThread = null;
95: }
96: super.stopService();
97: }
98:
99: }
|