List of usage examples for javax.management Attribute Attribute
public Attribute(String name, Object value)
From source file:org.rifidi.edge.configuration.RifidiService.java
/** * Get all attributes and their values./*from ww w . j a v a2 s . co m*/ * * @return */ public AttributeList getAttributes() { AttributeList ret = new AttributeList(); for (String name : nameToMethod.keySet()) { try { Object value = nameToMethod.get(name).invoke(this); ret.add(new Attribute(name, value)); } catch (IllegalArgumentException e) { logger.error("Error when invoking getter " + nameToMethod.get(name) + ": " + e); } catch (IllegalAccessException e) { logger.error("Error when invoking getter " + nameToMethod.get(name) + ": " + e); } catch (InvocationTargetException e) { logger.error("Error when invoking getter " + nameToMethod.get(name) + ": " + e); } } return ret; }
From source file:com.wakacommerce.common.cache.StatisticsServiceImpl.java
@Override public AttributeList getAttributes(String[] attributes) { AttributeList list = new AttributeList(); for (Map.Entry<String, CacheStat> stats : cacheStats.entrySet()) { list.add(new Attribute(stats.getKey(), stats.getValue().getHitRate().doubleValue())); }//w ww . j a va 2 s .com return list; }
From source file:net.sbbi.upnp.jmx.JMXManager.java
private MBeanServer initMBeanServer(MBeanServerConfig conf) throws Exception { mx4j.log.Log.redirectTo(new CommonsLogger()); // make sure that MX4j Server builder is used String oldSysProp = System.getProperty("javax.management.builder.initial"); System.setProperty("javax.management.builder.initial", "mx4j.server.MX4JMBeanServerBuilder"); MBeanServer server = MBeanServerFactory.createMBeanServer("UPNPLib"); if (oldSysProp != null) { System.setProperty("javax.management.builder.initial", oldSysProp); }/*from ww w . j a v a 2 s.co m*/ ObjectName serverName = new ObjectName("Http:name=HttpAdaptor"); server.createMBean("mx4j.tools.adaptor.http.HttpAdaptor", serverName, null); // set attributes server.setAttribute(serverName, new Attribute("Port", new Integer(conf.adapterAdapterPort))); Boolean allowWanBool = new Boolean(conf.allowWan); if (allowWanBool.booleanValue()) { server.setAttribute(serverName, new Attribute("Host", "0.0.0.0")); } else { server.setAttribute(serverName, new Attribute("Host", "localhost")); } ObjectName processorName = new ObjectName("Http:name=XSLTProcessor"); server.createMBean("mx4j.tools.adaptor.http.XSLTProcessor", processorName, null); server.setAttribute(processorName, new Attribute("LocaleString", conf.locale)); server.setAttribute(processorName, new Attribute("UseCache", Boolean.FALSE)); server.setAttribute(processorName, new Attribute("PathInJar", "net/sbbi/jmx/xsl")); server.setAttribute(serverName, new Attribute("ProcessorName", processorName)); // add user names server.invoke(serverName, "addAuthorization", new Object[] { conf.adapterUserName, conf.adapterPassword }, new String[] { "java.lang.String", "java.lang.String" }); // use basic authentication server.setAttribute(serverName, new Attribute("AuthenticationMethod", "basic")); // starts the server server.invoke(serverName, "start", null, null); return server; }
From source file:org.jolokia.jmx.JsonDymamicMBeanImplTest.java
@Test public void setGetAttributes() throws Exception { AttributeList attrList = new AttributeList( Arrays.asList(new Attribute("Chili", "aji"), new Attribute("Numbers", "16,11,68"))); platformServer.setAttributes(testName, attrList); AttributeList ret = platformServer.getAttributes(testName, new String[] { "Chili", "Numbers" }); Attribute chili = (Attribute) ret.get(0); Attribute num = (Attribute) ret.get(1); assertEquals(chili.getValue(), "aji"); JSONArray numsJ = (JSONArray) toJSON((String) num.getValue()); assertEquals(numsJ.get(0), 16L);//w ww .j ava 2 s. co m assertEquals(numsJ.get(1), 11L); assertEquals(numsJ.get(2), 68L); assertEquals(numsJ.size(), 3); Assert.assertTrue(platformServer.getAttributes(testName, new String[0]).size() == 0); }
From source file:org.rifidi.edge.configuration.RifidiService.java
/** * Get a list of attributes.// ww w .ja v a2s .com * * @param attributeNames * @return */ public AttributeList getAttributes(Collection<String> attributeNames) { AttributeList ret = new AttributeList(); try { for (String name : nameToMethod.keySet()) { if (attributeNames.contains(name)) { Object value = nameToMethod.get(name).invoke(this); ret.add(new Attribute(name, value)); } } return ret; } catch (IllegalArgumentException e) { logger.error(e); } catch (IllegalAccessException e) { logger.error(e); } catch (InvocationTargetException e) { logger.error(e); } return ret; }
From source file:org.apache.jk.common.JkMX.java
/** Initialize the worker. After this call the worker will be * ready to accept new requests./* ww w . j ava2 s . com*/ */ public void loadAdapter() throws IOException { boolean httpAdapterLoaded = false; boolean jrmpAdapterLoaded = false; if ((httpport != -1) && classExists("mx4j.adaptor.http.HttpAdaptor")) { try { httpServerName = new ObjectName("Http:name=HttpAdaptor"); mserver.createMBean("mx4j.adaptor.http.HttpAdaptor", httpServerName, null); if (httphost != null) mserver.setAttribute(httpServerName, new Attribute("Host", httphost)); mserver.setAttribute(httpServerName, new Attribute("Port", new Integer(httpport))); ObjectName processorName = new ObjectName("Http:name=XSLTProcessor"); mserver.createMBean("mx4j.adaptor.http.XSLTProcessor", processorName, null); //mserver.setAttribute(processorName, new Attribute("File", "/opt/41/server/lib/openjmx-tools.jar")); //mserver.setAttribute(processorName, new Attribute("UseCache", new Boolean(false))); //mserver.setAttribute(processorName, new Attribute("PathInJar", "/openjmx/adaptor/http/xsl")); mserver.setAttribute(httpServerName, new Attribute("ProcessorName", processorName)); //server.invoke(serverName, "addAuthorization", // new Object[] {"openjmx", "openjmx"}, // new String[] {"java.lang.String", "java.lang.String"}); // use basic authentication //server.setAttribute(serverName, new Attribute("AuthenticationMethod", "basic")); // ObjectName sslFactory = new ObjectName("Adaptor:service=SSLServerSocketFactory"); // server.createMBean("openjmx.adaptor.ssl.SSLAdaptorServerSocketFactory", sslFactory, null); // SSLAdaptorServerSocketFactoryMBean factory = // (SSLAdaptorServerSocketFactoryMBean)StandardMBeanProxy.create(SSLAdaptorServerSocketFactoryMBean.class, server, sslFactory); // // Customize the values below // factory.setKeyStoreName("certs"); // factory.setKeyStorePassword("openjmx"); // server.setAttribute(serverName, new Attribute("SocketFactoryName", sslFactory.toString())); // starts the server mserver.invoke(httpServerName, "start", null, null); log.info("Started MX4J console on host " + httphost + " at port " + httpport); //return; httpAdapterLoaded = true; } catch (Throwable t) { httpServerName = null; log.error("Can't load the MX4J http adapter " + t.toString()); } } if ((jrmpport != -1) && classExists("mx4j.tools.naming.NamingService")) { try { jrmpServerName = new ObjectName("Naming:name=rmiregistry"); mserver.createMBean("mx4j.tools.naming.NamingService", jrmpServerName, null); mserver.invoke(jrmpServerName, "start", null, null); log.info("Creating " + jrmpServerName); // Create the JRMP adaptor ObjectName adaptor = new ObjectName("Adaptor:protocol=jrmp"); mserver.createMBean("mx4j.adaptor.rmi.jrmp.JRMPAdaptor", adaptor, null); // mx4j.adaptor.rmi.jrmp.JRMPAdaptorMBean mbean = (mx4j.adaptor.rmi.jrmp.JRMPAdaptorMBean)mx4j.util.StandardMBeanProxy. // create(mx4j.adaptor.rmi.jrmp.JRMPAdaptorMBean.class, mserver, adaptor); mserver.setAttribute(adaptor, new Attribute("JNDIName", "jrmp")); mserver.invoke(adaptor, "putNamingProperty", new Object[] { javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory" }, new String[] { "java.lang.Object", "java.lang.Object" }); String jrpmurl = "rmi://" + jrmphost + ":" + Integer.toString(jrmpport); mserver.invoke(adaptor, "putNamingProperty", new Object[] { javax.naming.Context.PROVIDER_URL, jrpmurl }, new String[] { "java.lang.Object", "java.lang.Object" }); //mbean.putNamingProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); //mbean.putNamingProperty(javax.naming.Context.PROVIDER_URL, "rmi://localhost:1099"); // Registers the JRMP adaptor in JNDI and starts it mserver.invoke(adaptor, "start", null, null); // mbean.start(); log.info("Creating " + adaptor + " on host " + jrmphost + " at port " + jrmpport); jrmpAdapterLoaded = true; } catch (Exception ex) { jrmpServerName = null; log.error("MX4j RMI adapter not loaded: " + ex.toString()); } } if ((httpport != -1) && (!httpAdapterLoaded) && classExists("com.sun.jdmk.comm.HtmlAdaptorServer")) { try { Class c = Class.forName("com.sun.jdmk.comm.HtmlAdaptorServer"); Object o = c.newInstance(); httpServerName = new ObjectName("Adaptor:name=html,port=" + httpport); log.info("Registering the JMX_RI html adapter " + httpServerName + " at port " + httpport); mserver.registerMBean(o, httpServerName); mserver.setAttribute(httpServerName, new Attribute("Port", new Integer(httpport))); mserver.invoke(httpServerName, "start", null, null); httpAdapterLoaded = true; } catch (Throwable t) { httpServerName = null; log.error("Can't load the JMX_RI http adapter " + t.toString()); } } if ((!httpAdapterLoaded) && (!jrmpAdapterLoaded)) log.warn("No adaptors were loaded but mx.enabled was defined."); }
From source file:com.cyberway.issue.crawler.deciderules.DecideRuleSequenceTest.java
public void testRegex() throws InvalidAttributeValueException, AttributeNotFoundException, MBeanException, ReflectionException { final String regexName = "REGEX"; DecideRule r = addDecideRule(new MatchesRegExpDecideRule(regexName)); // Set regex to be match anything that ends in archive.org. r.setAttribute(new Attribute(MatchesRegExpDecideRule.ATTR_REGEXP, "^.*\\.archive\\.org")); Object decision = this.rule.decisionFor("http://google.com"); assertTrue("Expect PASS but got " + decision, decision == DecideRule.PASS); decision = this.rule.decisionFor("http://archive.org"); assertTrue("Expect PASS but got " + decision, decision == DecideRule.PASS); decision = this.rule.decisionFor("http://www.archive.org"); assertTrue("Expect ACCEPT but got " + decision, decision == DecideRule.ACCEPT); }
From source file:org.jminix.console.resource.AttributeResource.java
@Override public void acceptRepresentation(Representation entity) throws ResourceException { String value = new Form(entity).getFirstValue("value"); String domain = getRequest().getAttributes().get("domain").toString(); String mbean = new EncoderBean().decode(getRequest().getAttributes().get("mbean").toString()); String attributeName = new EncoderBean().decode(getRequest().getAttributes().get("attribute").toString()); MBeanServerConnection server = getServer(); try {/*w ww . j a v a2 s .c om*/ String type = "java.lang.String"; for (MBeanAttributeInfo info : server.getMBeanInfo(new ObjectName(domain + ":" + mbean)) .getAttributes()) { if (info.getName().equals(attributeName)) { type = info.getType(); } } Object attribute = new ValueParser().parse(value, type); if (attribute != null) { server.setAttribute(new ObjectName(domain + ":" + mbean), new Attribute(attributeName, attribute)); } String queryString = getQueryString(); if (queryString == null) { queryString = "?"; } queryString += "ok=1"; getResponse().redirectPermanent(new EncoderBean().encode(attributeName) + queryString); } catch (InstanceNotFoundException e) { throw new RuntimeException(e); } catch (AttributeNotFoundException e) { throw new RuntimeException(e); } catch (InvalidAttributeValueException e) { throw new RuntimeException(e); } catch (MalformedObjectNameException e) { throw new RuntimeException(e); } catch (MBeanException e) { throw new RuntimeException(e); } catch (ReflectionException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (IntrospectionException e) { throw new RuntimeException(e); } }
From source file:org.eclipse.smila.management.jmx.AgentMBean.java
/** * {@inheritDoc}// www . java 2 s . com * * @see javax.management.DynamicMBean#getAttributes(java.lang.String[]) */ public AttributeList getAttributes(final String[] attributes) { if (attributes == null) { throw new RuntimeOperationsException(new IllegalArgumentException("attributeNames must not be null"), "Exception occured trying to get attributes of a " + "LocalMBean"); } final AttributeList attributeList = new AttributeList(); String attributeName; for (int i = 0; i < attributes.length; i++) { attributeName = attributes[i]; try { attributeList.add(new Attribute(attributeName, getAttribute(attributeName))); } catch (final Throwable e) { _log.error("getAttributes(String[]), failed to get \"" + attributeName + "\"", e); } } return attributeList; }
From source file:org.rifidi.edge.core.configuration.services.ConfigurationServiceImpl.java
/** * Load the configuration. Not thread safe. * /*w ww . j a v a 2s. c o m*/ * @return */ private ConcurrentHashMap<String, Set<DefaultConfigurationImpl>> loadConfig() { ConcurrentHashMap<String, Set<DefaultConfigurationImpl>> ret = new ConcurrentHashMap<String, Set<DefaultConfigurationImpl>>(); ConfigurationStore store; try { store = (ConfigurationStore) jaxbContext.createUnmarshaller().unmarshal(persistanceResource.getFile()); } catch (IOException e) { logger.error(e); return ret; } catch (JAXBException e) { logger.error(e); return ret; } if (store.getServices() != null) { for (ServiceStore service : store.getServices()) { if (ret.get(service.getFactoryID()) == null) { ret.put(service.getFactoryID(), new CopyOnWriteArraySet<DefaultConfigurationImpl>()); } AttributeList attributes = new AttributeList(); // get all properties for (String key : service.getAttributes().keySet()) { // factoryid is already processed if (Constants.FACTORYID.equals(key)) { continue; } // type is already processed if (Constants.FACTORY_TYPE.equals(key)) { continue; } attributes.add(new Attribute(key, service.getAttributes().get(key))); } if (!checkName(service.getServiceID())) { continue; } ret.get(service.getFactoryID()).add(createAndRegisterConfiguration(service.getServiceID(), service.getFactoryID(), attributes, service.getSessionDTOs())); serviceNames.add(service.getServiceID()); } } return ret; }