Example usage for javax.management JMException getMessage

List of usage examples for javax.management JMException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:chronos.web.listener.ChronosServletListener.java

/**
 * @param mbeanServer//  w  w w .  j a  va2  s . co m
 *        the MBeanServer
 */
private void initializeQuartzSchedulerAdapter(final MBeanServer mbeanServer) {
    try {
        logger.debug("Creating and registering QuartzSchedulerAdapter MBean...");

        final ObjectName objectName = new ObjectName(CHRONOS, "type", QUARTZ_SCHEDULER_ADAPTER);

        final QuartzSchedulerAdapter quartzSchedulerAdapter = new QuartzSchedulerAdapter();
        mbeanServer.registerMBean(quartzSchedulerAdapter, objectName);

        logger.debug("Invoking start() on QuartzSchedulerAdapter MBean...");
        try {
            mbeanServer.invoke(objectName, "start", null, null);
        } catch (final JMException e) {
            logger.error("QuartzSchedulerAdapter start() failed: " + e.getMessage(), e);
        }
    } catch (final JMException e) {
        logger.error("Registering QuartzSchedulerAdapter failed: " + e.getMessage(), e);
    }
}

From source file:chronos.web.listener.ChronosServletListener.java

/**
 * {@inheritDoc}/*from  w  w w .j  av  a2  s . c  o  m*/
 *
 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
 */
public void contextDestroyed(final ServletContextEvent event) {
    logger.debug("Chronos is shutting down...");
    final ArrayList<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
    logger.debug("Got " + servers.size() + " MBean servers");
    if (servers.size() != 0) {
        final MBeanServer mbeanServer = servers.get(0);
        try {
            final ObjectName objectName = new ObjectName(CHRONOS, "type", QUARTZ_SCHEDULER_ADAPTER);

            logger.debug("Invoking shutdown() on QuartzSchedulerAdapter...");
            mbeanServer.invoke(objectName, "shutdown", null, null);

            logger.debug("Unregistering QuartzSchedulerAdapter Mbean");
            mbeanServer.unregisterMBean(objectName);
        } catch (final JMException e) {
            logger.error("Shutting down QuartzSchedulerAdapter failed: " + e.getMessage(), e);
        } catch (final NullPointerException e) {
            logger.error("Shutting down QuartzSchedulerAdapter failed: " + e.getMessage(), e);
        }
    } else {
        logger.warn("Unable to find MBeanServer!");
    }
    logger.info("Chronos shutdown");
}

From source file:com.springsource.hq.plugin.tcserver.plugin.TomcatMeasurementPlugin.java

private int getDeadlockedThreadCount(MBeanServerConnection connection)
        throws MetricInvalidException, MetricUnreachableException {
    int deadlockCount = 0;
    try {/*w w w . ja va 2 s  .  c  om*/
        // in version 1.6+ there is a findDeadlockedThreads method
        long[] deadlocks;
        try {
            deadlocks = (long[]) connection.invoke(new ObjectName("java.lang:type=Threading"),
                    "findDeadlockedThreads", null, null);
        } catch (MalformedObjectNameException e) {
            throw new MetricInvalidException("Error querying for deadlock thread mbean: " + e.getMessage(), e);
        } catch (JMException e) {
            LOGGER.debug("Method 'findDeadlockedThreads' for objectname 'java.lang:type=Threading'"
                    + "was not found. Trying method findMonitorDeadlockedThreads...", e);
            // If this occurs then the issue is most likely related to the
            // Java version.
            // Now check for the method on java 1.5
            try {
                deadlocks = (long[]) connection.invoke(new ObjectName("java.lang:type=Threading"),
                        "findMonitorDeadlockedThreads", null, null);
            } catch (MalformedObjectNameException me) {
                throw new MetricInvalidException("Error querying for deadlock thread mbean: " + me.getMessage(),
                        me);
            } catch (JMException ex) {
                LOGGER.debug("Unable to retrieve DeadlockedThreads count: ", ex);
                throw new MetricUnreachableException(
                        "Unable to reach deadlock thread mbean: " + ex.getMessage(), ex);
            }
        }

        if (deadlocks != null) {
            deadlockCount = deadlocks.length;
        }
        return deadlockCount;
    } catch (IOException e) {
        throw new MetricUnreachableException("Error querying for deadlock thread mbean: " + e.getMessage(), e);
    }
}

From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java

private void serveRequest(RequestMethod method, HttpServletRequest req, HttpServletResponse rsp)
        throws IOException, ServletException {
    if (logger.isDebugEnabled()) {
        logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]");
    }/*  w  w  w.  j  a  va 2 s .c  o  m*/

    if ((loopRetryTimeout > 0L) && (!loopDetected)) {
        long now = System.currentTimeMillis(), diff = now - initTimestamp;
        if ((diff > 0L) && (diff < loopRetryTimeout)) {
            try {
                MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(new ObjectName(
                        "net.community.chest.gitcloud.facade.backend.git:name=BackendRepositoryResolver"));
                if (mbeanInfo != null) {
                    logger.info("serveRequest(" + method + ")[" + req.getRequestURI() + "]["
                            + req.getQueryString() + "]" + " detected loop: " + mbeanInfo.getClassName() + "["
                            + mbeanInfo.getDescription() + "]");
                    loopDetected = true;
                }
            } catch (JMException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "]["
                            + req.getQueryString() + "]" + " failed " + e.getClass().getSimpleName()
                            + " to detect loop: " + e.getMessage());
                }
            }
        }
    }

    ResolvedRepositoryData repoData = resolveTargetRepository(method, req);
    if (repoData == null) {
        throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING,
                "serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]",
                new NoSuchElementException("Failed to resolve repository"));
    }

    String username = authenticate(req);
    // TODO check if the user is allowed to access the repository via the resolve operation (push/pull) if at all (e.g., private repo)
    logger.info("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "] user="
            + username);

    /*
     * NOTE: this feature requires enabling cross-context forwarding.
     * In Tomcat, the 'crossContext' attribute in 'Context' element of
     * 'TOMCAT_HOME\conf\context.xml' must be set to true, to enable cross-context 
     */
    if (loopDetected) {
        // TODO see if can find a more efficient way than splitting and re-constructing
        URI uri = repoData.getRepoLocation();
        ServletContext curContext = req.getServletContext();
        String urlPath = uri.getPath(), urlQuery = uri.getQuery();
        String[] comps = StringUtils.split(urlPath, '/');
        String appName = comps[0];
        ServletContext loopContext = Validate.notNull(curContext.getContext("/" + appName),
                "No cross-context for %s", appName);
        // build the relative path in the re-directed context
        StringBuilder sb = new StringBuilder(
                urlPath.length() + 1 + (StringUtils.isEmpty(urlQuery) ? 0 : urlQuery.length()));
        for (int index = 1; index < comps.length; index++) {
            sb.append('/').append(comps[index]);
        }
        if (!StringUtils.isEmpty(urlQuery)) {
            sb.append('?').append(urlQuery);
        }

        String redirectPath = sb.toString();
        RequestDispatcher dispatcher = Validate.notNull(loopContext.getRequestDispatcher(redirectPath),
                "No dispatcher for %s", redirectPath);
        dispatcher.forward(req, rsp);
        if (logger.isDebugEnabled()) {
            logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString()
                    + "]" + " forwarded to " + loopContext.getContextPath() + "/" + redirectPath);
        }
    } else {
        executeRemoteRequest(method, repoData.getRepoLocation(), req, rsp);
    }
}

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

/**
 * Stop the classloader container, removing the MBean from the MBean server.
 * @see org.sakaiproject.kernel.api.RequiresStop#stop()
 *//* w ww .ja  v a  2s.c  o  m*/
public void stop() {
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName common = new ObjectName(CommonObject.MBEAN_COMMON + ".sharedclassloader");
        mbs.unregisterMBean(common);
        LOG.info("Shared Classloader Container stopped Ok");
    } catch (JMException e) {
        LOG.debug(
                "Cant stop the shared classloader bean, this will cause problems if the kernel is restarted in this jvm "
                        + e.getMessage(),
                e);
    }
}

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

/**
 * Stop the classloader container, removing the MBean from the MBean server.
 * @see org.sakaiproject.kernel.api.RequiresStop#stop()
 *//*from w  w w.  j a  v  a  2s . c  o m*/
public void stop() {
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName common = new ObjectName(CommonObject.MBEAN_COMMON + ".sharedclassloader");
        mbs.unregisterMBean(common);
        LOG.info("Shared Classloader Container stopped Ok");
    } catch (JMException e) {
        LOG.info(
                "Cant stop the shared classloader bean, this will cause problems if the kernel is restarted in this jvm "
                        + e.getMessage(),
                e);
    }
}