Example usage for javax.management ObjectName ObjectName

List of usage examples for javax.management ObjectName ObjectName

Introduction

In this page you can find the example usage for javax.management ObjectName ObjectName.

Prototype

public ObjectName(String name) throws MalformedObjectNameException 

Source Link

Document

Construct an object name from the given string.

Usage

From source file:com.exxatools.monitoring.jmx.JmxStats.java

public void setObjectName(String objectName) throws MalformedObjectNameException {
    this.objectName = new ObjectName(objectName);
}

From source file:org.ff4j.jmx.FF4JMBeanTest.java

@Test
public void should_retrieve_changed_features_status() throws Exception {
    ff4j.enable("jmxDisabledFeature");
    ObjectName objectName = new ObjectName(FF4J_OBJECT_NAME);
    @SuppressWarnings("unchecked")
    Map<String, Boolean> fs = (Map<String, Boolean>) mbServConn.getAttribute(objectName, "FeaturesStatus");
    Assert.assertTrue(fs.containsKey("jmxEnabledFeature"));
    Assert.assertFalse(fs.get("jmxEnabledFeature"));
    Assert.assertTrue(fs.containsKey("jmxDisabledFeature"));
    Assert.assertTrue(fs.get("jmxDisabledFeature"));
    Assert.assertTrue(fs.containsKey("jmxFeatureWithAuth"));
    Assert.assertFalse(fs.get("jmxFeatureWithAuth"));
    Assert.assertEquals(3, fs.size());//from   www . j a v  a 2 s  .c  o  m
}

From source file:com.neophob.sematrix.jmx.PixelControllerStatus.java

/**
 * Register the JMX Bean.//from w  w w .j a  va 2s. com
 *
 * @param configuredFps the configured fps
 */
public PixelControllerStatus(int configuredFps) {
    LOG.log(Level.INFO, "Initialize the PixelControllerStatus JMX Bean");

    this.configuredFps = configuredFps;

    // initialize all buffers 
    this.timeMeasureMapGlobal = new ConcurrentHashMap<TimeMeasureItemGlobal, CircularFifoBuffer>();
    for (TimeMeasureItemGlobal timeMeasureItem : TimeMeasureItemGlobal.values()) {
        this.timeMeasureMapGlobal.put(timeMeasureItem, new CircularFifoBuffer(this.configuredFps * SECONDS));
    }
    this.timeMeasureMapOutput = new ConcurrentHashMap<Output, Map<TimeMeasureItemOutput, CircularFifoBuffer>>();
    this.outputList = new ArrayList<Output>();

    startTime = System.currentTimeMillis();

    // register MBean
    try {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = new ObjectName(JMX_BEAN_NAME);
        // check if the MBean is already registered
        if (!server.isRegistered(name)) {
            server.registerMBean(this, name);
        }
    } catch (JMException ex) {
        LOG.log(Level.WARNING, "Error while registering class as JMX Bean.", ex);
    }
}

From source file:fr.openfarm.jmx.service.JMXQuery.java

@Override
public String getJmxData(String name, String attributeName, String key)
        throws MalformedObjectNameException, NullPointerException, AttributeNotFoundException,
        InstanceNotFoundException, MBeanException, ReflectionException, IOException {
    ObjectName objectName = new ObjectName(name);
    Set<ObjectName> objectNameList = connection.queryNames(objectName, null);
    if (objectNameList != null && objectNameList.size() > 0) {
        objectName = objectNameList.iterator().next();
        Object attr = connection.getAttribute(objectName, attributeName);
        if (attr instanceof CompositeDataSupport) {
            CompositeDataSupport cds = (CompositeDataSupport) attr;
            if (key == null) {
                throw new IllegalArgumentException("Key is null for composed data " + name);
            }//from  ww  w.  j  av  a  2  s  .  co  m
            return cds.get(key).toString();

        } else {
            return attr.toString();
        }
    }
    return null;
}

From source file:com.oracle.osgi.jmx.Activator.java

public void start(BundleContext bundleContext) throws Exception {
    this.bundleContext = bundleContext;
    frameworkName = new ObjectName(FRAMEWORK);
    bundlesStateName = new ObjectName(BUNDLE_STATE);
    serviceStateName = new ObjectName(SERVICE_STATE);
    packageStateName = new ObjectName(PACKAGE_STATE);

    mbeanServiceTracker = new ServiceTracker(bundleContext, MBeanServer.class.getCanonicalName(),
            new MBeanServiceTracker());
    log.debug("Awaiting MBeanServer service registration");
    mbeanServiceTracker.open();/*from  ww  w.j  a  v a2  s . c o  m*/
}

From source file:com.nabla.project.application.core.spring.ExtractionScope.java

/**
 * DOCUMENT ME!//from  w  w  w.  ja  v  a2 s.  co  m
 * 
 * @param beanName DOCUMENT ME!
 * @param objectFactory DOCUMENT ME!
 * @return DOCUMENT ME!
 */
public Object get(String beanName, ObjectFactory objectFactory) {

    RequestId requestId = (RequestId) extractionId.get();

    if (logger.isDebugEnabled()) {

        logger.debug(
                new StringBuffer().append("get(").append(beanName).append(") extractionId=").append(requestId));

    }

    Map<String, Object> beansMap = scopeMaps.get(requestId);

    if (beansMap == null) {

        beansMap = new HashMap<String, Object>();
        scopeMaps.put(requestId, beansMap);

    }

    Object bean = beansMap.get(beanName);

    if (bean == null) {

        if (AbstractConfig.beanRequestIdName.equals(beanName)) {

            bean = requestId;

        } else {

            bean = objectFactory.getObject();

        }

        beansMap.put(beanName, bean);

        try {

            ObjectName name = new ObjectName(getJmxObjectName(beanName, requestId));

            mbs.registerMBean(bean, name);

            if (logger.isDebugEnabled()) {
                logger.debug("JMX registration done for " + name);
            }

        } catch (Exception ex) {

            logger.warn(ex);

        }

    }

    return bean;

}

From source file:com.googlecode.arit.mbeans.MBeanScanner.java

public void clean(ClassLoader classLoader) {
    ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null);
    for (MBeanServer mbs : mbeanServers) {
        MBeanAccessor mbeanAccessor = mbsInspector.inspect(mbs);
        if (mbeanAccessor == null) {
            String errorMsg = "Unable to inspect MBeanServer of type " + mbs.getClass().getName();
            LOG.error(errorMsg);// w w  w  .j  ava2  s  . c  om
            if (messages != null) {
                messages.addMessage(errorMsg);
            }
        } else {
            Set<ObjectName> mbeans;
            try {
                mbeans = mbs.queryNames(new ObjectName("*:*"), null);
            } catch (MalformedObjectNameException ex) {
                // We should never get here
                throw new Error(ex);
            }

            for (ObjectName name : mbeans) {
                Object mbean = mbeanAccessor.retrieve(name);
                if (mbean.getClass().getClassLoader().equals(classLoader)) {
                    try {
                        mbs.unregisterMBean(name);
                    } catch (JMException ex) {
                        String errorMsg = "Error during cleanup of mbean - unregistration of mbean "
                                + name.toString() + " failed";
                        LOG.error(errorMsg, ex);
                        if (messages != null) {
                            messages.addMessage(errorMsg);
                        }
                    }
                }
            }
        }
    }
}

From source file:com.uber.stream.kafka.chaperone.collector.KafkaIngesterConsumer.java

private void init() {
    // register kafka offset lag metrics, one Gauge is for per consumer level granularity
    MetricRegistry registry = Metrics.getRegistry();
    try {/*  w ww  .ja va2s . com*/
        fetchedMsgCounter = registry.meter("kafkaIngesterConsumer." + this.getName() + "-msgFetchRate");
        failedToIngestCounter = registry.meter("kafkaIngesterConsumer." + this.getName() + "-failedToIngest");
        kafkaOffsetLagGauge = registry.register("kafkaIngesterConsumer." + this.getName() + "-kafkaOffsetLag",
                new JmxAttributeGauge(new ObjectName(maxLagMetricName), "Value"));
    } catch (MalformedObjectNameException | IllegalArgumentException e) {
        logger.error("Register failure for metrics of KafkaIngesterConsumer", e);
    }

    TopicFilter topicFilter = new Whitelist(AuditConfig.AUDIT_TOPIC_NAME);
    logger.info("{}: Topic filter is {}", getName(), AuditConfig.AUDIT_TOPIC_NAME);
    this.consumer = Consumer.createJavaConsumerConnector(createConsumerConfig());
    KafkaStream<byte[], byte[]> stream = consumer.createMessageStreamsByFilter(topicFilter, 1).get(0);
    iterator = stream.iterator();
    logger.info("KafkaIngesterConsumer thread {} is initialized successfully", getName());

    if (AuditConfig.INGESTER_ENABLE_DEDUP) {
        deduplicator = new Deduplicator(threadId, AuditConfig.INGESTER_REDIS_HOST,
                AuditConfig.INGESTER_REDIS_PORT, AuditConfig.INGESTER_REDIS_KEY_TTL_SEC,
                AuditConfig.INGESTER_DUP_HOST_PREFIX, AuditConfig.INGESTER_HOSTS_WITH_DUP);
        deduplicator.open();
    } else {
        deduplicator = null;
    }
}

From source file:com.mtgi.analytics.aop.config.v11.XmlPersisterConfigurationTest.java

@Test
public void testXmlPersisterConfiguration() throws Exception {
    assertNotNull("custom tracking manager configured", xmlTracking);
    assertEquals("application name set", "testApp", xmlTracking.getApplication());
    assertEquals("correct persister type provided", XmlBehaviorEventPersisterImpl.class,
            xmlTracking.getPersister().getClass());

    XmlBehaviorEventPersisterImpl persister = (XmlBehaviorEventPersisterImpl) xmlTracking.getPersister();
    assertFalse("default setting overridden", persister.isBinary());
    assertFalse("default setting overridden", persister.isCompress());

    File location = new File(persister.getFile());
    assertTrue("custom file name [" + persister.getFile() + "]", location.getName().startsWith("xml-tracking"));
    assertEquals("custom XML attributes can be post-processed by property resolver",
            new File(System.getProperty("java.io.tmpdir")).getCanonicalPath(),
            location.getParentFile().getCanonicalPath());

    TaskExecutor executor = xmlTracking.getExecutor();
    assertSame("application executor is used", testExecutor, executor);

    List<String> triggers = Arrays.asList(testScheduler.getTriggerNames("beet"));
    assertEquals("flush and rotate jobs scheduled in application scheduler", 2, triggers.size());
    assertTrue("flush job scheduled", triggers.contains("xmlTracking_flush_trigger"));
    assertTrue("rotate job scheduled",
            triggers.contains("org.springframework.scheduling.quartz.CronTriggerBean_rotate_trigger"));

    SchedulerFactory factory = new StdSchedulerFactory();
    assertEquals("private scheduler was not created", 1, factory.getAllSchedulers().size());
    assertSame(testScheduler, factory.getAllSchedulers().iterator().next());

    //verify that MBeans have been registered
    MBeanServer server = JmxUtils.locateMBeanServer();
    assertNotNull("manager mbean found", server.getMBeanInfo(
            new ObjectName("testApp:package=com.mtgi.analytics,group=xmlTracking,name=BeetManager")));
    ObjectName logName = new ObjectName("testApp:package=com.mtgi.analytics,group=xmlTracking,name=BeetLog");
    assertNotNull("log mbean found", server.getMBeanInfo(logName));

    assertEquals(persister.getFileSize(), server.getAttribute(logName, "FileSize"));
}

From source file:org.red5.server.scheduling.ApplicationSchedulingService.java

protected void registerJMX() {
    //register with jmx server
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    try {//from  w w w. j  a  va 2s.  c o m
        ObjectName oName = null;
        if (instanceId == null) {
            oName = new ObjectName(
                    "org.red5.server:type=ApplicationSchedulingService,applicationName=" + applicationName);
        } else {
            oName = new ObjectName("org.red5.server:type=ApplicationSchedulingService,applicationName="
                    + applicationName + ",instanceId=" + instanceId);
        }
        mbeanServer.registerMBean(new StandardMBean(this, QuartzSchedulingServiceMXBean.class, true), oName);
    } catch (Exception e) {
        log.warn("Error on jmx registration", e);
    }
}