use of javax.management.InstanceNotFoundException in project quasar by puniverse.
the class JMXActorMonitor method registerMBean.
private void registerMBean() {
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName mxbeanName = new ObjectName(name);
if (mbs.isRegistered(mxbeanName)) {
try {
LOG.info("MBean named {} is already registered. Unregistering it.", name);
mbs.unregisterMBean(mxbeanName);
} catch (InstanceNotFoundException e) {
}
}
mbs.registerMBean(this, mxbeanName);
MonitoringServices.getInstance().addPerfNotificationListener(this, name);
this.registered = true;
} catch (InstanceAlreadyExistsException ex) {
throw new RuntimeException(ex);
} catch (MBeanRegistrationException ex) {
ex.printStackTrace();
} catch (NotCompliantMBeanException | MalformedObjectNameException ex) {
throw new AssertionError(ex);
}
}
use of javax.management.InstanceNotFoundException in project quasar by puniverse.
the class JMXActorsMonitor method unregister.
@SuppressWarnings({ "CallToPrintStackTrace", "CallToThreadDumpStack" })
private void unregister() {
try {
if (registered) {
MonitoringServices.getInstance().removePerfNotificationListener(this);
ManagementFactory.getPlatformMBeanServer().unregisterMBean(new ObjectName(mbeanName));
}
this.registered = false;
} catch (InstanceNotFoundException ex) {
ex.printStackTrace();
} catch (MBeanRegistrationException ex) {
ex.printStackTrace();
} catch (MalformedObjectNameException ex) {
throw new AssertionError(ex);
}
}
use of javax.management.InstanceNotFoundException in project spring-framework by spring-projects.
the class MBeanClientInterceptor method retrieveMBeanInfo.
/**
* Loads the management interface info for the configured MBean into the caches.
* This information is used by the proxy when determining whether an invocation matches
* a valid operation or attribute on the management interface of the managed resource.
*/
private void retrieveMBeanInfo() throws MBeanInfoRetrievalException {
try {
MBeanInfo info = this.serverToUse.getMBeanInfo(this.objectName);
MBeanAttributeInfo[] attributeInfo = info.getAttributes();
this.allowedAttributes = new HashMap<>(attributeInfo.length);
for (MBeanAttributeInfo infoEle : attributeInfo) {
this.allowedAttributes.put(infoEle.getName(), infoEle);
}
MBeanOperationInfo[] operationInfo = info.getOperations();
this.allowedOperations = new HashMap<>(operationInfo.length);
for (MBeanOperationInfo infoEle : operationInfo) {
Class<?>[] paramTypes = JmxUtils.parameterInfoToTypes(infoEle.getSignature(), this.beanClassLoader);
this.allowedOperations.put(new MethodCacheKey(infoEle.getName(), paramTypes), infoEle);
}
} catch (ClassNotFoundException ex) {
throw new MBeanInfoRetrievalException("Unable to locate class specified in method signature", ex);
} catch (IntrospectionException ex) {
throw new MBeanInfoRetrievalException("Unable to obtain MBean info for bean [" + this.objectName + "]", ex);
} catch (InstanceNotFoundException ex) {
// if we are this far this shouldn't happen, but...
throw new MBeanInfoRetrievalException("Unable to obtain MBean info for bean [" + this.objectName + "]: it is likely that this bean was unregistered during the proxy creation process", ex);
} catch (ReflectionException ex) {
throw new MBeanInfoRetrievalException("Unable to read MBean info for bean [ " + this.objectName + "]", ex);
} catch (IOException ex) {
throw new MBeanInfoRetrievalException("An IOException occurred when communicating with the " + "MBeanServer. It is likely that you are communicating with a remote MBeanServer. " + "Check the inner exception for exact details.", ex);
}
}
use of javax.management.InstanceNotFoundException in project voldemort by voldemort.
the class JmxUtils method createModelMBean.
/**
* Create a model mbean from an object using the description given in the
* Jmx annotation if present. Only operations are supported so far, no
* attributes, constructors, or notifications
*
* @param o The object to create an MBean for
* @return The ModelMBean for the given object
*/
public static ModelMBean createModelMBean(Object o) {
try {
ModelMBean mbean = new RequiredModelMBean();
JmxManaged annotation = o.getClass().getAnnotation(JmxManaged.class);
String description = annotation == null ? "" : annotation.description();
ModelMBeanInfo info = new ModelMBeanInfoSupport(o.getClass().getName(), description, extractAttributeInfo(o), new ModelMBeanConstructorInfo[0], extractOperationInfo(o), new ModelMBeanNotificationInfo[0]);
mbean.setModelMBeanInfo(info);
mbean.setManagedResource(o, "ObjectReference");
return mbean;
} catch (MBeanException e) {
throw new VoldemortException(e);
} catch (InvalidTargetObjectTypeException e) {
throw new VoldemortException(e);
} catch (InstanceNotFoundException e) {
throw new VoldemortException(e);
}
}
use of javax.management.InstanceNotFoundException in project opennms by OpenNMS.
the class JMXDetector method isServiceDetected.
public final boolean isServiceDetected(final InetAddress address, Map<String, String> runtimeAttributes) {
final String ipAddr = InetAddressUtils.str(address);
final int port = getPort();
final int retries = getRetries();
final int timeout = getTimeout();
LOG.info("isServiceDetected: {}: Checking address: {} for capability on port {}", getServiceName(), ipAddr, port);
for (int attempts = 0; attempts < retries; attempts++) {
try (final JmxServerConnectionWrapper client = this.connect(address, port, timeout, runtimeAttributes)) {
LOG.info("isServiceDetected: {}: Attempting to connect to address: {}, port: {}, attempt: #{}", getServiceName(), ipAddr, port, attempts);
if (client.getMBeanServerConnection().getMBeanCount() <= 0) {
return false;
}
if (m_object != null) {
client.getMBeanServerConnection().getObjectInstance(new ObjectName(m_object));
}
return true;
} catch (ConnectException e) {
// Connection refused!! Continue to retry.
LOG.info("isServiceDetected: {}: Unable to connect to address: {} port {}, attempt #{}", getServiceName(), ipAddr, port, attempts, e);
} catch (NoRouteToHostException e) {
// No Route to host!!!
LOG.info("isServiceDetected: {}: No route to address {} was available", getServiceName(), ipAddr, e);
} catch (final PortUnreachableException e) {
// Port unreachable
LOG.info("isServiceDetected: {}: Port unreachable while connecting to address {} port {} within timeout: {} attempt: {}", getServiceName(), ipAddr, port, timeout, attempts, e);
} catch (InterruptedIOException e) {
// Expected exception
LOG.info("isServiceDetected: {}: Did not connect to address {} port {} within timeout: {} attempt: {}", getServiceName(), ipAddr, port, timeout, attempts, e);
} catch (MalformedObjectNameException e) {
LOG.info("isServiceDetected: {}: Object instance {} is not valid on address {} port {} within timeout: {} attempt: {}", getServiceName(), m_object, ipAddr, port, timeout, attempts, e);
} catch (InstanceNotFoundException e) {
LOG.info("isServiceDetected: {}: Object instance {} does not exists on address {} port {} within timeout: {} attempt: {}", getServiceName(), m_object, ipAddr, port, timeout, attempts, e);
} catch (IOException e) {
// NMS-8096: Because the JMX connections wrap lower-level exceptions in an IOException,
// we need to unwrap the exceptions to provide INFO log messages about failures
boolean loggedIt = false;
// Unwrap exception
Throwable cause = e.getCause();
while (cause != null && loggedIt == false) {
if (cause instanceof ConnectException) {
// Connection refused!! Continue to retry.
LOG.info("isServiceDetected: {}: Unable to connect to address: {} port {}, attempt #{}", getServiceName(), ipAddr, port, attempts, e);
loggedIt = true;
} else if (cause instanceof NoRouteToHostException) {
// No Route to host!!!
LOG.info("isServiceDetected: {}: No route to address {} was available", getServiceName(), ipAddr, e);
loggedIt = true;
} else if (cause instanceof PortUnreachableException) {
// Port unreachable
LOG.info("isServiceDetected: {}: Port unreachable while connecting to address {} port {} within timeout: {} attempt: {}", getServiceName(), ipAddr, port, timeout, attempts, e);
loggedIt = true;
} else if (cause instanceof InterruptedIOException) {
// Expected exception
LOG.info("isServiceDetected: {}: Did not connect to address {} port {} within timeout: {} attempt: {}", getServiceName(), ipAddr, port, timeout, attempts, e);
loggedIt = true;
} else if (cause instanceof NameNotFoundException) {
LOG.info("isServiceDetected: {}: Name {} not found on address {} port {} within timeout: {} attempt: {}", getServiceName(), m_object, ipAddr, port, timeout, attempts, e);
loggedIt = true;
} else if (cause instanceof MalformedObjectNameException) {
LOG.info("isServiceDetected: {}: Object instance {} is not valid on address {} port {} within timeout: {} attempt: {}", getServiceName(), m_object, ipAddr, port, timeout, attempts, e);
loggedIt = true;
} else if (cause instanceof InstanceNotFoundException) {
LOG.info("isServiceDetected: {}: Object instance {} does not exists on address {} port {} within timeout: {} attempt: {}", getServiceName(), m_object, ipAddr, port, timeout, attempts, e);
loggedIt = true;
}
cause = cause.getCause();
}
if (!loggedIt) {
// If none of the causes are an expected type, log an error
LOG.error("isServiceDetected: {}: An unexpected I/O exception occured contacting address {} port {}", getServiceName(), ipAddr, port, e);
}
} catch (Throwable t) {
LOG.error("isServiceDetected: {}: Unexpected error trying to detect {} on address {} port {}", getServiceName(), getServiceName(), ipAddr, port, t);
}
}
return false;
}
Aggregations