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.github.stephanarts.cas.ticket.registry.ZMQTicketRegistry.java

/**
 * Creates a new TicketRegistry Backend.
 *
 * An instance of the ZMQTicketRegistry stores
 * CAS Tickets in a cluster of Registry-Providers.
 *
 * @param providers         Array of providers to connect to
 * @param address           Address to bind the RegistryProvider on
 * @param port              TCP port to bind the RegistryProvider on
 * @param requestTimeout    Timeout//from  w  w  w. j  av  a2  s . c om
 * @param heartbeatTimeout  Timeout
 * @param heartbeatInterval Interval
 *
 * @throws Exception if localProvider could not be found
 */
public ZMQTicketRegistry(final String[] providers, final String address, final int port,
        final int requestTimeout, final int heartbeatTimeout, final int heartbeatInterval) throws Exception {

    this.provider = new ZMQProvider("tcp://" + address + ":" + port, this.providerId);

    this.provider.start();

    this.pacemaker = new PaceMaker();

    pacemaker.setHeartbeatInterval(heartbeatInterval);
    pacemaker.setHeartbeatTimeout(heartbeatTimeout);

    this.registryBroker = new RegistryBroker(providers, requestTimeout, this.pacemaker, this.providerId);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    this.mbeanName = new ObjectName("CAS:type=TicketRegistry,provider='" + port + "'");
    mbs.registerMBean(this.provider, this.mbeanName);

    try {
        this.registryBroker.bootstrap();
        int nTickets = this.registryBroker.getTickets().size();
        logger.info("Bootstrapping complete, got " + nTickets + " tickets.");
    } catch (final BootstrapException e) {
        logger.warn(e.getMessage());
    }
}

From source file:com.ibm.soatf.component.osb.ServiceManager.java

public static boolean changeServiceStatus(String servicetype, boolean status, String serviceURI, String host,
        int port, String username, String password) throws FrameworkExecutionException {

    SessionManagementMBean sm = null;/*from ww  w.  j a va 2  s .  c  om*/
    JMXConnector conn = null;
    boolean result = true;
    String statusMsg = "";
    try {
        conn = initConnection(host, port, username, password);
        MBeanServerConnection mbconn = conn.getMBeanServerConnection();
        DomainRuntimeServiceMBean clusterService = (DomainRuntimeServiceMBean) MBeanServerInvocationHandler
                .newProxyInstance(mbconn, new ObjectName(DomainRuntimeServiceMBean.OBJECT_NAME));
        sm = (SessionManagementMBean) clusterService.findService(SessionManagementMBean.NAME,
                SessionManagementMBean.TYPE, null);
        sm.createSession(SESSION_NAME);
        ALSBConfigurationMBean alsbSession = (ALSBConfigurationMBean) clusterService.findService(
                ALSBConfigurationMBean.NAME + "." + SESSION_NAME, ALSBConfigurationMBean.TYPE, null);

        if (servicetype.equals("ProxyService")) {
            Ref ref = constructRef("ProxyService", serviceURI);
            ProxyServiceConfigurationMBean proxyConfigMBean = (ProxyServiceConfigurationMBean) clusterService
                    .findService(ProxyServiceConfigurationMBean.NAME + "." + SESSION_NAME,
                            ProxyServiceConfigurationMBean.TYPE, null);
            if (status) {
                proxyConfigMBean.enableService(ref);
                statusMsg = "Enable the ProxyService : " + serviceURI;
                logger.info(statusMsg);
            } else {
                proxyConfigMBean.disableService(ref);
                statusMsg = "Disable the ProxyService : " + serviceURI;
                logger.info(statusMsg);
            }
        } else if (servicetype.equals("BusinessService")) {
            try {
                Ref ref = constructRef("BusinessService", serviceURI);
                BusinessServiceConfigurationMBean businessConfigMBean = (BusinessServiceConfigurationMBean) clusterService
                        .findService(BusinessServiceConfigurationMBean.NAME + "." + SESSION_NAME,
                                BusinessServiceConfigurationMBean.TYPE, null);
                if (status) {
                    businessConfigMBean.enableService(ref);
                    statusMsg = "Enable the BusinessService : " + serviceURI;
                    logger.info(statusMsg);
                } else {
                    businessConfigMBean.disableService(ref);
                    statusMsg = "Disable the BusinessService : " + serviceURI;
                    logger.info(statusMsg);
                }
            } catch (IllegalArgumentException ex) {
                logger.fatal(ExceptionUtils.getStackTrace(ex));
            }
        }
        sm.activateSession(SESSION_NAME, statusMsg);
        conn.close();
    } catch (Exception ex) {
        if (null != sm) {
            try {
                sm.discardSession(SESSION_NAME);
            } catch (Exception e) {
                logger.debug("Not able to discard the session. " + e.getLocalizedMessage());
                throw new FrameworkExecutionException(e);
            }
        }
        result = false;
        logger.error("Error in MBean Server connection. " + ex.getLocalizedMessage());
        ex.printStackTrace();
    } finally {
        if (null != conn) {
            try {
                conn.close();
            } catch (Exception e) {
                logger.debug("Not able to close the JMX connection. " + e.getLocalizedMessage());
                throw new FrameworkExecutionException(e);

            }
        }
    }

    return result;
}

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

@Test
public void should_retrieve_features_status() throws Exception {
    ObjectName objectName = new ObjectName(FF4J_OBJECT_NAME);
    @SuppressWarnings("unchecked")
    Map<String, Boolean> fs = (Map<String, Boolean>) mbServConn.getAttribute(objectName, "FeaturesStatus");
    Assert.assertTrue(fs.containsKey("jmxEnabledFeature"));
    Assert.assertFalse(fs.get("jmxEnabledFeature"));
    Assert.assertTrue(fs.containsKey("jmxDisabledFeature"));
    Assert.assertTrue(fs.get("jmxDisabledFeature"));
    Assert.assertTrue(fs.containsKey("jmxFeatureWithAuth"));
    Assert.assertFalse(fs.get("jmxFeatureWithAuth"));
}

From source file:com.dianping.cache.service.impl.ServiceMonitorServiceImpl.java

private ObjectName getStatMbeanName() throws MalformedObjectNameException, NullPointerException {
    if (this.statMbeanName == null) {
        this.statMbeanName = new ObjectName(
                "com.dianping.hawk:name=com.dianping.dpsf.jmx.DpsfRequestorMonitor");
    }//from  w  w w  .  jav  a 2  s .co  m
    return this.statMbeanName;
}

From source file:hermes.ext.jbossmq.JBossMQAdmin.java

public int getDepth(DestinationConfig dConfig) throws JMSException {
    ObjectName objectName = null;

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

            return Integer.parseInt((getRMIAdapter().getAttribute(objectName, "QueueDepth")).toString());
        } else {
            if (dConfig.isDurable()) {
                throw new HermesException("JBoss does not support depth of a durable subscription");
            } else {
                return 0;
            }
        }
    } catch (HermesException ex) {
        throw ex;
    } catch (Exception e) {
        log.error(e.getMessage(), e);

        rmiAdaptor = null;
        throw new HermesException(e);
    }

}

From source file:com.ricston.connectors.dataanalysis.DataAnalysisConnector.java

/**
 * Start the module by registering to the platform Mbean server, and starting the Map DB
 * //from  w  w  w .j a  v a2s .  c o  m
 * @throws MalformedObjectNameException
 * @throws NotCompliantMBeanException
 * @throws InstanceAlreadyExistsException
 * @throws MBeanRegistrationException
 * @throws IOException 
 */
@Start
public void startModule() throws MalformedObjectNameException, NotCompliantMBeanException,
        InstanceAlreadyExistsException, MBeanRegistrationException, IOException {
    application = muleContext.getConfiguration().getId();

    logger.info("**********************************");
    logger.info("*Starting Data Analysis Connector*");
    logger.info("**********************************");

    startMapDb();

    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectName id = new ObjectName(String.format(MBEAN_NAME, application));
    StandardMBean mbean = new StandardMBean(this, DataAnalysisMBean.class);
    server.registerMBean(mbean, id);

    logger.info("Registered mbean using name: " + String.format(MBEAN_NAME, application));
}

From source file:org.jboss.console.plugins.monitor.ManageSnapshotServlet.java

protected void doit(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String action = req.getParameter("action");
    if (action == null) {
        error("unknown action: ", req, resp);
        return;/*ww  w  .j  a v a2 s.  com*/
    }
    action = action.trim();
    MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
    ObjectName monitorObjectName;
    String attribute = null;
    try {
        monitorObjectName = new ObjectName(req.getParameter("monitorObjectName"));
        attribute = (String) mbeanServer.getAttribute(monitorObjectName, "ObservedAttribute");
    } catch (Exception ex) {
        error("Malformed Monitor ObjectName: " + req.getParameter("monitorObjectName"), req, resp);
        return;
    }
    if (action.equals("Start Snapshot")) {
        Object[] nullArgs = {};
        String[] nullSig = {};
        try {
            mbeanServer.invoke(monitorObjectName, "startSnapshot", nullArgs, nullSig);
        } catch (Exception ex) {
            error("Problem invoking startSnapshot: " + ex.toString(), req, resp);
            return;
        }
        req.getRequestDispatcher("/manageSnapshot.jsp").forward(req, resp);
        return;
    } else if (action.equals("Stop Snapshot")) {
        Object[] nullArgs = {};
        String[] nullSig = {};
        try {
            mbeanServer.invoke(monitorObjectName, "endSnapshot", nullArgs, nullSig);
        } catch (Exception ex) {
            error("Problem invoking endSnapshot: " + ex.toString(), req, resp);
            return;
        }
        req.getRequestDispatcher("/manageSnapshot.jsp").forward(req, resp);
        return;
    } else if (action.equals("Clear Dataset")) {
        Object[] nullArgs = {};
        String[] nullSig = {};
        try {
            mbeanServer.invoke(monitorObjectName, "clearData", nullArgs, nullSig);
        } catch (Exception ex) {
            error("Problem invoking clearData: " + ex.toString(), req, resp);
            return;
        }
        req.setAttribute("error", "Dataset Cleared!");
        req.getRequestDispatcher("/manageSnapshot.jsp").forward(req, resp);
        return;
    } else if (action.equals("Remove Snapshot")) {
        try {
            log.debug("removing snapshot: " + monitorObjectName.toString());
            mbeanServer.unregisterMBean(monitorObjectName);
            req.getRequestDispatcher("/ServerInfo.jsp").forward(req, resp);
        } catch (Exception ex) {
            error("Failed to Remove Monitor: " + ex.toString(), req, resp);
        }
        return;
    } else if (action.equals("Show Dataset")) {
        ArrayList data = null;
        long start, end = 0;
        try {
            data = (ArrayList) mbeanServer.getAttribute(monitorObjectName, "Data");
            start = ((Long) mbeanServer.getAttribute(monitorObjectName, "StartTime")).longValue();
            end = ((Long) mbeanServer.getAttribute(monitorObjectName, "EndTime")).longValue();
        } catch (Exception ex) {
            error("Problem invoking getData: " + ex.toString(), req, resp);
            return;
        }
        resp.setContentType("text/html");
        PrintWriter writer = resp.getWriter();
        writer.println("<html>");
        writer.println("<body>");
        writer.println("<b>Start Time:</b> " + start + "ms<br>");
        writer.println("<b>End Time:</b> " + end + "ms<br>");
        writer.println("<b>Total Time:</b> " + (end - start) + "ms<br>");
        writer.println("<br><table border=\"0\">");
        for (int i = 0; i < data.size(); i++) {
            writer.println("<tr><td>" + data.get(i) + "</td></tr");
        }
        writer.println("</table></body></html>");
        return;
    } else if (action.equals("Graph Dataset")) {
        ArrayList data = null;
        long start, end = 0;
        try {
            data = (ArrayList) mbeanServer.getAttribute(monitorObjectName, "Data");
            start = ((Long) mbeanServer.getAttribute(monitorObjectName, "StartTime")).longValue();
            end = ((Long) mbeanServer.getAttribute(monitorObjectName, "EndTime")).longValue();
        } catch (Exception ex) {
            error("Problem invoking getData: " + ex.toString(), req, resp);
            return;
        }
        XYSeries set = new XYSeries(attribute, false, false);
        for (int i = 0; i < data.size(); i++) {
            set.add(new Integer(i), (Number) data.get(i));
        }
        DefaultTableXYDataset dataset = new DefaultTableXYDataset(false);
        dataset.addSeries(set);
        JFreeChart chart = ChartFactory.createXYLineChart("JMX Attribute: " + attribute, "count", attribute,
                dataset, PlotOrientation.VERTICAL, true, true, false);
        resp.setContentType("image/png");
        OutputStream out = resp.getOutputStream();
        ChartUtilities.writeChartAsPNG(out, chart, 400, 300);
        out.close();
        return;
    }
    error("Unknown Action", req, resp);
    return;
}

From source file:net.gcolin.simplerepo.test.AbstractRepoTest.java

protected void setAttributeJmx(String name, String attribute, Object arguments) throws Exception {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectName oname = server.queryNames(new ObjectName(name), null).iterator().next();
    server.setAttribute(oname, new Attribute(attribute, arguments));
}

From source file:fr.xebia.monitoring.demo.payment.ZeRandmolySlowAndBuggyCreditCardService.java

@Override
public ObjectName getObjectName() throws MalformedObjectNameException {
    return new ObjectName(
            Monitoring.JMX_DOMAIN + ":type=RandmolySlowAndBuggyCreditCardService,name=" + beanName);
}

From source file:com.enioka.jqm.tools.Loader.java

Loader(JobInstance job, JqmEngine engine, QueuePoller p, ClassloaderManager clm) {
    this.p = p;//  w ww  .j ava2  s. c  om
    this.engine = engine;
    this.clm = clm;
    this.job = job;
    this.threadName = this.job.getJd().getApplicationName() + ";payload;" + this.job.getId();

    // JMX
    if (p != null && this.p.getEngine().loadJmxBeans) {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        try {
            name = new ObjectName(
                    "com.enioka.jqm:type=Node.Queue.JobInstance,Node=" + this.p.getEngine().getNode().getName()
                            + ",Queue=" + this.p.getQueue().getName() + ",name=" + this.job.getId());
            mbs.registerMBean(this, name);
        } catch (Exception e) {
            throw new JqmInitError("Could not create JMX bean for running job instance", e);
        }
    }
}