List of usage examples for javax.management.openmbean CompositeData containsKey
public boolean containsKey(String key);
From source file:org.ngrinder.monitor.share.domain.MonitorInfo.java
protected static boolean containsKey(CompositeData cd, String itemName) { return cd.containsKey(itemName); }
From source file:org.rhq.core.pluginapi.util.ObjectUtil.java
/** * Looks up deep object graph attributes using a dot delimited java bean spec style path. So if I have an object A * with a Member object B with a String value C I can refer to it as "b.c" and pass in the object A and I'll get * back the value of a.getB().getC()//from w w w .j a v a 2s. com * * @param value The object to look into * @param propertyPath the property path to search * * @return the value read from the object's property path */ public static Object lookupDeepAttributeProperty(Object value, String propertyPath) { if (value == null) return null; String[] ps = propertyPath.split("\\.", 2); String searchProperty = ps[0]; if (value instanceof CompositeData) { CompositeData compositeData = ((CompositeData) value); if (compositeData.containsKey(searchProperty)) { value = compositeData.get(searchProperty); } else { LOG.debug("Unable to read attribute property [" + propertyPath + "] from composite data value"); } } else { // Try to use reflection try { PropertyDescriptor[] pds = Introspector.getBeanInfo(value.getClass()).getPropertyDescriptors(); for (PropertyDescriptor pd : pds) { if (pd.getName().equals(searchProperty)) { value = pd.getReadMethod().invoke(value); } } } catch (Exception e) { LOG.debug("Unable to read property from measurement attribute [" + searchProperty + "] not found on [" + ((value != null) ? value.getClass().getSimpleName() : "null") + "]"); } } if (ps.length > 1) { value = lookupDeepAttributeProperty(value, ps[1]); } return value; }
From source file:org.rhq.core.pluginapi.util.ObjectUtil.java
/** * Returns the value of the property with the specified name for the given Object, or null if the Object has no such * property./*from w w w. j a v a 2s. c o m*/ * * @param obj an Object * @param propertyName the name of the property whose value should be returned * * @return the value of the property with the specified name for the given Object, or null if the Object has no such * property */ @Nullable public static Object lookupAttributeProperty(Object obj, String propertyName) { Object value = null; if (obj instanceof CompositeData) { CompositeData compositeData = ((CompositeData) obj); if (compositeData.containsKey(propertyName)) { value = compositeData.get(propertyName); } else { LOG.debug("Unable to read attribute/property [" + propertyName + "] from object [" + obj + "] using OpenMBean API - no such property."); } } else { // Try to use reflection. try { PropertyDescriptor[] pds = Introspector.getBeanInfo(obj.getClass()).getPropertyDescriptors(); boolean propertyFound = false; for (PropertyDescriptor pd : pds) { if (pd.getName().equals(propertyName)) { propertyFound = true; Method readMethod = pd.getReadMethod(); if (readMethod == null) { LOG.debug("Unable to read attribute/property [" + propertyName + "] from object [" + obj + "] using Reflection - property is not readable (i.e. it has no getter)."); } else { value = readMethod.invoke(obj); } } } if (!propertyFound) { LOG.debug("Unable to read attribute/property [" + propertyName + "] from object [" + obj + "] using Reflection - no such property."); } } catch (Exception e) { LOG.debug("Unable to read attribute/property [" + propertyName + "] from object [" + obj + "] using Reflection - cause: " + ThrowableUtil.getAllMessages(e)); } } return value; }
From source file:org.red5.server.Client.java
/** * Allows for reconstruction via CompositeData. * * @param cd composite data/*from w w w. j a va2 s . c o m*/ * @return Client class instance */ public static Client from(CompositeData cd) { Client instance = null; if (cd.containsKey("id")) { String id = (String) cd.get("id"); instance = new Client(id, null); instance.setCreationTime((Long) cd.get("creationTime")); instance.setAttribute(PERMISSIONS, cd.get(PERMISSIONS)); } if (cd.containsKey("attributes")) { AttributeStore attrs = (AttributeStore) cd.get("attributes"); instance.setAttributes(attrs); } return instance; }
From source file:org.red5.server.Context.java
/** * Allows for reconstruction via CompositeData. * /* w ww .ja v a 2 s . co m*/ * @param cd composite data * @return Context class instance */ public static Context from(CompositeData cd) { Context instance = new Context(); if (cd.containsKey("context") && cd.containsKey("contextPath")) { Object context = cd.get("context"); Object contextPath = cd.get("contextPath"); if (context != null && contextPath != null) { instance = new Context((ApplicationContext) context, (String) contextPath); } } return instance; }
From source file:org.red5.server.scope.Scope.java
/** * Allows for reconstruction via CompositeData. * /*ww w . j a v a 2 s . c om*/ * @param cd composite data * @return Scope class instance */ public static Scope from(CompositeData cd) { IScope parent = null; ScopeType type = ScopeType.UNDEFINED; String name = null; boolean persistent = false; if (cd.containsKey("parent")) { parent = (IScope) cd.get("parent"); } if (cd.containsKey("type")) { type = (ScopeType) cd.get("type"); } if (cd.containsKey("name")) { name = (String) cd.get("name"); } if (cd.containsKey("persistent")) { persistent = (Boolean) cd.get("persistent"); } return new Scope(new Builder(parent, type, name, persistent)); }
From source file:org.wso2.andes.management.ui.views.ViewUtility.java
/** * Populates the given composite with the CompositeData. Creates required widgets to hold the data types * @param toolkit//from w w w. j a va 2s .co m * @param parent * @param data CompositeData */ @SuppressWarnings("unchecked") private static void populateCompositeWithCompositeData(FormToolkit toolkit, Composite parent, CompositeData data) { Control[] oldControls = parent.getChildren(); for (int i = 0; i < oldControls.length; i++) { oldControls[i].dispose(); } Composite compositeHolder = toolkit.createComposite(parent, SWT.NONE); GridLayout layout = new GridLayout(4, false); layout.horizontalSpacing = 10; compositeHolder.setLayout(layout); compositeHolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // ItemNames in composite data List<String> itemNames = new ArrayList<String>(data.getCompositeType().keySet()); for (String itemName : itemNames) { OpenType itemType = data.getCompositeType().getType(itemName); Label keyLabel = toolkit.createLabel(compositeHolder, itemName, SWT.TRAIL); GridData layoutData = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1); layoutData.minimumWidth = 70; keyLabel.setLayoutData(layoutData); if (itemType.isArray()) { OpenType type = ((ArrayType) itemType).getElementOpenType(); // If Byte array and mimetype is text, convert to text string if (type.getClassName().equals(Byte.class.getName())) { String mimeType = null; String encoding = null; if (data.containsKey("MimeType")) { mimeType = (String) data.get("MimeType"); } if (data.containsKey("Encoding")) { encoding = (String) data.get("Encoding"); } if (encoding == null || encoding.length() == 0) { encoding = Charset.defaultCharset().name(); } if ("text/plain".equals(mimeType)) { convertByteArray(toolkit, compositeHolder, data, itemName, encoding); } else { handleBinaryMessageContent(toolkit, compositeHolder, data, itemName, encoding); } } // If array of any other supported type, show as a list of String array else if (SUPPORTED_ARRAY_DATATYPES.contains(type.getClassName())) { convertArrayItemForDisplay(compositeHolder, data, itemName); } else { setNotSupportedDataType(toolkit, compositeHolder); } } else if (itemType instanceof TabularType) { Composite composite = toolkit.createComposite(compositeHolder, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1)); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); createTabularDataHolder(toolkit, composite, (TabularDataSupport) data.get(itemName)); } else { Text valueText = toolkit.createText(compositeHolder, String.valueOf(data.get(itemName)), SWT.READ_ONLY | SWT.BORDER); valueText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1)); } } // layout the composite after creating new widgets. parent.layout(); }
From source file:org.apache.geode.tools.pulse.internal.data.JMXDataUpdater.java
/** * function used for getting member clients from mbean and update the clients information in * member object's client arraylist//w w w . j a va 2 s . c om */ 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); } }
From source file:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java
/** * function used for getting member clients from mbean and update the clients * information in member object's client arraylist * /*from www . j av a2 s . c om*/ * @param mbeanName * @param memberName * @throws InstanceNotFoundException * @throws IntrospectionException * @throws ReflectionException * @throws IOException * @throws MBeanException * @throws AttributeNotFoundException * */ 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)); 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)); } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NAME)) { client.setName((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NAME)); } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME)) { client.setHost((String) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_HOSTNAME)); } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE)) { client.setQueueSize((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_QUEUESIZE)); } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME)) { client.setProcessCpuTime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_PROCESSCPUTIME)); } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_UPTIME)) { client.setUptime((Long) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_UPTIME)); } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS)) { client.setThreads((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFTHREADS)); } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS)) { client.setGets((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFGETS)); } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS)) { client.setPuts((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_NUMOFPUTS)); } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) { client.setCpus((Integer) cmd.get(PulseConstants.COMPOSITE_DATA_KEY_CPUS)); } else if (cmd.containsKey(PulseConstants.COMPOSITE_DATA_KEY_CPUS)) { client.setCpuUsage(0); } memberClientsHM.put(client.getId(), client); } existingMember.updateMemberClientsHMap(memberClientsHM); } } catch (InstanceNotFoundException infe) { LOGGER.warning(infe); } catch (ReflectionException re) { LOGGER.warning(re); } catch (MBeanException me) { LOGGER.warning(me); } catch (AttributeNotFoundException anfe) { LOGGER.warning(anfe); } }
From source file:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java
/** * function used to get attribute values of Member Region and map them to * Member vo//from ww w . ja v a2s . c o m * * @param mbeanName * Member Region MBean */ private void updateMemberRegion(ObjectName mbeanName) throws IOException { try { String memberName = mbeanName.getKeyProperty(PulseConstants.MBEAN_KEY_PROPERTY_MEMBER); Cluster.Member member = cluster.getMembersHMap().get(memberName); AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.REGION_MBEAN_ATTRIBUTES); // retrieve the full path of the region String regionFullPathKey = null; for (int i = 0; i < attributeList.size(); i++) { Attribute attribute = (Attribute) attributeList.get(i); if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_FULLPATH)) { regionFullPathKey = getStringAttribute(attribute.getValue(), attribute.getName()); break; } } // if member does not exists defined for this region then create a member if (null == member) { member = new Cluster.Member(); member.setName(memberName); cluster.getMembersHMap().put(memberName, member); } // if region with given path exists then update same else add new region Cluster.Region region = member.getMemberRegions().get(regionFullPathKey); if (null == region) { region = new Cluster.Region(); member.getMemberRegions().put(regionFullPathKey, region); member.setTotalRegionCount(member.getTotalRegionCount() + 1); // Initialize region attributes CompositeData compositeData = (CompositeData) (mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_LISTREGIONATTRIBUTES, null, null)); if (compositeData.containsKey(PulseConstants.COMPOSITE_DATA_KEY_SCOPE)) { region.setScope((String) compositeData.get(PulseConstants.COMPOSITE_DATA_KEY_SCOPE)); } if (compositeData.containsKey(PulseConstants.COMPOSITE_DATA_KEY_DISKSTORENAME)) { region.setDiskStoreName( (String) compositeData.get(PulseConstants.COMPOSITE_DATA_KEY_DISKSTORENAME)); } if (compositeData.containsKey(PulseConstants.COMPOSITE_DATA_KEY_DISKSYNCHRONOUS)) { region.setDiskSynchronous( (Boolean) compositeData.get(PulseConstants.COMPOSITE_DATA_KEY_DISKSYNCHRONOUS)); } } region.setFullPath(regionFullPathKey); // use already retrieved values // update the existing or new region for (int i = 0; i < attributeList.size(); i++) { Attribute attribute = (Attribute) attributeList.get(i); if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_FULLPATH)) { region.setFullPath(getStringAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE)) { region.setDiskReadsRate(getFloatAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE)) { region.setDiskWritesRate(getFloatAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_GETSRATE)) { region.setGetsRate(getFloatAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_LRUEVICTIONRATE)) { region.setLruEvictionRate(getFloatAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE)) { region.setPutsRate(getFloatAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS)) { region.setAverageReads(getFloatAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES)) { region.setAverageWrites(getFloatAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_REGIONTYPE)) { region.setRegionType(getStringAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT)) { region.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE)) { region.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_ENTRYCOUNT)) { region.setSystemRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NAME)) { region.setName(getStringAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_PERSISTENTENABLED)) { region.setPersistentEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_GATEWAYENABLED)) { region.setWanEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName())); } } // Remove deleted regions from member's regions list for (Iterator<String> it = cluster.getDeletedRegions().iterator(); it.hasNext();) { String deletedRegion = it.next(); if (member.getMemberRegions().get(deletedRegion) != null) { member.getMemberRegions().remove(deletedRegion); } member.setTotalRegionCount(member.getMemberRegions().size()); } } catch (InstanceNotFoundException infe) { LOGGER.warning(infe); } catch (ReflectionException re) { LOGGER.warning(re); } catch (MBeanException anfe) { LOGGER.warning(anfe); } }