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:net.lightbody.bmp.proxy.jetty.http.jmx.HttpContextMBean.java

protected ObjectName newObjectName(MBeanServer server) {
    ObjectName oName = super.newObjectName(server);
    String context = _httpContext.getContextPath();
    if (context.length() == 0)
        context = "/";
    try {//from   w  w  w . jav  a 2  s  .co m
        oName = new ObjectName(oName + ",context=" + context);
    } catch (Exception e) {
        log.warn(LogSupport.EXCEPTION, e);
    }
    return oName;
}

From source file:com.spotify.reaper.cassandra.JmxProxy.java

/**
 * Connect to JMX interface on the given host and port.
 *
 * @param handler  Implementation of {@link RepairStatusHandler} to process incoming
 *                 notifications//w  w w  .j a  v  a 2s.c om
 *                 of repair events.
 * @param host     hostname or ip address of Cassandra node
 * @param port     port number to use for JMX connection
 * @param username username to use for JMX authentication
 * @param password password to use for JMX authentication
 */
static JmxProxy connect(Optional<RepairStatusHandler> handler, String host, int port, String username,
        String password) throws ReaperException {
    ObjectName ssMbeanName;
    ObjectName cmMbeanName;
    JMXServiceURL jmxUrl;
    try {
        jmxUrl = new JMXServiceURL(String.format(JMX_URL, host, port));
        ssMbeanName = new ObjectName(SS_OBJECT_NAME);
        cmMbeanName = new ObjectName(CompactionManager.MBEAN_OBJECT_NAME);
    } catch (MalformedURLException | MalformedObjectNameException e) {
        LOG.error(String.format("Failed to prepare the JMX connection to %s:%s", host, port));
        throw new ReaperException("Failure during preparations for JMX connection", e);
    }
    try {
        Map<String, Object> env = new HashMap<String, Object>();
        if (username != null && password != null) {
            String[] creds = { username, password };
            env.put(JMXConnector.CREDENTIALS, creds);
        }
        JMXConnector jmxConn = JMXConnectorFactory.connect(jmxUrl, env);
        MBeanServerConnection mbeanServerConn = jmxConn.getMBeanServerConnection();
        Object ssProxy = JMX.newMBeanProxy(mbeanServerConn, ssMbeanName, StorageServiceMBean.class);
        String cassandraVersion = ((StorageServiceMBean) ssProxy).getReleaseVersion();
        if (cassandraVersion.startsWith("2.0") || cassandraVersion.startsWith("1.")) {
            ssProxy = JMX.newMBeanProxy(mbeanServerConn, ssMbeanName, StorageServiceMBean20.class);
        }

        CompactionManagerMBean cmProxy = JMX.newMBeanProxy(mbeanServerConn, cmMbeanName,
                CompactionManagerMBean.class);
        JmxProxy proxy = new JmxProxy(handler, host, jmxUrl, jmxConn, ssProxy, ssMbeanName, mbeanServerConn,
                cmProxy);
        // registering a listener throws bunch of exceptions, so we do it here rather than in the
        // constructor
        mbeanServerConn.addNotificationListener(ssMbeanName, proxy, null, null);
        LOG.debug("JMX connection to {} properly connected: {}", host, jmxUrl.toString());
        return proxy;
    } catch (IOException | InstanceNotFoundException e) {
        LOG.error("Failed to establish JMX connection to {}:{}", host, port);
        throw new ReaperException("Failure when establishing JMX connection", e);
    }
}

From source file:gr.cslab.Metric_test.java

static void loadJsonMetrics(JSONArray ja) {
    for (int i = 0; i < ja.length(); i++) {
        //read json args
        String name = "unknown";
        try {//from w ww .  j  a  v a  2 s  . com
            JSONObject jo = ja.getJSONObject(i);
            name = jo.getString("name");
            String attribute = jo.getString("attribute");
            String label = jo.getString("label");
            String unit = jo.getString("unit");
            Metric m = new Metric(new ObjectName(name), attribute, label, unit);
            metrics.add(m);
        } catch (JSONException ex) {
            System.err.println("ERROR: missing required json attributes for name: " + name);
        } catch (MalformedObjectNameException ex) {
            System.err.println("ERROR: Malformed Object name: " + name);
        }
    }
}

From source file:gridool.util.GridUtils.java

public static ObjectName makeMBeanName(@Nonnull final String domain, @Nonnull final String type,
        @Nonnull final String channelName) {
    final String mbeanName = makeMBeanNameString(domain, type, channelName);
    try {//w  ww .  java2  s  .c o m
        return new ObjectName(mbeanName);
    } catch (MalformedObjectNameException e) {
        throw new IllegalArgumentException(e);
    } catch (NullPointerException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java

/**
 * constructor used for creating JMX connection
 *///from   ww  w .  ja  v a  2s.  c o m
public JMXDataUpdater(String server, String port, Cluster cluster) {
    this.serverName = server;
    this.port = port;
    this.userName = cluster.getJmxUserName();
    this.userPassword = cluster.getJmxUserPassword();
    this.cluster = cluster;

    try {
        // Initialize MBean object names
        this.MBEAN_OBJECT_NAME_SYSTEM_DISTRIBUTED = new ObjectName(
                PulseConstants.OBJECT_NAME_SYSTEM_DISTRIBUTED);
        this.MBEAN_OBJECT_NAME_REGION_DISTRIBUTED = new ObjectName(
                PulseConstants.OBJECT_NAME_REGION_DISTRIBUTED);
        this.MBEAN_OBJECT_NAME_MEMBER_MANAGER = new ObjectName(PulseConstants.OBJECT_NAME_MEMBER_MANAGER);
        this.MBEAN_OBJECT_NAME_MEMBER = new ObjectName(PulseConstants.OBJECT_NAME_MEMBER);
        this.MBEAN_OBJECT_NAME_STATEMENT_DISTRIBUTED = new ObjectName(
                PulseConstants.OBJECT_NAME_STATEMENT_DISTRIBUTED);

        // For GemFireXD
        if (PulseConstants.PRODUCT_NAME_GEMFIREXD.equalsIgnoreCase(PulseController.getPulseProductSupport())) {
            this.MBEAN_OBJECT_NAME_TABLE_AGGREGATE = new ObjectName(PulseConstants.OBJECT_NAME_TABLE_AGGREGATE);
        }

    } catch (MalformedObjectNameException e) {
        if (LOGGER.severeEnabled()) {
            LOGGER.severe(e.getMessage(), e);
        }
    } catch (NullPointerException e) {
        if (LOGGER.severeEnabled()) {
            LOGGER.severe(e.getMessage(), e);
        }
    }

}

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

public void should_add_auth_role_to_feature() throws Exception {
    ObjectName objectName = new ObjectName(FF4J_OBJECT_NAME);
    mbServConn.invoke(objectName, "grantRoleOnFeature", new Object[] { "NEW_ROLE", "jmxEnabledFeature" },
            new String[] { "java.lang.String", "java.lang.String" });
}

From source file:com.googlecode.psiprobe.beans.JBossResourceResolverBean.java

public boolean resetResource(Context context, String resourceName, ContainerWrapperBean containerWrapper)
        throws NamingException {
    try {//from  w  ww  .j ava2s.co  m
        ObjectName poolOName = new ObjectName("jboss.jca:service=ManagedConnectionPool,name=" + resourceName);
        MBeanServer server = getMBeanServer();
        if (server != null) {
            try {
                server.invoke(poolOName, "stop", null, null);
                server.invoke(poolOName, "start", null, null);
                return true;
            } catch (Exception e) {
                logger.error("Could not reset resource \"" + resourceName + "\"", e);
            }
        }
        return false;
    } catch (MalformedObjectNameException e) {
        throw new NamingException("Resource name: \"" + resourceName + "\" makes a malformed ObjectName");
    }
}

From source file:be.fedict.trust.service.snmp.SNMPInterceptor.java

private static Long getValue(String oid, String service) {

    LOG.debug("get value of counter oid=" + oid + " @ service=" + service);

    try {/*from  ww  w  .  ja  va 2  s.c om*/
        for (MBeanServer mBeanServer : MBeanServerFactory.findMBeanServer(null)) {
            return (Long) mBeanServer.invoke(new ObjectName(service), "getValue", new Object[] { oid },
                    new String[] { "java.lang.String" });

        }
    } catch (Exception e) {
        LOG.error("Failed to contact SNMP Mbean: " + e.getMessage(), e);
    }

    return 0L;
}

From source file:com.springsource.hq.plugin.tcserver.plugin.appmgmt.TomcatJmxApplicationManager.java

private void fetchAndApplySessionCount(Properties configProperties, String hostName, Application application,
        boolean tomcat7) throws PluginException {
    Integer sessionCount = 0;//from   w  w w. j a v  a  2  s . com

    String appObjectName = ObjectNameUtils.getManagerMBeanObjectNameForApplication(hostName, application,
            tomcat7);

    try {
        MBeanServerConnection mbsc = mxUtil.getMBeanServer(configProperties);
        boolean mbeanIsRegistered = mbsc.isRegistered(new ObjectName(appObjectName));

        if (mbeanIsRegistered) {
            sessionCount = (Integer) mxUtil.getValue(configProperties, appObjectName, "activeSessions");
        }

        application.setSessionCount(sessionCount);
    } catch (PluginException pe) {
        throw pe;
    } catch (Exception e) {
        throw createPluginException(e);
    }
}

From source file:com.sun.grizzly.http.jk.server.JkCoyoteHandler.java

public void start() {
    try {/*from w w w.j a  v a 2 s .c om*/
        if (oname != null && getJkMain().getDomain() == null) {
            try {
                ObjectName jkmainOname = new ObjectName(oname.getDomain() + ":type=JkMain");
                Registry.getRegistry(null, null).registerComponent(getJkMain(), jkmainOname, "JkMain");
            } catch (Exception e) {
                LoggerUtils.getLogger().log(Level.SEVERE, "Error registering jkmain " + e);
            }
        }
        getJkMain().start();
    } catch (Exception ex) {
        LoggerUtils.getLogger().log(Level.SEVERE, "Error during startup", ex);
    }
}