KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > server > jmx > ClientMonitorInterceptor


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * 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: 37459 $
32  */

33 public class ClientMonitorInterceptor
34     extends InterceptorMBeanSupport
35     implements ClientMonitorInterceptorMBean {
36
37     private org.jboss.mq.server.ClientMonitorInterceptor interceptor =
38         new org.jboss.mq.server.ClientMonitorInterceptor();
39
40     long clientTimeout = 1000 * 60;
41     Thread JavaDoc serviceThread;
42
43     public JMSServerInterceptor getInterceptor() {
44         return interceptor;
45     }
46
47     /**
48      * Returns the clientTimeout.
49      * @return long
50      * @jmx:managed-attribute
51      */

52     public long getClientTimeout() {
53         return clientTimeout;
54     }
55
56     /**
57      * Sets the clientTimeout.
58      * @param clientTimeout The clientTimeout to set
59      * @jmx:managed-attribute
60      */

61     public void setClientTimeout(long clientTimeout) {
62         this.clientTimeout = clientTimeout;
63     }
64
65     /**
66      * @see org.jboss.system.ServiceMBeanSupport#startService()
67      */

68     protected void startService() throws Exception JavaDoc {
69         super.startService();
70         if( serviceThread != null )
71             return;
72             
73         serviceThread = new Thread JavaDoc(new Runnable JavaDoc() {
74             public void run() {
75                 try {
76                     while(true) {
77                         Thread.sleep(clientTimeout);
78                         interceptor.disconnectInactiveClients(
79                             System.currentTimeMillis() - clientTimeout);
80                     }
81                 } catch (InterruptedException JavaDoc e) {
82                 }
83             }
84         }, "ClientMonitor Service Thread");
85         serviceThread.setDaemon(true);
86         serviceThread.start();
87     }
88
89     /**
90      * @see org.jboss.system.ServiceMBeanSupport#stopService()
91      */

92     protected void stopService() throws Exception JavaDoc {
93         if (serviceThread != null) {
94             serviceThread.interrupt();
95             serviceThread = null;
96         }
97         super.stopService();
98     }
99
100 }
101
Popular Tags