KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > ManualChangeTracker


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 package com.sun.enterprise.admin.server.core;
24
25
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28
29 import com.sun.enterprise.admin.common.constant.AdminConstants;
30 import com.sun.enterprise.instance.ServerManager;
31 import com.sun.enterprise.instance.InstanceEnvironment;
32
33 /**
34  * This class provides a manager for tracking manual changes.
35  * A thread runs every so often and collects info about a server
36  * and updates its static variable.
37  *
38  * Whenever there is a request from user, we check only the variable
39  * to determine if there has been manual changes.
40  *
41  * @author Sridatta Viswanath
42  */

43
44 public final class ManualChangeTracker
45 {
46     /**
47      * Logger for admin service
48      */

49     static Logger JavaDoc logger = Logger.getLogger(AdminConstants.kLoggerName);
50        
51     /*
52      * Default sleep period for the thread is 2 minutes
53      */

54     private static int sleepPeriod = 120000; //2 minutes
55

56     //TODO: initialize from server.xml property
57
/*
58     static {
59         try {
60             //initialize sleep period from server.xml
61             // Get ConfigContext
62             // get admin service
63             // get property element called manual-changes-sleep-period in admin-service
64             // initialize sleepPeriod to this value
65         } catch(Throwable t) {
66             //ignore errors
67         }
68     }
69      */

70     
71     /*
72      * pointer to the thread for housekeeping
73      */

74     private static TrackerThread trackerThread = null;
75
76     /**
77      * called from admin service during initialization
78      * package specific
79      */

80     static void start() {
81         logger.log(Level.FINE, "core.tracker_thread_starting");
82         trackerThread = new TrackerThread();
83         trackerThread.start();
84     }
85     
86     /**
87      * called from AdminService during shutdown.
88      * thread.destroy() is bad
89      * thread.stop() is deprecated.
90      * making trakerThread null is an elegant and preferred way of cleaning up the thread
91      * Note that the while loop in the thread checks for null!
92      */

93     static void stop() {
94         trackerThread = null;
95         logger.log(Level.FINE, "core.tracker_thread_stopping");
96     }
97    
98     private static class TrackerThread extends Thread JavaDoc
99     {
100     private static final int SLEEPTIME = sleepPeriod;
101
102     public void run()
103     {
104        Thread JavaDoc t = Thread.currentThread();
105            
106            while (t == trackerThread) {
107         try {
108                     sleep(SLEEPTIME);
109         } catch ( InterruptedException JavaDoc ex ) {}
110
111         try {
112                     
113                     String JavaDoc[] instanceIds = ServerManager.instance().getInstanceNames(false);
114                     for (int i = 0 ; i < instanceIds.length ; i ++) {
115                         try {
116                             String JavaDoc instanceId = instanceIds[i];
117                             InstanceEnvironment ie = new InstanceEnvironment(instanceId);
118                             ManualChangeStatus mcs = new ManualChangeStatus();
119
120                             /* TOMCAT_BEGIN Ramakanth */
121                             mcs.setServerXmlFileChanged(
122                                 ie.hasHotXmlChanged());
123                             mcs.setRealmsKeyFileChanged(
124                                 ie.hasHotRealmsKeyChanged());
125                             /* TOMCAT_END Ramakanth */
126                             logger.log(Level.FINE, "Got Manual Change status for "+ instanceId);
127                             logger.log(Level.FINEST,"-------------------------------------");
128                             logger.log(Level.FINEST,mcs.toString());
129                             logger.log(Level.FINEST,"------------------------------------");
130                             ManualChangeManager.addManualChangeStatus(instanceId, mcs); // not synchronized.
131

132                             // If there are multiple threads, this thread should not take up the cpu all the time.
133
// just a prevention. note, if it is a multi-processor machine, jdk1.4 allows this thread
134
// to run on another cpu.
135
sleep(2000); //rest for 2 seconds.
136
}
137                         catch (Exception JavaDoc e) {
138                             //Log the exception for this instance.
139
// what can we do if there is an exception?
140
// just log and continue.
141
logger.log(Level.WARNING, "core.error_getting_manual_changes", e);
142                         }
143                     }
144                     
145         } catch ( Exception JavaDoc ex ) {}
146         }
147     }
148     }
149 }
150
Popular Tags