List of usage examples for javax.management ObjectInstance getObjectName
public ObjectName getObjectName()
From source file:com.stumbleupon.hbaseadmin.JMXQuery.java
protected Object doAttributeOperation(MBeanServerConnection mbsc, ObjectInstance instance, String command, MBeanAttributeInfo[] infos) throws Exception { final CommandParse parse = new CommandParse(command); if ((parse.getArgs() == null) || (parse.getArgs().length == 0)) { return mbsc.getAttribute(instance.getObjectName(), parse.getCmd()); }/*from w w w .j a v a2 s. c o m*/ if (parse.getArgs().length != 1) { throw new IllegalArgumentException("One only argument setting attribute values: " + parse.getArgs()); } final MBeanAttributeInfo info = (MBeanAttributeInfo) getFeatureInfo(infos, parse.getCmd()); final Constructor c = getResolvedClass(info.getType()).getConstructor(new Class[] { String.class }); final Attribute a = new Attribute(parse.getCmd(), c.newInstance(new Object[] { parse.getArgs()[0] })); mbsc.setAttribute(instance.getObjectName(), a); return null; }
From source file:org.jasig.portlet.utils.jdbc.TomcatDataSourceFactory.java
protected void registerWithMBeanServer() { if (this.dataSource == null) { //Nothing to do yet, no data source return;/*w w w . j a va 2s. co m*/ } if (this.mBeanServer == null) { //Nothing to do yet, no mbean server return; } //Make sure there is nothing already in the mbean server unregisterWithMBeanServer(); try { final ConnectionPool pool = dataSource.createPool(); final org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = pool.getJmxPool(); this.objectName = ObjectName.getInstance(this.baseObjectName + this.poolConfiguration.getName()); logger.info("Registering DataSource " + this.poolConfiguration.getName() + " in MBeanServer under name: " + this.objectName); final ObjectInstance instance = this.mBeanServer.registerMBean(jmxPool, this.objectName); this.objectName = instance.getObjectName(); } catch (Exception e) { logger.warn( "Failed to register connection pool with MBeanServer. JMX information will not be available for: " + this.poolConfiguration.getName(), e); } }
From source file:org.xmatthew.spy2servers.component.spy.jmx.JmxSpySupportComponent.java
public void startup() { bean = new MBeanServerConnectionFactoryBean(); try {//from w ww .j ava 2 s . c om bean.setServiceUrl(getServerUrl()); } catch (MalformedURLException e) { throw new RuntimeException(e.getMessage(), e); } runing = true; setStatusRun(); startJmxConnection(); ObjectInstance objInstance; while (runing) { try { // begin to get MBeans Set mbeans = mbsc.queryMBeans(null, null); if (mbeans != null && mbeans.size() > 0) { Iterator iter = mbeans.iterator(); while (iter.hasNext()) { objInstance = (ObjectInstance) iter.next(); if (!getNameFilterQueryExp().apply(objInstance.getObjectName())) { continue; } inspectMBean(objInstance, mbsc); } } //every repeat will call back MBeanServerConnection mscOnInterval(mbsc); } catch (Exception e) { LOGGER.error(e.getMessage(), e); if (e instanceof IOException) { try { bean.destroy(); } catch (Exception e1) { LOGGER.error(e1.getMessage(), e1); } finally { bean = new MBeanServerConnectionFactoryBean(); try { bean.setServiceUrl(getServerUrl()); } catch (MalformedURLException e1) { } isConnectionEstablished = false; reStartJmxConnection(); } } } try { Thread.sleep(detectInterval); } catch (InterruptedException e) { LOGGER.error(e.getMessage(), e); } } }
From source file:com.stumbleupon.hbaseadmin.JMXQuery.java
protected Object doBeanOperation(MBeanServerConnection mbsc, ObjectInstance instance, String command, MBeanOperationInfo[] infos) throws Exception { final CommandParse parse = new CommandParse(command); final MBeanOperationInfo op = (MBeanOperationInfo) getFeatureInfo(infos, parse.getCmd()); Object result = null;//w w w.j av a 2 s .com if (op == null) { result = "Operation " + parse.getCmd() + " not found."; } else { final MBeanParameterInfo[] paraminfos = op.getSignature(); final int paraminfosLength = (paraminfos == null) ? 0 : paraminfos.length; int objsLength = (parse.getArgs() == null) ? 0 : parse.getArgs().length; // FIXME: bad solution for comma containing parameter if (paraminfosLength == 1) { // concat all to one string String realParameter = parse.getArgs()[0]; for (int j = 1; j < objsLength; j++) { realParameter = realParameter + "," + parse.getArgs()[j]; } objsLength = 1; parse.setArgs(new String[] { realParameter }); } if (paraminfosLength != objsLength) { result = "Passed param count does not match signature count"; } else { final String[] signature = new String[paraminfosLength]; final Object[] params = (paraminfosLength == 0) ? null : new Object[paraminfosLength]; for (int i = 0; i < paraminfosLength; ++i) { final MBeanParameterInfo paraminfo = paraminfos[i]; // System.out.println( "paraminfo.getType() = " + paraminfo.getType()); final String classType = paraminfo.getType(); // Constructor c = Class.forName(classType).getConstructor(new Class[] { String.class }); final Constructor c = getResolvedClass(paraminfo.getType()) .getConstructor(new Class[] { String.class }); params[i] = c.newInstance(new Object[] { parse.getArgs()[i] }); signature[i] = classType; } result = mbsc.invoke(instance.getObjectName(), parse.getCmd(), params, signature); } } return result; }
From source file:org.apache.camel.management.DefaultManagementAgent.java
private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration) throws JMException { // have we already registered the bean, there can be shared instances in the camel routes boolean exists = server.isRegistered(name); if (exists) { if (forceRegistration) { LOG.info("ForceRegistration enabled, unregistering existing MBean"); server.unregisterMBean(name); } else {//from w w w . ja v a 2s. c o m // okay ignore we do not want to force it and it could be a shared instance if (LOG.isDebugEnabled()) { LOG.debug("MBean already registered with objectname: " + name); } } } // register bean if by force or not exists ObjectInstance instance = null; if (forceRegistration || !exists) { if (LOG.isTraceEnabled()) { LOG.trace("Registering MBean with objectname: " + name); } instance = server.registerMBean(obj, name); } if (instance != null) { ObjectName registeredName = instance.getObjectName(); if (LOG.isDebugEnabled()) { LOG.debug("Registered MBean with objectname: " + registeredName); } mbeansRegistered.add(registeredName); } }
From source file:org.apache.catalina.manager.StatusManagerServlet.java
/** * Initialize this servlet.//www . j a va2s . c o m */ public void init() throws ServletException { // Retrieve the MBean server mBeanServer = Registry.getServer(); // Set our properties from the initialization parameters String value = null; try { value = getServletConfig().getInitParameter("debug"); debug = Integer.parseInt(value); } catch (Throwable t) { ; } try { // Query protocol handlers String onStr = "*:type=ProtocolHandler,*"; ObjectName objectName = new ObjectName(onStr); Set set = mBeanServer.queryMBeans(objectName, null); Iterator iterator = set.iterator(); while (iterator.hasNext()) { ObjectInstance oi = (ObjectInstance) iterator.next(); protocolHandlers.addElement(oi.getObjectName()); } // Query Thread Pools onStr = "*:type=ThreadPool,*"; objectName = new ObjectName(onStr); set = mBeanServer.queryMBeans(objectName, null); iterator = set.iterator(); while (iterator.hasNext()) { ObjectInstance oi = (ObjectInstance) iterator.next(); threadPools.addElement(oi.getObjectName()); } // Query Global Request Processors onStr = "*:type=GlobalRequestProcessor,*"; objectName = new ObjectName(onStr); set = mBeanServer.queryMBeans(objectName, null); iterator = set.iterator(); while (iterator.hasNext()) { ObjectInstance oi = (ObjectInstance) iterator.next(); globalRequestProcessors.addElement(oi.getObjectName()); } // Query Request Processors onStr = "*:type=RequestProcessor,*"; objectName = new ObjectName(onStr); set = mBeanServer.queryMBeans(objectName, null); iterator = set.iterator(); while (iterator.hasNext()) { ObjectInstance oi = (ObjectInstance) iterator.next(); requestProcessors.addElement(oi.getObjectName()); } // Register with MBean server onStr = "JMImplementation:type=MBeanServerDelegate"; objectName = new ObjectName(onStr); mBeanServer.addNotificationListener(objectName, this, null, null); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.coyote.tomcat5.MapperListener.java
/** * Initialize associated mapper.//from w w w . j av a 2 s.c o m */ public void init() { try { mBeanServer = Registry.getServer(); registerEngine(); // Query hosts String onStr = domain + ":type=Host,*"; ObjectName objectName = new ObjectName(onStr); Set set = mBeanServer.queryMBeans(objectName, null); Iterator iterator = set.iterator(); while (iterator.hasNext()) { ObjectInstance oi = (ObjectInstance) iterator.next(); registerHost(oi.getObjectName()); } // Query contexts onStr = "*:j2eeType=WebModule,*"; objectName = new ObjectName(onStr); set = mBeanServer.queryMBeans(objectName, null); iterator = set.iterator(); while (iterator.hasNext()) { ObjectInstance oi = (ObjectInstance) iterator.next(); registerContext(oi.getObjectName()); } // Query wrappers onStr = "*:j2eeType=Servlet,*"; objectName = new ObjectName(onStr); set = mBeanServer.queryMBeans(objectName, null); iterator = set.iterator(); while (iterator.hasNext()) { ObjectInstance oi = (ObjectInstance) iterator.next(); registerWrapper(oi.getObjectName()); } onStr = "JMImplementation:type=MBeanServerDelegate"; objectName = new ObjectName(onStr); mBeanServer.addNotificationListener(objectName, this, null, null); } catch (Exception e) { log.warn("Error registering contexts", e); } }
From source file:org.apache.geronimo.tomcat.stats.ModuleStats.java
public ModuleStats(StandardContext context) { assert context != null; // Retrieve the MBean server mBeanServer = Registry.getRegistry(null, null).getMBeanServer(); try {/* w ww. j a va 2 s. c o m*/ // org.apache.commons.modeler.BaseModelMBean@Geronimo:type=Manager,path=/,host=localhost mgrName = new ObjectName("*:type=Manager,*"); } catch (Exception ex) { log.error("Error - " + ex.toString()); } // Query Session Managers for (ObjectInstance oi : mBeanServer.queryMBeans(mgrName, null)) { ObjectName objectName = oi.getObjectName(); if (objectName.getKeyProperty("context").indexOf(context.getPath()) > -1) { mgrName = objectName; break; } } // initialize static values stats.setProcessingTime(context.getProcessingTime()); stats.setStartupTime(context.getStartupTime()); stats.setTldScanTime(context.getTldScanTime()); }
From source file:org.apache.hadoop.hbase.TestStochasticBalancerJmxMetrics.java
/** * Read the attributes from Hadoop->HBase->Master->Balancer in JMX * @throws IOException /*w w w. j a v a2 s .c om*/ */ private Set<String> readJmxMetrics() throws IOException { JMXConnector connector = null; ObjectName target = null; MBeanServerConnection mb = null; try { connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(connectorPort, connectorPort)); mb = connector.getMBeanServerConnection(); Hashtable<String, String> pairs = new Hashtable<>(); pairs.put("service", "HBase"); pairs.put("name", "Master"); pairs.put("sub", "Balancer"); target = new ObjectName("Hadoop", pairs); MBeanInfo beanInfo = mb.getMBeanInfo(target); Set<String> existingAttrs = new HashSet<String>(); for (MBeanAttributeInfo attrInfo : beanInfo.getAttributes()) { existingAttrs.add(attrInfo.getName()); } return existingAttrs; } catch (Exception e) { LOG.warn("Failed to get bean!!! " + target, e); if (mb != null) { Set<ObjectInstance> instances = mb.queryMBeans(null, null); Iterator<ObjectInstance> iterator = instances.iterator(); System.out.println("MBean Found:"); while (iterator.hasNext()) { ObjectInstance instance = iterator.next(); System.out.println("Class Name: " + instance.getClassName()); System.out.println("Object Name: " + instance.getObjectName()); } } } finally { if (connector != null) { try { connector.close(); } catch (Exception e) { e.printStackTrace(); } } } return null; }
From source file:org.apache.helix.tools.JmxDumper.java
void init() throws Exception { try {/* w ww. j a v a2 s. c o m*/ Set<ObjectInstance> existingInstances = _mbeanServer.queryMBeans(new ObjectName(_namePattern), null); _logger.info("Total " + existingInstances.size() + " mbeans matched " + _namePattern); for (ObjectInstance instance : existingInstances) { if (instance.getClassName().equals(_beanClassName)) { _mbeanNames.put(instance.getObjectName(), instance.getObjectName()); _logger.info("Sampling " + instance.getObjectName()); } } FileWriter fos = new FileWriter(_outputFileName); System.out.println(_outputFileName); _outputFile = new PrintWriter(fos); } catch (Exception e) { _logger.error("fail to get all existing mbeans in " + _domain, e); throw e; } }