Class Registry
java.lang.Object
org.apache.tomcat.util.modeler.Registry
- All Implemented Interfaces:
MBeanRegistration
,RegistryMBean
- Direct Known Subclasses:
NoDescriptorRegistry
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.
- Author:
- Craig R. McClanahan, Costin Manolache
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addManagedBean
(ManagedBean bean) Add a new bean metadata to the set of beans known to this registry.convertValue
(String type, String value) Convert a string to object, based on type.static void
findManagedBean
(Object bean, Class<?> beanClass, String type) Find or load metadata.findManagedBean
(String name) Find and return the managed bean definition for the specified bean name, if any; otherwise returnnull
.int
Return an int ID for faster access.Factory method to create (if necessary) and return ourMBeanServer
instance.getMethodInfo
(ObjectName oname, String opName) Find the operation info for a methodgetMethodInfo
(ObjectName oname, String opName, int argCount) Find the operation info for a method.static Registry
getRegistry
(Object key, Object guard) Factory method to create (if necessary) and return ourRegistry
instance.getType
(ObjectName oname, String attName) Get the type of an attribute of the object, from the metadata.void
invoke
(List<ObjectName> mbeans, String operation, boolean failFirst) Invoke a operation on a list of mbeans.Load descriptors.void
loadDescriptors
(String packageName, ClassLoader classLoader) Lookup the component descriptor in the package and in the parent packages.void
void
postRegister
(Boolean registrationDone) void
preRegister
(MBeanServer server, ObjectName name) void
registerComponent
(Object bean, String oname, String type) Register a bean by creating a modeler mbean and adding it to the MBeanServer.void
registerComponent
(Object bean, ObjectName oname, String type) Register a componentvoid
stop()
Lifecycle method - clean up the registry metadata.void
unregisterComponent
(String oname) Unregister a component.void
unregisterComponent
(ObjectName oname) Unregister a component.
-
Constructor Details
-
Registry
protected Registry()
-
-
Method Details
-
getRegistry
-
disableRegistry
public static void disableRegistry() -
stop
public void stop()Lifecycle method - clean up the registry metadata. Called from resetMetadata().- Specified by:
stop
in interfaceRegistryMBean
- Since:
- 1.1
-
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.- Specified by:
registerComponent
in interfaceRegistryMBean
- Parameters:
bean
- Object to be registeredoname
- Name used for registrationtype
- 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.- Throws:
Exception
- if a registration error occurred- Since:
- 1.1
-
unregisterComponent
Unregister a component. We'll first check if it is registered, and mask all errors. This is mostly a helper.- Specified by:
unregisterComponent
in interfaceRegistryMBean
- Parameters:
oname
- Name used for unregistration- Since:
- 1.1
-
invoke
Invoke a operation on a list of mbeans. Can be used to implement lifecycle operations.- Specified by:
invoke
in interfaceRegistryMBean
- Parameters:
mbeans
- list of ObjectName on which we'll invoke the operationsoperation
- Name of the operation ( init, start, stop, etc)failFirst
- If false, exceptions will be ignored- Throws:
Exception
- Error invoking operation- Since:
- 1.1
-
getId
Return an int ID for faster access. Will be used for notifications and for other operations we want to optimize.- Specified by:
getId
in interfaceRegistryMBean
- Parameters:
domain
- Namespacename
- Type of the notification- Returns:
- A unique id for the domain:name combination
- Since:
- 1.1
-
addManagedBean
Add a new bean metadata to the set of beans known to this registry. This is used by internal components.- Parameters:
bean
- The managed bean to be added- Since:
- 1.0
-
findManagedBean
Find and return the managed bean definition for the specified bean name, if any; otherwise returnnull
.- Parameters:
name
- 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:
- the managed bean
- Since:
- 1.0
-
getType
Get the type of an attribute of the object, from the metadata.- Parameters:
oname
- The bean nameattName
- The attribute name- Returns:
- null if metadata about the attribute is not found
- Since:
- 1.1
-
getMethodInfo
Find the operation info for a method- Parameters:
oname
- The bean nameopName
- The operation name- Returns:
- the operation info for the specified operation
-
getMethodInfo
public MBeanOperationInfo getMethodInfo(ObjectName oname, String opName, int argCount) throws InstanceNotFoundException Find the operation info for a method.- Parameters:
oname
- The bean nameopName
- The operation nameargCount
- The number of arguments to the method- Returns:
- the operation info for the specified operation
- Throws:
InstanceNotFoundException
- If the object name is not bound to an MBean
-
unregisterComponent
Unregister a component. This is just a helper that avoids exceptions by checking if the mbean is already registered- Parameters:
oname
- The bean name
-
getMBeanServer
Factory method to create (if necessary) and return ourMBeanServer
instance.- Returns:
- the MBean server
-
findManagedBean
-
convertValue
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
- Fully qualified class name of the resulting valuevalue
- String value to be converted- Returns:
- Converted value
-
load
-
registerComponent
Register a component- Parameters:
bean
- The beanoname
- The object nametype
- The registry type- Throws:
Exception
- Error registering component
-
loadDescriptors
Lookup the component descriptor in the package and in the parent packages.- Parameters:
packageName
- The package nameclassLoader
- The class loader
-
preRegister
- Specified by:
preRegister
in interfaceMBeanRegistration
- Throws:
Exception
-
postRegister
- Specified by:
postRegister
in interfaceMBeanRegistration
-
preDeregister
- Specified by:
preDeregister
in interfaceMBeanRegistration
- Throws:
Exception
-
postDeregister
public void postDeregister()- Specified by:
postDeregister
in interfaceMBeanRegistration
-