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.beginner.core.utils.ProjectUtil.java

/**
 * ?Web???(???)//from w w  w  . jav  a  2  s.  c  o m
 */
public static String getPort() {
    String result = "";
    try {
        MBeanServer mBeanServer = null;
        List<MBeanServer> mBeanServers = MBeanServerFactory.findMBeanServer(null);
        if (mBeanServers.size() > 0) {
            for (MBeanServer _mBeanServer : mBeanServers) {
                mBeanServer = _mBeanServer;
                break;
            }
        }
        if (mBeanServer == null) {
            throw new IllegalStateException("?JVM?MBeanServer.");
        }
        Set<ObjectName> objectNames = null;
        objectNames = mBeanServer.queryNames(new ObjectName("Catalina:type=Connector,*"), null);
        if (objectNames == null || objectNames.size() <= 0) {
            throw new IllegalStateException("?JVM?MBeanServer : "
                    + mBeanServer.getDefaultDomain() + " ??.");
        }
        for (ObjectName objectName : objectNames) {
            String protocol = (String) mBeanServer.getAttribute(objectName, "protocol");
            if (protocol.equals("HTTP/1.1")) {
                int port = (Integer) mBeanServer.getAttribute(objectName, "port");
                result = port + StringUtils.EMPTY;
            }
        }
    } catch (Exception e) {
        logger.error("?WEB?HTTP/1.1???", e);
    }
    return result;
}

From source file:com.obergner.hzserver.ServerInfo.java

/**
 * @throws IOException//from w  w w  . j  a v  a  2s .  com
 * @throws MalformedURLException
 * @throws NullPointerException
 * @throws MalformedObjectNameException
 * @throws NotCompliantMBeanException
 * @throws MBeanRegistrationException
 * @throws InstanceAlreadyExistsException
 * 
 */
public ServerInfo()
        throws MalformedURLException, IOException, InstanceAlreadyExistsException, MBeanRegistrationException,
        NotCompliantMBeanException, MalformedObjectNameException, NullPointerException {
    this.serverManifest = loadServerManifest();
    this.objectName = new ObjectName(getClass().getPackage().getName() + ":name=ServerInfo");
    ManagementFactory.getPlatformMBeanServer().registerMBean(this, this.objectName);
}

From source file:psiprobe.AbstractTomcatContainer.java

@Override
public void setWrapper(Wrapper wrapper) {
    Valve valve = createValve();// ww  w.j  a v  a  2s. co  m
    if (wrapper != null) {
        host = (Host) wrapper.getParent().getParent();
        Engine engine = (Engine) host.getParent();
        Service service = engine.getService();
        connectors = service.findConnectors();
        try {
            deployerOName = new ObjectName(
                    host.getParent().getName() + ":type=Deployer,host=" + host.getName());
        } catch (MalformedObjectNameException e) {
            logger.trace("", e);
        }
        host.getPipeline().addValve(valve);
        mbeanServer = Registry.getRegistry(null, null).getMBeanServer();
    } else if (host != null) {
        host.getPipeline().removeValve(valve);
    }
}

From source file:com.rackspacecloud.blueflood.cache.TtlCache.java

public TtlCache(String label, TimeValue expiration, int cacheConcurrency, final InternalAPI internalAPI) {
    try {//w w  w  . ja v a2 s.  c  om
        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        final String name = String.format(
                TtlCache.class.getPackage().getName() + ":type=%s,scope=%s,name=Stats",
                TtlCache.class.getSimpleName(), label);
        final ObjectName nameObj = new ObjectName(name);
        mbs.registerMBean(this, nameObj);
        instantiateYammerMetrics(TtlCache.class, label, nameObj);
    } catch (Exception ex) {
        log.error("Unable to register mbean for " + getClass().getName());
    }
    generalErrorMeter = Metrics.newMeter(TtlCache.class, "Load Errors", label, "Rollups", TimeUnit.MINUTES);
    httpErrorMeter = Metrics.newMeter(TtlCache.class, "Http Errors", label, "Rollups", TimeUnit.MINUTES);

    CacheLoader<String, Map<ColumnFamily<Locator, Long>, TimeValue>> loader = new CacheLoader<String, Map<ColumnFamily<Locator, Long>, TimeValue>>() {

        // values from the default account are used to build a ttl map for tenants that do not exist in the
        // internal API.  These values are put into the cache, meaning subsequent cache requests do not
        // incur a miss and hit the internal API.
        private final Account DEFAULT_ACCOUNT = new Account() {
            @Override
            public TimeValue getMetricTtl(String resolution) {
                return SAFETY_TTLS
                        .get(AstyanaxIO.getColumnFamilyMapper().get(Granularity.fromString(resolution).name()));
            }
        };

        @Override
        public Map<ColumnFamily<Locator, Long>, TimeValue> load(final String key) throws Exception {
            // load account, build ttl map.
            try {
                Account acct = internalAPI.fetchAccount(key);
                return buildTtlMap(acct);
            } catch (HttpResponseException ex) {
                // cache the default value on a 404. this means that we will not be hammering the API for values
                // that are constantly not there.  The other option was to let the Http error bubble out, use a
                // and value from SAFETY_TTLS.  But the same thing (an HTTP round trip) would happen the very next
                // time a TTL is requested.
                if (ex.getStatusCode() == 404) {
                    httpErrorMeter.mark();
                    log.warn(ex.getMessage());
                    return buildTtlMap(DEFAULT_ACCOUNT);
                } else
                    throw ex;
            }

        }
    };
    cache = CacheBuilder.newBuilder().expireAfterWrite(expiration.getValue(), expiration.getUnit())
            .concurrencyLevel(cacheConcurrency).recordStats().build(loader);
}

From source file:com.taobao.diamond.server.service.task.processor.UpdateConfigInfoTaskProcessor.java

public void init() {
    try {/*  w w w .  j  a  v  a  2 s.c  om*/
        ObjectName oName = new ObjectName(UpdateConfigInfoTaskProcessor.class.getPackage().getName() + ":type="
                + UpdateConfigInfoTaskProcessor.class.getSimpleName());
        ManagementFactory.getPlatformMBeanServer().registerMBean(this, oName);
    } catch (Exception e) {
        log.error("mbean", e);
    }
}

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

/**
 * Integration test for the registration service
 *//* w  w w .  j a v a2s. com*/
public void testRegistrationServiceFourTrue() throws Exception {
    ManagementService.registerMBeans(manager, mBeanServer, true, true, true, true);
    assertEquals(OBJECTS_IN_TEST_EHCACHE,
            mBeanServer.queryNames(new ObjectName("net.sf.ehcache:*"), null).size());
}

From source file:com.hellblazer.slp.jmx.JmxDiscoveryConfiguration.java

public JmxServerListener construct() throws Exception {
    ServiceScope scope = discovery.construct();
    scope.start();/* ww w  .  jav  a2  s  . c  om*/
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    CascadingService cascadingService = new CascadingService();
    mbs.registerMBean(cascadingService, new ObjectName(name));
    JmxServerListener listener = new JmxServerListener(cascadingService, sourcePattern, sourceMap, scope,
            targetPath);
    for (String serviceType : serviceNames) {
        listener.listenFor("(" + SERVICE_TYPE + "=" + serviceType + ")");
    }
    return listener;
}

From source file:herddb.jdbc.MultipleDataSourcesSameJVMJMXTest.java

@Test
public void test() throws Exception {
    try (Server server = new Server(new ServerConfiguration(folder.newFolder().toPath()))) {
        server.start();//from   w  w w  .j  a v  a2s.  co  m
        server.waitForStandaloneBoot();
        try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()));) {
            client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
            try (BasicHerdDBDataSource dataSource = new BasicHerdDBDataSource(client);
                    BasicHerdDBDataSource dataSource_2 = new BasicHerdDBDataSource(client);
                    Connection con = dataSource.getConnection();
                    Connection con_2 = dataSource_2.getConnection();
                    Statement statement = con.createStatement();
                    Statement statement_2 = con.createStatement();) {
                statement.execute("CREATE TABLE mytable (key string primary key, name string)");

                assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k1','name1')"));
                assertEquals(1,
                        statement_2.executeUpdate("INSERT INTO mytable (key,name) values('k2','name2')"));
                assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k3','name3')"));

                try (ResultSet rs = statement
                        .executeQuery("SELECT * FROM mytable a" + " INNER JOIN mytable b ON 1=1")) {
                    int count = 0;
                    while (rs.next()) {
                        count++;
                    }
                    assertEquals(9, count);
                }
                MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();

                Object attributeValue = jmxServer.getAttribute(
                        new ObjectName("org.apache.commons.pool2:type=GenericObjectPool,name=HerdDBClient"),
                        "BorrowedCount");
                assertEquals(1L, attributeValue);

                Object attributeValue2 = jmxServer.getAttribute(
                        new ObjectName("org.apache.commons.pool2:type=GenericObjectPool,name=HerdDBClient2"),
                        "BorrowedCount");
                assertEquals(1L, attributeValue2);

            }
        }
    }
}

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

private ObjectName createAllRoutesObjectName() {
    ObjectName objectName = null;
    try {/*from  ww w .  j  av a2 s  .com*/
        objectName = new ObjectName(agent.getMBeanObjectDomainName() + ":type=routes,*");
    } catch (MalformedObjectNameException ex) {
        LOG.error(ExceptionUtils.getStackTrace(ex));
    }

    return objectName;
}

From source file:fr.juanwolf.mysqlbinlogreplicator.service.MysqlBinLogServiceTest.java

@Test
public void postConstruct_should_instanciate_a_new_binlogclientstatisticClient()
        throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException,
        MBeanRegistrationException {
    // Given/*from  w  w w . java 2 s . com*/
    ObjectName statsObjectName = new ObjectName("mysql.binlog:type=BinaryLogClientStatistics");
    // When
    mysqlBinLogService.postConstruct();
    // Then
    verify(mBeanServer).registerMBean(any(), eq(statsObjectName));
}