Example usage for javax.management MBeanServer registerMBean

List of usage examples for javax.management MBeanServer registerMBean

Introduction

In this page you can find the example usage for javax.management MBeanServer registerMBean.

Prototype

public ObjectInstance registerMBean(Object object, ObjectName name)
        throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException;

Source Link

Document

Registers a pre-existing object as an MBean with the MBean server.

Usage

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

/**
 * Start the module by registering to the platform Mbean server, and starting the Map DB
 * /*w  ww. j  a  va 2 s.  com*/
 * @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.ow2.proactive.scheduler.core.jmx.SchedulerJMXHelper.java

/**
 * {@inheritDoc}/*from  w w w .j  a  v  a2 s.c  o  m*/
 */
@Override
public void registerMBeans(final MBeanServer mbs) {
    // Register the Scheduler runtime MBean into the MBean server
    try {
        this.schedulerRuntimeMBean = new RuntimeDataMBeanImpl(dbManager);
        final ObjectName name = new ObjectName(RUNTIMEDATA_MBEAN_NAME);
        mbs.registerMBean(this.schedulerRuntimeMBean, name);

        String dataBaseName = PASchedulerProperties.SCHEDULER_HOME.getValueAsString()
                + System.getProperty("file.separator")
                + PASchedulerProperties.SCHEDULER_RRD_DATABASE_NAME.getValueAsString();

        FileUtils.forceMkdir(new File(dataBaseName).getParentFile());
        if (PASchedulerProperties.SCHEDULER_DB_HIBERNATE_DROPDB.getValueAsBoolean()) {
            // dropping the RDD data base
            File rrdDataBase = new File(dataBaseName);
            if (rrdDataBase.exists()) {
                rrdDataBase.delete();
            }
        }

        setDataStore(new RRDDataStore((StandardMBean) schedulerRuntimeMBean, dataBaseName,
                PASchedulerProperties.SCHEDULER_RRD_STEP.getValueAsInt(),
                Logger.getLogger(SchedulerJMXHelper.class)));

    } catch (Exception e) {
        LOGGER.error("Unable to register the RuntimeDataMBean", e);
    }

    // Register the MyAccount MBean into the MBean server
    try {
        final MyAccountMBeanImpl myAccountMBean = new MyAccountMBeanImpl(this.accountsManager);
        final ObjectName name = new ObjectName(MYACCOUNT_MBEAN_NAME);
        mbs.registerMBean(myAccountMBean, name);
    } catch (Exception e) {
        LOGGER.error("Unable to register the MyAccountMBean", e);
    }

    // Register the ViewAccount MBean into the MBean server
    try {
        final AllAccountsMBeanImpl viewAccountMBean = new AllAccountsMBeanImpl(this.accountsManager);
        final ObjectName name = new ObjectName(ALLACCOUNTS_MBEAN_NAME);
        mbs.registerMBean(viewAccountMBean, name);
    } catch (Exception e) {
        LOGGER.error("Unable to register the AllAccountsMBean", e);
    }

    // Register the Management MBean into the MBean server
    try {
        final ManagementMBeanImpl managementMBean = new ManagementMBeanImpl(this.accountsManager);
        final ObjectName name = new ObjectName(MANAGEMENT_MBEAN_NAME);
        mbs.registerMBean(managementMBean, name);
    } catch (Exception e) {
        LOGGER.error("Unable to register the ManagementMBean", e);
    }
}

From source file:org.geoserver.wfs.notification.GMLNotificationSerializer.java

private final void registerMBean() {
    if (name == null) {
        return;//  ww  w .  j a  v a 2 s  .c o m
    }

    for (MBeanServer server : MBeanServerFactory.findMBeanServer(null)) {
        try {
            server.registerMBean(this, name);
        } catch (JMException e) {
            LOG.warn("Unable to register in JMX:", e);
        }
    }
}

From source file:com.twitter.hraven.hadoopJobMonitor.HadoopJobMonitorService.java

public void init() {
    YarnConfiguration yConf = new YarnConfiguration();
    DefaultMetricsSystem.initialize("HadoopJobMonitor");
    String logDir = System.getProperty("hadoopJobMonitor.log.dir");
    if (logDir == null)
        logDir = "/tmp";
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {/*from ww  w .j av a  2s  .co  m*/
        ObjectName name = new ObjectName(
                "com.twitter.hraven.hadoopJobMonitor.jmx:type=" + WhiteList.class.getSimpleName());
        WhiteList.init(logDir);
        WhiteList mbean = WhiteList.getInstance();
        mbs.registerMBean(mbean, name);
        LOG.error("Current whitelist is: \n" + mbean.getExpirations());
    } catch (Exception e) {
        LOG.fatal("Error in retriving white list from dir " + logDir, e);
    }

    metrics = HadoopJobMonitorMetrics.initSingleton(conf);

    rmDelegate = new ResourceMgrDelegate(yConf);
    clientCache = new ClientCache(conf, rmDelegate);
    AppConfCache.init(conf);
    ProgressCache.init(conf);
    Mail.init(conf);
    Notifier.init(conf);
    clusterCheckerExecutor = Executors
            .newSingleThreadScheduledExecutor(new ClusterStatusChecker.SimpleThreadFactory());
    int concurrentAppCheckers = conf.getInt(HadoopJobMonitorConfiguration.NEW_APP_CHECKER_CONCURRENCY,
            HadoopJobMonitorConfiguration.DEFAULT_NEW_APP_CHECKER_CONCURRENCY);
    appCheckerExecutor = new BlockingExecutor(concurrentAppCheckers,
            new AppStatusChecker.SimpleThreadFactory());
}

From source file:org.apache.cassandra.db.HintedHandOffManager.java

public HintedHandOffManager() {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {//from  w w w. ja v  a 2 s  . co  m
        mbs.registerMBean(this, new ObjectName("org.apache.cassandra.db:type=HintedHandoffManager"));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.jolokia.detector.ServerHandle.java

/**
 * Register a MBean at the dedicated server. This method can be overridden if
 * something special registration procedure is required, like for using the
 * specific name for the registration or deligating the namin to MBean to register.
 *
 * @param pServer server an MBean should be registered
 * @param pMBean the MBean to register//from w  w  w . j a v a2  s.  c  om
 * @param pName an optional name under which the MBean should be registered. Can be null
 * @return the object name of the registered MBean
 * @throws MBeanRegistrationException when registration failed
 * @throws InstanceAlreadyExistsException when there is already MBean with this name
 * @throws NotCompliantMBeanException
 * @throws MalformedObjectNameException if the name is not valid
 */
public ObjectName registerMBeanAtServer(MBeanServer pServer, Object pMBean, String pName)
        throws MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException,
        MalformedObjectNameException {
    if (pName != null) {
        ObjectName oName = new ObjectName(pName);
        return pServer.registerMBean(pMBean, oName).getObjectName();
    } else {
        // Needs to implement MBeanRegistration interface
        return pServer.registerMBean(pMBean, null).getObjectName();
    }
}

From source file:org.opencastproject.userdirectory.ldap.LdapUserProviderInstance.java

/**
 * Registers an MXBean./*from   w  w  w. ja va 2  s .c  om*/
 */
protected void registerMBean(String pid) {
    // register with jmx
    requests = new AtomicLong();
    ldapLoads = new AtomicLong();
    try {
        ObjectName name;
        name = LdapUserProviderFactory.getObjectName(pid);
        Object mbean = this;
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        try {
            mbs.unregisterMBean(name);
        } catch (InstanceNotFoundException e) {
            logger.debug(name + " was not registered");
        }
        mbs.registerMBean(mbean, name);
    } catch (Exception e) {
        logger.warn("Unable to register {} as an mbean: {}", this, e);
    }
}

From source file:org.sakaiproject.search.mbeans.SearchServiceManagement.java

/**
 * //from w w  w . ja  v a2s . com
 */
public void init() {
    try {

        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

        final ObjectName searchServiceON = new ObjectName(MBEAN_COMPONENT_BASE + name);
        mbs.registerMBean(this, searchServiceON);

        indexStorageProvider.addIndexListener(new IndexListener() {

            public void doIndexReaderClose(IndexReader oldMultiReader) throws IOException {
                sendNotification(new Notification("index-reader-close", searchServiceON, notificationNo++,
                        "Closed oldMultiReader"));
            }

            public void doIndexReaderOpen(IndexReader newMultiReader) {
                sendNotification(new Notification("index-reader-open", searchServiceON, notificationNo++,
                        "Opened newMultiReader"));
            }

            public void doIndexSearcherClose(IndexSearcher indexSearcher) throws IOException {
                sendNotification(new Notification("index-searcher-close", searchServiceON, notificationNo++,
                        "Closed " + indexSearcher.toString()));

            }

            public void doIndexSearcherOpen(IndexSearcher indexSearcher) {
                sendNotification(new Notification("index-searcher-open", searchServiceON, notificationNo++,
                        "Opened " + indexSearcher.toString()));
            }

        });

        indexWorker.addIndexWorkerDocumentListener(new IndexWorkerDocumentListener() {

            public void indexDocumentEnd(IndexWorker worker, String ref) {
                sendNotification(new Notification("index-document-start", searchServiceON, notificationNo++,
                        "Doc Ref " + ref));
            }

            public void indexDocumentStart(IndexWorker worker, String ref) {
                sendNotification(new Notification("index-document-end", searchServiceON, notificationNo++,
                        "Doc Ref " + ref));
            }

        });

        indexWorker.addIndexWorkerListener(new IndexWorkerListener() {

            public void indexWorkerEnd(IndexWorker worker) {
                sendNotification(new Notification("index-woker-start", searchServiceON, notificationNo++,
                        "Worker " + worker));

            }

            public void indexWorkerStart(IndexWorker worker) {
                sendNotification(new Notification("index-woker-end", searchServiceON, notificationNo++,
                        "Worker " + worker));
            }

        });

    } catch (Exception ex) {
        log.warn("Failed to register mbean for search service ", ex);

    }

}

From source file:org.bigmouth.nvwa.transport.DelegatedSender.java

@Override
protected void doInit() {
    Preconditions.checkNotNull(this.nextSender, "nextSender");

    sendExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {

        @Override/*  www  .j  a v a  2  s  . com*/
        public Thread newThread(Runnable r) {
            return new Thread(r, threadName + "-" + idx.get());
        }
    });

    sendQueue = new LinkedBlockingQueue<Object>(pendingMessageCount);
    startupProcessor();

    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    if (null != senderMBeanName) {
        DelegatedSenderMBean acceptorMBean = new DelegatedSenderMBean(this);
        try {
            ObjectName acceptorName = new ObjectName(this.senderMBeanName);
            mBeanServer.registerMBean(acceptorMBean, acceptorName);
        } catch (MalformedObjectNameException e) {
            LOG.error("Unable DelegatedSender jmx register:", e);
        } catch (NullPointerException e) {
            LOG.error("Unable DelegatedSender jmx register:", e);
        } catch (InstanceAlreadyExistsException e) {
            LOG.error("Unable DelegatedSender jmx register:", e);
        } catch (MBeanRegistrationException e) {
            LOG.error("Unable DelegatedSender jmx register:", e);
        } catch (NotCompliantMBeanException e) {
            LOG.error("Unable MinaSender jmx register:", e);
        }
    }
}

From source file:com.tesora.dve.server.bootstrap.BootstrapHost.java

@Override
protected void registerMBeans() {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    try {//from   www .j a v a 2  s .co m
        server.registerMBean(this, new ObjectName(MBEAN_BOOTSTRAP_HOST));
    } catch (Exception e) {
        logger.error("Unable to register " + MBEAN_BOOTSTRAP_HOST + " mbean", e);
    }

    try {
        HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
        server.registerMBean(hdm, new ObjectName(MBEAN_LOG4J_HIERARCHY));

        // Add the root logger to the Hierarchy MBean
        hdm.addLoggerMBean(Logger.getRootLogger().getName());

        LoggerRepository r = LogManager.getLoggerRepository();

        @SuppressWarnings("rawtypes")
        Enumeration loggers = r.getCurrentLoggers();
        while (loggers.hasMoreElements()) {
            hdm.addLoggerMBean(((Logger) loggers.nextElement()).getName());
        }
    } catch (Exception e) {
        logger.error("Unable to register " + MBEAN_LOG4J_HIERARCHY + " mbean", e);
    }

    super.registerMBeans();
}