Lines 20-43
Link Here
|
20 |
import javax.management.ObjectName; |
20 |
import javax.management.ObjectName; |
21 |
import javax.management.MBeanServer; |
21 |
import javax.management.MBeanServer; |
22 |
import javax.management.MBeanServerFactory; |
22 |
import javax.management.MBeanServerFactory; |
23 |
import com.sun.jdmk.comm.HtmlAdaptorServer; |
|
|
24 |
|
23 |
|
25 |
import org.apache.log4j.Logger; |
24 |
import org.apache.log4j.Logger; |
26 |
|
25 |
|
|
|
26 |
import java.lang.reflect.InvocationTargetException; |
27 |
|
27 |
|
|
|
28 |
|
29 |
/** |
30 |
* Manages an instance of com.sun.jdmk.comm.HtmlAdapterServer which |
31 |
* was provided for demonstration purposes in the |
32 |
* Java Management Extensions Reference Implementation 1.2.1. |
33 |
* This class is provided to maintain compatibility with earlier |
34 |
* versions of log4j and use in new code is discouraged. |
35 |
* |
36 |
* @deprecated |
37 |
*/ |
28 |
public class Agent { |
38 |
public class Agent { |
29 |
|
39 |
|
|
|
40 |
/** |
41 |
* Diagnostic logger. |
42 |
* @deprecated |
43 |
*/ |
30 |
static Logger log = Logger.getLogger(Agent.class); |
44 |
static Logger log = Logger.getLogger(Agent.class); |
31 |
|
45 |
|
|
|
46 |
/** |
47 |
* Create new instance. |
48 |
*/ |
32 |
public Agent() { |
49 |
public Agent() { |
33 |
} |
50 |
} |
34 |
|
51 |
|
|
|
52 |
/** |
53 |
* Creates a new instance of com.sun.jdmk.comm.HtmlAdapterServer |
54 |
* using reflection. |
55 |
* |
56 |
* @since 1.2.16 |
57 |
* @return new instance. |
58 |
*/ |
59 |
private static Object createServer() { |
60 |
Object newInstance = null; |
61 |
try { |
62 |
newInstance = Class.forName( |
63 |
"com.sun.jdmk.comm.HtmlAdapterServer").newInstance(); |
64 |
} catch (ClassNotFoundException ex) { |
65 |
throw new NoClassDefFoundError(ex.toString()); |
66 |
} catch (IllegalAccessException ex) { |
67 |
throw new IllegalAccessError(ex.toString()); |
68 |
} catch (InstantiationException ex) { |
69 |
throw new InstantiationError(ex.toString()); |
70 |
} |
71 |
return newInstance; |
72 |
} |
35 |
|
73 |
|
36 |
public |
74 |
/** |
37 |
void start() { |
75 |
* Invokes HtmlAdapterServer.start() using reflection. |
|
|
76 |
* |
77 |
* @since 1.2.16 |
78 |
* @param server instance of com.sun.jdmk.comm.HtmlAdapterServer. |
79 |
*/ |
80 |
private static void startServer(final Object server) { |
81 |
try { |
82 |
server.getClass().getMethod("start", new Class[0]). |
83 |
invoke(server, new Object[0]); |
84 |
} catch(NoSuchMethodException ex) { |
85 |
throw new NoSuchMethodError(ex.toString()); |
86 |
} catch(IllegalAccessException ex) { |
87 |
throw new IllegalAccessError(ex.toString()); |
88 |
} catch(InvocationTargetException ex) { |
89 |
throw (RuntimeException) ex.getTargetException(); |
90 |
} |
91 |
} |
38 |
|
92 |
|
|
|
93 |
|
94 |
/** |
95 |
* Starts instance of HtmlAdapterServer. |
96 |
*/ |
97 |
public void start() { |
98 |
|
39 |
MBeanServer server = MBeanServerFactory.createMBeanServer(); |
99 |
MBeanServer server = MBeanServerFactory.createMBeanServer(); |
40 |
HtmlAdaptorServer html = new HtmlAdaptorServer(); |
100 |
Object html = createServer(); |
41 |
|
101 |
|
42 |
try { |
102 |
try { |
43 |
log.info("Registering HtmlAdaptorServer instance."); |
103 |
log.info("Registering HtmlAdaptorServer instance."); |
Lines 47-55
Link Here
|
47 |
server.registerMBean(hdm, new ObjectName("log4j:hiearchy=default")); |
107 |
server.registerMBean(hdm, new ObjectName("log4j:hiearchy=default")); |
48 |
|
108 |
|
49 |
} catch(Exception e) { |
109 |
} catch(Exception e) { |
50 |
log.error("Problem while regitering MBeans instances.", e); |
110 |
log.error("Problem while registering MBeans instances.", e); |
51 |
return; |
111 |
return; |
52 |
} |
112 |
} |
53 |
html.start(); |
113 |
startServer(html); |
54 |
} |
114 |
} |
55 |
} |
115 |
} |