jdk/src/share/classes/javax/management/package.html
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 833 bfa2bef7517c
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
<html>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
<head>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
<title>javax.management package</title>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
<!--
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
-->
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
</head>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
<body bgcolor="white">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
      <p>Provides the core classes for the Java Management Extensions.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
      <p>The Java Management Extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
	(JMX<sup><font size="-1">TM</font></sup>) API is a standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
	API for management and monitoring.  Typical uses include:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
      <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
	<li>consulting and changing application configuration</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
	<li>accumulating statistics about application behavior and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
	  making them available</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
	<li>notifying of state changes and erroneous conditions.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
      </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
      <p>The JMX API can also be used as part of a solution for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
	managing systems, networks, and so on.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
      <p>The API includes remote access, so a remote management
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
	program can interact with a running application for these
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
	purposes.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
      <h2>MBeans</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
      <p>The fundamental notion of the JMX API is the <em>MBean</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
	An MBean is a named <em>managed object</em> representing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
	resource.  It has a <em>management interface</em> consisting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
	of:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
      <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
	<li>named and typed attributes that can be read and/or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
	  written</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
	
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
	<li>named and typed operations that can be invoked</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
	<li>typed notifications that can be emitted by the MBean.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
      </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
      <p>For example, an MBean representing an application's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
	configuration could have attributes representing the different
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
	configuration items.  Reading the <code>CacheSize</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
	attribute would return the current value of that item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
	Writing it would update the item, potentially changing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
	behavior of the running application.  An operation such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
	<code>save</code> could store the current configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
	persistently.  A notification such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
	<code>ConfigurationChangedNotification</code> could be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
	every time the configuration is changed.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
      <p>In the standard usage of the JMX API, MBeans are implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
	as Java objects.  However, as explained below, these objects are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
	not usually referenced directly.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
      <h3>Standard MBeans</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
      <p>To make MBean implementation simple, the JMX API includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
	notion of <em>Standard MBeans</em>.  A Standard MBean is one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
	whose attributes and operations are deduced from a Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
	interface using certain naming patterns, similar to those used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
	by JavaBeans<sup><font size="-1">TM</font></sup>.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
	example, consider an interface like this:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public interface ConfigurationMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
	public int getCacheSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
	public void setCacheSize(int size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
	public long getLastChangedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
	public void save();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
      </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
      <p>The methods <code>getCacheSize</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
	<code>setCacheSize</code> define a read-write attribute of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
	type <code>int</code> called <code>CacheSize</code> (with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
	initial capital, unlike the JavaBeans convention).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
      <p>The method <code>getLastChangedTime</code> defines an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
	attribute of type <code>long</code> called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
	<code>LastChangedTime</code>.  This is a read-only attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
	since there is no method <code>setLastChangedTime</code>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      <p>The method <code>save</code> defines an operation called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
	<code>save</code>.  It is not an attribute, since its name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
	does not begin with <code>get</code>, <code>set</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
	<code>is</code>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      <p>The exact naming patterns for Standard MBeans are detailed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
	the <a href="#spec">JMX Specification</a>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      <p>There are two ways to make a Java object that is an MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
	with this management interface.  One is for the object to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
	of a class that has exactly the same name as the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
	interface but without the <code>MBean</code> suffix.  So in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
	the example the object would be of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
	<code>Configuration</code>, in the same Java package as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
	<code>ConfigurationMBean</code>.  The second way is to use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
	{@link javax.management.StandardMBean StandardMBean}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
	class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      <h3>MXBeans</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
      
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
      <p>An <em>MXBean</em> is a variant of Standard MBean where complex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        types are mapped to a standard set of types defined in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        {@link javax.management.openmbean} package.  MXBeans are appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if you would otherwise need to reference application-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        classes in your MBean interface.  They are described in detail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        in the specification for {@link javax.management.MXBean MXBean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      <h3>Dynamic MBeans</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      <p>A <em>Dynamic MBean</em> is an MBean that defines its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
	management interface at run-time.  For example, a configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
	MBean could determine the names and types of the attributes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
	exposes by parsing an XML file.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
      <p>Any Java object of a class that implements the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
	javax.management.DynamicMBean DynamicMBean} interface is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
	Dynamic MBean.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
      <h3>Open MBeans</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
      <p>An <em>Open MBean</em> is a kind of Dynamic MBean where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
	types of attributes and of operation parameters and return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
	values are built using a small set of predefined Java classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
	Open MBeans facilitate operation with remote management programs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
	that do not necessarily have access to application-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
	types, including non-Java programs.  Open MBeans are defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
	the package <a href="openmbean/package-summary.html"><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
	    javax.management.openmbean</code></a>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
      <h3>Model MBeans</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      <p>A <em>Model MBean</em> is a kind of Dynamic MBean that acts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
	as a bridge between the management interface and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
	underlying managed resource.  Both the management interface and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
	the managed resource are specified as Java objects.  The same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
	Model MBean implementation can be reused many times with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
	different management interfaces and managed resources, and it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
	provide common functionality such as persistence and caching.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
	Model MBeans are defined by the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
	<a href="modelmbean/package-summary.html"><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
	    javax.management.modelmbean</code></a>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
      <h2>MBean Server</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
      
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
      <p>To be useful, an MBean must be registered in an <em>MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
	  Server</em>.  An MBean Server is a repository of MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
	Usually the only access to the MBeans is through the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
	Server.  In other words, code no longer accesses the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
	object implementing the MBean directly, but instead accesses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
	the MBean by name through the MBean Server.  Each MBean has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
	unique name within the MBean Server, defined by the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
	javax.management.ObjectName ObjectName} class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      <p>An MBean Server is an object implementing the interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        {@link javax.management.MBeanServer MBeanServer}.  
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        The most convenient MBean Server to use is the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        <em>Platform MBean Server</em>.  This is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
	single MBean Server that can be shared by different managed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
	components running within the same Java Virtual Machine.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
	Platform MBean Server is accessed with the method {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
	java.lang.management.ManagementFactory#getPlatformMBeanServer()}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
      <p>Application code can also create a new MBean Server, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
	access already-created MBean Servers, using the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
	javax.management.MBeanServerFactory MBeanServerFactory} class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
      <h3>Creating MBeans in the MBean Server</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
      <p>There are two ways to create an MBean.  One is to construct a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
	Java object that will be the MBean, then use the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
	javax.management.MBeanServer#registerMBean registerMBean}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
	method to register it in the MBean Server.  The other is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
	create and register the MBean in a single operation using one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
	of the {@link javax.management.MBeanServer#createMBean(String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
	javax.management.ObjectName) createMBean} methods.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
      <p>The <code>registerMBean</code> method is simpler for local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
	use, but cannot be used remotely.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
	<code>createMBean</code> method can be used remotely, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
	sometimes requires attention to class loading issues.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
      <p>An MBean can perform actions when it is registered in or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
	unregistered from an MBean Server if it implements the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
	javax.management.MBeanRegistration MBeanRegistration}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
	interface.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
      <h3>Accessing MBeans in the MBean Server</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
      <p>Given an <code>ObjectName</code> <code>name</code> and an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
	<code>MBeanServer</code> <code>mbs</code>, you can access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
	attributes and operations as in this example:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
      <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    int cacheSize = mbs.getAttribute(name, "CacheSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    {@link javax.management.Attribute Attribute} newCacheSize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    	new Attribute("CacheSize", new Integer(2000));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    mbs.setAttribute(name, newCacheSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    mbs.invoke(name, "save", new Object[0], new Class[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
      </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
      <p>Alternatively, if you have a Java interface that corresponds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
	to the management interface for the MBean, you can use an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
	<em>MBean proxy</em> like this:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
      <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    ConfigurationMBean conf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        {@link javax.management.JMX#newMBeanProxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            JMX.newMBeanProxy}(mbs, name, ConfigurationMBean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    int cacheSize = conf.getCacheSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    conf.setCacheSize(2000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    conf.save();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
      </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      <p>Using an MBean proxy is just a convenience.  The second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
	example ends up calling the same <code>MBeanServer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
	operations as the first one.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      <p>An MBean Server can be queried for MBeans whose names match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
	certain patterns and/or whose attributes meet certain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
	constraints.  Name patterns are constructed using the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
	javax.management.ObjectName ObjectName} class and constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
	are constructed using the {@link javax.management.Query Query}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
	class.  The methods {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
	javax.management.MBeanServer#queryNames queryNames} and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
	javax.management.MBeanServer#queryMBeans queryMBeans} then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
	perform the query.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      <h2>Notifications</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      <p>A <em>notification</em> is an instance of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
	javax.management.Notification Notification} class or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
	subclass.  In addition to its Java class, it has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
	<em>type</em> string that can distinguish it from other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
	notifications of the same class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
      <p>An MBean that will emit notifications must implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
	{@link javax.management.NotificationBroadcaster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
	NotificationBroadcaster} or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
	javax.management.NotificationEmitter NotificationEmitter}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
	interface.  Usually, it does this by subclassing {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
	javax.management.NotificationBroadcasterSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
	NotificationBroadcasterSupport} or by delegating to an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
	of that class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      <p>Notifications can be received by a <em>listener</em>, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
	is an object that implements the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
	javax.management.NotificationListener NotificationListener}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
	interface.  You can add a listener to an MBean with the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
	{@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
	javax.management.MBeanServer#addNotificationListener(ObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
	NotificationListener, NotificationFilter, Object)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
	You can optionally supply a <em>filter</em> to this method, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
	select only notifications of interest.  A filter is an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
	that implements the {@link javax.management.NotificationFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
	NotificationFilter} interface.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
      <p>An MBean can be a listener for notifications emitted by other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
	MBeans in the same MBean Server.  In this case, it implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
	{@link javax.management.NotificationListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
	NotificationListener} and the method {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
	javax.management.MBeanServer#addNotificationListener(ObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
	ObjectName, NotificationFilter, Object)} is used to listen.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
      <h2>Remote Access to MBeans</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
      <p>An MBean Server can be accessed remotely through a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
	<em>connector</em>.  A connector allows a remote Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
	application to access an MBean Server in essentially the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
	way as a local one.  The package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
	<a href="remote/package-summary.html"><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
	    javax.management.remote</code></a> defines connectors.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
      <p>The JMX specification also defines the notion of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
	<em>adaptor</em>.  An adaptor translates between requests in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
	protocol such as SNMP or HTML and accesses to an MBean Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
	So for example an SNMP GET operation might result in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
	<code>getAttribute</code> on the MBean Server.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
      <p id="spec">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    @see <a href="{@docRoot}/../technotes/guides/jmx/index.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      Java SE 6 Platform documentation on JMX technology</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
      in particular the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
      <a href="{@docRoot}/../technotes/guides/jmx/JMX_1_4_specification.pdf">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
      JMX Specification, version 1.4(pdf).</a> 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
	@since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    </body>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
</html>