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.adaptris.core.runtime.RetryMessageErrorHandlerMonitorTest.java

public void testMBean_FailMessageById() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    MockMessageProducer failProducer = new MockMessageProducer();
    RetryMessageErrorHandler handler = new RetryMessageErrorHandler(getName(),
            new StandaloneProducer(failProducer));
    adapter.setMessageErrorHandler(handler);
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {//w ww  .ja  v a 2  s. c  o m
        registerMBeans(adapterManager);
        adapterManager.requestStart();
        ObjectName retryObjectName = ObjectName.getInstance(
                JMX_RETRY_MONITOR_TYPE + adapterManager.createObjectHierarchyString() + ID_PREFIX + getName());
        RetryMessageErrorHandlerMonitorMBean mbean = JMX.newMBeanProxy(mBeanServer, retryObjectName,
                RetryMessageErrorHandlerMonitorMBean.class);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        // 10 retries 10 minutes apart, so it should be waiting.
        handler.handleProcessingException(msg);
        assertEquals(1, mbean.waitingForRetry().size());
        assertTrue(mbean.waitingForRetry().contains(msg.getUniqueId()));
        mbean.failMessage("hello");
        mbean.failMessage(msg.getUniqueId());
        assertEquals(1, failProducer.messageCount());
    } finally {
        adapterManager.requestClose();
    }
}

From source file:org.openspaces.focalserver.FocalServer.java

private void listenForRegistration() {
    Logger logger = Logger.getLogger(FocalServer.class.getName());
    try {// w w w.jav  a  2 s .com
        ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
        mbeanServer.addNotificationListener(delegateName, this, null, null);
    } catch (InstanceNotFoundException e1) {
        logger.log(Level.WARNING, e1.toString(), e1);
    } catch (MalformedObjectNameException e1) {
        logger.log(Level.WARNING, e1.toString(), e1);
    }
}

From source file:org.apache.geode.management.internal.web.controllers.ShellCommandsController.java

@RequestMapping(method = RequestMethod.GET, value = "/mbean/attribute")
public ResponseEntity<?> getAttribute(@RequestParam("resourceName") final String resourceName,
        @RequestParam("attributeName") final String attributeName)
        throws AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException,
        IOException, MalformedObjectNameException {
    // Exceptions are caught by the @ExceptionHandler AbstractCommandsController.handleAppException
    MBeanServer mBeanServer = getMBeanServer();
    ObjectName objectName = ObjectName.getInstance(decode(resourceName));
    final Object attributeValue = mBeanServer.getAttribute(objectName, decode(attributeName));
    byte[] serializedResult = IOUtils.serializeObject(attributeValue);
    return new ResponseEntity<>(serializedResult, HttpStatus.OK);
}

From source file:org.dcm4chex.archive.hsm.FileCopyService.java

public final void setHSMModulServicename(String name) throws MalformedObjectNameException {
    this.hsmModuleServicename = NONE.equals(name) ? null : ObjectName.getInstance(name);
}

From source file:com.avanza.ymer.YmerMirrorIntegrationTest.java

@Test
public void mbeanInvoke() throws Exception {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectName nameTemplate = ObjectName.getInstance(
            "se.avanzabank.space.mirror:type=DocumentWriteExceptionHandler,name=documentWriteExceptionHandler");
    Set<ObjectName> names = server.queryNames(nameTemplate, null);
    assertThat(names.size(), is(greaterThan(0)));
    server.invoke(names.toArray(new ObjectName[1])[0], "useCatchesAllHandler", null, null);
}

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

public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
    ObjectName base = delegate.getObjectName(managedBean, beanKey);

    @SuppressWarnings("unchecked")
    HashMap<String, String> properties = new HashMap<String, String>(base.getKeyPropertyList());
    //change the domain if required
    String domain = this.domain;
    if (domain == null)
        domain = base.getDomain();/*  www  . ja  v  a 2 s  . c o  m*/
    else {
        String oldDomain = base.getDomain();
        if (oldDomain != null) {
            //append the prior domain name onto the package property.
            String pkg = properties.get("package");
            pkg = (pkg == null) ? oldDomain : pkg + "." + oldDomain;
            properties.put("package", pkg);
        }
    }

    //append extra key if required
    if (key != null && value != null) {
        //append the extra key to the object name
        String oldValue = properties.remove(key);
        properties.put(key, value);

        //move the displaced prior value to a different property
        if (oldValue != null && renameKey != null) {
            String prefix = properties.remove(renameKey);
            if (prefix != null)
                oldValue = prefix + "." + oldValue;
            properties.put(renameKey, oldValue);
        }
    }

    StringBuffer buf = new StringBuffer();
    buf.append(quote(domain));
    char sep = ':';
    //enforce a canonical order on all specified properties
    for (String prop : PROPERTY_ORDER) {
        String value = properties.remove(prop);
        if (value != null) {
            buf.append(sep).append(prop).append('=').append(quote(value));
            sep = ',';
        }
    }
    //all remaining properties get appended in unspecified order
    for (Iterator<Map.Entry<String, String>> it = properties.entrySet().iterator(); it.hasNext();) {
        Map.Entry<String, String> prop = it.next();
        it.remove();
        buf.append(sep).append(prop.getKey()).append('=').append(quote(prop.getValue()));
        sep = ',';
    }

    return ObjectName.getInstance(buf.toString());
}

From source file:org.geoserver.wfs.notification.GMLNotificationSerializer.java

public void setObjectName(String name) {
    try {/*from   w w  w  .  jav a  2 s . c om*/
        this.name = ObjectName.getInstance(name);
    } catch (MalformedObjectNameException e) {
        LOG.warn("Invalid ObjectName:", e);
    }
}

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

@Test
public void testReportString() throws MalformedObjectNameException {

    ReportClient client = new ReportClient(nodeInfo, httpClient, new ReportClientConfig(), objectMapper);
    collectedData = HashBasedTable.create();
    collectedData.put(ObjectName.getInstance("com.example:name=Foo"), "String", "test value");
    client.report(TEST_TIME, collectedData);
    assertEquals(sentJson,/* w w w. j  ava  2s.c om*/
            ImmutableList.of(ImmutableMap.of("name", "Foo.String", "timestamp", TEST_TIME, "type", "string",
                    "value", "test value", "tags", ImmutableMap.of("application", "test-application", "host",
                            "test.hostname", "environment", "test_environment", "pool", "test_pool"))));
}

From source file:org.jasig.portlet.utils.jdbc.TomcatDataSourceFactory.java

protected void registerWithMBeanServer() {
    if (this.dataSource == null) {
        //Nothing to do yet, no data source
        return;/*from w w  w.  ja v  a 2s  .c o m*/
    }

    if (this.mBeanServer == null) {
        //Nothing to do yet, no mbean server
        return;
    }

    //Make sure there is nothing already in the mbean server
    unregisterWithMBeanServer();

    try {
        final ConnectionPool pool = dataSource.createPool();
        final org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = pool.getJmxPool();

        this.objectName = ObjectName.getInstance(this.baseObjectName + this.poolConfiguration.getName());
        logger.info("Registering DataSource " + this.poolConfiguration.getName()
                + " in MBeanServer under name: " + this.objectName);

        final ObjectInstance instance = this.mBeanServer.registerMBean(jmxPool, this.objectName);
        this.objectName = instance.getObjectName();
    } catch (Exception e) {
        logger.warn(
                "Failed to register connection pool with MBeanServer. JMX information will not be available for: "
                        + this.poolConfiguration.getName(),
                e);
    }
}

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

private ObjectName createFileHandlerObjectName(AdapterManager parent) throws MalformedObjectNameException {
    return ObjectName.getInstance(JMX_LOG_HANDLER_TYPE + parent.createObjectHierarchyString() + ID_PREFIX
            + FileLogHandler.class.getSimpleName());
}