Search in sources :

Example 66 with InstanceNotFoundException

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

Example 67 with InstanceNotFoundException

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

Example 68 with InstanceNotFoundException

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);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) IOException(java.io.IOException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 69 with InstanceNotFoundException

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);
    }
}
Also used : RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) ModelMBean(javax.management.modelmbean.ModelMBean) JmxManaged(voldemort.annotations.jmx.JmxManaged) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) VoldemortException(voldemort.VoldemortException) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean)

Example 70 with InstanceNotFoundException

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;
}
Also used : InterruptedIOException(java.io.InterruptedIOException) PortUnreachableException(java.net.PortUnreachableException) MalformedObjectNameException(javax.management.MalformedObjectNameException) NameNotFoundException(javax.naming.NameNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) NoRouteToHostException(java.net.NoRouteToHostException) ObjectName(javax.management.ObjectName) JmxServerConnectionWrapper(org.opennms.netmgt.jmx.connection.JmxServerConnectionWrapper) ConnectException(java.net.ConnectException)

Aggregations

InstanceNotFoundException (javax.management.InstanceNotFoundException)102 ObjectName (javax.management.ObjectName)59 ReflectionException (javax.management.ReflectionException)44 MBeanException (javax.management.MBeanException)32 MalformedObjectNameException (javax.management.MalformedObjectNameException)28 MBeanRegistrationException (javax.management.MBeanRegistrationException)25 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)19 MBeanServer (javax.management.MBeanServer)17 IOException (java.io.IOException)16 AttributeNotFoundException (javax.management.AttributeNotFoundException)16 Attribute (javax.management.Attribute)15 IntrospectionException (javax.management.IntrospectionException)14 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)14 AttributeList (javax.management.AttributeList)12 ObjectInstance (javax.management.ObjectInstance)12 MBeanInfo (javax.management.MBeanInfo)11 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)10 RuntimeOperationsException (javax.management.RuntimeOperationsException)9 ArrayList (java.util.ArrayList)7 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)7