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:hermes.ext.jbossmq.JBossMQAdmin.java

@Override
public int truncate(DestinationConfig dConfig) throws JMSException {
    int rval = getDepth(dConfig);

    try {//from  w  ww  .ja va 2s.  c  o  m
        if (dConfig.getDomain() == Domain.QUEUE.getId()) {
            final ObjectName objectName = new ObjectName(
                    "jboss.mq.destination:name=" + getRealDestinationName(dConfig) + ",service=Queue");

            getRMIAdapter().invoke(objectName, "removeAllMessages", new String[0], new String[0]);
        } else {
            throw new HermesException("JBoss does not support truncating a durable subscription");
        }
    } catch (HermesException ex) {
        throw ex;
    } catch (Exception e) {
        log.error(e.getMessage(), e);

        rmiAdaptor = null;
        throw new HermesException(e);

    }

    return rval;
}

From source file:ddf.metrics.reporting.internal.rrd4j.JmxCollector.java

/**
 * Verify MBean and its attribute exists and can be collected, 
 * i.e., is numeric data (vs. CompositeData)
 * /*from ww w.  java 2s.  c o  m*/
 * @return true if MBean can be accessed, false otherwise
 */
private boolean isMbeanAccessible() {
    Object attr = null;
    long startTime = System.currentTimeMillis();
    while (attr == null && (System.currentTimeMillis() - startTime < mbeanTimeoutMillis)) {
        try {
            attr = localMBeanServer.getAttribute(new ObjectName(mbeanName), mbeanAttributeName);

            if (!isNumeric(attr)) {
                LOGGER.debug(mbeanAttributeName + " from MBean " + mbeanName + " has non-numeric data");
                return false;
            }

            if (!(attr instanceof Integer) && !(attr instanceof Long) && !(attr instanceof Float)
                    && !(attr instanceof Double)) {
                return false;
            }
        } catch (Exception e) {
            try {
                LOGGER.trace("MBean [" + mbeanName + "] not found, sleeping...");
                Thread.sleep(1000);
            } catch (InterruptedException ie) {
                // Ignore this
            }
        }
    }

    return attr != null;
}

From source file:com.paxxis.cornerstone.messaging.service.shell.ServiceShell.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public void doShutdown(String[] vals) throws Exception {
    StringBuilder buf = new StringBuilder("service:jmx:rmi://localhost/jndi/rmi://localhost:");
    String serviceName = vals[0];

    buf.append(vals[1]).append("/").append(serviceName);
    String serviceUrl = buf.toString();

    JMXServiceURL url = new JMXServiceURL(serviceUrl);
    JMXConnector jmxc = null;/*from  w  w w .j  ava  2 s .  com*/
    try {
        jmxc = JMXConnectorFactory.connect(url, null);

    } catch (Exception e) {
        throw new Exception("Unable to establish JMX connection at " + serviceUrl);
    }

    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    Set<ObjectInstance> mBeansSet = mbsc.queryMBeans(new ObjectName(serviceName + ":*"), null);
    List<IServiceController> serviceProxies = new ArrayList<IServiceController>();
    Class serviceBusInterface = Class.forName(IServiceBusManager.class.getName());
    Class serviceControllerInterface = Class.forName(IServiceController.class.getName());

    for (ObjectInstance mBeanObject : mBeansSet) {
        ObjectName mbeanName = mBeanObject.getObjectName();
        Class mbeanClass = Class.forName(mBeanObject.getClassName());
        if (serviceBusInterface.isAssignableFrom(mbeanClass)) {
            IServiceBusManager requestConnector = JMX.newMBeanProxy(mbsc, mbeanName, IServiceBusManager.class,
                    true);
            System.out.print(mbeanName + " terminating....");
            requestConnector.disconnect();
            while (true) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ie) {

                }

                if (!requestConnector.isConnected()) {
                    break;
                }
            }
            System.out.println(" Done");
        } else if (serviceControllerInterface.isAssignableFrom(mbeanClass)) {
            // save off the service proxies to make sure we disconnect
            // all connectors before shutting down the service itself
            IServiceController mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, IServiceController.class, true);
            serviceProxies.add(mbeanProxy);
        }
    }

    for (IServiceController mbeanProxy : serviceProxies) {
        try {
            mbeanProxy.shutdown();
        } catch (UndeclaredThrowableException ex) {
        }
    }

    System.out.println("Service terminated");
}

From source file:com.betfair.cougar.core.impl.jmx.HtmlAdaptorParser.java

private void query(StringBuilder buf, String son, String attrName, String separator) {
    try {/* www .  j  a  v  a2  s  .  c om*/
        ObjectName on = new ObjectName(son);
        if (on.isPattern()) {
            Set<ObjectInstance> res = mbs.queryMBeans(on, null);
            if (res != null && res.size() > 0) {
                Iterator<ObjectInstance> j = res.iterator();
                while (j.hasNext()) {
                    on = j.next().getObjectName();
                    appendMBean(mbs, on, attrName, separator, buf);
                    if (j.hasNext()) {
                        buf.append("|");
                    }
                }
            }
        } else {
            appendMBean(mbs, on, attrName, separator, buf);
        }
    } catch (Exception e) {
        LOGGER.debug("Unable to retrieve Bean information for bean " + son, e);

    }
}

From source file:net.tzolov.geode.jmx.JmxInfluxLoader.java

private GeodeDistributedSystem getDistributedSystemMXBean() {
    if (distributedSystemMXBean == null) {

        try {//from  w w  w  .j  a  v  a2 s .com
            distributedSystemMXBean = MBeanServerInvocationHandler.newProxyInstance(jmxConnection,
                    new ObjectName(GEM_FIRE_SERVICE_SYSTEM_TYPE_DISTRIBUTED), GeodeDistributedSystem.class,
                    false);
        } catch (MalformedObjectNameException e) {
            log.error("", e);
        }
    }

    return distributedSystemMXBean;
}

From source file:edu.umd.cs.buildServer.BuildServer.java

protected void configureBuildServerForMBeanManagement() {
    buildServerConfiguration = new BuildServerConfiguration();
    // Try to configure a BuildServerConfiguration object
    try {/*from  w  w  w.j a v  a 2 s  .  c  om*/
        buildServerConfiguration.loadAllProperties(getConfig(), getLog());
        // Get MBeanServer
        MBeanServer platformMBeanserver = ManagementFactory.getPlatformMBeanServer();
        // Register the BuildServerMBean
        ObjectName buildServerName = new ObjectName("edu.umd.cs.buildServer:id=BuildServerManager");
        platformMBeanserver.registerMBean(buildServerConfiguration, buildServerName);
    } catch (MalformedObjectNameException e) {
        throw new RuntimeException(e);
    } catch (MBeanRegistrationException e) {
        throw new RuntimeException(e);
    } catch (NotCompliantMBeanException e) {
        throw new RuntimeException(e);
    } catch (InstanceAlreadyExistsException e) {
        throw new RuntimeException(e);
    } catch (MissingConfigurationPropertyException e) {
        // getLog().warn("Unable to configure (experimental) BuildServerConfiguration object");
        if (!isQuiet()) {
            System.out.println(e);
            e.printStackTrace();
        }

    }
}

From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java

private void serveRequest(RequestMethod method, HttpServletRequest req, HttpServletResponse rsp)
        throws IOException, ServletException {
    if (logger.isDebugEnabled()) {
        logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]");
    }//from  w w w  .  j av  a2 s  .  co m

    if ((loopRetryTimeout > 0L) && (!loopDetected)) {
        long now = System.currentTimeMillis(), diff = now - initTimestamp;
        if ((diff > 0L) && (diff < loopRetryTimeout)) {
            try {
                MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(new ObjectName(
                        "net.community.chest.gitcloud.facade.backend.git:name=BackendRepositoryResolver"));
                if (mbeanInfo != null) {
                    logger.info("serveRequest(" + method + ")[" + req.getRequestURI() + "]["
                            + req.getQueryString() + "]" + " detected loop: " + mbeanInfo.getClassName() + "["
                            + mbeanInfo.getDescription() + "]");
                    loopDetected = true;
                }
            } catch (JMException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "]["
                            + req.getQueryString() + "]" + " failed " + e.getClass().getSimpleName()
                            + " to detect loop: " + e.getMessage());
                }
            }
        }
    }

    ResolvedRepositoryData repoData = resolveTargetRepository(method, req);
    if (repoData == null) {
        throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING,
                "serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]",
                new NoSuchElementException("Failed to resolve repository"));
    }

    String username = authenticate(req);
    // TODO check if the user is allowed to access the repository via the resolve operation (push/pull) if at all (e.g., private repo)
    logger.info("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "] user="
            + username);

    /*
     * NOTE: this feature requires enabling cross-context forwarding.
     * In Tomcat, the 'crossContext' attribute in 'Context' element of
     * 'TOMCAT_HOME\conf\context.xml' must be set to true, to enable cross-context 
     */
    if (loopDetected) {
        // TODO see if can find a more efficient way than splitting and re-constructing
        URI uri = repoData.getRepoLocation();
        ServletContext curContext = req.getServletContext();
        String urlPath = uri.getPath(), urlQuery = uri.getQuery();
        String[] comps = StringUtils.split(urlPath, '/');
        String appName = comps[0];
        ServletContext loopContext = Validate.notNull(curContext.getContext("/" + appName),
                "No cross-context for %s", appName);
        // build the relative path in the re-directed context
        StringBuilder sb = new StringBuilder(
                urlPath.length() + 1 + (StringUtils.isEmpty(urlQuery) ? 0 : urlQuery.length()));
        for (int index = 1; index < comps.length; index++) {
            sb.append('/').append(comps[index]);
        }
        if (!StringUtils.isEmpty(urlQuery)) {
            sb.append('?').append(urlQuery);
        }

        String redirectPath = sb.toString();
        RequestDispatcher dispatcher = Validate.notNull(loopContext.getRequestDispatcher(redirectPath),
                "No dispatcher for %s", redirectPath);
        dispatcher.forward(req, rsp);
        if (logger.isDebugEnabled()) {
            logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString()
                    + "]" + " forwarded to " + loopContext.getContextPath() + "/" + redirectPath);
        }
    } else {
        executeRemoteRequest(method, repoData.getRepoLocation(), req, rsp);
    }
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.MMXConfigurationTest.java

/**
 * Set the MBean attribute value via a remote JMX Connection and check whether the
 * returned value matches the set value//from  w ww  .  j  av a  2  s .  co m
 *
 * @throws Exception
 */
@Test
public void testSetGetMBeanRemote() throws Exception {
    JMXServiceURL jmxServiceUrl = jmxConnectorServer.getAddress();
    JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl);
    MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection();
    ObjectName name = new ObjectName(MMX_MBEAN_OBJECT_NAME);
    testSetGetAttribute(mbeanServerConnection, name);
}

From source file:io.github.albertopires.mjc.JConsoleM.java

public long getCMSUsageThresholdCount(ServerConfiguration serverConfiguration) throws Exception {
    ObjectName mbeanName = null;//from   w w w. j  ava2 s .  c  om
    if (serverConfiguration.getJdkVersion().equals(JdkVersion.JDK6)) {
        mbeanName = new ObjectName("java.lang:type=MemoryPool,name=CMS Old Gen");
    } else if (serverConfiguration.getJdkVersion().equals(JdkVersion.JDK8)) {
        mbeanName = new ObjectName("java.lang:type=MemoryPool,name=G1 Old Gen");
    }
    Long ut;
    ut = (Long) mbsc.getAttribute(mbeanName, "UsageThresholdCount");
    return ut.longValue();
}