use of javax.management.MalformedObjectNameException in project iaf by ibissource.
the class JmxMbeanHelper method unhookAdapter.
public static void unhookAdapter(IAdapter adapter) {
MBeanServer server = getMBeanServer();
if (server != null) {
try {
ObjectName objectName = getObjectName(adapter);
server.unregisterMBean(objectName);
} catch (InstanceNotFoundException e1) {
LOG.error(e1.getMessage(), e1);
} catch (MBeanRegistrationException e1) {
LOG.error(e1.getMessage(), e1);
} catch (MalformedObjectNameException e) {
LOG.error(e.getMessage(), e);
}
}
}
use of javax.management.MalformedObjectNameException 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.MalformedObjectNameException in project iaf by ibissource.
the class JmxNamingStrategy method getObjectName.
@Override
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
Hashtable<String, String> properties = new Hashtable<>();
if (managedBean == null) {
throw new MalformedObjectNameException("managedBean cannot be null");
}
if (managedBean instanceof IAdapter) {
IAdapter adapter = (IAdapter) managedBean;
Configuration config = adapter.getConfiguration();
if (config != null) {
String version = null;
if (StringUtils.isNotEmpty(config.getVersion())) {
version = config.getVersion();
} else {
// Give the configuration a version to differentiate when (re-/un-)loading.
version = Integer.toHexString(config.hashCode());
}
properties.put("type", String.format("%s-%s", config.getName(), version).replaceAll(ILLEGAL_CHARACTER_REGEX, "_"));
} else {
// if configuration is null (for whatever reason) we need to be able to differentiate adapters in between reloads.
properties.put("identity", Integer.toHexString(adapter.hashCode()));
}
properties.put("name", adapter.getName().replaceAll(ILLEGAL_CHARACTER_REGEX, "_"));
ObjectName name = new ObjectName(jmxDomain, properties);
if (log.isDebugEnabled())
log.debug("determined ObjectName [" + name + "] for MBean [" + managedBean + "]");
return name;
} else {
ObjectName name = super.getObjectName(managedBean, beanKey);
log.warn("currently only MBeans of type [Adapter] are supported, falling back to IdentityNamingStrategy converting key [" + beanKey + "] bean [" + managedBean + "] to ObjectName [" + name + "]");
return name;
}
}
use of javax.management.MalformedObjectNameException in project masquerade by cuba-platform.
the class JmxCallHandler method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
JMXServiceURL url;
try {
url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + hostInfo.getAddress() + "/jmxrmi");
} catch (MalformedURLException e) {
throw new RuntimeException("Incorrect service URL", e);
}
Map<String, Object> properties = new HashMap<>();
if (hostInfo.getUser() != null) {
properties.put(JMXConnector.CREDENTIALS, new String[] { hostInfo.getUser(), hostInfo.getPassword() });
}
try (JMXConnector jmxc = JMXConnectorFactory.connect(url, properties)) {
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName mbeanName;
try {
mbeanName = new ObjectName(objectName);
} catch (MalformedObjectNameException e) {
throw new RuntimeException("Incorrect JMX object name", e);
}
MBeanServerInvocationHandler wrappedHandler = new MBeanServerInvocationHandler(mbsc, mbeanName);
if (args != null) {
log.info("Invoke method {} of {} with parameters {}", method.getName(), objectName, args);
} else {
log.info("Invoke method {} of {}", method.getName(), objectName);
}
return wrappedHandler.invoke(proxy, method, args);
} catch (IOException e) {
throw new RuntimeException("Unable to perform JMX call", e);
}
}
use of javax.management.MalformedObjectNameException in project jackrabbit-oak by apache.
the class WhiteboardUtils method registerMBean.
public static <T> Registration registerMBean(Whiteboard whiteboard, Class<T> iface, T bean, String type, String name, Map<String, String> attrs) {
try {
Hashtable<String, String> table = new Hashtable<String, String>(attrs);
table.put("type", JmxUtil.quoteValueIfRequired(type));
table.put("name", JmxUtil.quoteValueIfRequired(name));
ImmutableMap.Builder properties = ImmutableMap.builder();
properties.put("jmx.objectname", new ObjectName(JMX_OAK_DOMAIN, table));
properties.putAll(attrs);
return whiteboard.register(iface, bean, properties.build());
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations