Example usage for javax.management Notification Notification

List of usage examples for javax.management Notification Notification

Introduction

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

Prototype

public Notification(String type, Object source, long sequenceNumber) 

Source Link

Document

Creates a Notification object.

Usage

From source file:org.apache.catalina.core.StandardContext.java

/**
 * Stop this Context component.//  www . j  av  a2  s .com
 *
 * @exception LifecycleException if a shutdown error occurs
 */
public synchronized void stop() throws LifecycleException {

    // Validate and update our current component state
    if (!started)
        throw new LifecycleException(sm.getString("containerBase.notStarted", logName()));

    if (log.isDebugEnabled())
        log.debug("Stopping");

    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null);

    // Send j2ee.state.stopping notification 
    if (this.getObjectName() != null) {
        Notification notification = new Notification("j2ee.state.stopping", this.getObjectName(),
                sequenceNumber++);
        broadcaster.sendNotification(notification);
    }

    // Mark this application as unavailable while we shut down
    setAvailable(false);

    // Binding thread
    ClassLoader oldCCL = bindThread();

    // Stop our filters
    filterStop();

    // Stop our application listeners
    listenerStop();

    // Finalize our character set mapper
    setCharsetMapper(null);

    // Stop ContainerBackgroundProcessor thread
    super.threadStop();

    if ((manager != null) && (manager instanceof Lifecycle)) {
        ((Lifecycle) manager).stop();
    }

    // Normal container shutdown processing
    if (log.isDebugEnabled())
        log.debug("Processing standard container shutdown");
    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(STOP_EVENT, null);
    started = false;

    try {

        // Stop the Valves in our pipeline (including the basic), if any
        if (pipeline instanceof Lifecycle) {
            ((Lifecycle) pipeline).stop();
        }

        // Stop our child containers, if any
        Container[] children = findChildren();
        for (int i = 0; i < children.length; i++) {
            if (children[i] instanceof Lifecycle)
                ((Lifecycle) children[i]).stop();
        }

        // Stop resources
        resourcesStop();

        if ((realm != null) && (realm instanceof Lifecycle)) {
            ((Lifecycle) realm).stop();
        }
        if ((cluster != null) && (cluster instanceof Lifecycle)) {
            ((Lifecycle) cluster).stop();
        }
        if ((logger != null) && (logger instanceof Lifecycle)) {
            ((Lifecycle) logger).stop();
        }
        if ((loader != null) && (loader instanceof Lifecycle)) {
            ((Lifecycle) loader).stop();
        }

    } finally {

        // Unbinding thread
        unbindThread(oldCCL);

    }

    // Send j2ee.state.stopped notification 
    if (this.getObjectName() != null) {
        Notification notification = new Notification("j2ee.state.stopped", this.getObjectName(),
                sequenceNumber++);
        broadcaster.sendNotification(notification);
    }

    // Reset application context
    context = null;

    wrappers = new ArrayList();

    // This object will no longer be visible or used. 
    try {
        resetContext();
    } catch (Exception ex) {
        log.error("Error reseting context " + this + " " + ex, ex);
    }

    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null);

    if (log.isDebugEnabled())
        log.debug("Stopping complete");

}

From source file:org.apache.catalina.core.StandardContext.java

/** Destroy needs to clean up the context completely.
 * //from  ww w  .  jav  a  2  s. c  o m
 * The problem is that undoing all the config in start() and restoring 
 * a 'fresh' state is impossible. After stop()/destroy()/init()/start()
 * we should have the same state as if a fresh start was done - i.e
 * read modified web.xml, etc. This can only be done by completely 
 * removing the context object and remapping a new one, or by cleaning
 * up everything.
 * 
 * XXX Should this be done in stop() ?
 * 
 */
public void destroy() throws Exception {
    if (oname != null) {
        // Send j2ee.object.deleted notification 
        Notification notification = new Notification("j2ee.object.deleted", this.getObjectName(),
                sequenceNumber++);
        broadcaster.sendNotification(notification);
    }
    super.destroy();
}

From source file:org.apache.catalina.core.StandardContext.java

private void registerJMX() {
    try {//from  ww w . j  av a2  s .co  m
        if (log.isDebugEnabled()) {
            log.debug("Checking for " + oname);
        }
        if (!Registry.getRegistry().getMBeanServer().isRegistered(oname)) {
            controller = oname;
            Registry.getRegistry().registerComponent(this, oname, null);

            // Send j2ee.object.created notification 
            if (this.getObjectName() != null) {
                Notification notification = new Notification("j2ee.object.created", this.getObjectName(),
                        sequenceNumber++);
                broadcaster.sendNotification(notification);
            }
        }
        for (Iterator it = wrappers.iterator(); it.hasNext();) {
            StandardWrapper wrapper = (StandardWrapper) it.next();
            // XXX prevent duplicated registration
            wrapper.registerJMX(this);
        }
    } catch (Exception ex) {
        log.info("Error registering wrapper with jmx " + this + " " + oname + " " + ex.toString(), ex);
    }
}

From source file:org.apache.catalina.core.StandardContext.java

public void init() throws Exception {

    if (this.getParent() == null) {
        ObjectName parentName = getParentName();

        if (!mserver.isRegistered(parentName)) {
            log.debug("No host, creating one " + parentName);
            StandardHost host = new StandardHost();
            host.setName(hostName);//from   w  w w. j  av a  2 s. c o m
            host.setAutoDeploy(false);
            Registry.getRegistry().registerComponent(host, parentName, null);
            mserver.invoke(parentName, "init", new Object[] {}, new String[] {});
        }
        ContextConfig config = new ContextConfig();
        this.addLifecycleListener(config);

        log.debug("AddChild " + parentName + " " + this);
        try {
            mserver.invoke(parentName, "addChild", new Object[] { this },
                    new String[] { "org.apache.catalina.Container" });
        } catch (Exception e) {
            destroy();
            throw e;
        }
    }
    super.init();

    // Send j2ee.state.starting notification 
    if (this.getObjectName() != null) {
        Notification notification = new Notification("j2ee.state.starting", this.getObjectName(),
                sequenceNumber++);
        broadcaster.sendNotification(notification);
    }

}