1 /* 2 * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.corba.se.impl.activation; 27 28 import java.util.*; 29 import com.sun.corba.se.impl.orbutil.ORBConstants; 30 31 /** ProcessMonitorThread is started when ServerManager is instantiated. The 32 * thread wakes up every minute (This can be changed by setting sleepTime) and 33 * makes sure that all the processes (Servers) registered with the ServerTool 34 * are healthy. If not the state in ServerTableEntry will be changed to 35 * De-Activated. 36 * Note: This thread can be killed from the main thread by calling 37 * interrupThread() 38 */ 39 public class ProcessMonitorThread extends java.lang.Thread { 40 private HashMap serverTable; 41 private int sleepTime; 42 private static ProcessMonitorThread instance = null; 43 44 private ProcessMonitorThread( HashMap ServerTable, int SleepTime ) { 45 serverTable = ServerTable; 46 sleepTime = SleepTime; 47 } 48 49 public void run( ) { 50 while( true ) { 51 try { 52 // Sleep's for a specified time, before checking 53 // the Servers health. This will repeat as long as 54 // the ServerManager (ORBD) is up and running. 55 Thread.sleep( sleepTime ); 56 } catch( java.lang.InterruptedException e ) { 57 break; 58 } 59 Iterator serverList; 60 synchronized ( serverTable ) { 61 // Check each ServerTableEntry to make sure that they 62 // are in the right state. 63 serverList = serverTable.values().iterator(); 64 } 65 try { 66 checkServerHealth( serverList ); 67 } catch( ConcurrentModificationException e ) { 68 break; 69 } 70 } 71 } 72 73 private void checkServerHealth( Iterator serverList ) { 74 if( serverList == null ) return; 75 while (serverList.hasNext( ) ) { 76 ServerTableEntry entry = (ServerTableEntry) serverList.next(); 77 entry.checkProcessHealth( ); 78 } 79 } 80 81 static void start( HashMap serverTable ) { 82 int sleepTime = ORBConstants.DEFAULT_SERVER_POLLING_TIME; 83 84 String pollingTime = System.getProperties().getProperty( 85 ORBConstants.SERVER_POLLING_TIME ); 86 87 if ( pollingTime != null ) { 88 try { 89 sleepTime = Integer.parseInt( pollingTime ); 90 } catch (Exception e ) { 91 // Too late to complain, Just use the default 92 // sleepTime 93 } 94 } 95 96 instance = new ProcessMonitorThread( serverTable, 97 sleepTime ); 98 instance.setDaemon( true ); 99 instance.start(); 100 } 101 102 static void interruptThread( ) { 103 instance.interrupt(); 104 } 105 }