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;
}
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);
}
}
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());
}
}
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;
}
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;
}
Aggregations