/** * Validates the agent. * * @return The object name for SWT resource monitor MXBean * @throws JvmCoreException */ private ObjectName validateAgent() throws JvmCoreException { if (!jvm.isRemote() && !JvmModel.getInstance().getAgentLoadHandler().isAgentLoaded()) { throw new JvmCoreException(IStatus.ERROR, Messages.agentNotLoadedMsg, new Exception()); } return jvm.getMBeanServer().getObjectName(SWT_RESOURCE_MONITOR_MXBEAN_NAME); }
/* * @see ISWTResourceMonitor#setTracking(boolean) */ @Override public void setTracking(boolean tracking) throws JvmCoreException { ObjectName objectName = validateAgent(); if (objectName != null) { jvm.getMBeanServer().setAttribute(objectName, new Attribute(TRACKING, tracking)); } }
/* * @see ISWTResourceMonitor#clear() */ @Override public void clear() throws JvmCoreException { ObjectName objectName = validateAgent(); if (objectName != null) { jvm.getMBeanServer().invoke(objectName, CLEAR, new Object[0], new String[0]); } }
/* * @see ISWTResourceMonitor#isTracking() */ @Override public boolean isTracking() throws JvmCoreException { ObjectName objectName = validateAgent(); if (objectName != null) { Object attribute = jvm.getMBeanServer().getAttribute(objectName, TRACKING); if (attribute instanceof Boolean) { return ((Boolean) attribute).booleanValue(); } } return false; }
/* * @see ISWTResourceMonitor#refreshResourcesCache() */ @Override public void refreshResourcesCache() throws JvmCoreException { resources.clear(); ObjectName objectName = validateAgent(); if (objectName != null) { Object attribute = jvm.getMBeanServer().getAttribute(objectName, RESOURCES); if (attribute instanceof CompositeData[]) { resources = new ArrayList<ISWTResourceElement>(getSWTResourceElements((CompositeData[]) attribute)); } } }
/* * @see ISWTResourceMonitor#isSupported() */ @Override public boolean isSupported() { try { ObjectName objectName = validateAgent(); if (objectName == null) { return false; } Object attribute = jvm.getMBeanServer().getAttribute(objectName, TRACKING); return attribute != null; } catch (JvmCoreException e) { return false; } }