Search in sources :

Example 26 with InstanceNotFoundException

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

the class MBeanJMXAdapter method hasNotificationSupport.

/**
   * Checks whether an MBean implements notification support classes or not
   * 
   * @param objectName
   * @return if this MBean can be a notification broadcaster
   */
public boolean hasNotificationSupport(ObjectName objectName) {
    try {
        if (!isRegistered(objectName)) {
            return false;
        }
        ObjectInstance instance = mbeanServer.getObjectInstance(objectName);
        String className = instance.getClassName();
        Class cls = ClassLoadUtil.classFromName(className);
        Type[] intfTyps = cls.getGenericInterfaces();
        for (int i = 0; i < intfTyps.length; i++) {
            Class intfTyp = (Class) intfTyps[i];
            if (intfTyp.equals(NotificationEmitter.class)) {
                return true;
            }
        }
        Class supreClassTyp = (Class) cls.getGenericSuperclass();
        if (supreClassTyp != null && supreClassTyp.equals(NotificationBroadcasterSupport.class)) {
            return true;
        }
    } catch (InstanceNotFoundException e) {
        throw new ManagementException(e);
    } catch (ClassNotFoundException e) {
        throw new ManagementException(e);
    }
    return false;
}
Also used : Type(java.lang.reflect.Type) ManagementException(org.apache.geode.management.ManagementException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance) NotificationBroadcasterSupport(javax.management.NotificationBroadcasterSupport)

Example 27 with InstanceNotFoundException

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

the class MBeanJMXAdapter method isAttributeAvailable.

public static boolean isAttributeAvailable(String attributeName, String objectName) {
    try {
        ObjectName objName = new ObjectName(objectName);
        mbeanServer.getAttribute(objName, attributeName);
    } catch (MalformedObjectNameException e) {
        return false;
    } catch (NullPointerException e) {
        return false;
    } catch (AttributeNotFoundException e) {
        return false;
    } catch (InstanceNotFoundException e) {
        return false;
    } catch (MBeanException e) {
        return false;
    } catch (ReflectionException e) {
        return false;
    }
    return true;
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 28 with InstanceNotFoundException

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

the class ManagementFunction method execute.

/**
   * Actual function execution. It delegates task at managed node according to the request received.
   * 
   * If any exception is encountered it will set the result to UNDEFINED
   */
public void execute(FunctionContext fc) {
    boolean executedSuccessfully = false;
    InternalCache cache = GemFireCacheImpl.getInstance();
    Object[] functionArguments = (Object[]) fc.getArguments();
    ObjectName objectName = (ObjectName) functionArguments[0];
    String methodName = (String) functionArguments[1];
    String[] signature = (String[]) functionArguments[2];
    Object[] args = (Object[]) functionArguments[3];
    String memberName = (String) functionArguments[4];
    Object returnObj = null;
    try {
        final int nargs = (args == null) ? 0 : args.length;
        if (methodName.startsWith("set") && methodName.length() > 3 && nargs == 1) {
            Attribute attr = new Attribute(methodName.substring(3), args[0]);
            mbeanServer.setAttribute(objectName, attr);
            fc.getResultSender().lastResult((Serializable) null);
        } else if (methodName.equals("addNotificationListener")) {
            notificationHub.addHubNotificationListener(memberName, objectName);
            fc.getResultSender().lastResult((Serializable) ManagementConstants.UNDEFINED);
        } else if (methodName.equals("removeNotificationListener")) {
            notificationHub.removeHubNotificationListener(memberName, objectName);
            fc.getResultSender().lastResult((Serializable) ManagementConstants.UNDEFINED);
        } else if (methodName.equals("getNotificationInfo")) {
            fc.getResultSender().lastResult(mbeanServer.getMBeanInfo(objectName));
        } else {
            returnObj = mbeanServer.invoke(objectName, methodName, args, signature);
            fc.getResultSender().lastResult((Serializable) returnObj);
        }
        executedSuccessfully = true;
    } catch (InstanceNotFoundException e) {
        if (cache != null && !cache.isClosed()) {
            sendException(e, fc);
        }
    } catch (ReflectionException e) {
        sendException(e, fc);
    } catch (MBeanException e) {
        sendException(e, fc);
    } catch (NullPointerException e) {
        sendException(e, fc);
    } catch (Exception e) {
        sendException(e, fc);
    } finally {
        if (!executedSuccessfully) {
            if (cache == null || (cache != null && cache.isClosed())) {
                Exception e = new Exception(ManagementStrings.MEMBER_IS_SHUTTING_DOWN.toLocalizedString());
                sendException(e, fc);
                // member is closing or invalid member
                return;
            }
        }
    }
}
Also used : ReflectionException(javax.management.ReflectionException) Serializable(java.io.Serializable) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) InternalCache(org.apache.geode.internal.cache.InternalCache) MBeanException(javax.management.MBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException)

Example 29 with InstanceNotFoundException

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

the class MBeanUtil method printBeanDetails.

public static void printBeanDetails(ObjectName objName) throws Exception {
    MBeanAttributeInfo[] attributeInfos;
    MBeanInfo info = null;
    try {
        info = mbeanServer.getMBeanInfo(objName);
    } catch (IntrospectionException e1) {
        fail("Could not obtain Sender Proxy Details");
    } catch (InstanceNotFoundException e1) {
        fail("Could not obtain Sender Proxy Details");
    } catch (ReflectionException e1) {
        fail("Could not obtain Sender Proxy Details");
    }
    attributeInfos = info.getAttributes();
    for (MBeanAttributeInfo attributeInfo : attributeInfos) {
        Object propertyValue = null;
        String propertyName = null;
        try {
            propertyName = attributeInfo.getName();
            propertyValue = mbeanServer.getAttribute(objName, propertyName);
            LogWriterUtils.getLogWriter().info("<ExpectedString> " + propertyName + " = " + propertyValue + "</ExpectedString> ");
        } catch (Exception e) {
        }
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MBeanInfo(javax.management.MBeanInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException)

Example 30 with InstanceNotFoundException

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

the class JMXDataUpdater method updateMemberClient.

/**
   * function used for getting member clients from mbean and update the clients information in
   * member object's client arraylist
   */
private void updateMemberClient(ObjectName mbeanName) throws IOException {
    try {
        String memberName = mbeanName.getKeyProperty(PulseConstants.MBEAN_KEY_PROPERTY_MEMBER);
        if (cluster.getMembersHMap().containsKey(memberName)) {
            Cluster.Member existingMember = cluster.getMembersHMap().get(memberName);
            HashMap<String, Cluster.Client> memberClientsHM = new HashMap<String, Cluster.Client>();
            existingMember.setMemberPort("" + this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_PORT));
            this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_HOSTNAMEFORCLIENTS_ALT);
            existingMember.setHostnameForClients((String) this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_HOSTNAMEFORCLIENTS_ALT));
            existingMember.setBindAddress((String) this.mbs.getAttribute(mbeanName, PulseConstants.MBEAN_ATTRIBUTE_BINDADDRESS));
            CompositeData[] compositeData = (CompositeData[]) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_SHOWALLCLIENTS, null, null));
            for (CompositeData cmd : compositeData) {
                Cluster.Client client = new Cluster.Client();
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CLIENTID)) {
                    client.setId((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CLIENTID));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NAME)) {
                    client.setName((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NAME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME)) {
                    client.setHost((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE)) {
                    client.setQueueSize((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME)) {
                    client.setProcessCpuTime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_UPTIME)) {
                    client.setUptime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_UPTIME));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS)) {
                    client.setThreads((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS)) {
                    client.setGets((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS)) {
                    client.setPuts((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) {
                    client.setCpus((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CPUS));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) {
                    client.setCpuUsage(0);
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CONNECTED)) {
                    client.setConnected((Boolean) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CONNECTED));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CLIENTCQCOUNT)) {
                    client.setClientCQCount((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CLIENTCQCOUNT));
                }
                if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_SUBSCRIPTIONENABLED)) {
                    client.setSubscriptionEnabled((Boolean) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_SUBSCRIPTIONENABLED));
                }
                memberClientsHM.put(client.getId(), client);
            }
            existingMember.updateMemberClientsHMap(memberClientsHM);
        }
    } catch (InstanceNotFoundException | ReflectionException | AttributeNotFoundException | MBeanException infe) {
        logger.warn(infe);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException)

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