public class ResourceManager extends Object implements Runnable, ResourceManagerMBean
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.
Modifier and Type | Method and Description |
---|---|
static 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 |
getResourceManager() |
static void |
registerResources(Object annotatedObject)
This method will inject resources into annotated fields of
the object instances passed as argument
|
void |
run() |
void |
start() |
String[] |
status()
JMX interface - show resource manager status
|
void |
stop() |
static void |
unregisterAllResources()
Unregister all resources
|
static void |
unregisterResources(Object annotatedObject)
Unregister all resources for an object instance.
|
static void |
unregisterResources(String packageName)
Unregister all resources for a Ncs package.
|
public static ResourceManager getResourceManager()
public static void registerResources(Object annotatedObject) throws IllegalAccessException, ConfException, IOException
annotatedObject
- the instance to inject resources intoIllegalAccessException
ConfException
IOException
public static Maapi getMaapiResource(Object object, Scope scope) throws IllegalAccessException, ConfException, IOException
public static Maapi getMaapiResource(Object object, Scope scope, String qualifier) throws IllegalAccessException, ConfException, IOException
public static Cdb getCdbResource(Object object, ResourceType cdbType, Scope scope) throws IllegalAccessException, ConfException, IOException
public static Cdb getCdbResource(Object object, ResourceType cdbType, Scope scope, String qualifier) throws IllegalAccessException, ConfException, IOException
public static void unregisterResources(Object annotatedObject) throws IllegalAccessException
annotatedObject
.annotatedObject
- the instance which has registered resources
through annotation @Resource(..)IllegalAccessException
public static void unregisterResources(String packageName)
packageName
- name of the Ncs packageIllegalAccessException
public static void unregisterAllResources() throws IllegalAccessException
IllegalAccessException
public void start()
public void stop()
public String[] status()
ResourceManagerMBean
status
in interface ResourceManagerMBean