Please note that this documentation is not final and is subject to change.

Java™ Platform
Standard Ed. 7

DRAFT ea-b76

javax.management.namespace
Class JMXNamespaceView

java.lang.Object
  extended by javax.management.namespace.JMXNamespaceView

public class JMXNamespaceView
extends Object

This class makes it possible to navigate easily within a hierarchical namespace view.

 MBeanServerConnnection rootConnection = ...;

 // create a view at the local root of the namespace hierarchy.
 //
 JMXNamespaceView view = new JMXNamespaceView(rootConnection);

 // list all top level namespaces
 String[] list = view.list();

 // select one namespace from the list
 String whereToGo = ... ;

 // go down to the selected namespace:
 view = view.down(whereToGo);
 System.out.println("I am now in: " + view.where());
 System.out.println("I can see these MBeans:" +
    view.getMBeanServerConnection().queryNames(null,null));

 // list sub namespaces in current view ('whereToGo')
 list = view.list();
 System.out.println("Here are the sub namespaces of "+view.where()+": "+
                    Arrays.toString(list));

 // go up one level
 view = view.up();
 System.out.println("I am now back to: " +
    (view.isRoot() ? "root namespace" : view.where()));
 

Since:
1.7

Constructor Summary
Constructor and Description
JMXNamespaceView(MBeanServerConnection namespaceRoot)
          Creates a view at the top of a JMX namespace hierarchy.
 
Method Summary
Modifier and Type Method and Description
 JMXNamespaceView down(String namespace)
          Go down into a sub namespace.
 boolean equals(Object o)
          Returns true if this object is equal to the given object.
 ObjectName getJMXNamespaceMBeanName()
          Get the name of the JMXNamespaceMBean handling the namespace shown by this view, relative to the root of the hierarchy.
 MBeanServerConnection getMBeanServerConnection()
          A MBeanServerConnection to the namespace shown by this view.
 int hashCode()
          Returns a hash code value for the object.
 boolean isRoot()
          Tells whether this view is at the root of the hierarchy.
 String[] list()
          Lists all direct sub namespaces in this view.
 JMXNamespaceView root()
          Returns the view at the root of the hierarchy.
 JMXNamespaceView up()
          Go back up one level.
 String where()
          Returns the path leading to the namespace in this view, from the top of the hierarchy.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JMXNamespaceView

public JMXNamespaceView(MBeanServerConnection namespaceRoot)
Creates a view at the top of a JMX namespace hierarchy.

Parameters:
namespaceRoot - The MBeanServerConnection at the top of the hierarchy.
Method Detail

where

public String where()
Returns the path leading to the namespace in this view, from the top of the hierarchy.

Returns:
The path to the namespace in this view.

list

public String[] list()
              throws IOException
Lists all direct sub namespaces in this view. The returned strings do not contain the // separator.

Returns:
A list of direct sub name spaces accessible from this namespace.
Throws:
IOException - if the attempt to list the namespaces fails because of a communication problem.

down

public JMXNamespaceView down(String namespace)
Go down into a sub namespace.

Parameters:
namespace - the namespace to go down to. It can contain one or more // separators, to traverse intermediate namespaces, but it must not begin or end with // or contain an empty intermediate namespace. If it is the empty string, then this is returned.
Returns:
A view of the named sub namespace.
Throws:
IllegalArgumentException - if the namespace begins or ends with //.

up

public JMXNamespaceView up()
Go back up one level. If this view is at the root of the hierarchy, returns null.

Returns:
A view of the parent namespace, or null if we're at the root of the hierarchy.

isRoot

public boolean isRoot()
Tells whether this view is at the root of the hierarchy.

Returns:
true if this view is at the root of the hierachy.

root

public JMXNamespaceView root()
Returns the view at the root of the hierarchy. If we are already at the root, this is this.

Returns:
the view at the root of the hierarchy.

getMBeanServerConnection

public MBeanServerConnection getMBeanServerConnection()
A MBeanServerConnection to the namespace shown by this view. This is what would have been obtained by doing:
   JMX.narrowToNamespace(this.root().getMBeanServerConnection(),
       this.where());
 

Returns:
A MBeanServerConnection to the namespace shown by this view.

getJMXNamespaceMBeanName

public ObjectName getJMXNamespaceMBeanName()

Get the name of the JMXNamespaceMBean handling the namespace shown by this view, relative to the root of the hierarchy. If we are at the root of the hierarchy, this method returns null.

You can use this method to make a proxy for the JMXNamespaceMBean as follows:

 JMXNamespaceView view = ...;
 ObjectName namespaceMBeanName = view.getJMXNamespaceMBeanName();
 JMXNamespaceMBean namespaceMBean = JMX.newMBeanProxy(
     view.root().getMBeanServerConnection(), namespaceMBeanName,
     JMXNamespaceMBean.class);
 

Returns:
The name of the JMXNamespaceMBean handling the namespace shown by this view, or null.

hashCode

public int hashCode()
Description copied from class: Object
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.

The general contract of hashCode is:

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), System.identityHashCode(java.lang.Object)

equals

public boolean equals(Object o)
Returns true if this object is equal to the given object. The two objects are equal if the other object is also a JMXNamespaceView and both objects have the same root MBeanServerConnection and the same path.

Overrides:
equals in class Object
Parameters:
o - the other object to compare to.
Returns:
true if both objects are equal.
See Also:
Object.hashCode(), HashMap

Java™ Platform
Standard Ed. 7

DRAFT ea-b76

Submit a bug or feature

Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.