Project JXTA

net.jxta.impl.util
Class ModuleManager

java.lang.Object
  extended by net.jxta.impl.util.ModuleManager

public class ModuleManager
extends Object

Module Manager. This class allows to manage modules to be loaded, started and stopped within a PeerGroup. Modules that are loaded using the ModuleManager do not need to be listed within the PeerGroup advertisement, nor do they have to have published their ModuleSpec and ModuleImpl advertisements: the ModuleManager takes care of this task. However, other peers which may want to load the Module will also have to use its own loader (or the ModuleManager itself, of course): the ModuleManager only manages Modules on the local peer. The Module Manager allows, as an option, to use an application provided class loader. The default class loader is the PeerGroup class loader. The following example shows how to use the ModuleManager:

      // Get the peergroup
      PeerGroup group = getMyPeerGroup();
      // Get the ModuleManager
      ModuleManager moduleManager = ModuleManager.getModuleManager (group);

      // Is the Module already loaded ?
      Module module = moduleManager.lookupModule ("SampleModule");
      if (module == null) {
          // SampleModue is not loaded yet. Load it now.
          module = moduleManager.loadModule ( "SampleModule", "net.jxta.app.SampleModule.SampleModule");
      }

      // Start SampleModule
      moduleManager.startModule ("SampleModule", moduleArgs);
 


Nested Class Summary
static interface ModuleManager.ModuleManagerLoader
          ModuleManagerLoader interface.
 
Method Summary
 void createServiceAdvertisement(PeerGroup group, String moduleName, String description, String moduleSpecURI, String moduleCode, String moduleCodeURI, ModuleClassID mcID, ModuleSpecID msID, String code, Advertisement serviceAdv, long localTTL, long remoteTTL)
          Creates a Module Class, Spec, and Impl advertisements, and adds the service Advertisement as part of the Module Impl Advertisement, and publishes the advertisements in local cache
static ModuleManager getModuleManager(PeerGroup group)
          getModuleManager This method is used in order to get the instance of the ModuleManager for a given PeerGroup. getModuleManager will create a new instance automatically if there is no instance for the given PeerGroup.
 Advertisement getServiceAdvertisement(PeerGroup group, ModuleImplAdvertisement mia, String advertismentType)
          Retreives a Service Advertisement from a module impl advertisement
 Module loadModule(String moduleName, ModuleManager.ModuleManagerLoader loader)
          loadModule Loads a Module.
 Module loadModule(String moduleName, String moduleCode)
          loadModule Loads a Module.
 Module lookupModule(String moduleName)
          lookupModule Get the Module from its symbolic name.
 void startModule(String moduleName, String[] args)
          startModule This method is invoked by the application to start a previously loaded module.
 void stopModule(String moduleName)
          stopModule This method is invoked by the application to stop a running module.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

startModule

public void startModule(String moduleName,
                        String[] args)
startModule This method is invoked by the application to start a previously loaded module.

Parameters:
moduleName - is the symbolic name of the module.
args - is an array of String containing optional arguments for the module. This array is passed directly to the startApp (String[] ) method of the Module.

stopModule

public void stopModule(String moduleName)
stopModule This method is invoked by the application to stop a running module.

Parameters:
moduleName - is the symbolic name of the module.

getModuleManager

public static ModuleManager getModuleManager(PeerGroup group)
getModuleManager This method is used in order to get the instance of the ModuleManager for a given PeerGroup. getModuleManager will create a new instance automatically if there is no instance for the given PeerGroup.

Parameters:
group - the PeerGroup for which the ModuleManager is asked.
Returns:
the ModuleManager instance for the given PeerGroup.

lookupModule

public Module lookupModule(String moduleName)
lookupModule Get the Module from its symbolic name.

Parameters:
moduleName - symbolic name of the Module
Returns:
the Module for the given name. null is returned if there is no module of the given name.

loadModule

public Module loadModule(String moduleName,
                         ModuleManager.ModuleManagerLoader loader)
loadModule Loads a Module. A class loaded is provided by the application. If the module has already been loaded, the existing Module is returned.

Parameters:
moduleName - symbolic name of the Module
loader - application provided class loader
Returns:
the Module for the given name. null is returned if the module could not be loaded

loadModule

public Module loadModule(String moduleName,
                         String moduleCode)
loadModule Loads a Module. The default PeerGroup class loader will be used. The class must be within the CLASSPATH of the platform. If the module has already been loaded, the existing Module is returned.

Parameters:
moduleName - symbolic name of the Module
moduleCode - the name of the class to be loaded.
Returns:
the Module for the given name. null is returned if the module could not be loaded

createServiceAdvertisement

public void createServiceAdvertisement(PeerGroup group,
                                       String moduleName,
                                       String description,
                                       String moduleSpecURI,
                                       String moduleCode,
                                       String moduleCodeURI,
                                       ModuleClassID mcID,
                                       ModuleSpecID msID,
                                       String code,
                                       Advertisement serviceAdv,
                                       long localTTL,
                                       long remoteTTL)
                                throws IOException
Creates a Module Class, Spec, and Impl advertisements, and adds the service Advertisement as part of the Module Impl Advertisement, and publishes the advertisements in local cache

Parameters:
group - group
moduleName - module name
description - module description
moduleSpecURI - module spec uri
moduleCode - module code
moduleCodeURI - module code uri
mcID - module class id
msID - module spec id
serviceAdv - service advertisement
localTTL - local cache lifetime in ms
remoteTTL - remote cache lifetime in ms
Throws:
IOException - if an io error occurs

getServiceAdvertisement

public Advertisement getServiceAdvertisement(PeerGroup group,
                                             ModuleImplAdvertisement mia,
                                             String advertismentType)
                                      throws IOException
Retreives a Service Advertisement from a module impl advertisement

Parameters:
group - peer group
mia - ModuleImplAdvertisement
advertismentType - service advertisment string Type
Returns:
The service Advertisement
Throws:
IOException - if an io error occurs

JXTA J2SE