1<html> 2<head> 3<title>javax.management.modelmbean package</title> 4<!-- 5Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. 6DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 8This code is free software; you can redistribute it and/or modify it 9under the terms of the GNU General Public License version 2 only, as 10published by the Free Software Foundation. Oracle designates this 11particular file as subject to the "Classpath" exception as provided 12by Oracle in the LICENSE file that accompanied this code. 13 14This code is distributed in the hope that it will be useful, but WITHOUT 15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17version 2 for more details (a copy is included in the LICENSE file that 18accompanied this code). 19 20You should have received a copy of the GNU General Public License version 212 along with this work; if not, write to the Free Software Foundation, 22Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23 24Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 25or visit www.oracle.com if you need additional information or have any 26questions. 27--> 28</head> 29<body bgcolor="white"> 30 31 <p>Provides the definition of the ModelMBean classes. A Model 32 MBean is an MBean that acts as a bridge between the management 33 interface and the underlying managed resource. Both the 34 management interface and the managed resource are specified as 35 Java objects. The same Model MBean implementation can be 36 reused many times with different management interfaces and 37 managed resources, and it can provide common functionality 38 such as persistence and caching.</p> 39 40 <p>A Model MBean implements the {@link 41 javax.management.modelmbean.ModelMBean ModelMBean} interface. 42 It is a {@link javax.management.DynamicMBean DynamicMBean} 43 whose {@link javax.management.DynamicMBean#getMBeanInfo() 44 getMBeanInfo} method returns an object implementing {@link 45 javax.management.modelmbean.ModelMBeanInfo 46 ModelMBeanInfo}.</p> 47 48 <p>Every MBean has an {@link javax.management.MBeanInfo 49 MBeanInfo} with information about the MBean itself, and its 50 attributes, operations, constructors, and notifications. A 51 Model MBean augments this <code>MBeanInfo</code> with {@link 52 javax.management.Descriptor Descriptor}s that encode 53 additional information in the form of (key,value) pairs. 54 Usually, <code>Descriptor</code>s are instances of {@link 55 javax.management.modelmbean.DescriptorSupport 56 DescriptorSupport}.</p> 57 58 <p>The class {@link 59 javax.management.modelmbean.RequiredModelMBean 60 RequiredModelMBean} provides a standard Model MBean 61 implementation.</p> 62 63 <p>The following example shows a Model MBean being used to make 64 the <code>get</code> method of a <code>HashMap</code> 65 available for management through an MBean server. No other 66 methods are available through the MBean server. There is 67 nothing special about <code>HashMap</code> here. Public 68 methods from any public class can be exposed for management in 69 the same way.</p> 70 71 <pre> 72import java.lang.reflect.Method; 73import java.util.HashMap; 74import javax.management.*; 75import javax.management.modelmbean.*; 76 77// ... 78 79MBeanServer mbs = MBeanServerFactory.createMBeanServer(); 80// The MBean Server 81 82HashMap map = new HashMap(); 83// The resource that will be managed 84 85// Construct the management interface for the Model MBean 86Method getMethod = HashMap.class.getMethod("get", new Class[] {Object.class}); 87ModelMBeanOperationInfo getInfo = 88 new ModelMBeanOperationInfo("Get value for key", getMethod); 89ModelMBeanInfo mmbi = 90 new ModelMBeanInfoSupport(HashMap.class.getName(), 91 "Map of keys and values", 92 null, // no attributes 93 null, // no constructors 94 new ModelMBeanOperationInfo[] {getInfo}, 95 null); // no notifications 96 97// Make the Model MBean and link it to the resource 98ModelMBean mmb = new RequiredModelMBean(mmbi); 99mmb.setManagedResource(map, "ObjectReference"); 100 101// Register the Model MBean in the MBean Server 102ObjectName mapName = new ObjectName(":type=Map,name=whatever"); 103mbs.registerMBean(mmb, mapName); 104 105// Resource can evolve independently of the MBean 106map.put("key", "value"); 107 108// Can access the "get" method through the MBean Server 109mbs.invoke(mapName, "get", new Object[] {"key"}, new String[] {Object.class.getName()}); 110// returns "value" 111 </pre> 112 113 <h2><a id="spec">Package Specification</a></h2> 114 115 <ul> 116 <li>See the <i>JMX 1.4 Specification</i> 117 <a href="https://jcp.org/aboutJava/communityprocess/mrel/jsr160/index2.html"> 118 JMX Specification, version 1.4</a> 119 </ul> 120 121 @since 1.5 122 123 </BODY> 124</HTML> 125