List of usage examples for javax.management Attribute getValue
public Object getValue()
From source file:catalina.mbeans.ContextResourceMBean.java
/** * Set the value of a specific attribute of this MBean. * * @param attribute The identification of the attribute to be set * and the new value//from w w w . j a va2s . c o m * * @exception AttributeNotFoundException if this attribute is not * supported by this MBean * @exception MBeanException if the initializer of an object * throws an exception * @exception ReflectionException if a Java reflection exception * occurs when invoking the getter */ public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { // Validate the input parameters if (attribute == null) throw new RuntimeOperationsException(new IllegalArgumentException("Attribute is null"), "Attribute is null"); String name = attribute.getName(); Object value = attribute.getValue(); if (name == null) throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null"); ContextResource cr = null; try { cr = (ContextResource) getManagedResource(); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } if ("auth".equals(name)) { cr.setAuth((String) value); } else if ("description".equals(name)) { cr.setDescription((String) value); } else if ("name".equals(name)) { cr.setName((String) value); } else if ("scope".equals(name)) { cr.setScope((String) value); } else if ("type".equals(name)) { cr.setType((String) value); } else { ResourceParams rp = cr.getNamingResources().findResourceParams(cr.getName()); if (rp != null) { String valueStr = "" + value; rp.addParameter(name, valueStr); cr.getNamingResources().removeResourceParams(cr.getName()); } else { rp = new ResourceParams(); rp.setName(cr.getName()); String valueStr = "" + value; rp.addParameter(name, valueStr); } cr.getNamingResources().addResourceParams(rp); } // cannot use side-efects. It's removed and added back each time // there is a modification in a resource. NamingResources nr = cr.getNamingResources(); nr.removeResource(cr.getName()); nr.addResource(cr); }
From source file:org.helios.netty.jmx.MetricCollector.java
/** * Returns a simple map of NIO metrics//w w w. ja va 2s . c o m * @return a simple map of NIO metrics */ protected Map<String, Long> getNio() { Map<String, Long> map = new HashMap<String, Long>(NIO_ATTRS.length); try { AttributeList attrs = ManagementFactory.getPlatformMBeanServer().getAttributes(directNio, NIO_ATTRS); for (Attribute attr : attrs.asList()) { map.put(attr.getName(), (Long) attr.getValue()); } } catch (Exception e) { e.printStackTrace(System.err); } return map; }
From source file:org.fishwife.jrugged.spring.jmx.TestWebMBeanAdapter.java
@Test public void testGetAttributeValues() throws Exception { MBeanAttributeInfo[] attributeInfoArray = new MBeanAttributeInfo[2]; MBeanAttributeInfo mockAttributeInfo1 = createMock(MBeanAttributeInfo.class); MBeanAttributeInfo mockAttributeInfo2 = createMock(MBeanAttributeInfo.class); attributeInfoArray[0] = mockAttributeInfo1; attributeInfoArray[1] = mockAttributeInfo2; expect(mockMBeanInfo.getAttributes()).andReturn(attributeInfoArray); String attributeName1 = "attribute_name_1"; String attributeName2 = "attribute_name_2"; expect(mockAttributeInfo1.getName()).andReturn(attributeName1); expect(mockAttributeInfo2.getName()).andReturn(attributeName2); AttributeList mockAttributeList = createMock(AttributeList.class); expect(mockMBeanServer.getAttributes(eq(mockObjectName), anyObject(String[].class))) .andReturn(mockAttributeList); List<Attribute> attributeList = new ArrayList<Attribute>(); Attribute mockAttribute1 = createMock(Attribute.class); Attribute mockAttribute2 = createMock(Attribute.class); attributeList.add(mockAttribute1);//from w ww .jav a2 s. co m attributeList.add(mockAttribute2); expect(mockAttributeList.asList()).andReturn(attributeList); String name1 = "name 1"; String value1 = "value 1"; expect(mockAttribute1.getName()).andReturn(name1); expect(mockAttribute1.getValue()).andReturn(value1); expect(mockSanitizer.escapeValue(value1)).andReturn(value1); String name2 = "name 2"; String value2 = "value 2"; expect(mockAttribute2.getName()).andReturn(name2); expect(mockAttribute2.getValue()).andReturn(value2); expect(mockSanitizer.escapeValue(value2)).andReturn(value2); replay(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockAttributeInfo1, mockAttributeInfo2, mockAttributeList, mockAttribute1, mockAttribute2); Map<String, Object> attributeValueMap = webMBeanAdapter.getAttributeValues(); assertEquals(2, attributeValueMap.size()); assertEquals(value1, attributeValueMap.get(name1)); assertEquals(value2, attributeValueMap.get(name2)); verify(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockAttributeInfo1, mockAttributeInfo2, mockAttributeList, mockAttribute1, mockAttribute2); }
From source file:org.rifidi.edge.configuration.DefaultConfigurationImpl.java
/** * Constructor.//from w w w . j a va 2 s. c om * * @param context * @param serviceID * @param factoryID * @param attributes * @param sessionDTOs */ public DefaultConfigurationImpl(final String serviceID, final String factoryID, final AttributeList attributes, final NotifierService notifierService, final JMXService jmxService, Set<SessionDTO> sessionDTOs) { this.notifierService = notifierService; this.nameToProperty = new HashMap<String, Property>(); this.nameToOperation = new HashMap<String, Operation>(); this.factoryID = factoryID; this.serviceID = serviceID; this.attributes = (AttributeList) attributes.clone(); disableAutoStart = false; for (Object o : this.attributes) { Attribute att = (Attribute) o; String name = att.getName(); if (name.equals("DisableAutoStart")) { // This is the 'override' autostart, so we will default to true // unless it is explicitly set to false if (att.getValue() != null && ((String) att.getValue()).equalsIgnoreCase("true")) { disableAutoStart = true; } break; } } this.listeners = new CopyOnWriteArraySet<AttributesChangedListener>(); this.target = new AtomicReference<RifidiService>(null); this.jmxService = jmxService; this.sessionDTOs = new ConcurrentHashMap<SessionDTO, String>(); if (sessionDTOs != null) { for (SessionDTO dto : sessionDTOs) { this.sessionDTOs.put(dto, "-1"); } } }
From source file:org.cleverbus.core.throttling.JmxThrottlingConfiguration.java
@Override public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { Assert.notNull(attribute, "attribute must not be null"); // attr name: systemName . serviceName String attrName = attribute.getName(); String[] nameParts = StringUtils.split(attrName, ThrottleScope.THROTTLE_SEPARATOR); if (nameParts.length != 2) { throw new AttributeNotFoundException( "attribute name is not in expected format: 'systemName . serviceName'"); }//from w w w . j a v a 2 s . c o m // attr value: limit / interval String attrValue = (String) attribute.getValue(); String[] valueParts = StringUtils.split(attrValue, ThrottleProps.PROP_VALUE_SEPARATOR); if (valueParts.length != 2) { throw new InvalidAttributeValueException( "attribute value is not in expected format: 'limit / interval'"); } configuration.addProperty(nameParts[0], nameParts[1], Integer.valueOf(valueParts[1]), Integer.valueOf(valueParts[0])); }
From source file:com.proofpoint.jmx.MBeanRepresentation.java
public MBeanRepresentation(MBeanServer mbeanServer, ObjectName objectName, ObjectMapper objectMapper) throws JMException { this.objectName = objectName; MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName); className = mbeanInfo.getClassName(); description = mbeanInfo.getDescription(); descriptor = toMap(mbeanInfo.getDescriptor()); ///*from ww w .j a v a2 s .com*/ // Attributes // LinkedHashMap<String, MBeanAttributeInfo> attributeInfos = Maps.newLinkedHashMap(); for (MBeanAttributeInfo attributeInfo : mbeanInfo.getAttributes()) { attributeInfos.put(attributeInfo.getName(), attributeInfo); } String[] attributeNames = attributeInfos.keySet().toArray(new String[attributeInfos.size()]); ImmutableList.Builder<AttributeRepresentation> attributes = ImmutableList.builder(); for (Attribute attribute : mbeanServer.getAttributes(objectName, attributeNames).asList()) { String attributeName = attribute.getName(); // use remove so we only include one value for each attribute MBeanAttributeInfo attributeInfo = attributeInfos.remove(attributeName); if (attributeInfo == null) { // unknown extra attribute, could have been added after MBeanInfo was fetched continue; } Object attributeValue = attribute.getValue(); AttributeRepresentation attributeRepresentation = new AttributeRepresentation(attributeInfo, attributeValue, objectMapper); attributes.add(attributeRepresentation); } this.attributes = attributes.build(); // // Operations // ImmutableList.Builder<OperationRepresentation> operations = ImmutableList.builder(); for (MBeanOperationInfo operationInfo : mbeanInfo.getOperations()) { operations.add(new OperationRepresentation(operationInfo)); } this.operations = operations.build(); }
From source file:org.rifidi.edge.configuration.RifidiService.java
/** * Private helper method so I don't have to duplicate JMS Notification calls * /* w ww . j a v a 2 s .c o m*/ * @param attribute * @throws AttributeNotFoundException * @throws InvalidAttributeValueException * @throws MBeanException * @throws ReflectionException */ private void _setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { // for now we go through the individual setters if (nameToProperty.containsKey(attribute.getName())) { try { Property prop = nameToProperty.get(attribute.getName()); Method method = this.getClass().getMethod("set" + attribute.getName(), PropertyType.getClassFromType(prop.type())); // if attribute is a string, but is supposed to be another // type, convert it if ((attribute.getValue() instanceof String) && prop.type() != PropertyType.PT_STRING) { attribute = new Attribute(attribute.getName(), PropertyType.convert((String) attribute.getValue(), prop.type())); } method.invoke(this, attribute.getValue()); return; } catch (SecurityException e) { logger.error(e); } catch (NoSuchMethodException e) { logger.error(e); } catch (IllegalArgumentException e) { logger.error(e); } catch (IllegalAccessException e) { logger.error(e); } catch (InvocationTargetException e) { logger.error(e); } } logger.warn("Unknown attribute: " + attribute); // throw new AttributeNotFoundException(); }
From source file:com.tc.stats.DSO.java
@Override public Map<ObjectName, Map<String, Object>> getAttributeMap(Map<ObjectName, Set<String>> attributeMap, long timeout, TimeUnit unit) { Map<ObjectName, Map<String, Object>> result = new HashMap<ObjectName, Map<String, Object>>(); List<Callable<SourcedAttributeList>> tasks = new ArrayList<Callable<SourcedAttributeList>>(); Iterator<Entry<ObjectName, Set<String>>> entryIter = attributeMap.entrySet().iterator(); while (entryIter.hasNext()) { Entry<ObjectName, Set<String>> entry = entryIter.next(); tasks.add(new AttributeListTask(entry.getKey(), entry.getValue())); }//w ww . jav a 2s . c o m try { List<Future<SourcedAttributeList>> results = pool.invokeAll(tasks, timeout, unit); Iterator<Future<SourcedAttributeList>> resultIter = results.iterator(); while (resultIter.hasNext()) { Future<SourcedAttributeList> future = resultIter.next(); if (future.isDone() && !future.isCancelled()) { try { SourcedAttributeList sal = future.get(); Iterator<Object> attrIter = sal.attributeList.iterator(); Map<String, Object> onMap = new HashMap<String, Object>(); while (attrIter.hasNext()) { Attribute attr = (Attribute) attrIter.next(); onMap.put(attr.getName(), attr.getValue()); } result.put(sal.objectName, onMap); } catch (CancellationException ce) { /**/ } catch (ExecutionException ee) { /**/ } } } } catch (InterruptedException ie) {/**/ } return result; }
From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { if (methods == null) init();// w ww . j a v a 2 s . c o m // XXX Send notification !!! Method m = (Method) setAttMap.get(attribute.getName()); if (m == null) throw new AttributeNotFoundException(attribute.getName()); try { log.info(real.getClass().getName() + "setAttribute " + attribute.getName()); m.invoke(real, new Object[] { attribute.getValue() }); } catch (IllegalAccessException ex) { ex.printStackTrace(); throw new MBeanException(ex); } catch (InvocationTargetException ex1) { ex1.printStackTrace(); throw new MBeanException(ex1); } }
From source file:dk.netarkivet.harvester.harvesting.controller.BnfHeritrixController.java
/** * Retrieve the values of the crawl service attributes and * add them to the CrawlProgressMessage being put together. * @param cpm the crawlProgress message being prepared *//* w ww. j av a 2 s .c o m*/ private void getCrawlServiceAttributes(CrawlProgressMessage cpm) { List<Attribute> heritrixAtts = getMBeanAttributes( new CrawlServiceAttribute[] { CrawlServiceAttribute.AlertCount, CrawlServiceAttribute.IsCrawling, CrawlServiceAttribute.CurrentJob }); CrawlServiceInfo hStatus = cpm.getHeritrixStatus(); for (Attribute att : heritrixAtts) { Object value = att.getValue(); CrawlServiceAttribute crawlServiceAttribute = CrawlServiceAttribute.fromString(att.getName()); switch (crawlServiceAttribute) { case AlertCount: Integer alertCount = -1; if (value != null) { alertCount = (Integer) value; } hStatus.setAlertCount(alertCount); break; case CurrentJob: String newCurrentJob = ""; if (value != null) { newCurrentJob = (String) value; } hStatus.setCurrentJob(newCurrentJob); break; case IsCrawling: Boolean newCrawling = false; if (value != null) { newCrawling = (Boolean) value; } hStatus.setCrawling(newCrawling); break; default: log.debug("Unhandled attribute: " + crawlServiceAttribute); } } }