List of usage examples for javax.management Attribute Attribute
public Attribute(String name, Object value)
From source file:org.apache.camel.component.zookeeper.ZooKeeperEndpointTest.java
private void verifyManagedAttribute(ObjectName zepName, String attributeName, Boolean attributeValue) throws Exception { mbsc.setAttribute(zepName, new Attribute(attributeName, attributeValue)); assertEquals(attributeValue, mbsc.getAttribute(zepName, attributeName)); }
From source file:org.mc4j.ems.impl.jmx.connection.bean.attribute.DAttribute.java
/** * Set the attribute on the server//from ww w . j a v a 2 s . com * * @param newValue The value to be set * @throws Exception */ public void setValue(Object newValue) throws Exception { try { MBeanServer server = bean.getConnectionProvider().getMBeanServer(); server.setAttribute(bean.getObjectName(), new Attribute(getName(), newValue)); alterValue(newValue); } catch (Exception e) { throw new InvocationTargetException(e); } refresh(); }
From source file:org.rifidi.edge.configuration.RifidiService.java
/** * Get an attribute.//from w ww . j av a 2 s . co m * * @param attributeName * @return */ public Attribute getAttribute(String attributeName) { try { Object value = nameToMethod.get(attributeName).invoke(this); return new Attribute(attributeName, value); } catch (IllegalArgumentException e) { logger.error(e); } catch (IllegalAccessException e) { logger.error(e); } catch (InvocationTargetException e) { logger.error(e); } return null; }
From source file:org.bigmouth.nvwa.utils.jmx.JmxClientTemplate.java
/** * ??MBean(MBeanClass)./* w w w . j a v a 2 s. c o m*/ * * attributeName?. */ public void setAttribute(final String mbeanName, final String attributeName, final Object value) { assertConnected(); try { ObjectName objectName = buildObjectName(mbeanName); Attribute attribute = new Attribute(attributeName, value); connection.setAttribute(objectName, attribute); } catch (JMException e) { throw new IllegalArgumentException("??", e); } catch (IOException e) { throw new IllegalStateException("", e); } }
From source file:org.jolokia.jmx.JsonDymamicMBeanImplTest.java
@Test public void setAttribute() throws Exception { platformServer.setAttribute(testName, new Attribute("Chili", "fatalii")); assertEquals(platformServer.getAttribute(testName, "Chili"), "fatalii"); platformServer.setAttribute(testName, new Attribute("Numbers", "8,15")); String nums = (String) platformServer.getAttribute(testName, "Numbers"); JSONArray numsJ = (JSONArray) toJSON(nums); assertEquals(numsJ.get(0), 8L);//from w ww. ja v a 2 s . co m assertEquals(numsJ.get(1), 15L); assertEquals(numsJ.size(), 2); }
From source file:org.apache.camel.component.zookeeper.ZooKeeperEndpointTest.java
private void verifyManagedAttribute(ObjectName zepName, String attributeName, Long attributeValue) throws Exception { mbsc.setAttribute(zepName, new Attribute(attributeName, attributeValue)); assertEquals(attributeValue, mbsc.getAttribute(zepName, attributeName)); }
From source file:org.apache.catalina.manager.JMXProxyServlet.java
public void setAttribute(PrintWriter writer, String onameStr, String att, String val) { try {/*from w w w . j a v a2s .co m*/ ObjectName oname = new ObjectName(onameStr); String type = registry.getType(oname, att); Object valueObj = registry.convertValue(type, val); mBeanServer.setAttribute(oname, new Attribute(att, valueObj)); writer.println("OK - Attribute set"); } catch (Exception ex) { writer.println("Error - " + ex.toString()); } }
From source file:io.fabric8.test.smoke.JolokiaEndpointTestBase.java
@Test public void testMXBeanEndpoint() throws Exception { ContainerManager cntManager = ContainerManagerLocator.getContainerManager(); Container cnt = cntManager.getCurrentContainer(); ServiceEndpoint sep = cnt.getServiceEndpoint(URLServiceEndpoint.JMX_SERVICE_ENDPOINT_IDENTITY); JMXServiceEndpoint jmxEndpoint = sep.adapt(JMXServiceEndpoint.class); String serviceURL = jmxEndpoint.getServiceURL(); Assert.assertNotNull("JMX URL not null", serviceURL); // Get the local MBeanServer MBeanServer server = ServiceLocator.getRequiredService(MBeanServer.class); server.registerMBean(new Simple(), SimpleMXBean.OBJECT_NAME); try {/*from w w w. j a v a 2 s . com*/ String[] userpass = RuntimeType.KARAF == RuntimeType.getRuntimeType() ? karafJmx : otherJmx; JMXConnector jmxConnector = jmxEndpoint.getJMXConnector(userpass[0], userpass[1], 200, TimeUnit.MILLISECONDS); MBeanServerConnection con = jmxConnector.getMBeanServerConnection(); try { // Simple string echo Object[] params = new Object[] { "Kermit" }; String[] signature = new String[] { String.class.getName() }; Object result = con.invoke(SimpleMXBean.OBJECT_NAME, "echo", params, signature); Assert.assertEquals("Hello: Kermit", result); // Set Bean attribute using CompositeData Bean bean = new Bean("Hello", "Foo"); CompositeData cdata = OpenTypeGenerator.toCompositeData(bean); con.setAttribute(SimpleMXBean.OBJECT_NAME, new Attribute("Bean", cdata)); // Get Bean attribute using CompositeData cdata = (CompositeData) con.getAttribute(SimpleMXBean.OBJECT_NAME, "Bean"); Assert.assertEquals(bean, OpenTypeGenerator.fromCompositeData(Bean.class, cdata)); // Simple Bean echo using CompositeData params = new Object[] { cdata }; signature = new String[] { CompositeData.class.getName() }; cdata = (CompositeData) con.invoke(SimpleMXBean.OBJECT_NAME, "echoBean", params, signature); Assert.assertEquals(bean, OpenTypeGenerator.fromCompositeData(Bean.class, cdata)); } finally { jmxConnector.close(); } } finally { server.unregisterMBean(SimpleMXBean.OBJECT_NAME); } }
From source file:com.rosy.bill.utils.jmx.JmxClientTemplate.java
/** * ??MBean(MBeanClass)./* ww w .java 2 s.c o m*/ * * attributeName?. */ public void setAttribute(final String mbeanName, final String attributeName, final Object value) { Assert.hasText(mbeanName, "mbeanName?"); Assert.hasText(attributeName, "attributeName?"); assertConnected(); try { ObjectName objectName = buildObjectName(mbeanName); Attribute attribute = new Attribute(attributeName, value); connection.setAttribute(objectName, attribute); } catch (JMException e) { throw new IllegalArgumentException("??", e); } catch (IOException e) { throw new IllegalStateException("", e); } }
From source file:com.cyberway.issue.crawler.extractor.ExtractorTool.java
public ExtractorTool(String[] e, String scratch) throws Exception { super();//from w w w . ja v a 2 s . c o m // Setup the scratch directory. this.scratchDir = scratch == null ? new File(DEFAULT_SCRATCH) : new File(scratch); if (!this.scratchDir.exists()) { this.scratchDir.mkdirs(); } // Set up settings system. Needed by extractors. File orderFile = new File(this.scratchDir.getAbsolutePath(), ExtractorTool.class.getName() + "_order.xml"); SettingsHandler settingsHandler = new XMLSettingsHandler(orderFile); settingsHandler.initialize(); settingsHandler.getOrder() .setAttribute(new Attribute(CrawlOrder.ATTR_SETTINGS_DIRECTORY, this.scratchDir.getAbsolutePath())); CrawlerSettings globalSettings = settingsHandler.getSettingsObject(null); MapType extractorsSettings = (MapType) settingsHandler.getOrder() .getAttribute(CrawlOrder.ATTR_EXTRACT_PROCESSORS); this.extractors = new ArrayList<Processor>(); for (int i = 0; i < e.length; i++) { Constructor c = Class.forName(e[i]).getConstructor(new Class[] { String.class }); String name = Integer.toString(i); Processor p = (Processor) c.newInstance(new Object[] { name }); extractorsSettings.addElement(globalSettings, p); p.setAttribute(new Attribute(Processor.ATTR_ENABLED, Boolean.TRUE)); this.extractors.add(p); } }