Example usage for javax.management StandardMBean StandardMBean

List of usage examples for javax.management StandardMBean StandardMBean

Introduction

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

Prototype

public <T> StandardMBean(T implementation, Class<T> mbeanInterface, boolean isMXBean) 

Source Link

Document

Make a DynamicMBean out of the object implementation, using the specified mbeanInterface class, and choosing whether the resultant MBean is an MXBean.

Usage

From source file:org.red5.server.ClientRegistry.java

public ClientRegistry(String name) {
    this.name = name;
    if (StringUtils.isNotBlank(this.name)) {
        try {//from w w w .  j  a v a2 s .  c o  m
            MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
            ObjectName oName = new ObjectName("org.red5.server:type=ClientRegistry,name=" + name);
            mbeanServer.registerMBean(new StandardMBean(this, ClientRegistryMXBean.class, true), oName);
        } catch (Exception e) {
            //log.warn("Error on jmx registration", e);
        }
    }
}

From source file:org.red5.server.scheduling.ApplicationSchedulingService.java

protected void registerJMX() {
    //register with jmx server
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    try {/*w  w  w. j a  va 2s .c om*/
        ObjectName oName = null;
        if (instanceId == null) {
            oName = new ObjectName(
                    "org.red5.server:type=ApplicationSchedulingService,applicationName=" + applicationName);
        } else {
            oName = new ObjectName("org.red5.server:type=ApplicationSchedulingService,applicationName="
                    + applicationName + ",instanceId=" + instanceId);
        }
        mbeanServer.registerMBean(new StandardMBean(this, QuartzSchedulingServiceMXBean.class, true), oName);
    } catch (Exception e) {
        log.warn("Error on jmx registration", e);
    }
}

From source file:io.fabric8.support.impl.SupportServiceImpl.java

@Activate
void activate() {
    activateComponent();/*from w  w  w.  j a  v  a2  s.  c  om*/
    if (objectName == null) {
        try {
            objectName = getObjectName();
        } catch (Exception e) {
            LOGGER.warn("Failed to create object name: ", e);
            throw new RuntimeException("Failed to create object name: ", e);
        }
    }

    if (mBeanServer == null) {
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    }

    if (mBeanServer != null) {
        try {
            mbean = new StandardMBean(this, SupportService.class, false);
            mBeanServer.registerMBean(mbean, objectName);
        } catch (InstanceAlreadyExistsException iaee) {
            // Try to remove and re-register
            try {
                mBeanServer.unregisterMBean(objectName);
                mBeanServer.registerMBean(this, objectName);
            } catch (Exception e) {
                LOGGER.warn("Failed to register mbean: " + objectName, e);
                throw new RuntimeException("Failed to register mbean: " + objectName, e);
            }
        } catch (Exception e) {
            LOGGER.warn("Failed to register mbean: " + objectName, e);
            throw new RuntimeException("Failed to register mbean: " + objectName, e);
        }
    }
}

From source file:io.fabric8.support.impl.SupportServiceImpl.java

@Deactivate
void deactivate() {
    deactivateComponent();/* ww w.  j a v  a 2  s.c om*/
    if (mBeanServer != null) {
        mbean = new StandardMBean(this, SupportService.class, false);
        try {
            mBeanServer.unregisterMBean(objectName);
        } catch (InstanceNotFoundException e) {
        } catch (MBeanRegistrationException e) {
            LOGGER.warn("Failed to deregister mbean: " + objectName, e);
            throw new RuntimeException("Failed to deregister mbean: " + objectName, e);
        }

    }
}

From source file:org.red5.server.stream.ClientBroadcastStream.java

protected void registerJMX() {
    if (registerJMX) {
        // register with jmx
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        try {// w  ww.  j a va  2 s .co m
            ObjectName oName = new ObjectName(
                    String.format("org.red5.server:type=ClientBroadcastStream,scope=%s,publishedName=%s",
                            getScope().getName(), publishedName));
            mbs.registerMBean(new StandardMBean(this, ClientBroadcastStreamMXBean.class, true), oName);
        } catch (InstanceAlreadyExistsException e) {
            log.debug("Instance already registered", e);
        } catch (Exception e) {
            log.warn("Error on jmx registration", e);
        }
    }
}

From source file:org.red5.server.scope.Scope.java

protected void registerJMX() {
    // register with jmx
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {/*from   ww  w .j  a v a 2 s.  c o m*/
        String cName = this.getClass().getName();
        if (cName.indexOf('.') != -1) {
            cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
        }
        oName = new ObjectName(String.format("org.red5.server:type=%s,name=%s", cName, name));
        // don't reregister
        if (!mbs.isRegistered(oName)) {
            mbs.registerMBean(new StandardMBean(this, ScopeMXBean.class, true), oName);
        }
    } catch (Exception e) {
        log.warn("Error on jmx registration", e);
    }
}

From source file:org.apache.accumulo.server.tabletserver.ScanRunState.java

public void run() {
    SecurityUtil.serverLogin();//from w  ww . j  a v a2  s .co  m

    try {
        clientAddress = startTabletClientService();
    } catch (UnknownHostException e1) {
        throw new RuntimeException("Failed to start the tablet client service", e1);
    }
    announceExistence();

    ThreadPoolExecutor distWorkQThreadPool = new SimpleThreadPool(
            getSystemConfiguration().getCount(Property.TSERV_WORKQ_THREADS), "distributed work queue");

    bulkFailedCopyQ = new DistributedWorkQueue(ZooUtil.getRoot(instance) + Constants.ZBULK_FAILED_COPYQ);
    try {
        bulkFailedCopyQ.startProcessing(new BulkFailedCopyProcessor(), distWorkQThreadPool);
    } catch (Exception e1) {
        throw new RuntimeException("Failed to start distributed work queue for copying ", e1);
    }

    try {
        logSorter.startWatchingForRecoveryLogs(distWorkQThreadPool);
    } catch (Exception ex) {
        log.error("Error setting watches for recoveries");
        throw new RuntimeException(ex);
    }

    try {
        OBJECT_NAME = new ObjectName(
                "accumulo.server.metrics:service=TServerInfo,name=TabletServerMBean,instance="
                        + Thread.currentThread().getName());
        // Do this because interface not in same package.
        StandardMBean mbean = new StandardMBean(this, TabletServerMBean.class, false);
        this.register(mbean);
        mincMetrics.register();
    } catch (Exception e) {
        log.error("Error registering with JMX", e);
    }

    String masterHost;
    while (!serverStopRequested) {
        // send all of the pending messages
        try {
            MasterMessage mm = null;
            MasterClientService.Client iface = null;

            try {
                // wait until a message is ready to send, or a sever stop
                // was requested
                while (mm == null && !serverStopRequested) {
                    mm = masterMessages.poll(1000, TimeUnit.MILLISECONDS);
                }

                // have a message to send to the master, so grab a
                // connection
                masterHost = getMasterAddress();
                iface = masterConnection(masterHost);
                TServiceClient client = iface;

                // if while loop does not execute at all and mm != null,
                // then
                // finally block should place mm back on queue
                while (!serverStopRequested && mm != null && client != null
                        && client.getOutputProtocol() != null
                        && client.getOutputProtocol().getTransport() != null
                        && client.getOutputProtocol().getTransport().isOpen()) {
                    try {
                        mm.send(SystemCredentials.get().toThrift(instance), getClientAddressString(), iface);
                        mm = null;
                    } catch (TException ex) {
                        log.warn("Error sending message: queuing message again");
                        masterMessages.putFirst(mm);
                        mm = null;
                        throw ex;
                    }

                    // if any messages are immediately available grab em and
                    // send them
                    mm = masterMessages.poll();
                }

            } finally {

                if (mm != null) {
                    masterMessages.putFirst(mm);
                }
                returnMasterConnection(iface);

                UtilWaitThread.sleep(1000);
            }
        } catch (InterruptedException e) {
            log.info("Interrupt Exception received, shutting down");
            serverStopRequested = true;

        } catch (Exception e) {
            // may have lost connection with master
            // loop back to the beginning and wait for a new one
            // this way we survive master failures
            log.error(getClientAddressString() + ": TServerInfo: Exception. Master down?", e);
        }
    }

    // wait for shutdown
    // if the main thread exits oldServer the master listener, the JVM will
    // kill the
    // other threads and finalize objects. We want the shutdown that is
    // running
    // in the master listener thread to complete oldServer this happens.
    // consider making other threads daemon threads so that objects don't
    // get prematurely finalized
    synchronized (this) {
        while (shutdownComplete == false) {
            try {
                this.wait(1000);
            } catch (InterruptedException e) {
                log.error(e.toString());
            }
        }
    }
    log.debug("Stopping Thrift Servers");
    TServerUtils.stopTServer(server);

    try {
        log.debug("Closing filesystem");
        fs.close();
    } catch (IOException e) {
        log.warn("Failed to close filesystem : " + e.getMessage(), e);
    }

    logGCInfo(getSystemConfiguration());

    log.info("TServerInfo: stop requested. exiting ... ");

    try {
        tabletServerLock.unlock();
    } catch (Exception e) {
        log.warn("Failed to release tablet server lock", e);
    }
}