KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > AbstractMonitor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * @(#) AbstractMonitor.java
26  *
27  * Copyright 2000-2001 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  *
31  * This software is the confidential and proprietary information
32  * of iPlanet/Sun Microsystems, Inc. ("Confidential Information").
33  * You shall not disclose such Confidential Information and shall
34  * use it only in accordance with the terms of the license
35  * agreement you entered into with iPlanet/Sun Microsystems.
36  */

37 package com.sun.enterprise.server;
38
39 import java.util.HashSet JavaDoc;
40 import java.util.TimerTask JavaDoc;
41 import java.util.Timer JavaDoc;
42
43 /**
44  * Base class for all monitors. It provides functionality to perform
45  * repeated tasks from server runtime.
46  *
47  * @atuthor Nazrul Islam
48  * @since JDK 1.4
49  */

50 abstract class AbstractMonitor extends TimerTask JavaDoc {
51
52     /** contains all the monitored entries */
53     protected HashSet JavaDoc _monitoredEntries;
54
55     /** timer to run this task */
56     protected Timer JavaDoc _timer;
57
58     /** polling interval for the timer */
59     protected long _pollInterval;
60
61     /**
62      * Constructor.
63      *
64      * @param pollInterval polling interval
65      */

66     AbstractMonitor(long pollInterval) {
67         this._pollInterval = pollInterval;
68         this._monitoredEntries = new HashSet JavaDoc();
69     }
70
71     /**
72      * Starts this monitor.
73      */

74     void start() {
75         this._timer = new Timer JavaDoc(true);
76         this._timer.schedule(this, 0, this._pollInterval);
77     }
78
79     /**
80      * Stops this monitor.
81      */

82     void stop() {
83         if (this._timer != null) {
84             this._timer.cancel();
85         }
86     }
87
88     /**
89      * Adds the given monitorable entry to the list.
90      *
91      * @param entry a monitorable entry
92      */

93     void addMonitorableEntry(MonitorableEntry entry) {
94
95         synchronized (this._monitoredEntries) {
96             this._monitoredEntries.add(entry);
97         }
98     }
99
100     /**
101      * Removes the monitorable entry from the list.
102      *
103      * @param entry monitorable entry to be removed
104      */

105     void removeMonitorableEntry(MonitorableEntry entry) {
106
107         synchronized (this._monitoredEntries) {
108             this._monitoredEntries.remove(entry);
109         }
110     }
111 }
112
Popular Tags