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. package com.sun.corba.se.impl.activation;
  8. import java.util.*;
  9. import com.sun.corba.se.impl.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. Iterator serverList;
  37. synchronized ( serverTable ) {
  38. // Check each ServerTableEntry to make sure that they
  39. // are in the right state.
  40. serverList = serverTable.values().iterator();
  41. }
  42. try {
  43. checkServerHealth( serverList );
  44. } catch( ConcurrentModificationException e ) {
  45. break;
  46. }
  47. }
  48. }
  49. private void checkServerHealth( Iterator serverList ) {
  50. if( serverList == null ) return;
  51. while (serverList.hasNext( ) ) {
  52. ServerTableEntry entry = (ServerTableEntry) serverList.next();
  53. entry.checkProcessHealth( );
  54. }
  55. }
  56. static void start( HashMap serverTable ) {
  57. int sleepTime = ORBConstants.DEFAULT_SERVER_POLLING_TIME;
  58. String pollingTime = System.getProperties().getProperty(
  59. ORBConstants.SERVER_POLLING_TIME );
  60. if ( pollingTime != null ) {
  61. try {
  62. sleepTime = Integer.parseInt( pollingTime );
  63. } catch (Exception e ) {
  64. // Too late to complain, Just use the default
  65. // sleepTime
  66. }
  67. }
  68. instance = new ProcessMonitorThread( serverTable,
  69. sleepTime );
  70. instance.setDaemon( true );
  71. instance.start();
  72. }
  73. static void interruptThread( ) {
  74. instance.interrupt();
  75. }
  76. }