List of usage examples for javax.management Attribute Attribute
public Attribute(String name, Object value)
From source file:com.custardsource.maven.plugins.jmx.SetAttribute.java
@Override public Object execute(MBeanServerConnection connection) throws Exception { ObjectName name = new ObjectName(objectName); ConvertUtilsBean converter = new ConvertUtilsBean(); Object attributeValue = converter.convert(value, ClassUtils.getClass(type)); connection.setAttribute(name, new Attribute(attributeName, attributeValue)); return connection.getAttribute(name, attributeName); }
From source file:com.armorize.hackalert.extractor.msword.MSBaseParser.java
/** * Main for testing. Pass a ms document as argument */// w ww .j a v a 2 s. c om public static void main(String mime, MSBaseParser parser, String args[]) { try { ExtractorUniversal extractor = new ExtractorUniversal("TEST"); File orderFile = new File("order.xml"); SettingsHandler settingsHandler = new XMLSettingsHandler(orderFile); settingsHandler.initialize(); // settingsHandler.getOrder().setAttribute( // new Attribute(CrawlOrder.ATTR_SETTINGS_DIRECTORY, "tmp/")); CrawlerSettings globalSettings = settingsHandler.getSettingsObject(null); MapType extractorsSettings = (MapType) settingsHandler.getOrder() .getAttribute(CrawlOrder.ATTR_EXTRACT_PROCESSORS); extractorsSettings.addElement(globalSettings, extractor); extractor.setAttribute(new Attribute(Processor.ATTR_ENABLED, Boolean.TRUE)); //====================== byte[] raw = IOUtils.toByteArray(new FileInputStream("C:\\temp\\userman.doc")); String text = parser.getParse(raw); ByteArrayInputStream in = new ByteArrayInputStream(text.getBytes("utf-8")); HttpRecorder recorder = HttpRecorder.wrapInputStreamWithHttpRecord(new File("tmp"), MSBaseParser.class.getName(), in, "utf-8"); CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.armorize.com/")); curi.setContentSize(recorder.getRecordedInput().getSize()); curi.setContentType("application/msword"); curi.setFetchStatus(200); curi.setHttpRecorder(recorder); curi.putObject(CoreAttributeConstants.A_HTTP_TRANSACTION, new Object()); extractor.process(curi); System.out.println(curi.getOutLinks()); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.hyperic.hq.plugin.websphere.WebsphereServiceControlPlugin.java
protected Object invoke(AdminClient mServer, String objectName, String method, Object[] args, String[] sig) throws MetricUnreachableException, MetricNotFoundException, PluginException { ObjectName obj;/*from w w w . j a va 2 s .c o m*/ try { obj = new ObjectName(objectName); } catch (MalformedObjectNameException e1) { throw new PluginException("Unable to create an ObjectName from " + objectName); } MBeanInfo info; try { info = mServer.getMBeanInfo(obj); } catch (Exception e1) { throw new PluginException("Unable to obtain MBeanInfo from " + objectName); } if (sig.length == 0) { MBeanUtil.OperationParams params = MBeanUtil.getOperationParams(info, method, args); if (params.isAttribute) { if (method.startsWith("set")) { try { mServer.setAttribute(obj, new Attribute(method.substring(3), params.arguments[0])); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(e.getMessage(), e); } catch (Exception e) { throw new PluginException(e); } return null; } else { try { return mServer.getAttribute(obj, method.substring(3)); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(e.getMessage(), e); } catch (Exception e) { throw new PluginException(e); } } } sig = params.signature; args = params.arguments; } try { return mServer.invoke(obj, method, args, sig); } catch (Exception e) { throw new PluginException(e); } }
From source file:org.apache.camel.component.zookeeper.ZooKeeperEndpointTest.java
private void verifyManagedAttribute(ObjectName zepName, String attributeName, String attributeValue) throws Exception { mbsc.setAttribute(zepName, new Attribute(attributeName, attributeValue)); assertEquals(attributeValue, mbsc.getAttribute(zepName, attributeName)); }
From source file:net.gcolin.simplerepo.test.AbstractRepoTest.java
protected void setAttributeJmx(String name, String attribute, Object arguments) throws Exception { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ObjectName oname = server.queryNames(new ObjectName(name), null).iterator().next(); server.setAttribute(oname, new Attribute(attribute, arguments)); }
From source file:org.hyperic.hq.plugin.weblogic.WeblogicServiceControlPlugin.java
protected Object invoke(MBeanServerConnection mServer, String objectName, String method, Object[] args, String[] sig) throws MetricUnreachableException, MetricNotFoundException, PluginException { ObjectName obj;//w w w .ja va 2 s . com try { obj = new ObjectName(objectName); } catch (MalformedObjectNameException e1) { throw new PluginException("Unable to create an ObjectName from " + objectName); } MBeanInfo info; try { info = mServer.getMBeanInfo(obj); } catch (Exception e1) { throw new PluginException("Unable to obtain MBeanInfo from " + objectName); } if (sig.length == 0) { MBeanUtil.OperationParams params = MBeanUtil.getOperationParams(info, method, args); if (params.isAttribute) { if (method.startsWith("set")) { try { mServer.setAttribute(obj, new Attribute(method.substring(3), params.arguments[0])); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(e.getMessage(), e); } catch (Exception e) { throw new PluginException(e); } return null; } else { try { return mServer.getAttribute(obj, method.substring(3)); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(e.getMessage(), e); } catch (Exception e) { throw new PluginException(e); } } } sig = params.signature; args = params.arguments; } try { return mServer.invoke(obj, method, args, sig); } catch (Exception e) { throw new PluginException(e); } }
From source file:org.ow2.proactive_grid_cloud_portal.rm.RMRestTest.java
private JSONObject callGetStatHistory() throws Exception { RMProxyUserInterface rmMock = mock(RMProxyUserInterface.class); String sessionId = SharedSessionStoreTestUtils.createValidSession(rmMock); AttributeList value = new AttributeList( Collections.singletonList(new Attribute("test", createRrdDb().getBytes()))); when(rmMock.getMBeanAttributes(Matchers.<ObjectName>any(), Matchers.<String[]>any())).thenReturn(value); RMRestInterface client = ProxyFactory.create(RMRestInterface.class, "http://localhost:" + port + "/"); String statHistory = client.getStatHistory(sessionId, "hhhhh"); return (JSONObject) new JSONParser().parse(statHistory); }
From source file:com.cyberway.issue.crawler.settings.XMLSettingsHandlerTest.java
public void testWriteSettingsObjectCrawlerSettings() throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { // Write a crawl order file CrawlerSettings settings = getGlobalSettings(); XMLSettingsHandler handler = getSettingsHandler(); handler.registerValueErrorHandler(this); handler.getOrder().setAttribute(new ClassicScope()); handler.writeSettingsObject(settings); assertTrue("Order file was not written", getOrderFile().exists()); // Get a module to alter a setting on ComplexType scope = settings.getModule(CrawlScope.ATTR_NAME); assertNotNull("Could not get module scope", scope); // Alter two settings in a per host file CrawlerSettings perHost = getPerHostSettings(); Integer newHops = new Integer(500); String newFrom = "newfrom"; scope.setAttribute(perHost, new Attribute(ClassicScope.ATTR_MAX_LINK_HOPS, newHops)); CrawlOrder order = handler.getOrder(); ComplexType httpHeaders = (ComplexType) order.getAttribute(CrawlOrder.ATTR_HTTP_HEADERS); httpHeaders.setAttribute(perHost, new Attribute(CrawlOrder.ATTR_FROM, newFrom)); // Write the per host file handler.writeSettingsObject(perHost); assertTrue("Per host file was not written", handler.settingsToFilename(perHost).exists()); // Create a new handler for testing that changes was written to disk XMLSettingsHandler newHandler = new XMLSettingsHandler(getOrderFile()); newHandler.initialize();//from ww w .ja v a 2 s . c om // Read perHost CrawlerSettings newPerHost = newHandler.getSettingsObject(perHost.getScope()); assertNotNull("Per host scope could not be read", newPerHost); ComplexType newScope = newHandler.getModule(CrawlScope.ATTR_NAME); assertNotNull(newScope); Integer r1 = (Integer) newScope.getAttribute(newPerHost, ClassicScope.ATTR_MAX_LINK_HOPS); assertEquals(newHops, r1); ComplexType newHttpHeaders = (ComplexType) newHandler.getOrder().getAttribute(newPerHost, CrawlOrder.ATTR_HTTP_HEADERS); assertNotNull(newHttpHeaders); String r2 = (String) newHttpHeaders.getAttribute(newPerHost, CrawlOrder.ATTR_FROM); assertEquals(newFrom, r2); }
From source file:org.apache.camel.component.zookeeper.ZooKeeperEndpointTest.java
private void verifyManagedAttribute(ObjectName zepName, String attributeName, Integer attributeValue) throws Exception { mbsc.setAttribute(zepName, new Attribute(attributeName, attributeValue)); assertEquals(attributeValue, mbsc.getAttribute(zepName, attributeName)); }
From source file:com.cyberway.issue.crawler.datamodel.credential.Credential.java
/** * @param context Context to use when searching for credential domain. * @param domain New domain.// ww w .ja v a2s .c o m * @throws AttributeNotFoundException * @throws InvalidAttributeValueException */ public void setCredentialDomain(CrawlerSettings context, String domain) throws InvalidAttributeValueException, AttributeNotFoundException { setAttribute(context, new Attribute(ATTR_CREDENTIAL_DOMAIN, domain)); }