1. /*
  2. * @(#)ProcessMonitorThread.java 1.7 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.Activation;
  8. import java.util.*;
  9. import com.sun.corba.se.internal.orbutil.ORBConstants;
  10. /** ProcessMonitorThread is started when ServerManager is instantiated. The
  11. * thread wakes up every minute (This can be changed by setting sleepTime) and
  12. * makes sure that all the processes (Servers) registered with the ServerTool
  13. * are healthy. If not the state in ServerTableEntry will be changed to
  14. * De-Activated.
  15. * Note: This thread can be killed from the main thread by calling
  16. * interrupThread()
  17. */
  18. public class ProcessMonitorThread extends java.lang.Thread {
  19. private HashMap serverTable;
  20. private int sleepTime;
  21. private static ProcessMonitorThread instance = null;
  22. private ProcessMonitorThread( HashMap ServerTable, int SleepTime ) {
  23. serverTable = ServerTable;
  24. sleepTime = SleepTime;
  25. }
  26. public void run( ) {
  27. while( true ) {
  28. try {
  29. // Sleep's for a specified time, before checking
  30. // the Servers health. This will repeat as long as
  31. // the ServerManager (ORBD) is up and running.
  32. Thread.sleep( sleepTime );
  33. } catch( java.lang.InterruptedException e ) {
  34. break;
  35. }
  36. synchronized ( serverTable ) {
  37. // Check each ServerTableEntry to make sure that they
  38. // are in the right state.
  39. Iterator serverList = serverTable.values().iterator();
  40. checkServerHealth( serverList );
  41. }
  42. }
  43. }
  44. private void checkServerHealth( Iterator serverList ) {
  45. while (serverList.hasNext( ) ) {
  46. ServerTableEntry entry = (ServerTableEntry) serverList.next();
  47. entry.checkProcessHealth( );
  48. }
  49. }
  50. static void start( HashMap serverTable ) {
  51. int sleepTime = ORBConstants.DEFAULT_SERVER_POLLING_TIME;
  52. String pollingTime = System.getProperties().getProperty(
  53. ORBConstants.SERVER_POLLING_TIME );
  54. if ( pollingTime != null ) {
  55. try {
  56. sleepTime = Integer.parseInt( pollingTime );
  57. } catch (Exception e ) {
  58. // Too late to complain, Just use the default
  59. // sleepTime
  60. }
  61. }
  62. instance = new ProcessMonitorThread( serverTable,
  63. sleepTime );
  64. instance.setDaemon( true );
  65. instance.start();
  66. }
  67. static void interruptThread( ) {
  68. instance.interrupt();
  69. }
  70. }