KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @(#) MonitorableEntry.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.io.File JavaDoc;
40
41 /**
42  * Represents a monitor entry in dynamic reloading.
43  *
44  * @author Nazrul Islam
45  * @since JDK 1.4
46  */

47 final class MonitorableEntry {
48
49     /**
50      * Constructor.
51      *
52      * @param id registered name of the application or stand alone module
53      * @param displayName the user-friendly display name
54      * @param monitoredFile file to be monitored
55      * @param listener listener that handles the callback
56      */

57     MonitorableEntry(String JavaDoc id, String JavaDoc displayName, File JavaDoc monitoredFile,
58                      MonitorListener listener) {
59
60         this.id = id;
61         this.displayName = displayName;
62         this.monitoredFile = monitoredFile;
63         this.lastReloadedAt = monitoredFile.lastModified();
64         this.listener = listener;
65     }
66
67     /**
68      * Constructor.
69      *
70      * @param id registered name of the application or stand alone module
71      * @param monitoredFile file to be monitored
72      * @param listener listener that handles the callback
73      */

74     MonitorableEntry(String JavaDoc id, File JavaDoc monitoredFile, MonitorListener listener) {
75
76         this(id, id, monitoredFile, listener);
77     }
78
79     /**
80      * Constructor. Use this when "id" is not necessary.
81      *
82      * @param monitoredFile file to be monitored
83      * @param listener listener that handles the callback
84      */

85     MonitorableEntry(File JavaDoc monitoredFile, MonitorListener listener) {
86
87         this("AutoDeployDirectory", monitoredFile, listener);
88     }
89
90     /**
91      * Returns the id of the entry.
92      *
93      * @return the id of the entry
94      */

95     String JavaDoc getId() {
96         return this.id;
97     }
98
99     /**
100      * Returns the display name of the entry (usually this is the same as
101      * the id).
102      *
103      * @return the display name of the entry
104      */

105     String JavaDoc getDisplayName() {
106         return this.displayName;
107     }
108
109     /**
110      * Returns the last attempted reload time stamp of the monitored entry.
111      *
112      * @return last attempted reload time stamp of the monitored entry
113      */

114     long getLastReloadedTimeStamp() {
115         return this.lastReloadedAt;
116     }
117
118     /**
119      * Returns the listener for this entry
120      *
121      * @return the listener for this entry
122      */

123     MonitorListener getListener() {
124         return this.listener;
125     }
126
127     /**
128      * Returns the monitored file for this entry.
129      *
130      * @return the monitored file for this entry
131      */

132     File JavaDoc getMonitoredFile() {
133         return this.monitoredFile;
134     }
135
136     /**
137      * Sets the time stamp of last reload attempt.
138      *
139      * @param ts new time stamp
140      */

141     void setLastReloadedTimeStamp(long ts) {
142         this.lastReloadedAt = ts;
143     }
144             
145     /**
146      * Returns a hash code for this object.
147      *
148      * @return hash code for this object
149      */

150     public int hashCode() {
151         return id.hashCode();
152     }
153             
154     /**
155      * Indicates whether the given object is equal to this one.
156      *
157      * @return true if the given object is equal
158      */

159     public boolean equals(Object JavaDoc other) {
160         return monitoredFile.equals(((MonitorableEntry) other).monitoredFile);
161     }
162
163     // ---- INSTANCE VARIABLE(S) - PRIVATE --------------------------------
164
private String JavaDoc id;
165     private String JavaDoc displayName;
166     private File JavaDoc monitoredFile;
167     private long lastReloadedAt;
168     private MonitorListener listener;
169 }
170
Popular Tags