Top Description Fields Constructors Methods
org.apache.tomcat.util.modeler

public Class Registry

extends Object
implements RegistryMBean, MBeanRegistration
Class Inheritance
All Implemented Interfaces
javax.management.MBeanRegistration, org.apache.tomcat.util.modeler.RegistryMBean
Known Direct Subclasses
org.apache.tomcat.util.modeler.NoDescriptorRegistry
Imports
java.io.File, .FileInputStream, .InputStream, java.lang.management.ManagementFactory, java.net.URL, java.util.HashMap, .Hashtable, .List, .Map, javax.management.DynamicMBean, .InstanceNotFoundException, .MBeanAttributeInfo, .MBeanInfo, .MBeanOperationInfo, .MBeanRegistration, .MBeanServer, .MBeanServerFactory, .MalformedObjectNameException, .ObjectName, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.modeler.modules.ModelerSource, org.apache.tomcat.util.res.StringManager

Registry for modeler MBeans. This is the main entry point into modeler. It provides methods to create and manipulate model mbeans and simplify their use. This class is itself an mbean.
Authors
Craig R. McClanahan, Costin Manolache

Field Summary

Modifier and TypeField and Description
private Map<String, ManagedBean>
descriptors

The set of ManagedBean instances for the beans this registry knows about, keyed by name.

private Map<String, ManagedBean>
descriptorsByClass

List of managed beans, keyed by class name

private Object
private final Hashtable<String, Hashtable<String, Integer>>
private final Hashtable<String, int[]>
private static final Log
log

The Log instance to which we will write our log messages.

private static Registry
registry

The registry instance created by our factory method the first time it is called.

private Map<String, URL>
private volatile MBeanServer
server

The MBeanServer instance that we will use to register management beans.

private final Object
private static final StringManager

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
addManagedBean(ManagedBean
The managed bean to be added
bean
)

Add a new bean metadata to the set of beans known to this registry.

public Object

Returns:

Converted value
convertValue
(String
Fully qualified class name of the resulting value
type
,
String
String value to be converted
value
)

Convert a string to object, based on type.

public static synchronized void
private void
findDescriptor(Class<?> beanClass, String type)

Lookup the component descriptor in the package and in the parent packages.

public ManagedBean

Returns:

the managed bean
findManagedBean
(String
Name of the managed bean to be returned. Since 1.1, both short names or the full name of the class can be used.
name
)

Find and return the managed bean definition for the specified bean name, if any; otherwise return null.

public ManagedBean

Returns:

the managed bean
findManagedBean
(Object
The bean
bean
,
Class<?>
The bean class
beanClass
,
String
The registry type
type
)

Find or load metadata.

public synchronized int

Returns:

A unique id for the domain:name combination
getId
(String
Namespace
domain
,
String
Type of the notification
name
)

Implements org.apache.tomcat.util.modeler.RegistryMBean.getId.

Return an int ID for faster access.

public MBeanServer

Returns:

the MBean server
getMBeanServer
()

Factory method to create (if necessary) and return our MBeanServer instance.

public MBeanOperationInfo

Returns:

the operation info for the specified operation
getMethodInfo
(ObjectName
The bean name
oname
,
String
The operation name
opName
)

Find the operation info for a method

public MBeanOperationInfo

Returns:

the operation info for the specified operation
getMethodInfo
(ObjectName
The bean name
oname
,
String
The operation name
opName
,
int
The number of arguments to the method
argCount
)

Find the operation info for a method.

private ModelerSource
public static synchronized Registry

Returns:

the registry
getRegistry
(Object
Unused
key
,
Object
Prevent access to the registry by untrusted components
guard
)

Factory method to create (if necessary) and return our Registry instance.

public String

Returns:

null if metadata about the attribute is not found
getType
(ObjectName
The bean name
oname
,
String
The attribute name
attName
)

Get the type of an attribute of the object, from the metadata.

public void
invoke(List<ObjectName>
list of ObjectName on which we'll invoke the operations
mbeans
,
String
Name of the operation ( init, start, stop, etc)
operation
,
boolean
If false, exceptions will be ignored
failFirst
)

Implements org.apache.tomcat.util.modeler.RegistryMBean.invoke.

Invoke a operation on a list of mbeans.

public List<ObjectName>

Returns:

List of descriptors
load
(String
The source type
sourceType
,
Object
The bean
source
,
String
A type to load
param
)

Load descriptors.

public void
loadDescriptors(String
The package name
packageName
,
ClassLoader
The class loader
classLoader
)

Lookup the component descriptor in the package and in the parent packages.

public void
postDeregister()

Implements javax.management.MBeanRegistration.postDeregister.

Allows the MBean to perform any operations needed after having been unregistered in the MBean server.

public void
postRegister(Boolean
Indicates whether or not the MBean has been successfully registered in the MBean server. The value false means that the registration phase has failed.
registrationDone
)

Implements javax.management.MBeanRegistration.postRegister.

Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.

public void
preDeregister()

Implements javax.management.MBeanRegistration.preDeregister.

Allows the MBean to perform any operations it needs before being unregistered by the MBean server.

public ObjectName
preRegister(MBeanServer
The MBean Server in which the MBean will be registered.
server
,
ObjectName
The object name of the MBean. This name is null if the name parameter to one of the createMBean or registerMBean methods in the MBeanServer interface is null. In that case, this method must return a non-null ObjectName for the new MBean.
name
)

Implements javax.management.MBeanRegistration.preRegister.

Allows the MBean to perform any operations it needs before being registered in the MBean Server.

public void
registerComponent(Object
Object to be registered
bean
,
String
Name used for registration
oname
,
String
The type of the mbean, as declared in mbeans-descriptors. If null, the name of the class will be used. This can be used as a hint or by subclasses.
type
)

Implements org.apache.tomcat.util.modeler.RegistryMBean.registerComponent.

Register a bean by creating a modeler mbean and adding it to the MBeanServer.

public void
registerComponent(Object
The bean
bean
,
ObjectName
The object name
oname
,
String
The registry type
type
)

Register a component

public void
stop()

Implements org.apache.tomcat.util.modeler.RegistryMBean.stop.

Lifecycle method - clean up the registry metadata.

public void
unregisterComponent(String
Name used for unregistration
oname
)

Implements org.apache.tomcat.util.modeler.RegistryMBean.unregisterComponent.

Unregister a component.

public void
unregisterComponent(ObjectName
The bean name
oname
)

Unregister a component.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

descriptorsback to summary
private Map<String, ManagedBean> descriptors

The set of ManagedBean instances for the beans this registry knows about, keyed by name.

descriptorsByClassback to summary
private Map<String, ManagedBean> descriptorsByClass

List of managed beans, keyed by class name

guardback to summary
private Object guard
idDomainsback to summary
private final Hashtable<String, Hashtable<String, Integer>> idDomains
idsback to summary
private final Hashtable<String, int[]> ids
logback to summary
private static final Log log

The Log instance to which we will write our log messages.

registryback to summary
private static Registry registry

The registry instance created by our factory method the first time it is called.

searchedPathsback to summary
private Map<String, URL> searchedPaths
serverback to summary
private volatile MBeanServer server

The MBeanServer instance that we will use to register management beans.

serverLockback to summary
private final Object serverLock
smback to summary
private static final StringManager sm

Constructor Detail

Registryback to summary
protected Registry()

Method Detail

addManagedBeanback to summary
public void addManagedBean(ManagedBean bean)

Add a new bean metadata to the set of beans known to this registry. This is used by internal components.

Parameters
bean:ManagedBean

The managed bean to be added

Since
1.0
convertValueback to summary
public Object convertValue(String type, String value)

Convert a string to object, based on type. Used by several components. We could provide some pluggability. It is here to keep things consistent and avoid duplication in other tasks

Parameters
type:String

Fully qualified class name of the resulting value

value:String

String value to be converted

Returns:Object

Converted value

disableRegistryback to summary
public static synchronized void disableRegistry()
findDescriptorback to summary
private void findDescriptor(Class<?> beanClass, String type)

Lookup the component descriptor in the package and in the parent packages.

findManagedBeanback to summary
public ManagedBean findManagedBean(String name)

Find and return the managed bean definition for the specified bean name, if any; otherwise return null.

Parameters
name:String

Name of the managed bean to be returned. Since 1.1, both short names or the full name of the class can be used.

Returns:ManagedBean

the managed bean

Since
1.0
findManagedBeanback to summary
public ManagedBean findManagedBean(Object bean, Class<?> beanClass, String type) throws Exception

Find or load metadata.

Parameters
bean:Object

The bean

beanClass:Class<?>

The bean class

type:String

The registry type

Returns:ManagedBean

the managed bean

Exceptions
Exception:
An error occurred
getIdback to summary
public synchronized int getId(String domain, String name)

Implements org.apache.tomcat.util.modeler.RegistryMBean.getId.

Return an int ID for faster access. Will be used for notifications and for other operations we want to optimize.

Parameters
domain:String

Namespace

name:String

Type of the notification

Returns:int

A unique id for the domain:name combination

Annotations
@Override
Since
1.1
getMBeanServerback to summary
public MBeanServer getMBeanServer()

Factory method to create (if necessary) and return our MBeanServer instance.

Returns:MBeanServer

the MBean server

getMethodInfoback to summary
public MBeanOperationInfo getMethodInfo(ObjectName oname, String opName)

Find the operation info for a method

Parameters
oname:ObjectName

The bean name

opName:String

The operation name

Returns:MBeanOperationInfo

the operation info for the specified operation

getMethodInfoback to summary
public MBeanOperationInfo getMethodInfo(ObjectName oname, String opName, int argCount) throws InstanceNotFoundException

Find the operation info for a method.

Parameters
oname:ObjectName

The bean name

opName:String

The operation name

argCount:int

The number of arguments to the method

Returns:MBeanOperationInfo

the operation info for the specified operation

Exceptions
InstanceNotFoundException:
If the object name is not bound to an MBean
getModelerSourceback to summary
private ModelerSource getModelerSource(String type) throws Exception
getRegistryback to summary
public static synchronized Registry getRegistry(Object key, Object guard)

Factory method to create (if necessary) and return our Registry instance.

Parameters
key:Object

Unused

guard:Object

Prevent access to the registry by untrusted components

Returns:Registry

the registry

Since
1.1
getTypeback to summary
public String getType(ObjectName oname, String attName)

Get the type of an attribute of the object, from the metadata.

Parameters
oname:ObjectName

The bean name

attName:String

The attribute name

Returns:String

null if metadata about the attribute is not found

Since
1.1
invokeback to summary
public void invoke(List<ObjectName> mbeans, String operation, boolean failFirst) throws Exception

Implements org.apache.tomcat.util.modeler.RegistryMBean.invoke.

Invoke a operation on a list of mbeans. Can be used to implement lifecycle operations.

Parameters
mbeans:List<ObjectName>

list of ObjectName on which we'll invoke the operations

operation:String

Name of the operation ( init, start, stop, etc)

failFirst:boolean

If false, exceptions will be ignored

Annotations
@Override
Exceptions
Exception:
Error invoking operation
Since
1.1
loadback to summary
public List<ObjectName> load(String sourceType, Object source, String param) throws Exception

Load descriptors.

Parameters
sourceType:String

The source type

source:Object

The bean

param:String

A type to load

Returns:List<ObjectName>

List of descriptors

Exceptions
Exception:
Error loading descriptors
loadDescriptorsback to summary
public void loadDescriptors(String packageName, ClassLoader classLoader)

Lookup the component descriptor in the package and in the parent packages.

Parameters
packageName:String

The package name

classLoader:ClassLoader

The class loader

postDeregisterback to summary
public void postDeregister()

Implements javax.management.MBeanRegistration.postDeregister.

Doc from javax.management.MBeanRegistration.postDeregister.

Allows the MBean to perform any operations needed after having been unregistered in the MBean server.

If the implementation of this method throws a RuntimeException or an Error, the MBean Server will rethrow those inside a RuntimeMBeanException or RuntimeErrorException, respectively. However, throwing an exception in postDeregister will not change the state of the MBean: the MBean was already successfully deregistered and will remain so.

This might be confusing for the code calling unregisterMBean(), as it might assume that MBean deregistration has failed. Therefore it is recommended that implementations of postDeregister do not throw Runtime Exceptions or Errors if it can be avoided.

Annotations
@Override
postRegisterback to summary
public void postRegister(Boolean registrationDone)

Implements javax.management.MBeanRegistration.postRegister.

Doc from javax.management.MBeanRegistration.postRegister.

Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.

If the implementation of this method throws a RuntimeException or an Error, the MBean Server will rethrow those inside a RuntimeMBeanException or RuntimeErrorException, respectively. However, throwing an exception in postRegister will not change the state of the MBean: if the MBean was already registered (registrationDone is true), the MBean will remain registered.

This might be confusing for the code calling createMBean() or registerMBean(), as such code might assume that MBean registration has failed when such an exception is raised. Therefore it is recommended that implementations of postRegister do not throw Runtime Exceptions or Errors if it can be avoided.

Parameters
registrationDone:Boolean

Indicates whether or not the MBean has been successfully registered in the MBean server. The value false means that the registration phase has failed.

Annotations
@Override
preDeregisterback to summary
public void preDeregister() throws Exception

Implements javax.management.MBeanRegistration.preDeregister.

Doc from javax.management.MBeanRegistration.preDeregister.

Allows the MBean to perform any operations it needs before being unregistered by the MBean server.

Annotations
@Override
Exceptions
Exception:
This exception will be caught by the MBean server and re-thrown as an MBeanRegistrationException.
preRegisterback to summary
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception

Implements javax.management.MBeanRegistration.preRegister.

Doc from javax.management.MBeanRegistration.preRegister.

Allows the MBean to perform any operations it needs before being registered in the MBean Server. If the name of the MBean is not specified, the MBean can provide a name for its registration. If any exception is raised, the MBean will not be registered in the MBean Server.

Parameters
server:MBeanServer

The MBean Server in which the MBean will be registered.

name:ObjectName

The object name of the MBean. This name is null if the name parameter to one of the createMBean or registerMBean methods in the MBeanServer interface is null. In that case, this method must return a non-null ObjectName for the new MBean.

Returns:ObjectName

The name under which the MBean is to be registered. This value must not be null. If the name parameter is not null, it will usually but not necessarily be the returned value.

Annotations
@Override
Exceptions
Exception:
This exception will be caught by the MBean Server and re-thrown as an MBeanRegistrationException.
registerComponentback to summary
public void registerComponent(Object bean, String oname, String type) throws Exception

Implements org.apache.tomcat.util.modeler.RegistryMBean.registerComponent.

Register a bean by creating a modeler mbean and adding it to the MBeanServer. If metadata is not loaded, we'll look up and read a file named "mbeans-descriptors.ser" or "mbeans-descriptors.xml" in the same package or parent. If the bean is an instance of DynamicMBean. it's metadata will be converted to a model mbean and we'll wrap it - so modeler services will be supported If the metadata is still not found, introspection will be used to extract it automatically. If an mbean is already registered under this name, it'll be first unregistered. If the component implements MBeanRegistration, the methods will be called. If the method has a method "setRegistry" that takes a RegistryMBean as parameter, it'll be called with the current registry.

Parameters
bean:Object

Object to be registered

oname:String

Name used for registration

type:String

The type of the mbean, as declared in mbeans-descriptors. If null, the name of the class will be used. This can be used as a hint or by subclasses.

Annotations
@Override
Exceptions
Exception:
if a registration error occurred
Since
1.1
registerComponentback to summary
public void registerComponent(Object bean, ObjectName oname, String type) throws Exception

Register a component

Parameters
bean:Object

The bean

oname:ObjectName

The object name

type:String

The registry type

Exceptions
Exception:
Error registering component
stopback to summary
public void stop()

Implements org.apache.tomcat.util.modeler.RegistryMBean.stop.

Lifecycle method - clean up the registry metadata. Called from resetMetadata().

Annotations
@Override
Since
1.1
unregisterComponentback to summary
public void unregisterComponent(String oname)

Implements org.apache.tomcat.util.modeler.RegistryMBean.unregisterComponent.

Unregister a component. We'll first check if it is registered, and mask all errors. This is mostly a helper.

Parameters
oname:String

Name used for unregistration

Annotations
@Override
Since
1.1
unregisterComponentback to summary
public void unregisterComponent(ObjectName oname)

Unregister a component. This is just a helper that avoids exceptions by checking if the mbean is already registered

Parameters
oname:ObjectName

The bean name