public Void run() { try { ManagementFactory.getPlatformMBeanServer().unregisterMBean(handle.getObjectName()); } catch (Throwable ignored) { } return null; } }, acc);
private void registerMBean(ObjectName objectName, Object mBean) { try { ObjectInstance objectInstance = mBeanServer.registerMBean(mBean, objectName); if (objectInstance != null) { // the websphere mbeanserver rewrites the objectname to include cell, node & server info // make sure we capture the new objectName for unregistration registered.put(objectName, objectInstance.getObjectName()); } else { registered.put(objectName, objectName); } } catch (InstanceAlreadyExistsException e) { logger.debug("Unable to register already exist mbean:" + objectName, e); } catch (JMException e) { logger.warn("Unable to register:" + objectName, e); } }
public static Object getValueFromMBean(ObjectInstance objectInstance, String mBeanAttributeName) { try { return mbeanServer.getAttribute(objectInstance.getObjectName(), mBeanAttributeName); } catch (Exception e) { logger.warn(e.getMessage(), e); return null; } } }
public void destroy() throws Exception { if (registered && objectName != null && mBeanServer != null) { registered = false; try { // favor object name from object instance as some containers may use special naming if (objectInstance != null && objectInstance.getObjectName() != null) { mBeanServer.unregisterMBean(objectInstance.getObjectName()); } else { mBeanServer.unregisterMBean(objectName); } } catch (Exception e) { LOG.debug("Error unregistering mbean " + objectName + ". This exception is ignored.", e); } } }
private void registerMBean(Object mBean, ObjectName objectName) throws JMException { ObjectInstance objectInstance = mBeanServer.registerMBean(mBean, objectName); if (objectInstance != null) { // the websphere mbeanserver rewrites the objectname to include // cell, node & server info // make sure we capture the new objectName for unregistration registered.put(objectName, objectInstance.getObjectName()); } else { registered.put(objectName, objectName); } }
actualObjectName = (registeredBean != null ? registeredBean.getObjectName() : null); if (actualObjectName == null) { actualObjectName = objectName;
public void unregisterMBeanServer(MBeanServer mbeanServer) { if (mbeanServer != null) { try { ObjectName name = objectInstance != null ? objectInstance.getObjectName() : getMbeanName(); if (name != null && mbeanServer.isRegistered(name)) { mbeanServer.unregisterMBean(name); objectInstance = null; } } catch (Exception e) { LOG.warn("An error occurred during mbean server registration: " + e, e); } } }
private void mappingCollctors() throws Exception { Set<ObjectInstance> beans = mbsc.queryMBeans(Client.getObjectName(GARBAGE_COLLECTORS), null); for (ObjectInstance collector : beans) { ObjectName collectorObjName = collector.getObjectName(); String collectorName = getAttribute(collectorObjName, "Name"); if ("Copy".equals(collectorName) || "PS Scavenge".equals(collectorName) || "ParNew".equals(collectorName) || "G1 Young Generation".equals(collectorName)) { ygcCollector = collectorObjName; } else if ("MarkSweepCompact".equals(collectorName) || "PS MarkSweep".equals(collectorName) || "ConcurrentMarkSweep".equals(collectorName) || "G1 Old Generation".equals(collectorName)) { fgcCollector = collectorObjName; } else { ygcCollector = collectorObjName; } } }
private void mappingPools() throws Exception { Set<ObjectInstance> beans = mbsc.queryMBeans(Client.getObjectName(MEM_POOL_PREFIX + "*"), null); for (ObjectInstance pool : beans) { ObjectName poolObjName = pool.getObjectName(); String poolName = getAttribute(poolObjName, "Name"); poolName = poolName.trim().toLowerCase(); if (poolName.contains("eden")) { eden = poolObjName; } else if (poolName.contains("survivor")) { sur = poolObjName; } else if (poolName.contains("old") || poolName.contains("tenured")) { old = poolObjName; } else if (poolName.contains("perm") || poolName.contains("metaspace")) { perm = poolObjName; } else if (poolName.contains("compressed class space")) { ccs = poolObjName; } } }
Map<String,String[]> env = new HashMap<String, String[]>(); env.put( JMXConnector.CREDENTIALS, new String[]{"user","pass"} ); JMXServiceURL address = new JMXServiceURL("service:rmi:///jndi/rmi://host:port/jmxrmi"); JMXConnector connector = JMXConnectorFactory.connect(address,env); MBeanServerConnection mbs = connector.getMBeanServerConnection(); //get all mbeans Set<ObjectInstance> beans = mbs.queryMBeans(null,null); for( ObjectInstance instance : beans ) { MBeanInfo info = mbs.getMBeanInfo( instance.getObjectName() ); }
public ObjectInstance registerMBean(Object bean, ObjectName name) throws Exception{ ObjectInstance result = null; if (isAllowedToRegister(name)) { result = getMBeanServer().registerMBean(bean, name); this.registeredMBeanNames.put(name, result.getObjectName()); } return result; }
public static List<MBeanPooledResource> of(String objectName, String poolTypeName, String mbeanKeyPropertyName, String mbeanActiveAttribute, String mbeanCountAttribute, String mbeanMaxAttribute, String mbeanQueueAttribute) { try { final Set<ObjectInstance> objectInstances = server.queryMBeans(new ObjectName(objectName), null); List<MBeanPooledResource> pools = new ArrayList<MBeanPooledResource>(objectInstances.size()); for (final ObjectInstance objectInstance : objectInstances) { pools.add(new MBeanPooledResource(poolTypeName, objectInstance.getObjectName(), mbeanKeyPropertyName, mbeanActiveAttribute, mbeanCountAttribute, mbeanMaxAttribute, mbeanQueueAttribute)); } return pools; } catch (Exception e) { logger.warn(e.getMessage() + " (this exception is ignored)", e); return new LinkedList<MBeanPooledResource>(); } }
buffer.append((((ObjectName) obj).getCanonicalName())); } else if (obj instanceof ObjectInstance) { buffer.append((((ObjectInstance) obj).getObjectName().getCanonicalName())); } else { throw new RuntimeException("Unexpected object type: " + obj);
/** * Create and add a new result. */ private void addNew(String attributeName, ImmutableList.Builder<String> valuePath, Object value) { accumulator.add(new Result(epoch, attributeName, className, objDomain, query.getResultAlias(), objectInstance.getObjectName().getKeyPropertyListString(), valuePath.build(), value)); }
private ObjectName getObjectName(Class<?> proxyClass, String beanQueryName) throws MalformedObjectNameException, IOException { ObjectName name = null; QueryExp query = null; if (proxyClass != null) { query = Query.isInstanceOf(Query.value(proxyClass.getName())); } if (beanQueryName != null) { name = ObjectName.getInstance(beanQueryName); } Set<ObjectInstance> beans = con.queryMBeans(name, query); assertEquals("failed to find only one instance of type " + proxyClass.getName() + " with name " + beanQueryName, 1, beans.size()); return ((ObjectInstance) beans.toArray()[0]).getObjectName(); }
private void addParticipants(final Resource parent, Set<ObjectInstance> participants, MBeanServer mbs) throws IntrospectionException, InstanceNotFoundException, IOException, ReflectionException { int i = 1; for (ObjectInstance participant : participants) { final Resource resource = new LogStoreResource.LogStoreRuntimeResource(participant.getObjectName()); final ModelNode model = resource.getModel(); Map<String, String> pAttributes = getMBeanValues(mbs, participant.getObjectName(), LogStoreConstants.PARTICIPANT_JMX_NAMES); String pAddress = pAttributes.get(JNDI_PROPNAME); if (pAddress == null || pAddress.length() == 0) { pAttributes.put(JNDI_PROPNAME, String.valueOf(i++)); pAddress = pAttributes.get(JNDI_PROPNAME); } addAttributes(model, LogStoreConstants.MODEL_TO_JMX_PARTICIPANT_NAMES, pAttributes); // model.get(LogStoreConstants.JMX_ON_ATTRIBUTE).set(participant.getObjectName().getCanonicalName()); final PathElement element = PathElement.pathElement(LogStoreConstants.PARTICIPANTS, pAddress); parent.registerChild(element, resource); } }
private void addTransactions(final Resource parent, Set<ObjectInstance> transactions, MBeanServer mbs) throws IntrospectionException, InstanceNotFoundException, IOException, ReflectionException, MalformedObjectNameException { for (ObjectInstance oi : transactions) { String transactionId = oi.getObjectName().getCanonicalName(); if (!transactionId.contains("puid") && transactionId.contains("itype")) { final Resource transaction = new LogStoreResource.LogStoreRuntimeResource(oi.getObjectName()); final ModelNode model = transaction.getModel(); Map<String, String> tAttributes = getMBeanValues( mbs, oi.getObjectName(), LogStoreConstants.TXN_JMX_NAMES); String txnId = tAttributes.get("Id"); addAttributes(model, LogStoreConstants.MODEL_TO_JMX_TXN_NAMES, tAttributes); // model.get(LogStoreConstants.JMX_ON_ATTRIBUTE).set(transactionId); String participantQuery = transactionId + ",puid=*"; Set<ObjectInstance> participants = mbs.queryMBeans(new ObjectName(participantQuery), null); addParticipants(transaction, participants, mbs); final PathElement element = PathElement.pathElement(LogStoreConstants.TRANSACTIONS, txnId); parent.registerChild(element, transaction); } } }
protected static Object doAttributeOperation(MBeanServerConnection mbsc, ObjectInstance instance, String command, MBeanAttributeInfo[] infos) throws Exception { // Usually we get attributes. If an argument, then we're being asked // to set attribute. CommandParse parse = new CommandParse(command); if (parse.getArgs() == null || parse.getArgs().length == 0) { // Special-casing. If the subCommand is 'Attributes', then return // list of all attributes. if (command.equals("Attributes")) { String[] names = new String[infos.length]; for (int i = 0; i < infos.length; i++) { names[i] = infos[i].getName(); } return mbsc.getAttributes(instance.getObjectName(), names); } return mbsc.getAttribute(instance.getObjectName(), parse.getCmd()); } if (parse.getArgs().length != 1) { throw new IllegalArgumentException("One only argument setting " + "attribute values: " + parse.getArgs()); } // Get first attribute of name 'cmd'. Assumption is no method // overrides. Then, look at the attribute and use its type. MBeanAttributeInfo info = (MBeanAttributeInfo) getFeatureInfo(infos, parse.getCmd()); java.lang.reflect.Constructor c = Class.forName(info.getType()).getConstructor(new Class[] { String.class }); Attribute a = new Attribute(parse.getCmd(), c.newInstance(new Object[] { parse.getArgs()[0] })); mbsc.setAttribute(instance.getObjectName(), a); return null; }
/** * Registers MBean with the server. * * @param <T> Type of mbean. * @param mbeanSrv MBean server. * @param name MBean object name. * @param impl MBean implementation. * @param itf MBean interface. * @return JMX object name. * @throws MBeanRegistrationException if MBeans are disabled. * @throws JMException If MBean creation failed. * @throws IgniteException If MBean creation are not allowed. */ public static <T> ObjectName registerMBean(MBeanServer mbeanSrv, ObjectName name, T impl, Class<T> itf) throws JMException { if(IGNITE_MBEANS_DISABLED) throw new MBeanRegistrationException(new IgniteIllegalStateException("MBeans are disabled.")); assert mbeanSrv != null; assert name != null; assert itf != null; DynamicMBean mbean = new IgniteStandardMXBean(impl, itf); mbean.getMBeanInfo(); return mbeanSrv.registerMBean(mbean, name).getObjectName(); }
signature[i] = paraminfo.getType(); result = mbsc.invoke(instance.getObjectName(), parse.getCmd(), params, signature);