List of usage examples for javax.management Attribute Attribute
public Attribute(String name, Object value)
From source file:org.jboss.web.tomcat.tc5.Tomcat5.java
public void startService() throws Exception { System.setProperty("catalina.ext.dirs", (System.getProperty("jboss.server.home.dir") + File.separator + "lib")); String objectNameS = catalinaDomain + ":type=server"; ObjectName objectName = new ObjectName(objectNameS); // Set the modeler Registry MBeanServer to the that of the tomcat service Registry.getRegistry().setMBeanServer(server); server.createMBean("org.apache.commons.modeler.BaseModelMBean", objectName, new Object[] { "org.apache.catalina.startup.Catalina" }, new String[] { "java.lang.String" }); server.setAttribute(objectName, new Attribute("catalinaHome", System.getProperty("jboss.server.home.dir"))); server.setAttribute(objectName, new Attribute("configFile", serverConfigFile)); server.setAttribute(objectName, new Attribute("useNaming", new Boolean(false))); server.setAttribute(objectName, new Attribute("useShutdownHook", new Boolean(false))); server.setAttribute(objectName, new Attribute("await", new Boolean(false))); server.setAttribute(objectName, new Attribute("redirectStreams", new Boolean(false))); server.invoke(objectName, "create", new Object[] {}, new String[] {}); server.invoke(objectName, "start", new Object[] {}, new String[] {}); // Configure any SingleSignOn valves ObjectName ssoQuery = new ObjectName("*:type=Valve,*"); Iterator iterator = server.queryMBeans(ssoQuery, null).iterator(); while (iterator.hasNext()) { ObjectName ssoObjectName = ((ObjectInstance) iterator.next()).getObjectName(); String name = ssoObjectName.getKeyProperty("name"); /* Ensure that the SingleSignOn valve requires that each request be reauthenticated to the security mgr. Should not be neccessary now that we cache the principal in the session. if ((name != null) && (name.indexOf("SingleSignOn") >= 0)) {/*from ww w .j a v a2 s . co m*/ log.info("Turning on reauthentication of each request on " + ssoObjectName); server.setAttribute(ssoObjectName, new Attribute ("requireReauthentication", Boolean.TRUE)); } */ // If the valve is a ClusteredSingleSignOn and we have a shared // TreeCache configured, configure the valve to use the shared one if (cacheName != null && "ClusteredSingleSignOn".equals(name)) { String tcName = (String) server.getAttribute(ssoObjectName, "treeCacheName"); tcName = (tcName != null ? tcName : DEFAULT_CACHE_NAME); ObjectName ssoCacheName = new ObjectName(tcName); // Only override if the valve's cacheName property was not // explicitly set in server.xml to a non-default value if (ssoCacheName.equals(new ObjectName(DEFAULT_CACHE_NAME))) { log.info("Setting the cache name to " + cacheName + " on " + ssoObjectName); server.setAttribute(ssoObjectName, new Attribute("treeCacheName", cacheName)); } } } // Register the web container JACC PolicyContextHandlers HttpServletRequestPolicyContextHandler handler = new HttpServletRequestPolicyContextHandler(); PolicyContext.registerHandler(HttpServletRequestPolicyContextHandler.WEB_REQUEST_KEY, handler, true); // The ServiceController used to control web app startup dependencies serviceController = (ServiceControllerMBean) MBeanProxyExt.create(ServiceControllerMBean.class, ServiceControllerMBean.OBJECT_NAME, server); // make a proxy to myself, so that calls from the MainDeployer // can go through the MBeanServer, so interceptors can be added thisProxy = (SubDeployerExt) MBeanProxyExt.create(SubDeployerExt.class, super.getServiceName(), super.getServer()); // Register with the main deployer mainDeployer.addDeployer(thisProxy); // If we are hot-deployed *after* the overall server is started // we'll never receive Server.START_NOTIFICATION_TYPE, so check // with the Server and start the connectors immediately, if this is the case. // Otherwise register to receive the server start-up notification. Boolean started = (Boolean) server.getAttribute(ServerImplMBean.OBJECT_NAME, "Started"); if (started.booleanValue() == true) { log.debug("Server '" + ServerImplMBean.OBJECT_NAME + "' already started, starting connectors now"); startConnectors(); } else { // Register for notification of the overall server startup log.debug("Server '" + ServerImplMBean.OBJECT_NAME + "' not started, registering for start-up notification"); server.addNotificationListener(ServerImplMBean.OBJECT_NAME, this, null, null); } }
From source file:org.jboss.as.test.integration.domain.rbac.JmxRBACProviderHostScopedRolesTestCase.java
private void setAttribute(String userName, JmxManagementInterface jmx) throws Exception { boolean successExpected = isWriteAllowed(userName); MBeanServerConnection connection = jmx.getConnection(); ObjectName domain = new ObjectName("java.lang:type=Memory"); try {/*from w ww. j a v a 2 s. c om*/ connection.setAttribute(domain, new Attribute("Verbose", true)); connection.setAttribute(domain, new Attribute("Verbose", false)); // back to default to not pollute the logs assertTrue("Failure was expected", successExpected); } catch (JMRuntimeException e) { if (e.getMessage().contains("WFLYJMX0037")) { assertFalse("Success was expected but failure happened: " + e, successExpected); } else { throw e; } } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.MMXConfigurationTest.java
private void testSetGetAttribute(MBeanServerConnection connection, ObjectName name) throws Exception { for (Triple<String, String, String> pair : mbeanAttributes) { String attrName = pair.getLeft(); String attrType = pair.getRight(); Object attrValue;/* w w w .ja v a 2 s . c o m*/ if (attrType.equals("int")) attrValue = RandomUtils.nextInt(30000, 65535); else if (attrType.equals("long")) attrValue = RandomUtils.nextLong(10, 1000); else attrValue = RandomStringUtils.randomAlphabetic(10); Attribute attr1 = new Attribute(attrName, attrValue); server.setAttribute(name, attr1); Object attr2 = server.getAttribute(name, attrName); assertEquals("Attribute values do not match", attrValue, attr2); } }
From source file:org.webcurator.core.harvester.agent.HarvesterHeritrix.java
/** @see org.webcurator.core.harvester.agent.Harvester#restrictBandwidth(int). */ public void restrictBandwidth(int aBandwidthLimit) { try {//from ww w. j ava 2s .c o m XMLSettingsHandler settings = job.getSettingsHandler(); if (settings == null) { if (log.isInfoEnabled()) { log.info("Attempted to restrict bandwidth on " + name + ". No settings available."); } return; } CrawlerSettings cs = null; try { cs = settings.getSettingsObject(null); } catch (RuntimeException e) { if (log.isInfoEnabled()) { log.info("Attempted to restrict bandwidth on " + name + ". Failed to get Crawler Settings."); } return; } BdbFrontier frontier = (BdbFrontier) cs.getModule(BdbFrontier.ATTR_NAME); frontier.setAttribute( new Attribute(BdbFrontier.ATTR_MAX_OVERALL_BANDWIDTH_USAGE, new Integer(aBandwidthLimit))); settings.writeSettingsObject(cs); if (log.isDebugEnabled()) { log.debug("Attempting to restrict bandwidth on " + job.getDisplayName() + " to " + aBandwidthLimit); } // Check that the job is in a state where we can set the bandwidth if (CrawlJob.STATUS_ABORTED.equals(job.getStatus()) || CrawlJob.STATUS_DELETED.equals(job.getStatus()) || CrawlJob.STATUS_MISCONFIGURED.equals(job.getStatus()) || job.getStatus().startsWith(CrawlJob.STATUS_FINISHED)) { if (log.isInfoEnabled()) { log.info("Job " + job.getDisplayName() + " is in the state " + job.getStatus() + ". Ignoring bandwidth restriction."); } return; } while (!job.isRunning()) { Thread.sleep(1000); // Need to check again just incase the job has now failed/finished if (CrawlJob.STATUS_ABORTED.equals(job.getStatus()) || CrawlJob.STATUS_DELETED.equals(job.getStatus()) || CrawlJob.STATUS_MISCONFIGURED.equals(job.getStatus()) || job.getStatus().startsWith(CrawlJob.STATUS_FINISHED)) { if (log.isInfoEnabled()) { log.info("The Job " + job.getDisplayName() + " is in the state " + job.getStatus() + ". Ignoring bandwidth restriction."); } return; } } job.kickUpdate(); if (log.isDebugEnabled()) { log.debug("Restricted the bandwidth for Job " + job.getDisplayName() + " to " + aBandwidthLimit + " KB."); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Failed to restrict bandwidth " + name + ": " + e.getMessage(), e); } throw new HarvesterException("Failed to restrict bandwidth " + name + ": " + e.getMessage(), e); } }
From source file:com.cyberway.issue.crawler.settings.XMLSettingsHandler.java
/** Creates a replica of the settings file structure in another directory * (fully recursive, includes all per host settings). The SettingsHandler * will then refer to the new files.// w w w .j a v a 2 s . com * * Observe that this method should only be called after the SettingsHandler * has been initialized. * * @param newOrderFileName where the new order file should be saved. * @param newSettingsDirectory the top level directory of the per host/domain * settings files. * @throws IOException */ public void copySettings(File newOrderFileName, String newSettingsDirectory) throws IOException { File oldSettingsDirectory = getSettingsDirectory(); // Write new orderfile and point the settingshandler to it orderFile = newOrderFileName; try { getOrder().setAttribute(new Attribute(CrawlOrder.ATTR_SETTINGS_DIRECTORY, newSettingsDirectory)); } catch (Exception e) { throw new IOException("Could not update settings with new location: " + e.getMessage()); } writeSettingsObject(getSettingsObject(null)); File newDir = getPathRelativeToWorkingDirectory(newSettingsDirectory); // Copy the per host files if src and dest directories are different. if (oldSettingsDirectory.compareTo(newDir) != 0) { FileUtils.copyFiles(oldSettingsDirectory, newDir); } }
From source file:org.hyperic.hq.plugin.jboss.JBossUtil.java
private static Object setAttribute(MBeanServerConnection mServer, ObjectName obj, String name, Object value) throws MetricUnreachableException, MetricNotFoundException, PluginException, ReflectionException, InstanceNotFoundException, MBeanException, IOException { if (name.startsWith("set")) { name = name.substring(3);//from w w w. ja v a 2 s. c o m } Attribute attr = new Attribute(name, value); try { mServer.setAttribute(obj, attr); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(e.getMessage(), e); } catch (InvalidAttributeValueException e) { throw new ReflectionException(e); } return null; }
From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java
public AttributeList getAttributes(String[] attributes) { AttributeList al = new AttributeList(); if (attributes == null) return null; for (int i = 0; i < attributes.length; i++) { try {/* w w w . j ava 2s.co m*/ Attribute att = new Attribute(attributes[i], getAttribute(attributes[i])); al.add(att); } catch (Exception ex) { ex.printStackTrace(); } } return al; }
From source file:com.cyberway.issue.crawler.deciderules.DecideRuleSequenceTest.java
public void testScopePlusOne() throws URIException, InvalidAttributeValueException, AttributeNotFoundException, MBeanException, ReflectionException { // first test host scope ScopePlusOneDecideRule t = new ScopePlusOneDecideRule("host"); SurtPrefixSet mSet = new SurtPrefixSet(); mSet.add(SurtPrefixSet.prefixFromPlain("http://audio.archive.org")); mSet.convertAllPrefixesToHosts();/*w w w . ja v a 2 s.c om*/ t.surtPrefixes = mSet; DecideRule s = addDecideRule(t); s.setAttribute(new Attribute(ScopePlusOneDecideRule.ATTR_SCOPE, ScopePlusOneDecideRule.HOST)); UURI uuri = UURIFactory.getInstance("http://audio.archive.org/examples"); CandidateURI candidate = new CandidateURI(uuri); Object decision = this.rule.decisionFor(candidate); assertTrue("URI Expect " + DecideRule.ACCEPT + " for " + candidate + " but got " + decision, decision == DecideRule.ACCEPT); UURI uuriOne = UURIFactory.getInstance("http://movies.archive.org"); CandidateURI plusOne = new CandidateURI(uuriOne); plusOne.setVia(uuri); decision = this.rule.decisionFor(plusOne); assertTrue("PlusOne Expect " + DecideRule.ACCEPT + " for " + plusOne + " with via " + plusOne.flattenVia() + " but got " + decision, decision == DecideRule.ACCEPT); UURI uuriTwo = UURIFactory.getInstance("http://sloan.archive.org"); CandidateURI plusTwo = new CandidateURI(uuriTwo); plusTwo.setVia(uuriOne); decision = this.rule.decisionFor(plusTwo); assertTrue("PlusTwo Expect " + DecideRule.PASS + " for " + plusTwo + " with via " + plusTwo.flattenVia() + " but got " + decision, decision == DecideRule.PASS); //now test domain scope ScopePlusOneDecideRule u = new ScopePlusOneDecideRule("domain"); SurtPrefixSet mSet1 = new SurtPrefixSet(); mSet1.add(SurtPrefixSet.prefixFromPlain("archive.org")); mSet1.convertAllPrefixesToDomains(); u.surtPrefixes = mSet1; DecideRule v = addDecideRule(u); v.setAttribute(new Attribute(ScopePlusOneDecideRule.ATTR_SCOPE, ScopePlusOneDecideRule.DOMAIN)); decision = this.rule.decisionFor(candidate); assertTrue("Domain: URI Expect " + DecideRule.ACCEPT + " for " + candidate + " but got " + decision, decision == DecideRule.ACCEPT); decision = this.rule.decisionFor(plusOne); assertTrue("Domain: PlusOne Expect " + DecideRule.ACCEPT + " for " + plusOne + " with via " + plusOne.flattenVia() + " but got " + decision, decision == DecideRule.ACCEPT); decision = this.rule.decisionFor(plusTwo); assertTrue("Domain: PlusTwo Expect " + DecideRule.ACCEPT + " for " + plusTwo + " with via " + plusTwo.flattenVia() + " but got " + decision, decision == DecideRule.ACCEPT); UURI uuriThree = UURIFactory.getInstance("http://sloan.org"); CandidateURI plusThree = new CandidateURI(uuriThree); plusThree.setVia(uuriTwo); decision = this.rule.decisionFor(plusThree); assertTrue("Domain: PlusThree Expect " + DecideRule.ACCEPT + " for " + plusThree + " with via " + plusThree.flattenVia() + " but got " + decision, decision == DecideRule.ACCEPT); UURI uuriFour = UURIFactory.getInstance("http://example.com"); CandidateURI plusFour = new CandidateURI(uuriFour); plusFour.setVia(uuriThree); decision = this.rule.decisionFor(plusFour); assertTrue("Domain: PlusFour Expect " + DecideRule.PASS + " for " + plusFour + " with via " + plusFour.flattenVia() + " but got " + decision, decision == DecideRule.PASS); }
From source file:edu.nwpu.gemfire.monitor.data.JMXDataUpdater.java
private void registerPulseUrlToManager(JMXConnector connection) throws IOException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, MalformedObjectNameException, InvalidAttributeValueException { if (LOGGER.infoEnabled()) { LOGGER.info(resourceBundle.getString("LOG_MSG_REGISTERING_APP_URL_TO_MANAGER")); }/*from www . j av a2 s .c o m*/ // Reference to repository Repository repository = Repository.get(); // Register Pulse URL if not already present in the JMX Manager if (connection != null) { MBeanServerConnection mbsc = connection.getMBeanServerConnection(); Set<ObjectName> mbeans = mbsc.queryNames(this.MBEAN_OBJECT_NAME_MEMBER_MANAGER, null); for (ObjectName mbeanName : mbeans) { String presentUrl = (String) mbsc.getAttribute(mbeanName, PulseConstants.MBEAN_MANAGER_ATTRIBUTE_PULSEURL); String pulseWebAppUrl = repository.getPulseWebAppUrl(); if (pulseWebAppUrl != null && (presentUrl == null || !pulseWebAppUrl.equals(presentUrl))) { if (LOGGER.fineEnabled()) { LOGGER.fine(resourceBundle.getString("LOG_MSG_SETTING_APP_URL_TO_MANAGER")); } Attribute pulseUrlAttr = new Attribute(PulseConstants.MBEAN_MANAGER_ATTRIBUTE_PULSEURL, pulseWebAppUrl); mbsc.setAttribute(mbeanName, pulseUrlAttr); } else { if (LOGGER.fineEnabled()) { LOGGER.fine(resourceBundle.getString("LOG_MSG_APP_URL_ALREADY_PRESENT_IN_MANAGER")); } } } } }
From source file:com.web.server.SARDeployer.java
/** * This method extracts the SAR archive and configures for the SAR and starts the services * @param file/*from ww w . j a v a 2 s. c o m*/ * @param warDirectoryPath * @throws IOException */ public void extractSar(File file, String warDirectoryPath) throws IOException { ZipFile zip = new ZipFile(file); ZipEntry ze = null; String fileName = file.getName(); fileName = fileName.substring(0, fileName.indexOf('.')); fileName += "sar"; String fileDirectory; CopyOnWriteArrayList classPath = new CopyOnWriteArrayList(); Enumeration<? extends ZipEntry> entries = zip.entries(); int numBytes; while (entries.hasMoreElements()) { ze = entries.nextElement(); // //System.out.println("Unzipping " + ze.getName()); String filePath = deployDirectory + "/" + fileName + "/" + ze.getName(); if (!ze.isDirectory()) { fileDirectory = filePath.substring(0, filePath.lastIndexOf('/')); } else { fileDirectory = filePath; } // //System.out.println(fileDirectory); createDirectory(fileDirectory); if (!ze.isDirectory()) { FileOutputStream fout = new FileOutputStream(filePath); byte[] inputbyt = new byte[8192]; InputStream istream = zip.getInputStream(ze); while ((numBytes = istream.read(inputbyt, 0, inputbyt.length)) >= 0) { fout.write(inputbyt, 0, numBytes); } fout.close(); istream.close(); if (ze.getName().endsWith(".jar")) { classPath.add(filePath); } } } zip.close(); URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); URL[] urls = loader.getURLs(); WebClassLoader sarClassLoader = new WebClassLoader(urls); for (int index = 0; index < classPath.size(); index++) { System.out.println("file:" + classPath.get(index)); new WebServer().addURL(new URL("file:" + classPath.get(index)), sarClassLoader); } new WebServer().addURL(new URL("file:" + deployDirectory + "/" + fileName + "/"), sarClassLoader); sarsMap.put(fileName, sarClassLoader); System.out.println(sarClassLoader.geturlS()); try { Sar sar = (Sar) sardigester.parse(new InputSource( new FileInputStream(deployDirectory + "/" + fileName + "/META-INF/" + "mbean-service.xml"))); CopyOnWriteArrayList mbeans = sar.getMbean(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); System.out.println(mbs); ObjectName objName; for (int index = 0; index < mbeans.size(); index++) { Mbean mbean = (Mbean) mbeans.get(index); System.out.println(mbean.getObjectname()); System.out.println(mbean.getCls()); objName = new ObjectName(mbean.getObjectname()); Class helloWorldService = sarClassLoader.loadClass(mbean.getCls()); Object obj = helloWorldService.newInstance(); if (mbs.isRegistered(objName)) { mbs.invoke(objName, "stopService", null, null); //mbs.invoke(objName, "destroy", null, null); mbs.unregisterMBean(objName); } mbs.registerMBean(obj, objName); CopyOnWriteArrayList attrlist = mbean.getMbeanAttribute(); if (attrlist != null) { for (int count = 0; count < attrlist.size(); count++) { MBeanAttribute attr = (MBeanAttribute) attrlist.get(count); Attribute mbeanattribute = new Attribute(attr.getName(), attr.getValue()); mbs.setAttribute(objName, mbeanattribute); } } mbs.invoke(objName, "startService", null, null); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedObjectNameException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstanceAlreadyExistsException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MBeanRegistrationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NotCompliantMBeanException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstanceNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ReflectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MBeanException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidAttributeValueException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AttributeNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }