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