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:com.apress.prospringintegration.jmx.BasicMBean.java

@ManagedOperation
public Integer add(Integer a, Integer b) {
    notificationPublisher.sendNotification(new Notification("add", this, 0));
    return a + b;
}

From source file:de.stefanheintz.log.jmxservice.LoggingConfigImpl.java

private synchronized void sendNotification(NotificationType notificationType, String message) {
    Long counter = 0L;// w  ww  .  j a va  2  s.c o  m
    if (!notificationTypeMap.containsKey(notificationType))
        notificationTypeMap.put(notificationType, counter);

    counter = notificationTypeMap.get(notificationType);
    notificationTypeMap.put(notificationType, Long.valueOf(counter + 1));

    Notification notification = new Notification(notificationType.toString(), this, counter);
    notification.setUserData(message);
    publisher.sendNotification(notification);
}

From source file:org.jboss.web.tomcat.tc5.Tomcat5.java

public void startConnectors() throws Exception {
    ObjectName service = new ObjectName(catalinaDomain + ":type=Service,serviceName=jboss.web");
    Object[] args = {};/*from   www.  j a  v a2  s.  c  o m*/
    String[] sig = {};
    Connector[] connectors = (Connector[]) server.invoke(service, "findConnectors", args, sig);
    for (int n = 0; n < connectors.length; n++) {
        Lifecycle lc = (Lifecycle) connectors[n];
        lc.start();
    }

    //There may be a need to start the connectors that are defined in
    //the multiple services in tomcat server.xml
    startAllConnectors();

    // Notify listeners that connectors have started processing requests
    sendNotification(new Notification(TOMCAT_CONNECTORS_STARTED, this, getNextNotificationSequenceNumber()));
}

From source file:org.apache.jk.common.ChannelSocket.java

public int invoke(Msg msg, MsgContext ep) throws IOException {
    int type = ep.getType();

    switch (type) {
    case JkHandler.HANDLE_RECEIVE_PACKET:
        if (log.isDebugEnabled())
            log.debug("RECEIVE_PACKET ?? ");
        return receive(msg, ep);
    case JkHandler.HANDLE_SEND_PACKET:
        return send(msg, ep);
    case JkHandler.HANDLE_FLUSH:
        return flush(msg, ep);
    }/*from  www . j ava 2s  .co m*/

    if (log.isDebugEnabled())
        log.debug("Call next " + type + " " + next);

    // Send notification
    if (nSupport != null) {
        Notification notif = (Notification) ep.getNote(notifNote);
        if (notif == null) {
            notif = new Notification("channelSocket.message", ep, requestCount);
            ep.setNote(notifNote, notif);
        }
        nSupport.sendNotification(notif);
    }

    if (next != null) {
        return next.invoke(msg, ep);
    } else {
        log.info("No next ");
    }

    return OK;
}

From source file:com.sun.grizzly.http.jk.common.ChannelNioSocket.java

@Override
public int invoke(Msg msg, MsgContext ep) throws IOException {
    int type = ep.getType();

    switch (type) {
    case JkHandler.HANDLE_RECEIVE_PACKET:
        if (LoggerUtils.getLogger().isLoggable(Level.FINEST)) {
            LoggerUtils.getLogger().log(Level.FINEST, "RECEIVE_PACKET ?? ");
        }/*from   w ww. j  a  v  a  2s .c o  m*/
        return receive(msg, ep);
    case JkHandler.HANDLE_SEND_PACKET:
        return send(msg, ep);
    case JkHandler.HANDLE_FLUSH:
        return flush(msg, ep);
    }

    if (LoggerUtils.getLogger().isLoggable(Level.FINE)) {
        LoggerUtils.getLogger().log(Level.FINE, "Call next " + type + " " + next);
    }

    // Send notification
    if (nSupport != null) {
        Notification notif = (Notification) ep.getNote(notifNote);
        if (notif == null) {
            notif = new Notification("channelNioSocket.message", ep, requestCount);
            ep.setNote(notifNote, notif);
        }
        nSupport.sendNotification(notif);
    }

    if (next != null) {
        return next.invoke(msg, ep);
    } else {
        LoggerUtils.getLogger().info("No next ");
    }

    return OK;
}

From source file:com.sun.grizzly.http.jk.common.ChannelSocket.java

public int invoke(Msg msg, MsgContext ep) throws IOException {
    int type = ep.getType();

    switch (type) {
    case JkHandler.HANDLE_RECEIVE_PACKET:
        if (LoggerUtils.getLogger().isLoggable(Level.FINEST)) {
            LoggerUtils.getLogger().log(Level.FINEST, "RECEIVE_PACKET ?? ");
        }//from w ww.j  av a2  s.  c  o  m
        return receive(msg, ep);
    case JkHandler.HANDLE_SEND_PACKET:
        return send(msg, ep);
    case JkHandler.HANDLE_FLUSH:
        return flush(msg, ep);
    }

    if (LoggerUtils.getLogger().isLoggable(Level.FINEST)) {
        LoggerUtils.getLogger().log(Level.FINEST, "Call next " + type + " " + next);
    }

    // Send notification
    if (nSupport != null) {
        Notification notif = (Notification) ep.getNote(notifNote);
        if (notif == null) {
            notif = new Notification("channelSocket.message", ep, requestCount);
            ep.setNote(notifNote, notif);
        }
        nSupport.sendNotification(notif);
    }

    if (next != null) {
        return next.invoke(msg, ep);
    } else {
        LoggerUtils.getLogger().info("No next ");
    }

    return OK;
}

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

/**
 * Start this component, pre-loading the servlet if the load-on-startup
 * value is set appropriately./*  w  ww.j a  v a  2  s .c  o  m*/
 *
 * @exception LifecycleException if a fatal error occurs during startup
 */
public void start() throws LifecycleException {

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

    // Start up this component
    super.start();

    if (oname != null)
        registerJMX((StandardContext) getParent());

    // Load and initialize an instance of this servlet if requested
    // MOVED TO StandardContext START() METHOD

    setAvailable(0L);

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

}

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

/**
 * Stop this component, gracefully shutting down the servlet if it has
 * been initialized./*from  ww  w .j  a v a 2 s  .  c om*/
 *
 * @exception LifecycleException if a fatal error occurs during shutdown
 */
public void stop() throws LifecycleException {

    setAvailable(Long.MAX_VALUE);

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

    // Shut down our servlet instance (if it has been initialized)
    try {
        unload();
    } catch (ServletException e) {
        getServletContext().log(sm.getString("standardWrapper.unloadException", getName()), e);
    }

    // Shut down this component
    super.stop();

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

    if (oname != null) {
        Registry.getRegistry().unregisterComponent(oname);

        // Send j2ee.object.deleted notification 
        Notification notification = new Notification("j2ee.object.deleted", this.getObjectName(),
                sequenceNumber++);
        broadcaster.sendNotification(notification);
    }
}

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

protected void registerJMX(StandardContext ctx) {
    try {//  w w w. j ava 2 s.  co m
        // it should be full name
        String parentName = ctx.getName();
        String hostName = ctx.getParent().getName();
        String webMod = "//" + ((hostName == null) ? "DEFAULT" : hostName)
                + (("".equals(parentName)) ? "/" : parentName);
        String onameStr = ctx.getDomain() + ":j2eeType=Servlet,name=" + getName() + ",WebModule=" + webMod
                + ",J2EEApplication=" + ctx.getJ2EEApplication() + ",J2EEServer=" + ctx.getJ2EEServer();

        oname = new ObjectName(onameStr);
        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);
        }
    } catch (Exception ex) {
        log.info("Error registering servlet with jmx " + this);
    }
}

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

/**
 * Start this Context component./*  ww  w .  j a  va 2  s .  c  om*/
 *
 * @exception LifecycleException if a startup error occurs
 */
public synchronized void start() throws LifecycleException {
    //if (lazy ) return;
    if (started) {
        log.info(sm.getString("containerBase.alreadyStarted", logName()));
        return;
    }
    if (!initialized) {
        try {
            init();
        } catch (Exception ex) {
            throw new LifecycleException("Error initializaing ", ex);
        }
    }

    String logName = "tomcat." + getParent().getName() + "." + ("".equals(getName()) ? "ROOT" : getName())
            + ".Context";
    log = org.apache.commons.logging.LogFactory.getLog(logName);

    log.debug("Starting " + logName);

    // Set JMX object name for proper pipeline registration
    preRegisterJMX();

    if ((oname != null) && (Registry.getRegistry().getMBeanServer().isRegistered(oname))) {
        // As things depend on the JMX registration, the context
        // must be reregistered again once properly initialized
        Registry.getRegistry().unregisterComponent(oname);
    }

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

    setAvailable(false);
    setConfigured(false);
    boolean ok = true;

    // Set config file name
    File configBase = getConfigBase();
    if (configBase != null) {
        if (getConfigFile() == null) {
            File file = new File(configBase, getDefaultConfigFile());
            setConfigFile(file.getPath());
            // If the docbase is outside the appBase, we should save our
            // config
            try {
                File appBaseFile = new File(getAppBase());
                if (!appBaseFile.isAbsolute()) {
                    appBaseFile = new File(engineBase(), getAppBase());
                }
                String appBase = appBaseFile.getCanonicalPath();
                String basePath = (new File(getBasePath())).getCanonicalPath();
                if (!basePath.startsWith(appBase)) {
                    Server server = ServerFactory.getServer();
                    ((StandardServer) server).storeContext(this);
                }
            } catch (Exception e) {
                log.warn("Error storing config file", e);
            }
        } else {
            try {
                String canConfigFile = (new File(getConfigFile())).getCanonicalPath();
                if (!canConfigFile.startsWith(configBase.getCanonicalPath())) {
                    File file = new File(configBase, getDefaultConfigFile());
                    if (copy(new File(canConfigFile), file)) {
                        setConfigFile(file.getPath());
                    }
                }
            } catch (Exception e) {
                log.warn("Error setting config file", e);
            }
        }
    }

    // Install DefaultContext configuration
    if (!getOverride()) {
        Container host = getParent();
        if (host instanceof StandardHost) {
            ((StandardHost) host).installDefaultContext(this);
            Container engine = host.getParent();
            if (engine instanceof StandardEngine) {
                ((StandardEngine) engine).installDefaultContext(this);
            }
        }
    }

    // Add missing components as necessary
    if (webappResources == null) { // (1) Required by Loader
        if (log.isDebugEnabled())
            log.debug("Configuring default Resources");
        try {
            if ((docBase != null) && (docBase.endsWith(".war")))
                setResources(new WARDirContext());
            else
                setResources(new FileDirContext());
        } catch (IllegalArgumentException e) {
            log.error("Error initializing resources: " + e.getMessage());
            ok = false;
        }
    }
    if (ok) {
        if (!resourcesStart()) {
            log.error("Error in resourceStart()");
            ok = false;
        }
    }

    // Look for a realm - that may have been configured earlier. 
    // If the realm is added after context - it'll set itself.
    if (realm == null) {
        ObjectName realmName = null;
        try {
            realmName = new ObjectName(
                    getEngineName() + ":type=Host,host=" + getHostname() + ",path=" + getPath());
            if (mserver.isRegistered(realmName)) {
                mserver.invoke(realmName, "init", new Object[] {}, new String[] {});
            }
        } catch (Throwable t) {
            log.debug("No realm for this host " + realmName);
        }
    }

    if (getLoader() == null) {
        ClassLoader parent = null;
        if (getPrivileged()) {
            if (log.isDebugEnabled())
                log.debug("Configuring privileged default Loader");
            parent = this.getClass().getClassLoader();
        } else {
            if (log.isDebugEnabled())
                log.debug("Configuring non-privileged default Loader");
            parent = getParentClassLoader();
        }
        WebappLoader webappLoader = new WebappLoader(parent);
        webappLoader.setDelegate(getDelegate());
        setLoader(webappLoader);
    }

    // Initialize character set mapper
    getCharsetMapper();

    // Post work directory
    postWorkDirectory();

    // Validate required extensions
    boolean dependencyCheck = true;
    try {
        ExtensionValidator validator = ExtensionValidator.getInstance();
        dependencyCheck = validator.validateApplication(getResources(), this);
    } catch (IOException ioe) {
        log.error("Error in dependencyCheck", ioe);
        dependencyCheck = false;
    }

    if (!dependencyCheck) {
        // do not make application available if depency check fails
        ok = false;
    }

    // Reading the "catalina.useNaming" environment variable
    String useNamingProperty = System.getProperty("catalina.useNaming");
    if ((useNamingProperty != null) && (useNamingProperty.equals("false"))) {
        useNaming = false;
    }

    if (ok && isUseNaming()) {
        if (namingContextListener == null) {
            namingContextListener = new NamingContextListener();
            namingContextListener.setDebug(getDebug());
            namingContextListener.setName(getNamingContextName());
            addLifecycleListener(namingContextListener);
        }
    }

    // Binding thread
    ClassLoader oldCCL = bindThread();

    // Standard container startup
    if (log.isDebugEnabled())
        log.debug("Processing standard container startup");

    if (ok) {

        boolean mainOk = false;
        try {

            started = true;

            // Start our subordinate components, if any
            if ((loader != null) && (loader instanceof Lifecycle))
                ((Lifecycle) loader).start();
            if ((logger != null) && (logger instanceof Lifecycle))
                ((Lifecycle) logger).start();

            // Unbinding thread
            unbindThread(oldCCL);

            // Binding thread
            oldCCL = bindThread();

            if ((cluster != null) && (cluster instanceof Lifecycle))
                ((Lifecycle) cluster).start();
            if ((realm != null) && (realm instanceof Lifecycle))
                ((Lifecycle) realm).start();
            if ((resources != null) && (resources instanceof Lifecycle))
                ((Lifecycle) resources).start();

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

            // Start the Valves in our pipeline (including the basic),
            // if any
            if (pipeline instanceof Lifecycle)
                ((Lifecycle) pipeline).start();

            // Read tldListeners. XXX Option to disable
            TldConfig tldConfig = new TldConfig();
            tldConfig.setContext(this);
            tldConfig.setXmlValidation(((StandardHost) getParent()).getXmlValidation());
            tldConfig.setXmlNamespaceAware(((StandardHost) getParent()).getXmlNamespaceAware());
            try {
                tldConfig.execute();
            } catch (Exception ex) {
                log.error("Error reading tld listeners " + ex.toString(), ex);
                //ok=false;
            }

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

            // Start manager
            if ((manager != null) && (manager instanceof Lifecycle)) {
                ((Lifecycle) getManager()).start();
            }

            // Start ContainerBackgroundProcessor thread
            super.threadStart();

            mainOk = true;

        } finally {
            // Unbinding thread
            unbindThread(oldCCL);
            if (!mainOk) {
                // An exception occurred
                // Register with JMX anyway, to allow management
                registerJMX();
            }
        }

    }
    if (!getConfigured()) {
        log.error("Error getConfigured");
        ok = false;
    }

    // We put the resources into the servlet context
    if (ok)
        getServletContext().setAttribute(Globals.RESOURCES_ATTR, getResources());

    // Binding thread
    oldCCL = bindThread();

    // Create context attributes that will be required
    if (ok) {
        if (log.isDebugEnabled())
            log.debug("Posting standard context attributes");
        postWelcomeFiles();
    }

    // Configure and call application event listeners and filters
    if (ok) {
        if (!listenerStart()) {
            log.error("Error listenerStart");
            ok = false;
        }
    }
    if (ok) {
        if (!filterStart()) {
            log.error("Error filterStart");
            ok = false;
        }
    }

    // Load and initialize all "load on startup" servlets
    if (ok) {
        loadOnStartup(findChildren());
    }

    // Unbinding thread
    unbindThread(oldCCL);

    // Initialize associated mapper
    mapper.setContext(getPath(), welcomeFiles, resources);

    // Set available status depending upon startup success
    if (ok) {
        if (log.isDebugEnabled())
            log.debug("Starting completed");
        setAvailable(true);
    } else {
        log.error(sm.getString("standardContext.startFailed"));
        try {
            stop();
        } catch (Throwable t) {
            log.error(sm.getString("standardContext.startCleanup"), t);
        }
        setAvailable(false);
    }

    // JMX registration
    registerJMX();

    if (ok) {
        // Notify our interested LifecycleListeners
        lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
    }

    startTime = System.currentTimeMillis();

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

    // Close all JARs right away to avoid always opening a peak number 
    // of files on startup
    if (getLoader() instanceof WebappLoader) {
        ((WebappLoader) getLoader()).closeJARs(true);
    }

    // Reinitializing if something went wrong
    if (!ok && started) {
        stop();
    }

    //cacheContext();
}