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.flexive.shared.cache.impl.FxJBossExternalCacheProvider.java

/**
 * {@inheritDoc}/*from w  w  w .ja v  a  2s.  c om*/
 */
@Override
public void init() throws FxCacheException {
    if (cache != null)
        return;
    try {
        // first check if the cache MBean exists
        final ObjectName objectName = new ObjectName("jboss.cache:service=JNDITreeCache");
        final Pair<MBeanServer, MBeanInfo> beanInfo = MBeanHelper.getMBeanInfo(objectName);
        // create wrapper MBean (cast necessary for java 1.5)
        final CacheJmxWrapperMBean wrapper = (CacheJmxWrapperMBean) MBeanServerInvocationHandler
                .newProxyInstance(beanInfo.getFirst(), objectName, CacheJmxWrapperMBean.class, false);
        cache = new FxJBossTreeCacheMBeanWrapper(wrapper);
        evictChildren(""); // clean up possible leftovers from previous deployment
        LOG.trace(Fqn.class);
    } catch (Exception e) {
        throw new FxCacheException(e);
    }
}

From source file:io.hawt.osgi.jmx.RBACDecorator.java

void init() throws Exception {
    if (objectName == null) {
        objectName = new ObjectName("hawtio:type=security,area=jolokia,name=RBACDecorator");
    }//from  w w w.ja va 2 s.c  om
    if (mBeanServer == null) {
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    }
    mBeanServer.registerMBean(this, objectName);
}

From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.jmx.ConfigurationMBean.java

/**uniqueObjectName
 * Make a unique jmx name for this configuration object
 * @see net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl#uniqueObjectName(javax.management.MBeanServer, java.lang.String)
 *//*from   w  ww .j av  a 2s. c o  m*/
public synchronized ObjectName uniqueObjectName(MBeanServer server, String on) {
    ObjectName oName = null;
    try {
        oName = new ObjectName(on + ",config=" + _config.getClass().getName());
    } catch (Exception e) {
        log.warn(LogSupport.EXCEPTION, e);
    }

    return oName;
}

From source file:net.sf.ehcache.management.ManagementServiceTest.java

/**
 * teardown//from   w  w w.  ja v  a 2s.  c  o m
 */
protected void tearDown() throws Exception {
    super.tearDown();
    //Ensure the CacheManager shutdown clears all ObjectNames from the MBeanServer
    assertEquals(0, mBeanServer.queryNames(new ObjectName("net.sf.ehcache:*"), null).size());
}

From source file:com.fatwire.gst.web.status.StatusRequestListener.java

public void contextInitialized(ServletContextEvent sce) {
    String n = sce.getServletContext().getContextPath();
    if (n == null || n.length() == 0) {
        n = "/";/*from   ww  w  . j av  a  2  s .c om*/
    }

    requestCounter = new RequestCounter(n);
    ConcurrencyCounter<?, ?> old = ConcurrencyCounterLocator.getInstance().register(requestCounter);
    if (old != null) {
        requestCounter = (RequestCounter) old;
    }
    try {
        name = new ObjectName("com.fatwire.gst.web:type=RequestCounter,name=" + ObjectName.quote(n));
        ManagementFactory.getPlatformMBeanServer().registerMBean(new StatusCounter(requestCounter), name);
    } catch (Throwable e) {
        log.warn(e.getMessage(), e);
    }

}

From source file:com.app.server.node.NodeServer.java

/**
 * This method implements the node server request
 *//*w ww .j av a  2  s .c  o m*/
public void run() {
    //deployer.start();
    try {
        ObjectName objName = new ObjectName("com.app.server:type=deployer,service=RMIDeployer");
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.createMBean("com.app.server.node.RMIDeployer", objName);
        mbeanServer.invoke(objName, "init", new Object[] { deployerList },
                new String[] { Vector.class.getName() });
        ServerConfig serverConfig = new ServerConfig();
        serverConfig.setRmiregistryport(port + "");
        serverConfig.setCachedir("d:/AppServer/cache");
        mbeanServer.invoke(objName, "init", new Object[] { serviceList, serverConfig, mbeanServer },
                new String[] { Vector.class.getName(), ServerConfig.class.getName(),
                        MBeanServer.class.getName() });
        InetAddress inet = null;
        inet = InetAddress.getLocalHost();
        mbeanServer.invoke(objName, "deploy",
                new Object[] { new URL("file:///D:/AppServer/deploy/rmitest.rmi"), false, null,
                        inet.getHostName() + ":" + port },
                new String[] { URL.class.getName(), boolean.class.getName(), ClassLoader.class.getName(),
                        String.class.getName() });
        //deployer.deploy(new URL("file:///D:/AppServer/deploy/rmitest.rmi"),false,null,inet.getHostName()+":"+port);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:net.centro.rtb.monitoringcenter.metrics.tomcat.TomcatMetricSet.java

public TomcatMetricSet() {
    this.mBeanServer = ManagementFactory.getPlatformMBeanServer();

    Map<String, Metric> metricsByNames = new HashMap<>();

    // Executors//  w  w w . j a v a2 s.  c o m
    List<TomcatExecutorStatus> executorStatuses = new ArrayList<>();

    Set<ObjectName> executorObjectNames = null;
    try {
        executorObjectNames = mBeanServer.queryNames(new ObjectName("Catalina:type=Executor,*"), null);
    } catch (MalformedObjectNameException e) {
        logger.debug("Invalid ObjectName defined for the Tomcat's Executor MxBean", e);
    }

    if (executorObjectNames != null && !executorObjectNames.isEmpty()) {
        for (final ObjectName executorObjectName : executorObjectNames) {
            TomcatExecutorMetricSet executorMetricSet = new TomcatExecutorMetricSet(executorObjectName);
            if (!executorMetricSet.getMetrics().isEmpty()) {
                metricsByNames.put(MetricNamingUtil.join("executors", executorMetricSet.getName()),
                        executorMetricSet);
            }
            executorStatuses.add(executorMetricSet);
        }
    }

    this.executorStatuses = executorStatuses;

    // Thread Pools
    final List<TomcatConnectorMetricSet> connectorMetricSets = new ArrayList<>();
    List<TomcatConnectorStatus> connectorStatuses = new ArrayList<>();

    Set<ObjectName> threadPoolObjectNames = null;
    try {
        threadPoolObjectNames = mBeanServer.queryNames(new ObjectName("Catalina:type=ThreadPool,*"), null);
    } catch (MalformedObjectNameException e) {
        logger.debug("Invalid ObjectName defined for the Tomcat's ThreadPool MxBean", e);
    }

    if (threadPoolObjectNames != null && !threadPoolObjectNames.isEmpty()) {
        for (final ObjectName threadPoolObjectName : threadPoolObjectNames) {
            TomcatConnectorMetricSet connectorMetricSet = new TomcatConnectorMetricSet(threadPoolObjectName);
            if (!connectorMetricSet.getMetrics().isEmpty()) {
                metricsByNames.put(MetricNamingUtil.join("connectors", connectorMetricSet.getName()),
                        connectorMetricSet);
                connectorMetricSets.add(connectorMetricSet);
            }
            connectorStatuses.add(connectorMetricSet);
        }
    }

    this.connectorStatuses = connectorStatuses;

    if (!connectorMetricSets.isEmpty()) {
        this.executorService = Executors.newSingleThreadScheduledExecutor(
                new ThreadFactoryBuilder().setNameFormat("TomcatMetricSet-%d").build());
        this.executorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                for (TomcatConnectorMetricSet connectorMetricSet : connectorMetricSets) {
                    try {
                        connectorMetricSet.updateQps();
                    } catch (Exception e) {
                        logger.debug("Error while updating QPS for connector {}", connectorMetricSet.getName(),
                                e);

                        if (InterruptedException.class.isInstance(e)) {
                            Thread.currentThread().interrupt();
                        }
                    }
                }
            }
        }, 1, 1, TimeUnit.SECONDS);
    }

    this.metricsByNames = metricsByNames;

    this.shutdown = new AtomicBoolean(false);
}

From source file:com.garethahealy.camel.dynamic.loadbalancer.statistics.mbeans.BaseMBeanAttributeCollector.java

private ObjectName createObjectName(String query) {
    ObjectName objectName = null;
    try {//from w ww. ja  va2s.c om
        objectName = new ObjectName(agent.getMBeanObjectDomainName() + query);
    } catch (MalformedObjectNameException ex) {
        LOG.error(ExceptionUtils.getStackTrace(ex));
    }

    return objectName;
}

From source file:co.paralleluniverse.common.monitoring.PeriodicMonitor.java

private void registerMBean() {
    try {//from   w  w w. j  av  a 2s.c  o  m
        LOG.info("Registering MBean {}", name);
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName mxbeanName = new ObjectName(name);
        mbs.registerMBean(this, mxbeanName);

        timer.addNotificationListener(this, new NotificationFilter() {
            @Override
            public boolean isNotificationEnabled(Notification notification) {
                return "tickTimer".equals(notification.getType());
            }
        }, null);
        this.registered = true;
    } catch (InstanceAlreadyExistsException ex) {
        throw new RuntimeException(ex);
    } catch (MBeanRegistrationException ex) {
        throw new RuntimeException(ex);
    } catch (NotCompliantMBeanException ex) {
        throw new AssertionError(ex);
    } catch (MalformedObjectNameException ex) {
        throw new AssertionError(ex);
    }
}

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

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

    ChainingEventPersisterImpl persister = (ChainingEventPersisterImpl) multiTracking.getPersister();
    BehaviorEventPersister[] delegates = persister.getDelegates().toArray(new BehaviorEventPersister[0]);
    assertEquals("all delegates registered", 3, delegates.length);
    assertEquals("first delegate has correct type", XmlBehaviorEventPersisterImpl.class,
            delegates[0].getClass());/*ww  w  . ja  v a 2 s  . c om*/
    assertEquals("second delegate has correct type", StatisticsMBeanEventPersisterImpl.class,
            delegates[1].getClass());
    assertSame("third delegate is reference to top-level bean", customPersister, delegates[2]);

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