javax.management.modelmbean.ModelMBeanOperationInfo Java Examples
The following examples show how to use
javax.management.modelmbean.ModelMBeanOperationInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JmxUtils.java From iaf with Apache License 2.0 | 6 votes |
/** * Builds an operationInfor for getter purposes. */ public static ModelMBeanOperationInfo buildGetterModelMBeanOperationInfo( String name, String klass, String description, String signature) { Descriptor theDescriptor = buildGetterDescriptor(name, klass); return new ModelMBeanOperationInfo( name, description, null, signature, ModelMBeanOperationInfo.INFO, theDescriptor); }
Example #2
Source File: ModelMBeanInfoSupporter.java From cxf with Apache License 2.0 | 6 votes |
public ModelMBeanInfo buildModelMBeanInfo(Descriptor desc) { ModelMBeanOperationInfo[] ops = operations.values().toArray(new ModelMBeanOperationInfo[operations.values().size()]); ModelMBeanAttributeInfo[] atts = attributes.values().toArray(new ModelMBeanAttributeInfo[attributes.values().size()]); ModelMBeanConstructorInfo[] cons = constructors.values().toArray(new ModelMBeanConstructorInfo[constructors.values().size()]); ModelMBeanNotificationInfo[] notifs = notifications.values().toArray(new ModelMBeanNotificationInfo[notifications.values().size()]); return new ModelMBeanInfoSupport("javax.management.modelmbean.ModelMBeanInfo", "description", atts, cons, ops, notifs, desc); }
Example #3
Source File: AnnotationMetadataAssemblerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testRegistrationOnInterface() throws Exception { Object bean = getContext().getBean("testInterfaceBean"); ModelMBeanInfo inf = getAssembler().getMBeanInfo(bean, "bean:name=interfaceTestBean"); assertNotNull(inf); assertEquals("My Managed Bean", inf.getDescription()); ModelMBeanOperationInfo op = inf.getOperation("foo"); assertNotNull("foo operation not exposed", op); assertEquals("invoke foo", op.getDescription()); assertNull("doNotExpose operation should not be exposed", inf.getOperation("doNotExpose")); ModelMBeanAttributeInfo attr = inf.getAttribute("Bar"); assertNotNull("bar attribute not exposed", attr); assertEquals("Bar description", attr.getDescription()); ModelMBeanAttributeInfo attr2 = inf.getAttribute("CacheEntries"); assertNotNull("cacheEntries attribute not exposed", attr2); assertEquals("Metric Type should be COUNTER", "COUNTER", attr2.getDescriptor().getFieldValue("metricType")); }
Example #4
Source File: ModelMBeanInfoSupporter.java From cxf with Apache License 2.0 | 6 votes |
public void addModelMBeanMethod(String name, String[] paramTypes, String[] paramNames, String[] paramDescs, String description, String rtype, Descriptor desc) { MBeanParameterInfo[] params = null; if (paramTypes != null) { params = new MBeanParameterInfo[ paramTypes.length ]; for (int i = 0; i < paramTypes.length; i++) { params[i] = new MBeanParameterInfo(paramNames[i], paramTypes[i], paramDescs[i]); } } operations.put(name, new ModelMBeanOperationInfo(name, description, params, rtype, MBeanOperationInfo.ACTION, desc)); }
Example #5
Source File: TestModelMBean.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public MBeanInfo getMBeanInfo() { try { ModelMBeanAttributeInfo[] attributes = new ModelMBeanAttributeInfo[0]; ModelMBeanConstructorInfo[] constructors = new ModelMBeanConstructorInfo[] { new ModelMBeanConstructorInfo("-", this.getClass().getConstructor()) }; ModelMBeanOperationInfo[] operations = new ModelMBeanOperationInfo[] { new ModelMBeanOperationInfo("info", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.INFO), new ModelMBeanOperationInfo("action", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.ACTION), new ModelMBeanOperationInfo("actionInfo", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.ACTION_INFO), new ModelMBeanOperationInfo("unknown", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.UNKNOWN) }; ModelMBeanNotificationInfo[] notifications = new ModelMBeanNotificationInfo[0]; return new ModelMBeanInfoSupport(this.getClass().getName(), "-", attributes, constructors, operations, notifications); } catch (Exception e) { throw new RuntimeException(e); } }
Example #6
Source File: AbstractJmxAssemblerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testAttributeHasCorrespondingOperations() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanOperationInfo get = info.getOperation("getName"); assertNotNull("get operation should not be null", get); assertEquals("get operation should have visibility of four", get.getDescriptor().getFieldValue("visibility"), new Integer(4)); assertEquals("get operation should have role \"getter\"", "getter", get.getDescriptor().getFieldValue("role")); ModelMBeanOperationInfo set = info.getOperation("setName"); assertNotNull("set operation should not be null", set); assertEquals("set operation should have visibility of four", set.getDescriptor().getFieldValue("visibility"), new Integer(4)); assertEquals("set operation should have role \"setter\"", "setter", set.getDescriptor().getFieldValue("role")); }
Example #7
Source File: AbstractJmxAssemblerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAttributeHasCorrespondingOperations() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanOperationInfo get = info.getOperation("getName"); assertNotNull("get operation should not be null", get); assertEquals("get operation should have visibility of four", get.getDescriptor().getFieldValue("visibility"), new Integer(4)); assertEquals("get operation should have role \"getter\"", "getter", get.getDescriptor().getFieldValue("role")); ModelMBeanOperationInfo set = info.getOperation("setName"); assertNotNull("set operation should not be null", set); assertEquals("set operation should have visibility of four", set.getDescriptor().getFieldValue("visibility"), new Integer(4)); assertEquals("set operation should have role \"setter\"", "setter", set.getDescriptor().getFieldValue("role")); }
Example #8
Source File: AnnotationMetadataAssemblerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testRegistrationOnInterface() throws Exception { Object bean = getContext().getBean("testInterfaceBean"); ModelMBeanInfo inf = getAssembler().getMBeanInfo(bean, "bean:name=interfaceTestBean"); assertNotNull(inf); assertEquals("My Managed Bean", inf.getDescription()); ModelMBeanOperationInfo op = inf.getOperation("foo"); assertNotNull("foo operation not exposed", op); assertEquals("invoke foo", op.getDescription()); assertNull("doNotExpose operation should not be exposed", inf.getOperation("doNotExpose")); ModelMBeanAttributeInfo attr = inf.getAttribute("Bar"); assertNotNull("bar attribute not exposed", attr); assertEquals("Bar description", attr.getDescription()); ModelMBeanAttributeInfo attr2 = inf.getAttribute("CacheEntries"); assertNotNull("cacheEntries attribute not exposed", attr2); assertEquals("Metric Type should be COUNTER", "COUNTER", attr2.getDescriptor().getFieldValue("metricType")); }
Example #9
Source File: AbstractJmxAssemblerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testAttributeHasCorrespondingOperations() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanOperationInfo get = info.getOperation("getName"); assertNotNull("get operation should not be null", get); assertEquals("get operation should have visibility of four", get.getDescriptor().getFieldValue("visibility"), new Integer(4)); assertEquals("get operation should have role \"getter\"", "getter", get.getDescriptor().getFieldValue("role")); ModelMBeanOperationInfo set = info.getOperation("setName"); assertNotNull("set operation should not be null", set); assertEquals("set operation should have visibility of four", set.getDescriptor().getFieldValue("visibility"), new Integer(4)); assertEquals("set operation should have role \"setter\"", "setter", set.getDescriptor().getFieldValue("role")); }
Example #10
Source File: AbstractReflectiveMBeanInfoAssembler.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Creates an instance of {@code ModelMBeanOperationInfo} for the * given method. Populates the parameter info for the operation. * @param method the {@code Method} to create a {@code ModelMBeanOperationInfo} for * @param name the logical name for the operation (method name or property name); * not used by the default implementation but possibly by subclasses * @param beanKey the key associated with the MBean in the beans map * of the {@code MBeanExporter} * @return the {@code ModelMBeanOperationInfo} */ protected ModelMBeanOperationInfo createModelMBeanOperationInfo(Method method, String name, String beanKey) { MBeanParameterInfo[] params = getOperationParameters(method, beanKey); if (params.length == 0) { return new ModelMBeanOperationInfo(getOperationDescription(method, beanKey), method); } else { return new ModelMBeanOperationInfo(method.getName(), getOperationDescription(method, beanKey), getOperationParameters(method, beanKey), method.getReturnType().getName(), MBeanOperationInfo.UNKNOWN); } }
Example #11
Source File: ModelMBeanAssemblerTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testAttributeHasCorrespondingOperations() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanOperationInfo myOperation = info.getOperation("myOperation"); assertNotNull("get operation should not be null", myOperation); assertEquals("Incorrect myOperation return type", "long", myOperation.getReturnType()); ModelMBeanOperationInfo add = info.getOperation("add"); assertNotNull("set operation should not be null", add); assertEquals("Incorrect add method description", "Add Two Numbers Together", add.getDescription()); }
Example #12
Source File: MBeanInfoAssembler.java From flowable-engine with Apache License 2.0 | 5 votes |
private void extractMbeanOperations(Object managedBean, Set<ManagedOperationInfo> operations, Set<ModelMBeanOperationInfo> mBeanOperations) { for (ManagedOperationInfo info : operations) { ModelMBeanOperationInfo mbean = new ModelMBeanOperationInfo(info.getDescription(), info.getOperation()); Descriptor opDesc = mbean.getDescriptor(); mbean.setDescriptor(opDesc); mBeanOperations.add(mbean); LOGGER.trace("Assembled operation: {}", mbean); } }
Example #13
Source File: AbstractMetadataAssemblerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testMetricDescription() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo metric = inf.getAttribute(QUEUE_SIZE_METRIC); ModelMBeanOperationInfo operation = inf.getOperation("getQueueSize"); assertEquals("The description for the queue size metric is incorrect", "The QueueSize metric", metric.getDescription()); assertEquals("The description for the getter operation of the queue size metric is incorrect", "The QueueSize metric", operation.getDescription()); }
Example #14
Source File: AbstractMetadataAssemblerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testOperationParameterMetadata() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanOperationInfo oper = info.getOperation("add"); MBeanParameterInfo[] params = oper.getSignature(); assertEquals("Invalid number of params", 2, params.length); assertEquals("Incorrect name for x param", "x", params[0].getName()); assertEquals("Incorrect type for x param", int.class.getName(), params[0].getType()); assertEquals("Incorrect name for y param", "y", params[1].getName()); assertEquals("Incorrect type for y param", int.class.getName(), params[1].getType()); }
Example #15
Source File: AbstractReflectiveMBeanInfoAssembler.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Creates an instance of {@code ModelMBeanOperationInfo} for the * given method. Populates the parameter info for the operation. * @param method the {@code Method} to create a {@code ModelMBeanOperationInfo} for * @param name the logical name for the operation (method name or property name); * not used by the default implementation but possibly by subclasses * @param beanKey the key associated with the MBean in the beans map * of the {@code MBeanExporter} * @return the {@code ModelMBeanOperationInfo} */ protected ModelMBeanOperationInfo createModelMBeanOperationInfo(Method method, String name, String beanKey) { MBeanParameterInfo[] params = getOperationParameters(method, beanKey); if (params.length == 0) { return new ModelMBeanOperationInfo(getOperationDescription(method, beanKey), method); } else { return new ModelMBeanOperationInfo(method.getName(), getOperationDescription(method, beanKey), getOperationParameters(method, beanKey), method.getReturnType().getName(), MBeanOperationInfo.UNKNOWN); } }
Example #16
Source File: MBeanInfoAssembler.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
private void extractMbeanOperations(Object managedBean, Set<ManagedOperationInfo> operations, Set<ModelMBeanOperationInfo> mBeanOperations) { for (ManagedOperationInfo info : operations) { ModelMBeanOperationInfo mbean = new ModelMBeanOperationInfo(info.getDescription(), info.getOperation()); Descriptor opDesc = mbean.getDescriptor(); mbean.setDescriptor(opDesc); mBeanOperations.add(mbean); LOG.trace("Assembled operation: {}", mbean); } }
Example #17
Source File: AbstractMetadataAssemblerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testOperationParameterMetadata() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanOperationInfo oper = info.getOperation("add"); MBeanParameterInfo[] params = oper.getSignature(); assertEquals("Invalid number of params", 2, params.length); assertEquals("Incorrect name for x param", "x", params[0].getName()); assertEquals("Incorrect type for x param", int.class.getName(), params[0].getType()); assertEquals("Incorrect name for y param", "y", params[1].getName()); assertEquals("Incorrect type for y param", int.class.getName(), params[1].getType()); }
Example #18
Source File: AbstractReflectiveMBeanInfoAssembler.java From spring-analysis-note with MIT License | 5 votes |
/** * Creates an instance of {@code ModelMBeanOperationInfo} for the * given method. Populates the parameter info for the operation. * @param method the {@code Method} to create a {@code ModelMBeanOperationInfo} for * @param name the logical name for the operation (method name or property name); * not used by the default implementation but possibly by subclasses * @param beanKey the key associated with the MBean in the beans map * of the {@code MBeanExporter} * @return the {@code ModelMBeanOperationInfo} */ protected ModelMBeanOperationInfo createModelMBeanOperationInfo(Method method, String name, String beanKey) { MBeanParameterInfo[] params = getOperationParameters(method, beanKey); if (params.length == 0) { return new ModelMBeanOperationInfo(getOperationDescription(method, beanKey), method); } else { return new ModelMBeanOperationInfo(method.getName(), getOperationDescription(method, beanKey), getOperationParameters(method, beanKey), method.getReturnType().getName(), MBeanOperationInfo.UNKNOWN); } }
Example #19
Source File: AbstractMetadataAssemblerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testOperationParameterMetadata() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanOperationInfo oper = info.getOperation("add"); MBeanParameterInfo[] params = oper.getSignature(); assertEquals("Invalid number of params", 2, params.length); assertEquals("Incorrect name for x param", "x", params[0].getName()); assertEquals("Incorrect type for x param", int.class.getName(), params[0].getType()); assertEquals("Incorrect name for y param", "y", params[1].getName()); assertEquals("Incorrect type for y param", int.class.getName(), params[1].getType()); }
Example #20
Source File: AbstractMetadataAssemblerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testMetricDescription() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo metric = inf.getAttribute(QUEUE_SIZE_METRIC); ModelMBeanOperationInfo operation = inf.getOperation("getQueueSize"); assertEquals("The description for the queue size metric is incorrect", "The QueueSize metric", metric.getDescription()); assertEquals("The description for the getter operation of the queue size metric is incorrect", "The QueueSize metric", operation.getDescription()); }
Example #21
Source File: AbstractReflectiveMBeanInfoAssembler.java From java-technology-stack with MIT License | 5 votes |
/** * Creates an instance of {@code ModelMBeanOperationInfo} for the * given method. Populates the parameter info for the operation. * @param method the {@code Method} to create a {@code ModelMBeanOperationInfo} for * @param name the logical name for the operation (method name or property name); * not used by the default implementation but possibly by subclasses * @param beanKey the key associated with the MBean in the beans map * of the {@code MBeanExporter} * @return the {@code ModelMBeanOperationInfo} */ protected ModelMBeanOperationInfo createModelMBeanOperationInfo(Method method, String name, String beanKey) { MBeanParameterInfo[] params = getOperationParameters(method, beanKey); if (params.length == 0) { return new ModelMBeanOperationInfo(getOperationDescription(method, beanKey), method); } else { return new ModelMBeanOperationInfo(method.getName(), getOperationDescription(method, beanKey), getOperationParameters(method, beanKey), method.getReturnType().getName(), MBeanOperationInfo.UNKNOWN); } }
Example #22
Source File: AbstractMetadataAssemblerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testMetricDescription() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo metric = inf.getAttribute(QUEUE_SIZE_METRIC); ModelMBeanOperationInfo operation = inf.getOperation("getQueueSize"); assertEquals("The description for the queue size metric is incorrect", "The QueueSize metric", metric.getDescription()); assertEquals("The description for the getter operation of the queue size metric is incorrect", "The QueueSize metric", operation.getDescription()); }
Example #23
Source File: UnserializableTargetObjectTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName name = new ObjectName("a:b=c"); Resource resource1 = new Resource(); Resource resource2 = new Resource(); Resource resource3 = new Resource(); Method operationMethod = Resource.class.getMethod("operation"); Method getCountMethod = Resource.class.getMethod("getCount"); Method setCountMethod = Resource.class.getMethod("setCount", int.class); Descriptor operationDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "operation", resource1 }); Descriptor getCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "getCount", resource2 }); Descriptor setCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "setCount", resource2 }); Descriptor countDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "getMethod", "setMethod" }, new Object[] { "attribute", "Count", "getCount", "setCount" }); ModelMBeanOperationInfo operationInfo = new ModelMBeanOperationInfo("operation description", operationMethod, operationDescriptor); ModelMBeanOperationInfo getCountInfo = new ModelMBeanOperationInfo("getCount description", getCountMethod, getCountDescriptor); ModelMBeanOperationInfo setCountInfo = new ModelMBeanOperationInfo("setCount description", setCountMethod, setCountDescriptor); ModelMBeanAttributeInfo countInfo = new ModelMBeanAttributeInfo("Count", "Count description", getCountMethod, setCountMethod, countDescriptor); ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(Resource.class.getName(), "ModelMBean to test targetObject", new ModelMBeanAttributeInfo[] {countInfo}, null, // no constructors new ModelMBeanOperationInfo[] { operationInfo, getCountInfo, setCountInfo }, null); // no notifications ModelMBean mmb = new RequiredModelMBean(mmbi); mmb.setManagedResource(resource3, "ObjectReference"); mbs.registerMBean(mmb, name); mbs.invoke(name, "operation", null, null); mbs.setAttribute(name, new Attribute("Count", 53)); if (resource1.operationCount != 1) throw new Exception("operationCount: " + resource1.operationCount); if (resource2.count != 53) throw new Exception("count: " + resource2.count); int got = (Integer) mbs.getAttribute(name, "Count"); if (got != 53) throw new Exception("got count: " + got); JMXServiceURL url = new JMXServiceURL("rmi", null, 0); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); JMXConnector cc = JMXConnectorFactory.connect(addr); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name); // Above gets NotSerializableException if resource included in // serialized form cc.close(); cs.stop(); System.out.println("TEST PASSED"); }
Example #24
Source File: MBeanInfoAssembler.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public ModelMBeanInfo getMBeanInfo(Object defaultManagedBean, Object customManagedBean, String objectName) throws JMException { if ((defaultManagedBean == null && customManagedBean == null) || objectName == null) return null; // skip proxy classes if (defaultManagedBean != null && Proxy.isProxyClass(defaultManagedBean.getClass())) { LOG.trace("Skip creating ModelMBeanInfo due proxy class {}", defaultManagedBean.getClass()); return null; } // maps and lists to contain information about attributes and operations Map<String, ManagedAttributeInfo> attributes = new LinkedHashMap<String, ManagedAttributeInfo>(); Set<ManagedOperationInfo> operations = new LinkedHashSet<ManagedOperationInfo>(); Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<ModelMBeanAttributeInfo>(); Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<ModelMBeanOperationInfo>(); Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<ModelMBeanNotificationInfo>(); // extract details from default managed bean if (defaultManagedBean != null) { extractAttributesAndOperations(defaultManagedBean.getClass(), attributes, operations); extractMbeanAttributes(defaultManagedBean, attributes, mBeanAttributes, mBeanOperations); extractMbeanOperations(defaultManagedBean, operations, mBeanOperations); extractMbeanNotifications(defaultManagedBean, mBeanNotifications); } // extract details from custom managed bean if (customManagedBean != null) { extractAttributesAndOperations(customManagedBean.getClass(), attributes, operations); extractMbeanAttributes(customManagedBean, attributes, mBeanAttributes, mBeanOperations); extractMbeanOperations(customManagedBean, operations, mBeanOperations); extractMbeanNotifications(customManagedBean, mBeanNotifications); } // create the ModelMBeanInfo String name = getName(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName); String description = getDescription(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName); ModelMBeanAttributeInfo[] arrayAttributes = mBeanAttributes.toArray(new ModelMBeanAttributeInfo[mBeanAttributes.size()]); ModelMBeanOperationInfo[] arrayOperations = mBeanOperations.toArray(new ModelMBeanOperationInfo[mBeanOperations.size()]); ModelMBeanNotificationInfo[] arrayNotifications = mBeanNotifications.toArray(new ModelMBeanNotificationInfo[mBeanNotifications.size()]); ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, arrayNotifications); LOG.trace("Created ModelMBeanInfo {}", info); return info; }
Example #25
Source File: UnserializableTargetObjectTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName name = new ObjectName("a:b=c"); Resource resource1 = new Resource(); Resource resource2 = new Resource(); Resource resource3 = new Resource(); Method operationMethod = Resource.class.getMethod("operation"); Method getCountMethod = Resource.class.getMethod("getCount"); Method setCountMethod = Resource.class.getMethod("setCount", int.class); Descriptor operationDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "operation", resource1 }); Descriptor getCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "getCount", resource2 }); Descriptor setCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "setCount", resource2 }); Descriptor countDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "getMethod", "setMethod" }, new Object[] { "attribute", "Count", "getCount", "setCount" }); ModelMBeanOperationInfo operationInfo = new ModelMBeanOperationInfo("operation description", operationMethod, operationDescriptor); ModelMBeanOperationInfo getCountInfo = new ModelMBeanOperationInfo("getCount description", getCountMethod, getCountDescriptor); ModelMBeanOperationInfo setCountInfo = new ModelMBeanOperationInfo("setCount description", setCountMethod, setCountDescriptor); ModelMBeanAttributeInfo countInfo = new ModelMBeanAttributeInfo("Count", "Count description", getCountMethod, setCountMethod, countDescriptor); ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(Resource.class.getName(), "ModelMBean to test targetObject", new ModelMBeanAttributeInfo[] {countInfo}, null, // no constructors new ModelMBeanOperationInfo[] { operationInfo, getCountInfo, setCountInfo }, null); // no notifications ModelMBean mmb = new RequiredModelMBean(mmbi); mmb.setManagedResource(resource3, "ObjectReference"); mbs.registerMBean(mmb, name); mbs.invoke(name, "operation", null, null); mbs.setAttribute(name, new Attribute("Count", 53)); if (resource1.operationCount != 1) throw new Exception("operationCount: " + resource1.operationCount); if (resource2.count != 53) throw new Exception("count: " + resource2.count); int got = (Integer) mbs.getAttribute(name, "Count"); if (got != 53) throw new Exception("got count: " + got); JMXServiceURL url = new JMXServiceURL("rmi", null, 0); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); JMXConnector cc = JMXConnectorFactory.connect(addr); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name); // Above gets NotSerializableException if resource included in // serialized form cc.close(); cs.stop(); System.out.println("TEST PASSED"); }
Example #26
Source File: UnserializableTargetObjectTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName name = new ObjectName("a:b=c"); Resource resource1 = new Resource(); Resource resource2 = new Resource(); Resource resource3 = new Resource(); Method operationMethod = Resource.class.getMethod("operation"); Method getCountMethod = Resource.class.getMethod("getCount"); Method setCountMethod = Resource.class.getMethod("setCount", int.class); Descriptor operationDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "operation", resource1 }); Descriptor getCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "getCount", resource2 }); Descriptor setCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "setCount", resource2 }); Descriptor countDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "getMethod", "setMethod" }, new Object[] { "attribute", "Count", "getCount", "setCount" }); ModelMBeanOperationInfo operationInfo = new ModelMBeanOperationInfo("operation description", operationMethod, operationDescriptor); ModelMBeanOperationInfo getCountInfo = new ModelMBeanOperationInfo("getCount description", getCountMethod, getCountDescriptor); ModelMBeanOperationInfo setCountInfo = new ModelMBeanOperationInfo("setCount description", setCountMethod, setCountDescriptor); ModelMBeanAttributeInfo countInfo = new ModelMBeanAttributeInfo("Count", "Count description", getCountMethod, setCountMethod, countDescriptor); ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(Resource.class.getName(), "ModelMBean to test targetObject", new ModelMBeanAttributeInfo[] {countInfo}, null, // no constructors new ModelMBeanOperationInfo[] { operationInfo, getCountInfo, setCountInfo }, null); // no notifications ModelMBean mmb = new RequiredModelMBean(mmbi); mmb.setManagedResource(resource3, "ObjectReference"); mbs.registerMBean(mmb, name); mbs.invoke(name, "operation", null, null); mbs.setAttribute(name, new Attribute("Count", 53)); if (resource1.operationCount != 1) throw new Exception("operationCount: " + resource1.operationCount); if (resource2.count != 53) throw new Exception("count: " + resource2.count); int got = (Integer) mbs.getAttribute(name, "Count"); if (got != 53) throw new Exception("got count: " + got); JMXServiceURL url = new JMXServiceURL("rmi", null, 0); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); JMXConnector cc = JMXConnectorFactory.connect(addr); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name); // Above gets NotSerializableException if resource included in // serialized form cc.close(); cs.stop(); System.out.println("TEST PASSED"); }
Example #27
Source File: UnserializableTargetObjectTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName name = new ObjectName("a:b=c"); Resource resource1 = new Resource(); Resource resource2 = new Resource(); Resource resource3 = new Resource(); Method operationMethod = Resource.class.getMethod("operation"); Method getCountMethod = Resource.class.getMethod("getCount"); Method setCountMethod = Resource.class.getMethod("setCount", int.class); Descriptor operationDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "operation", resource1 }); Descriptor getCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "getCount", resource2 }); Descriptor setCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "setCount", resource2 }); Descriptor countDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "getMethod", "setMethod" }, new Object[] { "attribute", "Count", "getCount", "setCount" }); ModelMBeanOperationInfo operationInfo = new ModelMBeanOperationInfo("operation description", operationMethod, operationDescriptor); ModelMBeanOperationInfo getCountInfo = new ModelMBeanOperationInfo("getCount description", getCountMethod, getCountDescriptor); ModelMBeanOperationInfo setCountInfo = new ModelMBeanOperationInfo("setCount description", setCountMethod, setCountDescriptor); ModelMBeanAttributeInfo countInfo = new ModelMBeanAttributeInfo("Count", "Count description", getCountMethod, setCountMethod, countDescriptor); ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(Resource.class.getName(), "ModelMBean to test targetObject", new ModelMBeanAttributeInfo[] {countInfo}, null, // no constructors new ModelMBeanOperationInfo[] { operationInfo, getCountInfo, setCountInfo }, null); // no notifications ModelMBean mmb = new RequiredModelMBean(mmbi); mmb.setManagedResource(resource3, "ObjectReference"); mbs.registerMBean(mmb, name); mbs.invoke(name, "operation", null, null); mbs.setAttribute(name, new Attribute("Count", 53)); if (resource1.operationCount != 1) throw new Exception("operationCount: " + resource1.operationCount); if (resource2.count != 53) throw new Exception("count: " + resource2.count); int got = (Integer) mbs.getAttribute(name, "Count"); if (got != 53) throw new Exception("got count: " + got); JMXServiceURL url = new JMXServiceURL("rmi", null, 0); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); JMXConnector cc = JMXConnectorFactory.connect(addr); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name); // Above gets NotSerializableException if resource included in // serialized form cc.close(); cs.stop(); System.out.println("TEST PASSED"); }
Example #28
Source File: MBeanInfoAssembler.java From flowable-engine with Apache License 2.0 | 4 votes |
public ModelMBeanInfo getMBeanInfo(Object defaultManagedBean, Object customManagedBean, String objectName) throws JMException { if ((defaultManagedBean == null && customManagedBean == null) || objectName == null) return null; // skip proxy classes if (defaultManagedBean != null && Proxy.isProxyClass(defaultManagedBean.getClass())) { LOGGER.trace("Skip creating ModelMBeanInfo due proxy class {}", defaultManagedBean.getClass()); return null; } // maps and lists to contain information about attributes and operations Map<String, ManagedAttributeInfo> attributes = new LinkedHashMap<>(); Set<ManagedOperationInfo> operations = new LinkedHashSet<>(); Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<>(); Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<>(); Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<>(); // extract details from default managed bean if (defaultManagedBean != null) { extractAttributesAndOperations(defaultManagedBean.getClass(), attributes, operations); extractMbeanAttributes(defaultManagedBean, attributes, mBeanAttributes, mBeanOperations); extractMbeanOperations(defaultManagedBean, operations, mBeanOperations); extractMbeanNotifications(defaultManagedBean, mBeanNotifications); } // extract details from custom managed bean if (customManagedBean != null) { extractAttributesAndOperations(customManagedBean.getClass(), attributes, operations); extractMbeanAttributes(customManagedBean, attributes, mBeanAttributes, mBeanOperations); extractMbeanOperations(customManagedBean, operations, mBeanOperations); extractMbeanNotifications(customManagedBean, mBeanNotifications); } // create the ModelMBeanInfo String name = getName(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName); String description = getDescription(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName); ModelMBeanAttributeInfo[] arrayAttributes = mBeanAttributes.toArray(new ModelMBeanAttributeInfo[mBeanAttributes.size()]); ModelMBeanOperationInfo[] arrayOperations = mBeanOperations.toArray(new ModelMBeanOperationInfo[mBeanOperations.size()]); ModelMBeanNotificationInfo[] arrayNotifications = mBeanNotifications.toArray(new ModelMBeanNotificationInfo[mBeanNotifications.size()]); ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, arrayNotifications); LOGGER.trace("Created ModelMBeanInfo {}", info); return info; }
Example #29
Source File: UnserializableTargetObjectTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName name = new ObjectName("a:b=c"); Resource resource1 = new Resource(); Resource resource2 = new Resource(); Resource resource3 = new Resource(); Method operationMethod = Resource.class.getMethod("operation"); Method getCountMethod = Resource.class.getMethod("getCount"); Method setCountMethod = Resource.class.getMethod("setCount", int.class); Descriptor operationDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "operation", resource1 }); Descriptor getCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "getCount", resource2 }); Descriptor setCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "setCount", resource2 }); Descriptor countDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "getMethod", "setMethod" }, new Object[] { "attribute", "Count", "getCount", "setCount" }); ModelMBeanOperationInfo operationInfo = new ModelMBeanOperationInfo("operation description", operationMethod, operationDescriptor); ModelMBeanOperationInfo getCountInfo = new ModelMBeanOperationInfo("getCount description", getCountMethod, getCountDescriptor); ModelMBeanOperationInfo setCountInfo = new ModelMBeanOperationInfo("setCount description", setCountMethod, setCountDescriptor); ModelMBeanAttributeInfo countInfo = new ModelMBeanAttributeInfo("Count", "Count description", getCountMethod, setCountMethod, countDescriptor); ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(Resource.class.getName(), "ModelMBean to test targetObject", new ModelMBeanAttributeInfo[] {countInfo}, null, // no constructors new ModelMBeanOperationInfo[] { operationInfo, getCountInfo, setCountInfo }, null); // no notifications ModelMBean mmb = new RequiredModelMBean(mmbi); mmb.setManagedResource(resource3, "ObjectReference"); mbs.registerMBean(mmb, name); mbs.invoke(name, "operation", null, null); mbs.setAttribute(name, new Attribute("Count", 53)); if (resource1.operationCount != 1) throw new Exception("operationCount: " + resource1.operationCount); if (resource2.count != 53) throw new Exception("count: " + resource2.count); int got = (Integer) mbs.getAttribute(name, "Count"); if (got != 53) throw new Exception("got count: " + got); JMXServiceURL url = new JMXServiceURL("rmi", null, 0); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); JMXConnector cc = JMXConnectorFactory.connect(addr); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name); // Above gets NotSerializableException if resource included in // serialized form cc.close(); cs.stop(); System.out.println("TEST PASSED"); }
Example #30
Source File: UnserializableTargetObjectTest.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName name = new ObjectName("a:b=c"); Resource resource1 = new Resource(); Resource resource2 = new Resource(); Resource resource3 = new Resource(); Method operationMethod = Resource.class.getMethod("operation"); Method getCountMethod = Resource.class.getMethod("getCount"); Method setCountMethod = Resource.class.getMethod("setCount", int.class); Descriptor operationDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "operation", resource1 }); Descriptor getCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "getCount", resource2 }); Descriptor setCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "setCount", resource2 }); Descriptor countDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "getMethod", "setMethod" }, new Object[] { "attribute", "Count", "getCount", "setCount" }); ModelMBeanOperationInfo operationInfo = new ModelMBeanOperationInfo("operation description", operationMethod, operationDescriptor); ModelMBeanOperationInfo getCountInfo = new ModelMBeanOperationInfo("getCount description", getCountMethod, getCountDescriptor); ModelMBeanOperationInfo setCountInfo = new ModelMBeanOperationInfo("setCount description", setCountMethod, setCountDescriptor); ModelMBeanAttributeInfo countInfo = new ModelMBeanAttributeInfo("Count", "Count description", getCountMethod, setCountMethod, countDescriptor); ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(Resource.class.getName(), "ModelMBean to test targetObject", new ModelMBeanAttributeInfo[] {countInfo}, null, // no constructors new ModelMBeanOperationInfo[] { operationInfo, getCountInfo, setCountInfo }, null); // no notifications ModelMBean mmb = new RequiredModelMBean(mmbi); mmb.setManagedResource(resource3, "ObjectReference"); mbs.registerMBean(mmb, name); mbs.invoke(name, "operation", null, null); mbs.setAttribute(name, new Attribute("Count", 53)); if (resource1.operationCount != 1) throw new Exception("operationCount: " + resource1.operationCount); if (resource2.count != 53) throw new Exception("count: " + resource2.count); int got = (Integer) mbs.getAttribute(name, "Count"); if (got != 53) throw new Exception("got count: " + got); JMXServiceURL url = new JMXServiceURL("rmi", null, 0); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); JMXConnector cc = JMXConnectorFactory.connect(addr); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name); // Above gets NotSerializableException if resource included in // serialized form cc.close(); cs.stop(); System.out.println("TEST PASSED"); }