org.norther.tammi.core.base
Class MBeanBroker

java.lang.Object
  extended by org.norther.tammi.core.base.MBeanBroker
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
MBeanConfig

public class MBeanBroker
extends Object
implements Serializable

An MBean broker resolving MBean references and supporting access to their properties and methods. Internally, it utilizes services provided by the default broker.

It may be used in situations where direct access to the above services is not available, like in template contexts and scripting environments. It can also resolve parameter signatures automatically based on their class types, which makes script access to MBeans more convenient.

Author:
Marketta Priha, Ilkka Priha
See Also:
Serialized Form

Field Summary
static String MBEAN_BROKER
          The global MBean broker bean.
 
Constructor Summary
MBeanBroker()
          Constructs a new broker.
MBeanBroker(MBeanServer server)
          Constructs a new broker for a specific server.
 
Method Summary
 ObjectName adapt(String className)
          Adapts and registers an MBean with the default name.
 ObjectName adapt(String className, ObjectName name)
          Adapts and registers an MBean with an object name .
 ObjectName adapt(String className, ObjectName name, String ifname)
          Adapts and registers an MBean with an object name and interface.
 ObjectName adapt(String className, ObjectName name, String ifname, Object params)
          Adapts and registers an MBean with an object name, interface and parameters.
 ObjectName adapt(String className, ObjectName name, String ifname, ObjectName loader, Object params, Object sign)
          Adapts and registers an MBean with an object name, interface, class loader, parameters and signature.
 ObjectName adapt(String className, ObjectName name, String ifname, Object params, Object sign)
          Adapts and registers an MBean with an object name, interface, parameters and signature.
 ObjectName adapt(String className, String ifname)
          Adapts and registers an MBean with the default name and interface.
 ObjectName adapt(String className, String name, String ifname)
          Adapts and registers an MBean with a string name and interface.
 ObjectName adapt(String className, String name, String ifname, Object params)
          Adapts and registers an MBean with a string name, interface and parameters.
 ObjectName adapt(String className, String name, String ifname, Object params, Object sign)
          Adapts and registers an MBean with a string name, interface, parameters and signature.
 ObjectName adapt(String className, String name, String ifname, String loader, Object params, Object sign)
          Adapts and registers an MBean with a string name, interface, class loader, parameters and signature.
 ObjectName create(String className)
          Creates and registers an MBean with the default name.
 ObjectName create(String className, ObjectName name)
          Creates and registers an MBean with an object name.
 ObjectName create(String className, ObjectName name, Object params)
          Creates and registers an MBean with an object name and parameters.
 ObjectName create(String className, ObjectName name, ObjectName loader, Object params, Object sign)
          Creates and registers an MBean with an object name, class loader, parameters and signature.
 ObjectName create(String className, ObjectName name, Object params, Object sign)
          Creates and registers an MBean with an object name, parameters and signature.
 ObjectName create(String className, String name)
          Creates and registers an MBean with a string name.
 ObjectName create(String className, String name, Object params)
          Creates and registers an MBean with a string name and parameters.
 ObjectName create(String className, String name, Object params, Object sign)
          Creates and registers an MBean with a string name, parameters and signature.
 ObjectName create(String className, String name, String loader, Object params, Object sign)
          Creates and registers an MBean with a string name, class loader, parameters and signature.
 Object find(ObjectName name)
          Finds the referent of the specified MBean.
 Object find(ObjectName name, String className)
          Finds a direct reference to the specified MBean implementing a specific class.
 Object find(String spec)
          Finds the referent of the specified MBean.
 Object find(String name, String className)
          Finds the referent of the MBean with the specified name string implementing a specific class.
 ObjectName findName(ObjectName name)
          Finds an object name of the specified MBean.
 ObjectName findName(ObjectName name, String className)
          Finds an object name of the specified MBean implementing a specific class.
 ObjectName findName(String spec)
          Finds the object name of the specified MBean.
 ObjectName findName(String name, String className)
          Finds the object name of the MBean with the specified name string implementing a specific class.
 Set findNames(boolean all)
          Finds a set of object names registered to the domains of this application.
 Set findNames(boolean all, String className)
          Finds a set of object names implementing a specific class registered to the domains of this application.
 Set findNames(ObjectName name)
          Finds a set of object name of the specified MBeans.
 Set findNames(ObjectName name, String className)
          Finds a set of object name of the specified MBeans implementing a specific class.
 Set findNames(String spec)
          Finds a set of object names of the specified MBeans.
 Set findNames(String name, String className)
          Finds a set of object name of MBeans with the specified name string implementing a specific class.
 Object get(ObjectName name, String key)
          Gets an attribute value of the specified MBean.
 Object get(ObjectName name, String key, Object tag)
          Gets a taggeg attribute value of the specified MBean.
 Object get(String spec, String key)
          Gets an attribute value of the specified MBean.
 Object get(String spec, String key, String tag)
          Gets a tagged attribute value of the specified MBean.
 String[] getAllDomains()
          Gets all domains.
protected  Broker getBroker()
          Gets the broker.
 String getClassName(ObjectName name)
          Gets the class name of the specified MBean.
 String getClassName(String spec)
          Gets the class name of the specified MBean.
 String getDefaultDomain()
          Gets the default domain.
protected  Domain getDomain()
          Gets the domain.
 String getDomainName()
          Gets the domain name.
 String[] getDomainNames()
          Gets the domain names.
protected  Factory getFactory()
          Gets the factory.
 MBeanInfo getInfo(ObjectName name)
          Gets MBean info about the specified MBean.
 MBeanInfo getInfo(String spec)
          Gets MBean info about the specified MBean.
protected  LoaderMBean getLoader()
          Gets the loader.
 Log getLog()
          Gets a log.
 MBeanServer getMBeanServer()
          Gets a reference to the MBean server.
 Package getPackage(String name)
          Gets the named package.
 Package[] getPackages()
          Gets all known packages.
 String getSystemProperty(String name)
          Gets a system property.
 Object instantiate(String className)
          Intantiates an object.
 Object instantiate(String className, Object params)
          Intantiates an object with parameters.
 Object instantiate(String className, Object params, Object sign)
          Intantiates an object with parameters and a signature.
 Object invoke(ObjectName name, String method)
          Invokes a method of the specified MBean.
 Object invoke(ObjectName name, String method, Object params)
          Invokes a method of the specified MBean with parameters.
 Object invoke(ObjectName name, String method, Object params, Object sign)
          Invokes a method of the specified MBean with parameters and a signature.
 Object invoke(String spec, String method)
          Invokes a method of the specified MBean.
 Object invoke(String spec, String method, Object params)
          Invokes a method of the specified MBean with parameters.
 Object invoke(String spec, String method, Object params, Object sign)
          Invokes a method of the specified MBean with parameters and a signature.
 boolean isDefined(String className)
          Checks whether a class is defined.
 boolean isInstanceOf(ObjectName name, String className)
          Checks whether the named MBean implements a specific class.
 boolean isInstanceOf(String name, String className)
          Checks whether an MBean with a string name implements a specific class.
 boolean isRegistered(ObjectName name)
          Checks whether the named MBean is registered.
 boolean isRegistered(String name)
          Checks whether an MBean with a string name is registered.
 Class load(String className)
          Loads a class.
 ObjectName register(Object object)
          Registers an unnamed MBean.
 ObjectName register(Object object, ObjectName name)
          Registers the named MBean.
 ObjectName register(Object object, ObjectName name, String ifname)
          Registers the named MBean exposing the specified class or interface.
 ObjectName register(Object object, String name)
          Registers an MBean with a string name.
 void set(ObjectName name, String key, Object value)
          Sets an attribute value of the specified MBean.
 void set(ObjectName name, String key, Object tag, Object value)
          Sets a tagged attribute value of the specified MBean.
 void set(ObjectName name, String key, Object tag, Object value, String type)
          Sets a tagged and typed attribute value of the specified MBean.
 void set(String spec, String key, Object value)
          Sets an attribute value of the specified MBean.
 void set(String spec, String key, Object tag, Object value)
          Sets a tagged attribute value of the specified MBean.
 void set(String spec, String key, Object tag, Object value, String type)
          Sets a tagged and typed attribute value of the specified MBean.
 void setAlias(String alias, ObjectName name)
          Sets an alias for the specified MBean.
 void setAlias(String alias, String spec)
          Sets an alias for the specified MBean.
 void setFactory(String className, ObjectName name)
          Sets the factory MBean for the specified class name.
 void setFactory(String className, String spec)
          Sets the factory MBean for the specified class name.
protected  void setMBeanServer(MBeanServer server)
          Sets a reference to the MBean server.
 void setSystemProperty(String name, String value)
          Sets a system property.
 ObjectName toObjectName(String name)
          Converts a string to an object name.
 String toPackageName(String uri)
          Converts an URI path to a package name.
 void unregister(ObjectName name)
          Unregisters the named MBean.
 void unregister(String name)
          Unregisters an MBean with a string name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MBEAN_BROKER

public static final String MBEAN_BROKER
The global MBean broker bean.

See Also:
Constant Field Values
Constructor Detail

MBeanBroker

public MBeanBroker()
Constructs a new broker.


MBeanBroker

public MBeanBroker(MBeanServer server)
Constructs a new broker for a specific server. Note that the MBean server cannot be serialized.

Parameters:
server - the MBean server.
Method Detail

findNames

public Set findNames(boolean all)
Finds a set of object names registered to the domains of this application.

Parameters:
all - true for all names, false for default names.
Returns:
a set of object names or an empty set.

findNames

public Set findNames(boolean all,
                     String className)
Finds a set of object names implementing a specific class registered to the domains of this application.

Parameters:
all - true for all names, false for default names.
className - the class name.
Returns:
a set of object names or an empty set.

find

public Object find(String spec)
Finds the referent of the specified MBean. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
spec - the MBean specification.
Returns:
the MBean reference or null.

findName

public ObjectName findName(String spec)
Finds the object name of the specified MBean. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
spec - the MBean specification.
Returns:
the object name or null.

findNames

public Set findNames(String spec)
Finds a set of object names of the specified MBeans. The MBeans can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
spec - the MBean specification.
Returns:
a set of object names or an empty set.

find

public Object find(String name,
                   String className)
Finds the referent of the MBean with the specified name string implementing a specific class. The name string can be a query pattern or fully qualified object name.

Parameters:
name - the name string or pattern.
className - the class name.
Returns:
the MBean reference or null.

findName

public ObjectName findName(String name,
                           String className)
Finds the object name of the MBean with the specified name string implementing a specific class. The name string can be a query pattern or fully qualified object name.

Parameters:
name - the name string or pattern.
className - the class name.
Returns:
the object name or null.

findNames

public Set findNames(String name,
                     String className)
Finds a set of object name of MBeans with the specified name string implementing a specific class. The name string can be a query pattern or fully qualified object name.

Parameters:
name - the name string or pattern.
className - the class name.
Returns:
a set of object names or an empty set.

find

public Object find(ObjectName name)
Finds the referent of the specified MBean. The MBean can be specified by a query pattern or fully qualified object name.

Parameters:
name - the MBean name.
Returns:
the MBean reference or null.

findName

public ObjectName findName(ObjectName name)
Finds an object name of the specified MBean. The MBean can be specified by a query pattern or fully qualified object name.

Parameters:
name - the MBean name.
Returns:
the MBean reference or null.

findNames

public Set findNames(ObjectName name)
Finds a set of object name of the specified MBeans. The MBeans can be specified by a query pattern or fully qualified object name.

Parameters:
name - the MBean name.
Returns:
a set of object names or an empty set.

find

public Object find(ObjectName name,
                   String className)
Finds a direct reference to the specified MBean implementing a specific class. The MBean can be specified by a query pattern or fully qualified object name.

Parameters:
name - the MBean name.
className - the class name.
Returns:
the MBean reference or null.

findName

public ObjectName findName(ObjectName name,
                           String className)
Finds an object name of the specified MBean implementing a specific class. The MBean can be specified by a query pattern or fully qualified object name.

Parameters:
name - the MBean name.
className - the class name.
Returns:
the object name or null.

findNames

public Set findNames(ObjectName name,
                     String className)
Finds a set of object name of the specified MBeans implementing a specific class. The MBeans can be specified by a query pattern or fully qualified object name.

Parameters:
name - the MBean name.
className - the class name.
Returns:
a set of object names or an empty set.

getClassName

public String getClassName(String spec)
                    throws LogException
Gets the class name of the specified MBean. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
spec - the MBean specification.
Returns:
the class name of the MBean.
Throws:
LogException - on errors.

getInfo

public MBeanInfo getInfo(String spec)
                  throws LogException
Gets MBean info about the specified MBean. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
spec - the MBean specification.
Returns:
info about the MBean.
Throws:
LogException - on errors.

setAlias

public void setAlias(String alias,
                     String spec)
Sets an alias for the specified MBean. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
alias - the alias key.
spec - the MBean specification.

setFactory

public void setFactory(String className,
                       String spec)
Sets the factory MBean for the specified class name. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
className - the class name.
spec - the MBean specification.

get

public Object get(String spec,
                  String key)
           throws LogException
Gets an attribute value of the specified MBean. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
spec - the MBean specification.
key - the attribute key.
Returns:
the value of the attribute.
Throws:
LogException - on errors.

set

public void set(String spec,
                String key,
                Object value)
         throws LogException
Sets an attribute value of the specified MBean. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
spec - the MBean specification.
key - the attribute key.
value - the attribute value.
Throws:
LogException - on errors.

get

public Object get(String spec,
                  String key,
                  String tag)
           throws LogException
Gets a tagged attribute value of the specified MBean. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
spec - the MBean specification.
key - the attribute key.
tag - the attribute tag.
Returns:
the value of the attribute.
Throws:
LogException - on errors.

set

public void set(String spec,
                String key,
                Object tag,
                Object value)
         throws LogException
Sets a tagged attribute value of the specified MBean. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
spec - the MBean specification.
key - the attribute key.
tag - the attribute tag.
value - the attribute value.
Throws:
LogException - on errors.

set

public void set(String spec,
                String key,
                Object tag,
                Object value,
                String type)
         throws LogException
Sets a tagged and typed attribute value of the specified MBean. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
spec - the MBean specification.
key - the attribute key.
tag - the attribute tag.
value - the attribute value.
type - the attribute type.
Throws:
LogException - on errors.

invoke

public Object invoke(String spec,
                     String method)
              throws LogException
Invokes a method of the specified MBean. The MBean can be specified by a broker alias, query pattern or fully qualified object name.

Parameters:
spec - the MBean specification.
method - the method name.
Returns:
the return value of the method.
Throws:
LogException - on errors.

invoke

public Object invoke(String spec,
                     String method,
                     Object params)
              throws LogException
Invokes a method of the specified MBean with parameters. The MBean can be specified by a broker alias, query pattern or fully qualified object name. A single parameter can be given as an object and multiple parameters as a list or an array.

Parameters:
spec - the MBean specification.
method - the method name.
params - the parameters to the method.
Returns:
the return value of the method.
Throws:
LogException - on errors.

invoke

public Object invoke(String spec,
                     String method,
                     Object params,
                     Object sign)
              throws LogException
Invokes a method of the specified MBean with parameters and a signature. The MBean can be specified by a broker alias, query pattern or fully qualified object name. A single parameter can be given as an object and multiple parameters as a list or an array. If the parameters are given as a list, the signature must be null or also a list.

Parameters:
spec - the MBean specification.
method - the method name.
params - the parameters to the method.
sign - the signature of the parameters.
Returns:
the return value of the method.
Throws:
LogException - on errors.

create

public ObjectName create(String className)
                  throws LogException
Creates and registers an MBean with the default name.

Parameters:
className - the class name of the MBean.
Returns:
the object name of the new MBean.
Throws:
LogException - on errors.

create

public ObjectName create(String className,
                         String name)
                  throws LogException
Creates and registers an MBean with a string name.

Parameters:
className - the class name of the MBean.
name - the string name of the MBean.
Returns:
the object name of the new MBean.
Throws:
LogException - on errors.

create

public ObjectName create(String className,
                         String name,
                         Object params)
                  throws LogException
Creates and registers an MBean with a string name and parameters. A single parameter can be given as an object and multiple parameters as a list or an array.

Parameters:
className - the class name of the MBean.
name - the string name of the MBean.
params - the parameter to the constructor.
Returns:
the object name of the new MBean.
Throws:
LogException - on errors.

create

public ObjectName create(String className,
                         String name,
                         Object params,
                         Object sign)
                  throws LogException
Creates and registers an MBean with a string name, parameters and signature. A single parameter can be given as an object and multiple parameters as a list or an array. If the parameters are given as a list, the signature must be null or also a list.

Parameters:
className - the class name of the MBean.
name - the string name of the MBean.
params - the parameter to the constructor.
sign - the signature of the parameters.
Returns:
the object name of the new MBean.
Throws:
LogException - on errors.

create

public ObjectName create(String className,
                         String name,
                         String loader,
                         Object params,
                         Object sign)
                  throws LogException
Creates and registers an MBean with a string name, class loader, parameters and signature. A single parameter can be given as an object and multiple parameters as a list or an array. If the parameters are given as a list, the signature must be null or also a list.

Parameters:
className - the class name of the MBean.
name - the string name of the MBean.
loader - the string name of the loader.
params - the parameter to the constructor.
sign - the signature of the parameters.
Returns:
the object name of the new MBean.
Throws:
LogException - on errors.

adapt

public ObjectName adapt(String className)
                 throws LogException
Adapts and registers an MBean with the default name.

Parameters:
className - the class name of the MBean.
Returns:
the object name of the new MBean.
Throws:
LogException - on errors.

adapt

public ObjectName adapt(String className,
                        String ifname)
                 throws LogException
Adapts and registers an MBean with the default name and interface.

Parameters:
className - the class name of the MBean.
ifname - the interface of the MBean.
Returns:
the object name of the new MBean.
Throws:
LogException - on errors.

adapt

public ObjectName adapt(String className,
                        String name,
                        String ifname)
                 throws LogException
Adapts and registers an MBean with a string name and interface.

Parameters:
className - the class name of the MBean.
name - the string name of the MBean.
ifname - the interface of the MBean.
Returns:
the object name of the new MBean.
Throws:
LogException - on errors.

adapt

public ObjectName adapt(String className,
                        String name,
                        String ifname,
                        Object params)
                 throws LogException
Adapts and registers an MBean with a string name, interface and parameters. A single parameter can be given as an object and multiple parameters as a list or an array.

Parameters:
className - the class name of the MBean.
name - the string name of the MBean.
ifname - the interface of the MBean.
params - the parameter to the constructor.
Returns:
the object name of the new MBean.
Throws:
LogException - on errors.

adapt

public ObjectName adapt(String className,
                        String name,
                        String ifname,
                        Object params,
                        Object sign)
                 throws LogException
Adapts and registers an MBean with a string name, interface, parameters and signature. A single parameter can be given as an object and multiple parameters as a list or an array. If the parameters are given as a list, the signature must be null or also a list.

Parameters:
className - the class name of the MBean.
name - the string name of the MBean.
ifname - the interface of the MBean.
params - the parameter to the constructor.
sign - the signature of the parameters.
Returns:
the object name of the new MBean.
Throws:
LogException - on errors.

adapt

public ObjectName adapt(String className,
                        String name,
                        String ifname,
                        String loader,
                        Object params,
                        Object sign)
                 throws LogException
Adapts and registers an MBean with a string name, interface, class