Search in sources :

Example 51 with MalformedObjectNameException

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);
        }
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 52 with MalformedObjectNameException

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());
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 53 with MalformedObjectNameException

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;
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Configuration(nl.nn.adapterframework.configuration.Configuration) Hashtable(java.util.Hashtable) IAdapter(nl.nn.adapterframework.core.IAdapter) ObjectName(javax.management.ObjectName)

Example 54 with MalformedObjectNameException

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);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedURLException(java.net.MalformedURLException) MalformedObjectNameException(javax.management.MalformedObjectNameException) HashMap(java.util.HashMap) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 55 with MalformedObjectNameException

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);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Hashtable(java.util.Hashtable) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectName(javax.management.ObjectName)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)309 ObjectName (javax.management.ObjectName)285 InstanceNotFoundException (javax.management.InstanceNotFoundException)88 MBeanServer (javax.management.MBeanServer)80 MBeanRegistrationException (javax.management.MBeanRegistrationException)75 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)63 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)59 IOException (java.io.IOException)53 ArrayList (java.util.ArrayList)45 ReflectionException (javax.management.ReflectionException)30 MBeanException (javax.management.MBeanException)23 Test (org.testng.annotations.Test)23 CompositeData (javax.management.openmbean.CompositeData)18 Notification (javax.management.Notification)15 MBeanInfo (javax.management.MBeanInfo)14 AttributeNotFoundException (javax.management.AttributeNotFoundException)13 HashMap (java.util.HashMap)11 Map (java.util.Map)11 IntrospectionException (javax.management.IntrospectionException)11 MalformedURLException (java.net.MalformedURLException)10