Example usage for javax.management InstanceNotFoundException printStackTrace

List of usage examples for javax.management InstanceNotFoundException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

static public void unregisterMBean(ObjectName mbeanName) {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    if (mbeanName == null)
        return;/*from  w  ww. j a  v  a  2  s. c o m*/
    try {
        mbs.unregisterMBean(mbeanName);
    } catch (InstanceNotFoundException e) {
        // ignore
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.cyberway.issue.crawler.Heritrix.java

public static void unregisterMBean(final MBeanServer server, final ObjectName name) {
    try {//from  ww  w  .  j  a  v a 2  s  . c o m
        server.unregisterMBean(name);
        logger.info("Unregistered bean " + name.getCanonicalName());
    } catch (InstanceNotFoundException e) {
        e.printStackTrace();
    } catch (MBeanRegistrationException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:com.cyberway.issue.crawler.Heritrix.java

/**
 * Do inverse of construction. Used by anyone who does a 'new Heritrix' when
 * they want to cleanup the instance.//w  w w . j a  v  a2 s  .com
 * Of note, there may be Heritrix threads still hanging around after the
 * call to destroy completes.  They'll eventually go down after they've
 * finished their cleanup routines.  In particular, if you are watching
 * Heritrix via JMX, you can see the Heritrix instance JMX bean unregister
 * ahead of the CrawlJob JMX bean that its hosting.
 */
public void destroy() {
    stop();
    try {
        Heritrix.unregisterHeritrix(this);
    } catch (InstanceNotFoundException e) {
        e.printStackTrace();
    } catch (MBeanRegistrationException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    this.jobHandler = null;
    this.openMBeanInfo = null;
}

From source file:com.tribloom.module.JmxClient.java

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("connectionSuccess", true);
    model.put("time", System.currentTimeMillis());
    try {//from   ww w.  j a v a2 s  .  c om
        // Create an RMI connector client and
        // connect it to the RMI connector server
        //
        echo("\nCreate an RMI connector client and " + "connect it to the RMI connector server");
        JMXServiceURL url = new JMXServiceURL(
                "service:jmx:rmi://ignored/jndi/rmi://localhost:50500/alfresco/jmxrmi");
        Map<String, Object> env = new HashMap<String, Object>();
        String[] creds = { "controlRole", "change_asap" };
        env.put(JMXConnector.CREDENTIALS, creds);
        JMXConnector jmxc = JMXConnectorFactory.connect(url, env);

        // Get an MBeanServerConnection
        //
        echo("\nGet an MBeanServerConnection");
        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

        ObjectName memory = new ObjectName("java.lang:type=Memory");
        CompositeData heapMemUsage = (CompositeData) mbsc.getAttribute(memory, "HeapMemoryUsage");
        addCompositeData(model, heapMemUsage, "heapMemoryUsage");
        CompositeData nonHeapMemUsage = (CompositeData) mbsc.getAttribute(memory, "NonHeapMemoryUsage");
        addCompositeData(model, nonHeapMemUsage, "nonHeapMemoryUsage");

        ObjectName operatingSystem = new ObjectName("java.lang:type=OperatingSystem");
        model.put("openFileDescriptorCount", mbsc.getAttribute(operatingSystem, "OpenFileDescriptorCount"));
        model.put("maxFileDescriptorCount", mbsc.getAttribute(operatingSystem, "MaxFileDescriptorCount"));
        model.put("committedVirtualMemorySize",
                mbsc.getAttribute(operatingSystem, "CommittedVirtualMemorySize"));
        model.put("totalSwapSpaceSize", mbsc.getAttribute(operatingSystem, "TotalSwapSpaceSize"));
        model.put("freeSwapSpaceSize", mbsc.getAttribute(operatingSystem, "FreeSwapSpaceSize"));
        model.put("processCpuTime", mbsc.getAttribute(operatingSystem, "ProcessCpuTime"));
        model.put("freePhysicalMemorySize", mbsc.getAttribute(operatingSystem, "FreePhysicalMemorySize"));
        model.put("totalPhysicalMemorySize", mbsc.getAttribute(operatingSystem, "TotalPhysicalMemorySize"));
        model.put("operatingSystemName", mbsc.getAttribute(operatingSystem, "Name"));
        model.put("operatingSystemVersion", mbsc.getAttribute(operatingSystem, "Version"));
        model.put("operatingSystemArch", mbsc.getAttribute(operatingSystem, "Arch"));
        model.put("availableProcessors", mbsc.getAttribute(operatingSystem, "AvailableProcessors"));
        model.put("systemLoadAverage", mbsc.getAttribute(operatingSystem, "SystemLoadAverage"));

        try {
            ObjectName parNewGarbageCollector = new ObjectName("java.lang:type=GarbageCollector,name=ParNew");
            echo("\nparNewGarbageCollector = " + parNewGarbageCollector);
            CompositeData parNewLastGcInfo = (CompositeData) mbsc.getAttribute(parNewGarbageCollector,
                    "LastGcInfo");
            addCompositeData(model, parNewLastGcInfo, "parNewLastGcInfo");
        } catch (InstanceNotFoundException ex) {
            // No Garbage Collection has occurred yet
            echo("No Garbage Collection found: " + ex.getMessage());
        }
        try {
            ObjectName concurrentGarbageCollector = new ObjectName(
                    "java.lang:type=GarbageCollector,name=ConcurrentMarkSweep");
            echo("\nconcurrentGarbageCollector = " + concurrentGarbageCollector);
            CompositeData concurrentGarbageCollectorLastGcInfo = (CompositeData) mbsc
                    .getAttribute(concurrentGarbageCollector, "LastGcInfo");
            addCompositeData(model, concurrentGarbageCollectorLastGcInfo, "concurrentMarkSweepLastGcInfo");
        } catch (InstanceNotFoundException ex) {
            // No Garbage Collection has occurred yet
            echo("No Garbage Collection found: " + ex.getMessage());
        }

        ObjectName classLoading = new ObjectName("java.lang:type=ClassLoading");
        model.put("classLoadingLoadedClassCount", mbsc.getAttribute(classLoading, "LoadedClassCount"));
        model.put("classLoadingUnloadedClassCount", mbsc.getAttribute(classLoading, "UnloadedClassCount"));
        model.put("classLoadingTotalLoadedClassCount",
                mbsc.getAttribute(classLoading, "TotalLoadedClassCount"));

        ObjectName runtime = new ObjectName("java.lang:type=Runtime");
        model.put("runtimeName", mbsc.getAttribute(runtime, "Name"));
        model.put("runtimeClassPath", mbsc.getAttribute(runtime, "ClassPath"));

        // TODO: Tabular type...
        Object sysProps = mbsc.getAttribute(runtime, "SystemProperties");
        echo("\nsysProps = " + sysProps);

        model.put("runtimeStartTime", mbsc.getAttribute(runtime, "StartTime"));
        model.put("runtimeVmName", mbsc.getAttribute(runtime, "VmName"));
        model.put("runtimeVmVendor", mbsc.getAttribute(runtime, "VmVendor"));
        model.put("runtimeVmVersion", mbsc.getAttribute(runtime, "VmVersion"));
        model.put("runtimeLibraryPath", mbsc.getAttribute(runtime, "LibraryPath"));
        model.put("runtimeBootClassPath", mbsc.getAttribute(runtime, "BootClassPath"));
        model.put("runtimeManagementSpecVersion", mbsc.getAttribute(runtime, "ManagementSpecVersion"));
        model.put("runtimeSpecName", mbsc.getAttribute(runtime, "SpecName"));
        model.put("runtimeSpecVendor", mbsc.getAttribute(runtime, "SpecVendor"));
        model.put("runtimeSpecVersion", mbsc.getAttribute(runtime, "SpecVersion"));
        model.put("runtimeInputArguments", mbsc.getAttribute(runtime, "InputArguments")); // TODO: Array...
        model.put("runtimeUptime", mbsc.getAttribute(runtime, "Uptime"));

        try {
            ObjectName memoryPool = new ObjectName("java.lang:type=MemoryPool");
            model.put("memoryPoolName", mbsc.getAttribute(memoryPool, "Name"));
            model.put("memoryPoolType", mbsc.getAttribute(memoryPool, "Type"));
            CompositeData memoryPoolUsage = (CompositeData) mbsc.getAttribute(memoryPool, "Usage");
            addCompositeData(model, memoryPoolUsage, "memoryPoolUsage");
            CompositeData memoryPoolPeakUsage = (CompositeData) mbsc.getAttribute(memoryPool, "PeakUsage");
            addCompositeData(model, memoryPoolPeakUsage, "memoryPoolPeakUsage");
            model.put("memoryPoolMemoryManagerNames", mbsc.getAttribute(memoryPool, "MemoryManagerNames")); // Array of strings
            model.put("memoryPoolUsageThreshold", mbsc.getAttribute(memoryPool, "UsageThreshold"));
            model.put("memoryPoolUsageThresholdExceeded",
                    mbsc.getAttribute(memoryPool, "UsageThresholdExceeded"));
            model.put("memoryPoolUsageThresholdCount", mbsc.getAttribute(memoryPool, "UsageThresholdCount"));
            model.put("memoryPoolUsageThresholdSupported",
                    mbsc.getAttribute(memoryPool, "UsageThresholdSupported"));
            model.put("memoryPoolCollectionUsageThreshold",
                    mbsc.getAttribute(memoryPool, "CollectionUsageThreshold"));
            model.put("memoryPoolCollectionUsageThresholdExceeded",
                    mbsc.getAttribute(memoryPool, "CollectionUsageThresholdExceeded"));
            model.put("memoryPoolCollectionUsageThresholdCount",
                    mbsc.getAttribute(memoryPool, "CollectionUsageThresholdCount"));
            CompositeData collectionUsage = (CompositeData) mbsc.getAttribute(memoryPool, "CollectionUsage");
            addCompositeData(model, collectionUsage, "memoryPoolCollectionUsage");
            model.put("memoryPoolCollectionUsageThresholdSupported",
                    mbsc.getAttribute(memoryPool, "CollectionUsageThresholdSupported"));

        } catch (InstanceNotFoundException ex) {
            // Memory pool not initialized yet

        }

        echo("\nClose the connection to the server");
        jmxc.close();
        echo("\nBye! Bye!");
    } catch (Exception ex) {
        ex.printStackTrace();
        model.put("connectionSuccess", false);
        model.put("exception", ex.getMessage());
    }
    return model;
}

From source file:org.cloudata.core.common.metrics.CloudataMetricsFactory.java

public void unregisterMBean(ObjectName mbeanName) {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    if (mbeanName == null)
        return;//from   www  .  j ava  2  s  . c om
    try {
        mbs.unregisterMBean(mbeanName);
    } catch (InstanceNotFoundException e) {
        // ignore
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.energy_home.jemma.osgi.ah.felix.console.web.HacWebCommandProvider.java

private void renderEndPoints(String appRoot, IApplianceConfiguration config, IEndPoint[] endPoints,
        PrintWriter pw) {/*  w  w w.j  ava2 s. c o  m*/
    for (int i = 0; i < endPoints.length; i++) {
        IEndPoint endPoint = endPoints[i];
        IAppliance appliance = endPoint.getAppliance();
        String appliancePid = appliance.getPid();
        Integer endPointId = new Integer(endPoint.getId());
        boolean isAvailable = appliance.isAvailable();
        if (isAvailable)
            pw.println("<b>");
        else
            pw.println("<b><font color=\"gray\">");
        String name = null;
        ICategory category = null;
        ILocation location = null;
        if (config != null) {
            name = config.getName(endPointId);
            category = appliancesProxy.getCategory(config.getCategoryPid(endPointId));
            location = appliancesProxy.getLocation(config.getLocationPid(endPointId));
        }
        pw.println("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ENDPOINT");
        if (!appliance.isSingleton())
            pw.println("&nbsp;(<a href=\"" + appRoot + "/" + LABEL + "/config/" + appliancePid + "/"
                    + endPointId + "\">Configuration</a>)");
        pw.println("<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID: " + endPoint.getId()
                + "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TYPE: " + endPoint.getType()
                + ((name != null) ? "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name: " + name : "")
                + ((category != null) ? "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Category: " + category.getName()
                        : "")
                + ((location != null) ? "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Location: " + location.getName()
                        : ""));
        if (isAvailable)
            pw.println(
                    "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + (endPointId > 0 ? "Clusters:" : "") + "</b><br/>");
        else
            pw.println("<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + (endPointId > 0 ? "Clusters:" : "")
                    + "</b></font><br/>");
        try {
            IServiceCluster[] clusterArray = endPoint.getServiceClusters(IServiceCluster.SERVER_SIDE);
            if (clusterArray != null && clusterArray.length > 0) {
                renderClusterList(appRoot, appliancePid, endPointId, clusterArray, pw);
            }
            clusterArray = endPoint.getServiceClusters(IServiceCluster.CLIENT_SIDE);
            if (clusterArray != null && clusterArray.length > 0) {
                renderClusterList(appRoot, appliancePid, endPointId, clusterArray, pw);
            }
            String[] clusterNames = endPoint.getAdditionalClusterNames();
            if (clusterNames != null && clusterNames.length > 0) {
                renderClusterList(appRoot, appliancePid, endPoint, clusterNames, pw);
            }
            pw.println("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>");
        } catch (InstanceNotFoundException e) {
            e.printStackTrace();
        } catch (IntrospectionException e) {
            e.printStackTrace();
        } catch (ReflectionException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.jpos.q2.Q2.java

public void run() {
    started = true;/*from  w w  w .  j  a v  a 2 s.c o m*/
    Thread.currentThread().setName("Q2-" + getInstanceId().toString());
    try {
        /*
        * The following code determines whether a MBeanServer exists 
        * already. If so then the first one in the list is used. 
        * I have not yet find a way to interrogate the server for 
        * information other than MBeans so to pick a specific one 
        * would be difficult.
        */
        ArrayList mbeanServerList = MBeanServerFactory.findMBeanServer(null);
        if (mbeanServerList.isEmpty()) {
            server = MBeanServerFactory.createMBeanServer(JMX_NAME);
        } else {
            server = (MBeanServer) mbeanServerList.get(0);
        }
        final ObjectName loaderName = new ObjectName(Q2_CLASS_LOADER);
        try {
            loader = (QClassLoader) java.security.AccessController
                    .doPrivileged(new java.security.PrivilegedAction() {
                        public Object run() {
                            return new QClassLoader(server, libDir, loaderName, mainClassLoader);
                        }
                    });
            server.registerMBean(loader, loaderName);
            loader = loader.scan(false);
        } catch (Throwable t) {
            if (log != null)
                log.error("initial-scan", t);
            else
                t.printStackTrace();
        }
        factory = new QFactory(loaderName, this);
        initSystemLogger();
        if (bundleContext == null)
            addShutdownHook();
        q2Thread = Thread.currentThread();
        q2Thread.setContextClassLoader(loader);
        if (cli != null)
            cli.start();
        initConfigDecorator();
        if (startOSGI)
            startOSGIFramework();
        for (int i = 1; !shutdown; i++) {
            try {
                boolean forceNewClassLoader = scan();
                QClassLoader oldClassLoader = loader;
                loader = loader.scan(forceNewClassLoader);
                if (loader != oldClassLoader) {
                    oldClassLoader = null; // We want this to be null so it gets GCed.
                    System.gc(); // force a GC
                    log.info("new classloader [" + Integer.toString(loader.hashCode(), 16)
                            + "] has been created");
                }
                deploy();
                checkModified();
                relax(SCAN_INTERVAL);
                if (i % (3600000 / SCAN_INTERVAL) == 0)
                    logVersion();
            } catch (Throwable t) {
                log.error("start", t);
                relax();
            }
        }
        undeploy();
        try {
            server.unregisterMBean(loaderName);
        } catch (InstanceNotFoundException e) {
            log.error(e);
        }
        if (decorator != null) {
            decorator.uninitialize();
        }
        if (exit && !shuttingDown)
            System.exit(0);
    } catch (Exception e) {
        if (log != null)
            log.error(e);
        else
            e.printStackTrace();
        System.exit(1);
    }
}