Search in sources :

Example 61 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException in project databus by linkedin.

the class GoldenGateEventProducer method shutdown.

// TBD : Reconcile this behavior in parent class
@Override
public synchronized void shutdown() {
    _log.info("Golden gate evert producer shutdown requested.");
    _shutdownRequested = true;
    for (ObjectName name : _registeredMbeans) {
        try {
            _mbeanServer.unregisterMBean(name);
            _log.info("Unregistered gg-source mbean: " + name);
        } catch (MBeanRegistrationException e) {
            _log.warn("Exception when unregistering gg-source statistics mbean: " + name + e);
        } catch (InstanceNotFoundException e) {
            _log.warn("Exception when unregistering gg-source statistics mbean: " + name + e);
        }
    }
    if (_worker != null) {
        if (_worker._parser == null) {
            _log.error("The parser is null, unable to shutdown the event producer");
            return;
        }
        _worker._parser.setShutDownRequested(true);
        _worker.interrupt();
    }
    _log.warn("Shut down request sent to thread");
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 62 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException in project hadoop by apache.

the class JMXJsonServlet method listBeans.

// --------------------------------------------------------- Private Methods
private void listBeans(JsonGenerator jg, ObjectName qry, String attribute, HttpServletResponse response) throws IOException {
    LOG.debug("Listing beans for " + qry);
    Set<ObjectName> names = null;
    names = mBeanServer.queryNames(qry, null);
    jg.writeArrayFieldStart("beans");
    Iterator<ObjectName> it = names.iterator();
    while (it.hasNext()) {
        ObjectName oname = it.next();
        MBeanInfo minfo;
        String code = "";
        Object attributeinfo = null;
        try {
            minfo = mBeanServer.getMBeanInfo(oname);
            code = minfo.getClassName();
            String prs = "";
            try {
                if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
                    prs = "modelerType";
                    code = (String) mBeanServer.getAttribute(oname, prs);
                }
                if (attribute != null) {
                    prs = attribute;
                    attributeinfo = mBeanServer.getAttribute(oname, prs);
                }
            } catch (AttributeNotFoundException e) {
                // If the modelerType attribute was not found, the class name is used
                // instead.
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            } catch (MBeanException e) {
                // The code inside the attribute getter threw an exception so log it,
                // and fall back on the class name
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            } catch (RuntimeException e) {
                // For some reason even with an MBeanException available to them
                // Runtime exceptionscan still find their way through, so treat them
                // the same as MBeanException
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            } catch (ReflectionException e) {
                // This happens when the code inside the JMX bean (setter?? from the
                // java docs) threw an exception, so log it and fall back on the 
                // class name
                LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
            }
        } catch (InstanceNotFoundException e) {
            //Ignored for some reason the bean was not found so don't output it
            continue;
        } catch (IntrospectionException e) {
            // This is an internal error, something odd happened with reflection so
            // log it and don't output the bean.
            LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e);
            continue;
        } catch (ReflectionException e) {
            // This happens when the code inside the JMX bean threw an exception, so
            // log it and don't output the bean.
            LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e);
            continue;
        }
        jg.writeStartObject();
        jg.writeStringField("name", oname.toString());
        jg.writeStringField("modelerType", code);
        if ((attribute != null) && (attributeinfo == null)) {
            jg.writeStringField("result", "ERROR");
            jg.writeStringField("message", "No attribute with name " + attribute + " was found.");
            jg.writeEndObject();
            jg.writeEndArray();
            jg.close();
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        if (attribute != null) {
            writeAttribute(jg, attribute, attributeinfo);
        } else {
            MBeanAttributeInfo[] attrs = minfo.getAttributes();
            for (int i = 0; i < attrs.length; i++) {
                writeAttribute(jg, oname, attrs[i]);
            }
        }
        jg.writeEndObject();
    }
    jg.writeEndArray();
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanException(javax.management.MBeanException)

Example 63 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException in project presto by prestodb.

the class RebindSafeMBeanServer method registerMBean.

/**
     * Delegates to the wrapped mbean server, but if a mbean is already registered
     * with the specified name, the existing instance is returned.
     */
@Override
public ObjectInstance registerMBean(Object object, ObjectName name) throws MBeanRegistrationException, NotCompliantMBeanException {
    while (true) {
        try {
            // try to register the mbean
            return mbeanServer.registerMBean(object, name);
        } catch (InstanceAlreadyExistsException ignored) {
        }
        try {
            // a mbean is already installed, try to return the already registered instance
            ObjectInstance objectInstance = mbeanServer.getObjectInstance(name);
            log.debug("%s already bound to %s", name, objectInstance);
            return objectInstance;
        } catch (InstanceNotFoundException ignored) {
        // the mbean was removed before we could get the reference
        // start the whole process over again
        }
    }
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance)

Example 64 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException in project presto by prestodb.

the class RebindSafeMBeanServer method registerMBean.

/**
     * Delegates to the wrapped mbean server, but if a mbean is already registered
     * with the specified name, the existing instance is returned.
     */
@Override
public ObjectInstance registerMBean(Object object, ObjectName name) throws MBeanRegistrationException, NotCompliantMBeanException {
    while (true) {
        try {
            // try to register the mbean
            return mbeanServer.registerMBean(object, name);
        } catch (InstanceAlreadyExistsException ignored) {
        }
        try {
            // a mbean is already installed, try to return the already registered instance
            ObjectInstance objectInstance = mbeanServer.getObjectInstance(name);
            log.debug("%s already bound to %s", name, objectInstance);
            return objectInstance;
        } catch (InstanceNotFoundException ignored) {
        // the mbean was removed before we could get the reference
        // start the whole process over again
        }
    }
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance)

Example 65 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException in project meteo by pierre.

the class JMXSubscriber method subscribe.

@Override
public void subscribe() {
    try {
        connect();
    } catch (IOException e) {
        // ignored
        return;
    }
    this.worker = Executors.newScheduledThreadPool(1).scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            final AttributeList attrList;
            try {
                attrList = mbeanConn.getAttributes(mbeanName, attrNames);
                final LinkedHashMap<String, Object> data = new LinkedHashMap<String, Object>();
                log.debug(String.format("Found %d data points", attrList.size()));
                for (Object attrObj : attrList) {
                    Attribute attr = (Attribute) attrObj;
                    data.put(attr.getName(), attr.getValue());
                }
                log.debug("Received a message, yay!\n" + data);
                esperSink.getEPRuntime().sendEvent(data, jmxConfig.getEventOutputName());
            } catch (InstanceNotFoundException ex) {
                log.error("Could not fetch from JMX", ex);
            } catch (ReflectionException ex) {
                log.error("Could not fetch from JMX", ex);
            } catch (IOException ex) {
                log.error("Could not fetch from JMX", ex);
            }
        }
    }, 0, jmxConfig.getPollIntervalInMillis(), TimeUnit.MILLISECONDS);
}
Also used : ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) InstanceNotFoundException(javax.management.InstanceNotFoundException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

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