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