1 11 12 13 package com.sun.jmx.snmp.daemon; 14 15 16 17 import java.io.*; 20 21 import javax.management.MBeanServer ; 24 import javax.management.ObjectName ; 25 26 import com.sun.jmx.trace.Trace; 29 30 34 35 abstract class ClientHandler implements Runnable { 36 37 public ClientHandler(CommunicatorServer server, int id, MBeanServer f, ObjectName n) { 38 adaptorServer = server ; 39 requestId = id ; 40 mbs = f ; 41 objectName = n ; 42 interruptCalled = false ; 43 dbgTag = makeDebugTag() ; 44 thread = createThread(this); 47 48 } 53 54 Thread createThread(Runnable r) { 56 return new Thread (this); 57 } 58 59 public void interrupt() { 60 if (isTraceOn()) { 61 trace("interrupt","start") ; 62 } 63 interruptCalled = true ; 64 if (thread != null) { 65 thread.interrupt() ; 66 } 67 if (isTraceOn()) { 68 trace("interrupt","end") ; 69 } 70 } 71 72 73 public void join() { 74 if (thread != null) { 75 try { 76 thread.join() ; 77 } 78 catch(InterruptedException x) { 79 } 80 } 81 } 82 83 public void run() { 84 85 try { 86 adaptorServer.notifyClientHandlerCreated(this) ; 90 91 doRun() ; 95 } 96 finally { 97 adaptorServer.notifyClientHandlerDeleted(this) ; 103 } 104 } 105 106 public abstract void doRun() ; 110 111 protected CommunicatorServer adaptorServer = null ; 112 protected int requestId = -1 ; 113 protected MBeanServer mbs = null ; 114 protected ObjectName objectName = null ; 115 protected Thread thread = null ; 116 protected boolean interruptCalled = false ; 117 protected String dbgTag = null ; 118 119 protected boolean isTraceOn() { 120 return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP); 121 } 122 123 protected void trace(String clz, String func, String info) { 124 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_ADAPTOR_SNMP, clz, func, info); 125 } 126 127 protected boolean isDebugOn() { 128 return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP); 129 } 130 131 protected void debug(String clz, String func, String info) { 132 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_ADAPTOR_SNMP, clz, func, info); 133 } 134 135 protected void trace(String func, String info) { 136 trace(dbgTag, func, info); 137 } 138 139 protected void debug(String func, String info) { 140 debug(dbgTag, func, info); 141 } 142 143 protected String makeDebugTag() { 144 return "ClientHandler[" + adaptorServer.getProtocol() + ":" + adaptorServer.getPort() + "][" + requestId + "]"; 145 } 146 } 147 | Popular Tags |