Package com.tailf.ncs

Class ResourceManager

Object
com.tailf.ncs.ResourceManager
All Implemented Interfaces:
ResourceManagerMBean, Runnable

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.