Example usage for javax.management.modelmbean RequiredModelMBean RequiredModelMBean

List of usage examples for javax.management.modelmbean RequiredModelMBean RequiredModelMBean

Introduction

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

Prototype

public RequiredModelMBean(ModelMBeanInfo mbi) throws MBeanException, RuntimeOperationsException 

Source Link

Document

Constructs a RequiredModelMBean object using ModelMBeanInfo passed in.

Usage

From source file:org.sakaiproject.kernel.loader.server.test.DummySharedClassLoaderContainer.java

/**
 * Create a shared classloader object./*  ww w .  j  a  v a2 s . co  m*/
 * 
 * @param kernel
 *          the kernel to connect to.
 * @param shutdownService
 *          the shutdown service.
 * @throws JMRuntimeException
 * @throws JMException
 * @throws InvalidTargetObjectTypeException
 */
public DummySharedClassLoaderContainer(ClassLoader classLoader)
        throws JMRuntimeException, JMException, InvalidTargetObjectTypeException {
    this.sharedClassLoader = classLoader;
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    RequiredModelMBean model = new RequiredModelMBean(createMBeanInfo());
    model.setManagedResource(this, "objectReference");
    ObjectName common = new ObjectName(CommonObject.MBEAN_COMMON + ".sharedclassloader");
    mbs.registerMBean(model, common);
}

From source file:org.sakaiproject.kernel.component.core.SharedClassLoaderContainer.java

/**
 * Create a shared classloader object./*from   w  w  w  .  j  av  a 2 s. c o m*/
 * 
 * @param kernel
 *          the kernel to connect to.
 * @param shutdownService
 *          the shutdown service.
 * @throws JMRuntimeException
 * @throws JMException
 * @throws InvalidTargetObjectTypeException
 */
@Inject
public SharedClassLoaderContainer(Kernel kernel, ShutdownService shutdownService, SharedClassLoader classLoader)
        throws JMRuntimeException, JMException, InvalidTargetObjectTypeException {
    this.sharedClassLoader = classLoader;
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    RequiredModelMBean model = new RequiredModelMBean(createMBeanInfo());
    model.setManagedResource(this, "objectReference");
    ObjectName common = new ObjectName(CommonObject.MBEAN_COMMON + ".sharedclassloader");
    mbs.registerMBean(model, common);

    // Explicit register this container to be shutdown, we dont want this
    // container exposed as a service, so we register directly. Within the
    // same module, this approach should be taken to give the IoC container
    // a dependency graph.
    shutdownService.register(this);
}

From source file:org.sakaiproject.kernel.component.KernelLifecycle.java

/**
 * Execute the start phase of the lifecycle, creating the MBean and registering the newly started
 * Kernel with JMX.//from ww w  .jav  a 2 s . c  o  m
 *
 * @see org.sakaiproject.kernel.loader.common.CommonLifecycle#start()
 */
public void start() {
    LOG.info("==========PHASE 1 STARTING =================");
    try {
        long start = System.currentTimeMillis();
        lifecycleEvent(CommonLifecycleEvent.BEFORE_START);
        lastLoadDate = new Date();

        // Start the kernel
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        RequiredModelMBean model = new RequiredModelMBean(createMBeanInfo());
        model.setManagedResource(this, "objectReference");
        ObjectName kernelName = new ObjectName(Kernel.MBEAN_KERNEL);
        mbs.registerMBean(model, kernelName);

        kernel = new KernelImpl();

        kernel.start();

        // Start the service manager
        serviceManager = new ServiceManagerImpl(kernel);
        serviceManager.start();

        // Start the component manager.
        componentManager = new ComponentManagerImpl(kernel);
        componentManager.start();

        try {
            System.runFinalization();
            Runtime.getRuntime().gc();
            CompositeData permGen = null;
            try {
                permGen = (CompositeData) mbs
                        .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Perm Gen"), "Usage");
            } catch (Exception ex) {
                permGen = (CompositeData) mbs
                        .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=CMS Perm Gen"), "Usage");
            }
            CompositeData tenuredGen;
            try {
                tenuredGen = (CompositeData) mbs
                        .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Tenured Gen"), "Usage");
            } catch (Exception ex) {
                tenuredGen = (CompositeData) mbs
                        .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=CMS Old Gen"), "Usage");
            }
            CompositeData codeCache = (CompositeData) mbs
                    .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Code Cache"), "Usage");
            CompositeData edenSpace = null;
            try {
                edenSpace = (CompositeData) mbs
                        .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Eden Space"), "Usage");
            } catch (Exception ex) {
                edenSpace = (CompositeData) mbs
                        .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Par Eden Space"), "Usage");

            }
            CompositeData survivorSpace = null;
            try {
                survivorSpace = (CompositeData) mbs
                        .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Survivor Space"), "Usage");
            } catch (Exception ex) {
                survivorSpace = (CompositeData) mbs.getAttribute(
                        new ObjectName("java.lang:type=MemoryPool,name=Par Survivor Space"), "Usage");
            }
            long permGenUsed = Long.parseLong(String.valueOf(permGen.get("used")));
            long codeCacheUsed = Long.parseLong(String.valueOf(codeCache.get("used")));
            long edenSpaceUsed = Long.parseLong(String.valueOf(edenSpace.get("used")));
            long tenuredGenUsed = Long.parseLong(String.valueOf(tenuredGen.get("used")));
            long survivorSpaceUsed = Long.parseLong(String.valueOf(survivorSpace.get("used")));

            LOG.info("Memory Stats after startup\n" + "\tPermgen Used " + permGenUsed / (ONEM) + " MB\n"
                    + "\tCode Cache Used " + codeCacheUsed / (ONEM) + " MB\n" + "\tEden Used "
                    + edenSpaceUsed / (ONEM) + " MB\n" + "\tTenured Used " + tenuredGenUsed / (ONEM) + " MB\n"
                    + "\tSurvivour Used " + survivorSpaceUsed / (ONEM) + " MB");
        } catch (RuntimeException ex2) {
            LOG.info("Startup Memory Stats Not available ", ex2);
        } catch (Exception ex2) {
            LOG.info("Startup Memory Stats Not available ", ex2);
        }
        lifecycleEvent(CommonLifecycleEvent.START);
        lifecycleEvent(CommonLifecycleEvent.AFTER_START);
        loadTime = System.currentTimeMillis() - start;

    } catch (Throwable ex) {
        LOG.error("Failed to start Component Lifecycle ", ex);
        throw new Error("Failed to start Component Lifecycle ", ex);
    }
    LOG.info("============END of LIFECYCLE STARTUP===============================");

}