Example usage for javax.management ObjectName getInstance

List of usage examples for javax.management ObjectName getInstance

Introduction

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

Prototype

public static ObjectName getInstance(ObjectName name) 

Source Link

Document

Return an instance of ObjectName that can be used anywhere the given object can be used.

Usage

From source file:com.proofpoint.reporting.TestReportClient.java

@BeforeMethod
public void setup() throws MalformedObjectNameException {
    nodeInfo = new NodeInfo("test-application", new NodeConfig().setEnvironment("test_environment")
            .setNodeInternalHostname("test.hostname").setPool("test_pool"));

    collectedData = HashBasedTable.create();
    collectedData.put(ObjectName.getInstance("com.example:name=Foo"), "Size", 1.1);
    collectedData.put(ObjectName.getInstance("com.example:type=Foo,name=\"ba:r\",tag1=\"B\\\\a\\\"z\""), "Size",
            1.2);/*from   w ww .  ja  v a 2 s .c o  m*/

    httpClient = new TestingHttpClient(new TestingResponseFunction());
    sentJson = null;
}

From source file:org.jboss.test.cluster.defaultcfg.web.test.CleanShutdownTestCase.java

/**
 * @see org.jboss.test.JBossClusteredTestCase#setUp()
 *///w w w .ja  v  a  2  s  .c o  m
@Override
protected void setUp() throws Exception {
    super.setUp();

    this.name = ObjectName.getInstance(SERVER_NAME);
    this.server = this.getAdaptors()[0];
    this.baseURL = this.getHttpURLs()[0];

    this.manager = new MultiThreadedHttpConnectionManager();

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(MAX_THREADS);
    params.setMaxTotalConnections(MAX_THREADS);

    this.manager.setParams(params);

    this.client = new HttpClient();
}

From source file:com.mtgi.jmx.export.naming.AppendNamingStrategyTest.java

@Test
public void testPackage() throws MalformedObjectNameException {

    Object inst = new XmlBehaviorEventPersisterImpl();
    String beanName = "aName";

    ObjectNamingStrategy mock = createMock(ObjectNamingStrategy.class);
    expect(mock.getObjectName(inst, beanName))
            .andReturn(ObjectName.getInstance("topLevel:package=com.mtgi.analytics,group=stuff,name=foobar"))
            .once();/*from   ww  w.  j  a  va2 s  .c  o m*/
    replay(mock);

    AppendNamingStrategy ans = new AppendNamingStrategy();
    ans.setDelegate(mock);
    ans.setValue("testPersister");
    ans.setDomain("testApplication");

    ObjectName name = ans.getObjectName(inst, beanName);
    assertNotNull("name is constructed", name);
    assertEquals("name has been transformed correctly",
            "testApplication:package=com.mtgi.analytics.topLevel,group=stuff.foobar,name=testPersister",
            name.toString());
}

From source file:org.camelcookbook.monitoring.naming.JmxNamingContextSpringTest.java

@Test
public void testNamingContextSpring() throws Exception {
    final ManagementAgent managementAgent = context.getManagementStrategy().getManagementAgent();
    assertNotNull(managementAgent);/*from  ww  w  .ja v a 2s. co  m*/

    final MBeanServer mBeanServer = managementAgent.getMBeanServer();
    assertNotNull(mBeanServer);

    final String mBeanServerDefaultDomain = managementAgent.getMBeanServerDefaultDomain();
    assertEquals("org.apache.camel", mBeanServerDefaultDomain);

    final String managementName = context.getManagementName();
    assertNotNull("CamelContext should have a management name if JMX is enabled", managementName);
    LOG.info("managementName = {}", managementName);

    // Get the Camel Context MBean
    ObjectName onContext = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/"
            + managementName + ",type=context,name=\"" + context.getName() + "\"");
    assertTrue("Should be registered", mBeanServer.isRegistered(onContext));

    // Get the first Route MBean by id
    ObjectName onRoute1 = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/"
            + managementName + ",type=routes,name=\"first-route\"");
    LOG.info("Canonical Name = {}", onRoute1.getCanonicalName());
    assertTrue("Should be registered", mBeanServer.isRegistered(onRoute1));

    // Send a couple of messages to get some route statistics
    template.sendBody("direct:start", "Hello Camel");
    template.sendBody("direct:start", "Camel Rocks!");

    // Get an MBean attribute for the number of messages processed
    assertEquals(2L, mBeanServer.getAttribute(onRoute1, "ExchangesCompleted"));

    // Get the other Route MBean by id
    ObjectName onRoute2 = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/"
            + managementName + ",type=routes,name=\"other-route\"");
    assertTrue("Should be registered", mBeanServer.isRegistered(onRoute2));

    // Get an MBean attribute for the number of messages processed
    assertEquals(0L, mBeanServer.getAttribute(onRoute2, "ExchangesCompleted"));

    // Send some messages to the other route
    template.sendBody("direct:startOther", "Hello Other Camel");
    template.sendBody("direct:startOther", "Other Camel Rocks!");

    // Verify that the MBean statistics updated correctly
    assertEquals(2L, mBeanServer.getAttribute(onRoute2, "ExchangesCompleted"));

    // Check this routes running state
    assertEquals("Started", mBeanServer.getAttribute(onRoute2, "State"));

    // Stop the route via JMX
    mBeanServer.invoke(onRoute2, "stop", null, null);

    // verify the route now shows its state as stopped
    assertEquals("Stopped", mBeanServer.getAttribute(onRoute2, "State"));
}

From source file:com.lmig.cf.metrics.opsmetrics.OpsMetrics.java

public List<JmxMetric> getMetrics() throws OpsMetricsException {
    return execute(new JmxTemplate<List<JmxMetric>>() {
        @Override/*  w ww.  jav  a2s  . c om*/
        public List<JmxMetric> execute(MBeanServerConnection connection) throws Exception {
            ObjectName query = ObjectName.getInstance(WILDCARD_OBJECT_NAME);
            return searchForMetrics(connection, query);
        }
    });
}

From source file:com.adaptris.core.runtime.ChannelManager.java

private void initMembers() throws MalformedObjectNameException, CoreException {
    if (isEmpty(channel.getUniqueId())) {
        throw new CoreException("No UniqueID, this channel cannot be managed");
    }//  ww  w.j  a  va 2  s . c  om
    // Builds up a name com.adaptris:type=Channel, adapter=<adapter-id,>, id=<channel-id>
    myObjectName = ObjectName.getInstance(JMX_CHANNEL_TYPE + ADAPTER_PREFIX + parent.getUniqueId() + ID_PREFIX
            + getWrappedComponent().getUniqueId());
    for (Workflow c : channel.getWorkflowList()) {
        if (!isEmpty(c.getUniqueId())) {
            addChild(new WorkflowManager(c, this, true), true);
        }
    }
    addChildJmxComponentQuietly((ChildRuntimeInfoComponent) RuntimeInfoComponentFactory.create(this,
            channel.getMessageErrorHandler()));
    marshalConfig();
}

From source file:be.fgov.kszbcss.rhq.websphere.config.ConfigQueryServiceImpl.java

public ConfigQueryServiceImpl(String cacheName, File persistentFile, WebSphereServer server, String cell) {
    this.cell = cell;
    config = new CellConfiguration(server, cell);
    queryCache = new ConfigQueryCache(cacheName, config, persistentFile);
    epochPollExecutorService = Executors.newScheduledThreadPool(1,
            new NamedThreadFactory(cacheName + "-epoch-poll"));
    future = epochPollExecutorService.scheduleWithFixedDelay(this, 0, 30, TimeUnit.SECONDS);
    queryCache.start(2);//  w w  w  .j  a va  2s  .co m
    try {
        mbean = ManagementFactory.getPlatformMBeanServer().registerMBean(this, ObjectName
                .getInstance("rhq.websphere:type=ConfigQueryService,cell=" + cell + ",cacheName=" + cacheName));
    } catch (Throwable ex) {
        log.error("MBean registration failed", ex);
    }
}

From source file:com.adaptris.core.services.jmx.JmxWaitService.java

@Override
public void doService(AdaptrisMessage message) throws ServiceException {
    try {//w w  w.j a va  2s .  co  m
        MBeanServerConnection mbeanConn = getConnection().retrieveConnection(JmxConnection.class)
                .mbeanServerConnection();
        Object[] params = parametersToArray(message);
        String[] paramTypes = parametersToTypeArray(message);
        ObjectName objectNameInst = ObjectName.getInstance(message.resolve(getObjectName()));
        String operation = message.resolve(getOperationName());
        long sleepTime = retryInterval();
        boolean conditionReached = evaluate(
                getInvoker().invoke(mbeanConn, objectNameInst, operation, params, paramTypes));
        while (!conditionReached) {
            Thread.sleep(sleepTime);
            conditionReached = evaluate(
                    getInvoker().invoke(mbeanConn, objectNameInst, operation, params, paramTypes));
        }
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException(e);
    }
}

From source file:org.camelcookbook.monitoring.naming.JmxNamingPatternSpringTest.java

@Test
public void testNamingPatternSpring() throws Exception {
    final ManagementAgent managementAgent = context.getManagementStrategy().getManagementAgent();
    assertNotNull(managementAgent);//w w  w  . j  a  va 2s. c o  m

    final MBeanServer mBeanServer = managementAgent.getMBeanServer();
    assertNotNull(mBeanServer);

    final String mBeanServerDefaultDomain = managementAgent.getMBeanServerDefaultDomain();
    assertEquals("org.apache.camel", mBeanServerDefaultDomain);

    final String managementName = context.getManagementName();
    assertNotNull("CamelContext should have a management name if JMX is enabled", managementName);
    LOG.info("managementName = {}; name = {}", managementName, context.getName());
    assertTrue(managementName.startsWith("CustomName"));

    // Get the Camel Context MBean
    ObjectName onContext = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/"
            + managementName + ",type=context,name=\"" + context.getName() + "\"");
    assertTrue("Should be registered", mBeanServer.isRegistered(onContext));

    // Get the first Route MBean by id
    ObjectName onRoute1 = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/"
            + managementName + ",type=routes,name=\"first-route\"");
    LOG.info("Canonical Name = {}", onRoute1.getCanonicalName());
    assertTrue("Should be registered", mBeanServer.isRegistered(onRoute1));

    // Send a couple of messages to get some route statistics
    template.sendBody("direct:start", "Hello Camel");
    template.sendBody("direct:start", "Camel Rocks!");

    // Get an MBean attribute for the number of messages processed
    assertEquals(2L, mBeanServer.getAttribute(onRoute1, "ExchangesCompleted"));

    // Get the other Route MBean by id
    ObjectName onRoute2 = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/"
            + managementName + ",type=routes,name=\"other-route\"");
    assertTrue("Should be registered", mBeanServer.isRegistered(onRoute2));

    // Get an MBean attribute for the number of messages processed
    assertEquals(0L, mBeanServer.getAttribute(onRoute2, "ExchangesCompleted"));

    // Send some messages to the other route
    template.sendBody("direct:startOther", "Hello Other Camel");
    template.sendBody("direct:startOther", "Other Camel Rocks!");

    // Verify that the MBean statistics updated correctly
    assertEquals(2L, mBeanServer.getAttribute(onRoute2, "ExchangesCompleted"));

    // Check this routes running state
    assertEquals("Started", mBeanServer.getAttribute(onRoute2, "State"));

    // Stop the route via JMX
    mBeanServer.invoke(onRoute2, "stop", null, null);

    // verify the route now shows its state as stopped
    assertEquals("Stopped", mBeanServer.getAttribute(onRoute2, "State"));
}

From source file:com.adaptris.core.runtime.AdapterBuilder.java

public AdapterBuilder(AdapterRegistry owner, Properties cfg) throws MalformedObjectNameException {
    this();/*  www.jav  a 2s.c o  m*/
    parent = owner;
    this.config = new BootstrapProperties(cfg);
    runtimeVCS = loadVCS();
    boolean enableValidation = config.isEnabled(Constants.CFG_KEY_VALIDATE_CONFIG);
    if (enableValidation) {
        validatorFactory = Validation.buildDefaultValidatorFactory();
    }
    myObjectName = ObjectName
            .getInstance(JMX_OBJECT_PREFIX + Integer.toHexString(System.identityHashCode(cfg)));
}