1. /*
  2. * @(#)file SnmpTimerServer.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 1.6
  5. * @(#)date 04/09/15
  6. *
  7. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  8. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  9. *
  10. */
  11. package com.sun.jmx.snmp.daemon;
  12. // import debug stuff
  13. //
  14. import com.sun.jmx.trace.Trace;
  15. /**
  16. * This class retries any timed out inform requests. This class is for internal use.
  17. */
  18. final class SnmpTimerServer extends Thread {
  19. // VARIABLES
  20. //----------
  21. private SnmpInformRequest req = null ;
  22. SnmpQManager snmpq = null ;
  23. String dbgTag = "SnmpTimerServer";
  24. // This boolean is used to stop handling requests while the corresponding SnmpQManager
  25. // is being destroyed.
  26. //
  27. boolean isBeingDestroyed = false;
  28. // CONSTRUCTORS
  29. //-------------
  30. public SnmpTimerServer (ThreadGroup grp, SnmpQManager q) {
  31. super(grp, "SnmpTimerServer") ;
  32. setName(dbgTag) ;
  33. snmpq = q ;
  34. start() ;
  35. }
  36. public synchronized void stopTimerServer() {
  37. if (isAlive()) {
  38. interrupt();
  39. try {
  40. // Wait until the thread die.
  41. //
  42. join();
  43. } catch (InterruptedException e) {
  44. // Ignore...
  45. }
  46. }
  47. }
  48. public void run() {
  49. Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
  50. if (isTraceOn()) {
  51. trace("run", "Timer Thread started");
  52. }
  53. while (true) {
  54. try {
  55. if (isTraceOn()) {
  56. trace("run", "Blocking for inform requests");
  57. }
  58. if (req == null) {
  59. req = snmpq.getTimeoutRequests() ;
  60. }
  61. if (req != null && req.inProgress()) {
  62. if (isTraceOn()) {
  63. trace("run", "Handle timeout inform request " + req.getRequestId());
  64. }
  65. req.action() ;
  66. req = null ;
  67. }
  68. if (isBeingDestroyed == true)
  69. break;
  70. } catch (Exception e) {
  71. if (isDebugOn()) {
  72. debug("run", e.getMessage());
  73. }
  74. } catch (ThreadDeath d) {
  75. if (isDebugOn()) {
  76. debug("run", "Timer server unexpectedly shutting down");
  77. debug("run", d);
  78. }
  79. throw d ;
  80. } catch (OutOfMemoryError ome) {
  81. if (isDebugOn()) {
  82. debug("run", "Received OutOfMemory");
  83. }
  84. yield();
  85. } catch (Error err) {
  86. if (isDebugOn()) {
  87. debug("run", "Received Internal error");
  88. debug("run", err);
  89. }
  90. }
  91. }
  92. }
  93. // TRACES & DEBUG
  94. //---------------
  95. boolean isTraceOn() {
  96. return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP);
  97. }
  98. void trace(String clz, String func, String info) {
  99. Trace.send(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP, clz, func, info);
  100. }
  101. void trace(String func, String info) {
  102. trace(dbgTag, func, info);
  103. }
  104. boolean isDebugOn() {
  105. return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP);
  106. }
  107. void debug(String clz, String func, String info) {
  108. Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, info);
  109. }
  110. void debug(String clz, String func, Throwable exception) {
  111. Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, exception);
  112. }
  113. void debug(String func, String info) {
  114. debug(dbgTag, func, info);
  115. }
  116. void debug(String func, Throwable exception) {
  117. debug(dbgTag, func, exception);
  118. }
  119. }