Search in sources :

Example 56 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project jPOS by jpos.

the class Q2 method deploy.

private boolean deploy(File f) {
    LogEvent evt = log != null ? log.createInfo() : null;
    try {
        QEntry qentry = dirMap.get(f);
        SAXBuilder builder = createSAXBuilder();
        Document doc;
        if (decorator != null && !f.getName().equals(LOGGER_CONFIG)) {
            doc = decrypt(builder.build(new StringReader(decorator.decorateFile(f))));
        } else {
            doc = decrypt(builder.build(f));
        }
        Element rootElement = doc.getRootElement();
        String iuuid = rootElement.getAttributeValue("instance");
        if (iuuid != null) {
            UUID uuid = UUID.fromString(iuuid);
            if (!uuid.equals(getInstanceId())) {
                deleteFile(f, iuuid);
                return false;
            }
        }
        if (QFactory.isEnabled(rootElement)) {
            if (evt != null)
                evt.addMessage("deploy: " + f.getCanonicalPath());
            Object obj = factory.instantiate(this, rootElement);
            qentry.setObject(obj);
            ObjectInstance instance = factory.createQBean(this, doc.getRootElement(), obj);
            qentry.setInstance(instance);
        } else if (evt != null) {
            evt.addMessage("deploy ignored (enabled='" + QFactory.getEnabledAttribute(rootElement) + "'): " + f.getCanonicalPath());
        }
    } catch (InstanceAlreadyExistsException e) {
        /*
            * Ok, the file we tried to deploy, holds an object
            *  that already has been deployed.
            *  
            * Rename it out of the way.
            * 
            */
        tidyFileAway(f, DUPLICATE_EXTENSION);
        if (evt != null)
            evt.addMessage(e);
        return false;
    } catch (Exception e) {
        if (evt != null)
            evt.addMessage(e);
        tidyFileAway(f, ERROR_EXTENSION);
        // This will also save deploy error repeats...
        return false;
    } catch (Error e) {
        if (evt != null)
            evt.addMessage(e);
        tidyFileAway(f, ENV_EXTENSION);
        // This will also save deploy error repeats...
        return false;
    } finally {
        if (evt != null)
            Logger.log(evt);
    }
    return true;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) LogEvent(org.jpos.util.LogEvent) Element(org.jdom2.Element) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectInstance(javax.management.ObjectInstance) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) GeneralSecurityException(java.security.GeneralSecurityException) BundleException(org.osgi.framework.BundleException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) SAXException(org.xml.sax.SAXException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ISOException(org.jpos.iso.ISOException) MissingArgumentException(org.apache.commons.cli.MissingArgumentException)

Example 57 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project sonarqube by SonarSource.

the class Jmx method register.

/**
 * Register a MBean to JMX server
 */
public static void register(String name, Object instance) {
    try {
        Class<Object> mbeanInterface = guessMBeanInterface(instance);
        ManagementFactory.getPlatformMBeanServer().registerMBean(new StandardMBean(instance, mbeanInterface), new ObjectName(name));
    } catch (MalformedObjectNameException | NotCompliantMBeanException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
        throw new IllegalStateException("Can not register MBean [" + name + "]", e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 58 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project SEPA by arces-wot.

the class SEPABeans method registerMBean.

public static void registerMBean(final String mBeanObjectName, final Object mBean) {
    try {
        final ObjectName name = new ObjectName(mBeanObjectName);
        mbs.registerMBean(mBean, name);
    } catch (MalformedObjectNameException badObjectName) {
        logger.error(badObjectName.getMessage());
    } catch (InstanceAlreadyExistsException duplicateMBeanInstance) {
        logger.error(duplicateMBeanInstance.getMessage());
    } catch (MBeanRegistrationException mbeanRegistrationProblem) {
        logger.error(mbeanRegistrationProblem.getMessage());
    } catch (NotCompliantMBeanException badMBean) {
        logger.error(badMBean.getMessage());
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 59 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project archaius by Netflix.

the class ConfigJMXManager method registerConfigMbean.

public static ConfigMBean registerConfigMbean(AbstractConfiguration config) {
    StandardMBean mbean = null;
    ConfigMBean bean = null;
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        bean = new BaseConfigMBean(config);
        mbean = new StandardMBean(bean, ConfigMBean.class);
        mbs.registerMBean(mbean, getJMXObjectName(config, bean));
    } catch (NotCompliantMBeanException e) {
        throw new RuntimeException("NotCompliantMBeanException", e);
    } catch (InstanceAlreadyExistsException e) {
        throw new RuntimeException("InstanceAlreadyExistsException", e);
    } catch (MBeanRegistrationException e) {
        throw new RuntimeException("MBeanRegistrationException", e);
    } catch (Exception e) {
        throw new RuntimeException("registerConfigMbeanException", e);
    }
    return bean;
}
Also used : StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer)

Example 60 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project hadoop by apache.

the class MBeans method register.

/**
   * Register the MBean using our standard MBeanName format
   * "hadoop:service=<serviceName>,name=<nameName>"
   * Where the <serviceName> and <nameName> are the supplied parameters
   *
   * @param serviceName
   * @param nameName
   * @param theMbean - the MBean to register
   * @return the named used to register the MBean
   */
public static ObjectName register(String serviceName, String nameName, Object theMbean) {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = getMBeanName(serviceName, nameName);
    if (name != null) {
        try {
            mbs.registerMBean(theMbean, name);
            LOG.debug("Registered " + name);
            return name;
        } catch (InstanceAlreadyExistsException iaee) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Failed to register MBean \"" + name + "\"", iaee);
            } else {
                LOG.warn("Failed to register MBean \"" + name + "\": Instance already exists.");
            }
        } catch (Exception e) {
            LOG.warn("Failed to register MBean \"" + name + "\"", e);
        }
    }
    return null;
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)116 ObjectName (javax.management.ObjectName)87 MBeanRegistrationException (javax.management.MBeanRegistrationException)73 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)70 MalformedObjectNameException (javax.management.MalformedObjectNameException)64 MBeanServer (javax.management.MBeanServer)48 InstanceNotFoundException (javax.management.InstanceNotFoundException)37 IOException (java.io.IOException)13 ObjectInstance (javax.management.ObjectInstance)12 Test (org.junit.Test)12 StandardMBean (javax.management.StandardMBean)9 MBeanException (javax.management.MBeanException)7 ReflectionException (javax.management.ReflectionException)7 HashMap (java.util.HashMap)5 JMRuntimeException (javax.management.JMRuntimeException)4 RuntimeOperationsException (javax.management.RuntimeOperationsException)4 MalformedURLException (java.net.MalformedURLException)3 AttributeNotFoundException (javax.management.AttributeNotFoundException)3 DynamicMBean (javax.management.DynamicMBean)3 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3