Java源码示例:com.codahale.metrics.jmx.ObjectNameFactory
示例1
public static void setupJMXReporter(Bus b, MetricRegistry reg) {
InstrumentationManager im = b.getExtension(InstrumentationManager.class);
if (im != null) {
JmxReporter reporter = JmxReporter.forRegistry(reg).registerWith(im.getMBeanServer())
.inDomain("org.apache.cxf")
.createsObjectNamesWith(new ObjectNameFactory() {
public ObjectName createName(String type, String domain, String name) {
try {
return new ObjectName(name);
} catch (MalformedObjectNameException e) {
throw new RuntimeException(e);
}
}
})
.build();
reporter.start();
}
}
示例2
public Builder createsObjectNamesWith(ObjectNameFactory onFactory) {
if(onFactory == null) {
throw new IllegalArgumentException("null objectNameFactory");
}
this.objectNameFactory = onFactory;
return this;
}
示例3
private JmxListener(MBeanServer mBeanServer, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit,
ObjectNameFactory objectNameFactory, String tag) {
this.mBeanServer = mBeanServer;
this.name = name;
this.filter = filter;
this.rateUnit = rateUnit;
this.durationUnit = durationUnit;
this.registered = new ConcurrentHashMap<>();
this.objectNameFactory = objectNameFactory;
this.tag = tag;
this.exp = Query.eq(Query.attr(INSTANCE_TAG), Query.value(tag));
}
示例4
private JmxMetricsReporter(MBeanServer mBeanServer,
String domain,
MetricRegistry registry,
MetricFilter filter,
TimeUnit rateUnit,
TimeUnit durationUnit,
ObjectNameFactory objectNameFactory,
String tag) {
this.registry = registry;
this.listener = new JmxListener(mBeanServer, domain, filter, rateUnit, durationUnit, objectNameFactory, tag);
}