1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.component.jmx; |
18 |
|
|
19 |
|
import javax.management.MBeanServer; |
20 |
|
import javax.management.Notification; |
21 |
|
import javax.management.ObjectName; |
22 |
|
import javax.management.monitor.CounterMonitor; |
23 |
|
import org.apache.camel.Consumer; |
24 |
|
import org.apache.camel.Processor; |
25 |
|
import org.apache.camel.Producer; |
26 |
|
import org.apache.camel.impl.DefaultEndpoint; |
27 |
|
import org.apache.commons.logging.Log; |
28 |
|
import org.apache.commons.logging.LogFactory; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
0 |
public class JMXEndpoint extends DefaultEndpoint<JMXExchange> { |
36 |
|
|
37 |
0 |
private static final Log LOG = LogFactory.getLog(JMXEndpoint.class); |
38 |
|
private String name; |
39 |
|
private ObjectName ourName; |
40 |
|
private String observedObjectName; |
41 |
|
private String attributeName; |
42 |
0 |
private long granularityPeriod = 5000; |
43 |
|
private Number threshold; |
44 |
|
private Number offset; |
45 |
|
private MBeanServer mbeanServer; |
46 |
0 |
private CounterMonitor counterMonitor = new CounterMonitor(); |
47 |
|
|
48 |
|
protected JMXEndpoint(String endpointUri, JMXComponent component) { |
49 |
0 |
super(endpointUri, component); |
50 |
0 |
observedObjectName = endpointUri; |
51 |
0 |
} |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
public Producer<JMXExchange> createProducer() throws Exception { |
59 |
0 |
throw new RuntimeException("Not supported"); |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
public Consumer<JMXExchange> createConsumer(Processor proc) throws Exception { |
69 |
0 |
ObjectName observedName = new ObjectName(observedObjectName); |
70 |
0 |
if (name == null) { |
71 |
0 |
String type = observedName.getKeyProperty("type"); |
72 |
0 |
type = type != null ? type : "UNKNOWN"; |
73 |
0 |
name = mbeanServer.getDefaultDomain() + ":type=CounterMonitor_" + type; |
74 |
|
} |
75 |
0 |
JMXConsumer result = new JMXConsumer(this, proc); |
76 |
0 |
ourName = new ObjectName(name); |
77 |
0 |
counterMonitor.setNotify(true); |
78 |
0 |
counterMonitor.addObservedObject(observedName); |
79 |
0 |
counterMonitor.setObservedAttribute(attributeName); |
80 |
0 |
counterMonitor.setGranularityPeriod(granularityPeriod); |
81 |
0 |
counterMonitor.setDifferenceMode(false); |
82 |
0 |
counterMonitor.setInitThreshold(threshold); |
83 |
0 |
counterMonitor.setOffset(offset); |
84 |
0 |
mbeanServer.registerMBean(counterMonitor, ourName); |
85 |
0 |
mbeanServer.addNotificationListener(ourName, result, null, new Object()); |
86 |
0 |
return result; |
87 |
|
} |
88 |
|
|
89 |
|
public boolean isSingleton() { |
90 |
0 |
return true; |
91 |
|
} |
92 |
|
|
93 |
|
public JMXExchange createExchange(Notification notification) { |
94 |
0 |
return new JMXExchange(getContext(), notification); |
95 |
|
} |
96 |
|
|
97 |
|
public JMXExchange createExchange() { |
98 |
0 |
return new JMXExchange(getContext(), null); |
99 |
|
} |
100 |
|
|
101 |
|
public String getAttributeName() { |
102 |
0 |
return attributeName; |
103 |
|
} |
104 |
|
|
105 |
|
public void setAttributeName(String attributeName) { |
106 |
0 |
this.attributeName = attributeName; |
107 |
0 |
} |
108 |
|
|
109 |
|
public long getGranularityPeriod() { |
110 |
0 |
return granularityPeriod; |
111 |
|
} |
112 |
|
|
113 |
|
public void setGranularityPeriod(long granularityPeriod) { |
114 |
0 |
this.granularityPeriod = granularityPeriod; |
115 |
0 |
} |
116 |
|
|
117 |
|
public String getName() { |
118 |
0 |
return name; |
119 |
|
} |
120 |
|
|
121 |
|
public void setName(String name) { |
122 |
0 |
this.name = name; |
123 |
0 |
} |
124 |
|
|
125 |
|
public Number getOffset() { |
126 |
0 |
return offset; |
127 |
|
} |
128 |
|
|
129 |
|
public void setOffset(Number offset) { |
130 |
0 |
this.offset = offset; |
131 |
0 |
} |
132 |
|
|
133 |
|
public Number getThreshold() { |
134 |
0 |
return threshold; |
135 |
|
} |
136 |
|
|
137 |
|
public void setThreshold(Number threshold) { |
138 |
0 |
this.threshold = threshold; |
139 |
0 |
} |
140 |
|
|
141 |
|
public MBeanServer getMbeanServer() { |
142 |
0 |
return mbeanServer; |
143 |
|
} |
144 |
|
|
145 |
|
public void setMbeanServer(MBeanServer mbeanServer) { |
146 |
0 |
this.mbeanServer = mbeanServer; |
147 |
0 |
} |
148 |
|
} |