KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > activation > ProcessMonitorThread


1 /*
2  * @(#)ProcessMonitorThread.java 1.10 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.activation;
9
10 import java.util.*;
11 import com.sun.corba.se.impl.orbutil.ORBConstants;
12
13 /** ProcessMonitorThread is started when ServerManager is instantiated. The
14   * thread wakes up every minute (This can be changed by setting sleepTime) and
15   * makes sure that all the processes (Servers) registered with the ServerTool
16   * are healthy. If not the state in ServerTableEntry will be changed to
17   * De-Activated.
18   * Note: This thread can be killed from the main thread by calling
19   * interrupThread()
20   */

21 public class ProcessMonitorThread extends java.lang.Thread JavaDoc {
22     private HashMap serverTable;
23     private int sleepTime;
24     private static ProcessMonitorThread instance = null;
25
26     private ProcessMonitorThread( HashMap ServerTable, int SleepTime ) {
27         serverTable = ServerTable;
28         sleepTime = SleepTime;
29     }
30
31     public void run( ) {
32         while( true ) {
33             try {
34                 // Sleep's for a specified time, before checking
35
// the Servers health. This will repeat as long as
36
// the ServerManager (ORBD) is up and running.
37
Thread.sleep( sleepTime );
38             } catch( java.lang.InterruptedException JavaDoc e ) {
39                 break;
40             }
41             Iterator serverList;
42             synchronized ( serverTable ) {
43                 // Check each ServerTableEntry to make sure that they
44
// are in the right state.
45
serverList = serverTable.values().iterator();
46             }
47             try {
48                 checkServerHealth( serverList );
49             } catch( ConcurrentModificationException e ) {
50                 break;
51             }
52         }
53     }
54
55     private void checkServerHealth( Iterator serverList ) {
56         if( serverList == null ) return;
57         while (serverList.hasNext( ) ) {
58             ServerTableEntry entry = (ServerTableEntry) serverList.next();
59             entry.checkProcessHealth( );
60         }
61     }
62
63     static void start( HashMap serverTable ) {
64     int sleepTime = ORBConstants.DEFAULT_SERVER_POLLING_TIME;
65
66     String JavaDoc pollingTime = System.getProperties().getProperty(
67         ORBConstants.SERVER_POLLING_TIME );
68
69     if ( pollingTime != null ) {
70         try {
71         sleepTime = Integer.parseInt( pollingTime );
72         } catch (Exception JavaDoc e ) {
73         // Too late to complain, Just use the default
74
// sleepTime
75
}
76     }
77
78     instance = new ProcessMonitorThread( serverTable,
79         sleepTime );
80     instance.setDaemon( true );
81     instance.start();
82     }
83
84     static void interruptThread( ) {
85         instance.interrupt();
86     }
87 }
88  
89
Popular Tags