Search in sources :

Example 16 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project jdk8u_jdk by JetBrains.

the class MXBeanLookup method addReference.

synchronized void addReference(ObjectName name, Object mxbean) throws InstanceAlreadyExistsException {
    ObjectName existing = mxbeanToObjectName.get(mxbean);
    if (existing != null) {
        String multiname = AccessController.doPrivileged(new GetPropertyAction("jmx.mxbean.multiname"));
        if (!"true".equalsIgnoreCase(multiname)) {
            throw new InstanceAlreadyExistsException("MXBean already registered with name " + existing);
        }
    }
    mxbeanToObjectName.put(mxbean, name);
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectName(javax.management.ObjectName)

Example 17 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project jdk8u_jdk by JetBrains.

the class ManagementFactoryHelper method addMBean.

/**
     * Registers a given MBean if not registered in the MBeanServer;
     * otherwise, just return.
     */
private static void addMBean(MBeanServer mbs, Object mbean, String mbeanName) {
    try {
        final ObjectName objName = Util.newObjectName(mbeanName);
        // inner class requires these fields to be final
        final MBeanServer mbs0 = mbs;
        final Object mbean0 = mbean;
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {

            public Void run() throws MBeanRegistrationException, NotCompliantMBeanException {
                try {
                    mbs0.registerMBean(mbean0, objName);
                    return null;
                } catch (InstanceAlreadyExistsException e) {
                // if an instance with the object name exists in
                // the MBeanServer ignore the exception
                }
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw Util.newException(e.getException());
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 18 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project ddf by codice.

the class SolrCache method configureMBean.

private void configureMBean() {
    LOGGER.debug("Registering Cache Manager Service MBean");
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        objectName = new ObjectName(SolrCacheMBean.OBJECTNAME);
    } catch (MalformedObjectNameException e) {
        LOGGER.info("Could not create object name", e);
    }
    try {
        try {
            mbeanServer.registerMBean(new StandardMBean(this, SolrCacheMBean.class), objectName);
        } catch (InstanceAlreadyExistsException e) {
            LOGGER.debug("Re-registering Cache Manager MBean");
            mbeanServer.unregisterMBean(objectName);
            mbeanServer.registerMBean(new StandardMBean(this, SolrCacheMBean.class), objectName);
        }
    } catch (Exception e) {
        LOGGER.debug("Could not register MBean.", e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) StandardMBean(javax.management.StandardMBean) SolrCacheMBean(ddf.catalog.cache.SolrCacheMBean) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) MetacardCreationException(ddf.catalog.data.MetacardCreationException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 19 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project ddf by codice.

the class QueryMonitor method registerMbean.

private void registerMbean() {
    try {
        objectName = new ObjectName(QueryMonitor.class.getName() + ":service=querymonitor");
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    } catch (MalformedObjectNameException e) {
        LOGGER.info("Unable to create Query Monitor Configuration MBean.", e);
    }
    if (mBeanServer == null) {
        return;
    }
    try {
        try {
            mBeanServer.registerMBean(this, objectName);
            LOGGER.debug("Registered Query Monitor Configuration MBean under object name: {}", objectName.toString());
        } catch (InstanceAlreadyExistsException e) {
            // Try to remove and re-register
            mBeanServer.unregisterMBean(objectName);
            mBeanServer.registerMBean(this, objectName);
            LOGGER.debug("Re-registered Query Monitor Configuration MBean");
        }
    } catch (MBeanRegistrationException | InstanceNotFoundException | InstanceAlreadyExistsException | NotCompliantMBeanException e) {
        LOGGER.info("Could not register MBean [{}].", objectName.toString(), e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 20 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project ddf by codice.

the class KeystoreEditor method registerMbean.

private void registerMbean() {
    ObjectName objectName = null;
    MBeanServer mBeanServer = null;
    try {
        objectName = new ObjectName(KeystoreEditor.class.getName() + ":service=keystore");
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    } catch (MalformedObjectNameException e) {
        LOGGER.info("Unable to create Keystore Editor MBean.", e);
    }
    if (mBeanServer != null) {
        try {
            try {
                mBeanServer.registerMBean(this, objectName);
                LOGGER.debug("Registered Keystore Editor MBean under object name: {}", objectName.toString());
            } catch (InstanceAlreadyExistsException e) {
                // Try to remove and re-register
                mBeanServer.unregisterMBean(objectName);
                mBeanServer.registerMBean(this, objectName);
                LOGGER.debug("Re-registered Keystore Editor MBean");
            }
        } catch (Exception e) {
            //objectName is not always non-null because new ObjectName(...) can throw an exception
            LOGGER.info("Could not register MBean [{}].", objectName != null ? objectName.toString() : KeystoreEditor.class.getName(), e);
        }
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) KeyManagementException(java.security.KeyManagementException) MalformedObjectNameException(javax.management.MalformedObjectNameException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CertificateEncodingException(java.security.cert.CertificateEncodingException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoSuchProviderException(java.security.NoSuchProviderException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Aggregations

InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)49 ObjectName (javax.management.ObjectName)38 MalformedObjectNameException (javax.management.MalformedObjectNameException)30 MBeanRegistrationException (javax.management.MBeanRegistrationException)29 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)28 MBeanServer (javax.management.MBeanServer)25 InstanceNotFoundException (javax.management.InstanceNotFoundException)14 ObjectInstance (javax.management.ObjectInstance)8 IOException (java.io.IOException)6 StandardMBean (javax.management.StandardMBean)6 Test (org.junit.Test)3 MalformedURLException (java.net.MalformedURLException)2 CacheException (javax.cache.CacheException)2 JMRuntimeException (javax.management.JMRuntimeException)2 MBeanException (javax.management.MBeanException)2 ReflectionException (javax.management.ReflectionException)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 Logger (ch.qos.logback.classic.Logger)1 JMXConfigurator (ch.qos.logback.classic.jmx.JMXConfigurator)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1