Search in sources :

Example 31 with JMException

use of javax.management.JMException in project spring-integration by spring-projects.

the class OperationInvokingMessageHandler method handleRequestMessage.

@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
    ObjectName objectName = this.resolveObjectName(requestMessage);
    String operationName = this.resolveOperationName(requestMessage);
    Map<String, Object> paramsFromMessage = this.resolveParameters(requestMessage);
    try {
        MBeanInfo mbeanInfo = this.server.getMBeanInfo(objectName);
        MBeanOperationInfo[] opInfoArray = mbeanInfo.getOperations();
        boolean hasNoArgOption = false;
        for (MBeanOperationInfo opInfo : opInfoArray) {
            if (operationName.equals(opInfo.getName())) {
                MBeanParameterInfo[] paramInfoArray = opInfo.getSignature();
                if (paramInfoArray.length == 0) {
                    hasNoArgOption = true;
                }
                if (paramInfoArray.length == paramsFromMessage.size()) {
                    int index = 0;
                    Object[] values = new Object[paramInfoArray.length];
                    String[] signature = new String[paramInfoArray.length];
                    for (MBeanParameterInfo paramInfo : paramInfoArray) {
                        Object value = paramsFromMessage.get(paramInfo.getName());
                        if (value == null) {
                            /*
								 * With Spring 3.2.3 and greater, the parameter names are
								 * registered instead of the JVM's default p1, p2 etc.
								 * Fall back to that naming style if not found.
								 */
                            value = paramsFromMessage.get("p" + (index + 1));
                        }
                        if (value != null && valueTypeMatchesParameterType(value, paramInfo)) {
                            values[index] = value;
                            signature[index] = paramInfo.getType();
                            index++;
                        }
                    }
                    if (index == paramInfoArray.length) {
                        return this.server.invoke(objectName, operationName, values, signature);
                    }
                }
            }
        }
        if (hasNoArgOption) {
            return this.server.invoke(objectName, operationName, null, null);
        }
        throw new MessagingException(requestMessage, "failed to find JMX operation '" + operationName + "' on MBean [" + objectName + "] of type [" + mbeanInfo.getClassName() + "] with " + paramsFromMessage.size() + " parameters: " + paramsFromMessage);
    } catch (JMException e) {
        throw new MessageHandlingException(requestMessage, "failed to invoke JMX operation '" + operationName + "' on MBean [" + objectName + "]" + " with " + paramsFromMessage.size() + " parameters: " + paramsFromMessage, e);
    } catch (IOException e) {
        throw new MessageHandlingException(requestMessage, "IOException on MBeanServerConnection", e);
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) MessagingException(org.springframework.messaging.MessagingException) MBeanOperationInfo(javax.management.MBeanOperationInfo) IOException(java.io.IOException) MessageHandlingException(org.springframework.messaging.MessageHandlingException) ObjectName(javax.management.ObjectName) JMException(javax.management.JMException) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 32 with JMException

use of javax.management.JMException in project cf-java-client by cloudfoundry.

the class _DefaultConnectionContext method dispose.

/**
 * Disposes resources created to service this connection context
 */
@PreDestroy
public final void dispose() {
    getConnectionPool().ifPresent(PoolResources::dispose);
    getThreadPool().dispose();
    try {
        ObjectName name = getByteBufAllocatorObjectName();
        if (ManagementFactory.getPlatformMBeanServer().isRegistered(name)) {
            ManagementFactory.getPlatformMBeanServer().unregisterMBean(name);
        }
    } catch (JMException e) {
        this.logger.error("Unable to register ByteBufAllocator MBean", e);
    }
}
Also used : PoolResources(reactor.ipc.netty.resources.PoolResources) JMException(javax.management.JMException) ObjectName(javax.management.ObjectName) PreDestroy(javax.annotation.PreDestroy)

Example 33 with JMException

use of javax.management.JMException in project debezium by debezium.

the class Metrics method register.

public void register(MySqlTaskContext context, Logger logger) {
    try {
        this.name = context.metricName(this.contextName);
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        mBeanServer.registerMBean(this, name);
    } catch (JMException e) {
        logger.warn("Error while register the MBean '{}': {}", name, e.getMessage());
    }
}
Also used : JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer)

Example 34 with JMException

use of javax.management.JMException in project fabric8 by fabric8io.

the class EnableJMXFeature method initialize.

@Override
public void initialize(Bus bus) {
    List<Server> servers = new ArrayList<Server>();
    ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class);
    servers.addAll(serverRegistry.getServers());
    for (Iterator<Server> iter = servers.iterator(); iter.hasNext(); ) {
        Server server = (Server) iter.next();
        ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
        ManagedEndpoint mEndpoint = new ManagedEndpoint(bus, server.getEndpoint(), server);
        InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
        if (iMgr == null) {
            iMgr = new InstrumentationManagerImpl(bus);
        }
        ((InstrumentationManagerImpl) iMgr).setUsePlatformMBeanServer(true);
        ((InstrumentationManagerImpl) iMgr).setCreateMBServerConnectorFactory(false);
        ((InstrumentationManagerImpl) iMgr).setEnabled(true);
        ((InstrumentationManagerImpl) iMgr).init();
        if (iMgr != null) {
            try {
                iMgr.register(mApi);
                iMgr.register(mEndpoint);
            } catch (JMException jmex) {
                jmex.printStackTrace();
                LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
            }
        }
    }
}
Also used : InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) Server(org.apache.cxf.endpoint.Server) ArrayList(java.util.ArrayList) JMException(javax.management.JMException) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) ManagedEndpoint(org.apache.cxf.endpoint.ManagedEndpoint) InstrumentationManager(org.apache.cxf.management.InstrumentationManager)

Example 35 with JMException

use of javax.management.JMException in project fabric8 by fabric8io.

the class EnableJMXFeature method initialize.

@Override
public void initialize(Server server, Bus bus) {
    ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
    ManagedEndpoint mEndpoint = new ManagedEndpoint(bus, server.getEndpoint(), server);
    InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
    if (iMgr == null) {
        iMgr = new InstrumentationManagerImpl(bus);
    }
    ((InstrumentationManagerImpl) iMgr).setUsePlatformMBeanServer(true);
    ((InstrumentationManagerImpl) iMgr).setCreateMBServerConnectorFactory(false);
    ((InstrumentationManagerImpl) iMgr).setEnabled(true);
    ((InstrumentationManagerImpl) iMgr).init();
    if (iMgr != null) {
        try {
            iMgr.register(mApi);
            iMgr.register(mEndpoint);
            ServerLifeCycleManager slcMgr = bus.getExtension(ServerLifeCycleManager.class);
            if (slcMgr != null) {
                slcMgr.registerListener(mApi);
                slcMgr.registerListener(mEndpoint);
                mApi.startServer(server);
                mEndpoint.startServer(server);
            }
        } catch (JMException jmex) {
            jmex.printStackTrace();
            LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
        }
    }
}
Also used : InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) JMException(javax.management.JMException) ManagedEndpoint(org.apache.cxf.endpoint.ManagedEndpoint) InstrumentationManager(org.apache.cxf.management.InstrumentationManager)

Aggregations

JMException (javax.management.JMException)114 ObjectName (javax.management.ObjectName)65 MBeanServer (javax.management.MBeanServer)35 IOException (java.io.IOException)21 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)13 MalformedObjectNameException (javax.management.MalformedObjectNameException)12 MBeanInfo (javax.management.MBeanInfo)10 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)8 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 StandardMBean (javax.management.StandardMBean)7 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)6 Date (java.util.Date)5 Attribute (javax.management.Attribute)5 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)5 Element (org.w3c.dom.Element)5 PostConstruct (javax.annotation.PostConstruct)4 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)4