Here is how we add nested plugins. This is adapted from the LifeCyclePlugin
class of our skeleton application (Section ![[*]](crossref.png) ):
):
try
{
    String WORKER_POOL = "worker_pool_1";
    pluginManager().add(ServiceManager.class, false);
    pluginManager().add(WORKER_POOL, WorkerPool.class, null, false);
    
    // Service manager and worker pool need to be initialised before we
    // can use them
    IServiceManager sm
        = (IServiceManager)pluginManager().lookup(IServiceManager.class)[0];
    sm.add("admin", new AdminServiceProvider(), null, false);
    IWorkerPool wp
        = (IWorkerPool)pluginManager().lookup(WORKER_POOL, IWorkerPool.class)[0];
    wp.setRedundancyMin(2);
    wp.setRedundancyMax(4);
    wp.setWorkerType(WORKER_POOL);
    wp.add(InternalFacetCache.class, false);
    wp.add(SkeletonWorkerManager.class, false);
}
catch(BeatrixPluginException e)
{
    // Deal with add failure
}
This piece of code is in a subclass of AbstractPlugin whose pluginManager() method just gets the plugin manager. We see that we add a ServiceManager plugin and a WorkerPool plugin. Neither is initialised, and their init() methods don't need a parameter object.
Then we want to add a plugin to the service manager. The service manager
is a plugin which acts as a collection point for all the services
provided by this netlet. It is also a plugin manager itself. We want
to add a plugin called AdminServiceProvider by which our
application owner can control the application. So we (a) lookup the
service manager plugin. Only this way will we get an initialised instance
of it. Then we (b) add the desired service provider plugin. We add
it under a specific name, admin. See Section ![[*]](crossref.png) for more on how services are implemented.
for more on how services are implemented.
The WorkerPool plugin is also a plugin manager. By adding
plugins to it we define a specific kind of worker netlet--in this
case the worker_pool_1 netlet. Again we (a) look it up and
(b) add plugins to it. But in between we set various criteria for
that worker pool: that there should be between 2 and 4 workers at
any one time and that it is called worker_pool_1. See Section ![[*]](crossref.png) for more on managing workers.
for more on managing workers.
Here is an example of using the entire array returned by lookup, rather than just the first element. It is adapted from code inside the Manager class and shows what happens when it gets a worker-started event. It looks for all those plugins which implement the IWorkerLifeCycle interface, because that indicates an interest in workers' life and death, and calls their workerStarted() methods in turn:
// Variable worker is the netlet which has just started
Object[] p = _plugin_manager.lookup(IWorkerLifeCycle.class);
for(int i=0; i<p.length; i++)
{
    ((IWorkerLifeCycle)p[i]).workerStarted(worker);
}
Nik Silver 2002-03-09