Class ResourceManager
- All Implemented Interfaces:
ResourceManagerMBean
,Runnable
The NCS resource manager able to create Maapi and Cdb objects connected to the NCS server. The resource manager will then inject these to annotated fields in known java class instances. Known instances are either from classes that are referred to in package component meta data, or instances that are passed to the ResourceManager via the registerResources method. An example of an cdb instance which is a unique instance for every object instance of the container class:
public class MyContainerClass { @Resource(type=ResourceType.CDB, scope=Scope.INSTANCE) private Cdb cdb; ... }
If this class is not referred to in a package-meta-data.xml for some Ncs package, then the resource manager registration has to be manual:
MyContainerClass myC = new MyContainerClass(); ResourceManager.registerResources(myC);
It is also possible have the same resource shared by several container instances within the same NCS package. In this case the resource should be of type CONTEXT and have a qualifier name which can be used as reference:
public class MyContainerClass1 { @Resource(type=ResourceType.MAAPI, scope=Scope.CONTEXT, qualifier="MyMaapi") private Maapi theMaapi; ... } public class MyContainerClass2 { @Resource(type=ResourceType.MAAPI, scope=Scope.CONTEXT, qualifier="MyMaapi") private Maapi aMaapi; ... }
In this case all instances of both class MyContainerClass1 and MyContainerClass2 will share the same unique Maapi instance.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Cdb
getCdbResource
(Object object, ResourceType cdbType, Scope scope) static Cdb
getCdbResource
(Object object, ResourceType cdbType, Scope scope, String qualifier) static Maapi
getMaapiResource
(Object object, Scope scope) static Maapi
getMaapiResource
(Object object, Scope scope, String qualifier) static ResourceManager
static void
registerResources
(Object annotatedObject) This method will inject resources into annotated fields of the object instances passed as argumentvoid
run()
void
start()
String[]
status()
JMX interface - show resource manager statusvoid
stop()
static void
Unregister all resourcesstatic void
unregisterResources
(Object annotatedObject) Unregister all resources for an object instance.static void
unregisterResources
(String packageName) Unregister all resources for a Ncs package.
-
Method Details
-
getResourceManager
-
registerResources
public static void registerResources(Object annotatedObject) throws IllegalAccessException, ConfException, IOException This method will inject resources into annotated fields of the object instances passed as argument- Parameters:
annotatedObject
- the instance to inject resources into- Throws:
IllegalAccessException
ConfException
IOException
-
getMaapiResource
public static Maapi getMaapiResource(Object object, Scope scope) throws IllegalAccessException, ConfException, IOException -
getMaapiResource
public static Maapi getMaapiResource(Object object, Scope scope, String qualifier) throws IllegalAccessException, ConfException, IOException -
getCdbResource
public static Cdb getCdbResource(Object object, ResourceType cdbType, Scope scope) throws IllegalAccessException, ConfException, IOException -
getCdbResource
public static Cdb getCdbResource(Object object, ResourceType cdbType, Scope scope, String qualifier) throws IllegalAccessException, ConfException, IOException -
unregisterResources
Unregister all resources for an object instance. If the instance have no registered resources, this method is a noop meaning it will return without affecting theannotatedObject
.- Parameters:
annotatedObject
- the instance which has registered resources through annotation @Resource(..)- Throws:
IllegalAccessException
-
unregisterResources
Unregister all resources for a Ncs package. If the package have no registered resources, this method is a noop.- Parameters:
packageName
- name of the Ncs package
-
unregisterAllResources
Unregister all resources- Throws:
IllegalAccessException
-
run
public void run() -
start
public void start() -
stop
public void stop() -
status
Description copied from interface:ResourceManagerMBean
JMX interface - show resource manager status- Specified by:
status
in interfaceResourceManagerMBean
-