copyright The Portico Project 2008.

org.portico.core
Class BootstrapManager

java.lang.Object
  extended by org.portico.core.BootstrapManager

public class BootstrapManager
extends Object

This class contains and allows for the management of a collection of Bootstrap instances for a given RTIExec. In order ensure that the MulticastRegistry starts before any bootstraps (as they may want to use it), an instance of that class is contained within the manager. It can be obtained by calling the getMulticastRegistry() method.


Field Summary
private  com.lbf.commons.messaging.IMessageHandler bootstrapHandler
           
private  com.lbf.commons.component.ComponentGroup<Bootstrap> group
           
protected  org.apache.log4j.Logger logger
           
protected  RTIExec rti
           
 
Constructor Summary
BootstrapManager(RTIExec execution)
          Create a new bootstrap manager for the given execution.
 
Method Summary
private  int _startBootstraps(boolean strict)
           
 boolean containsBootstrap(String name)
          Returns true if this manager contains a bootstrap by the given name, false otherwise.
private  com.lbf.commons.utils.Bag<String,Object> convert(com.lbf.commons.utils.Bag<String,?> bag)
          Converts a Bag
 Set<Bootstrap> getAllBootstraps()
          Get a list of all the bootstraps contained in this manager
 MulticastRegistry getMulticastRegistry()
          Fetch the contained MulticastRegistry.
 void notifyBootstrapsFederationCreated(Federation theFederation)
          Notify all the contained and active bootstraps that a new federation has been created, passing the instance that was started.
 void notifyBootstrapsFederationDestroyed(String federationName)
          Notify all the contained and active bootstraps taht a federation with the provided name has been destroyed.
 void registerBootstrap(Bootstrap bootstrap, com.lbf.commons.utils.Bag<String,?> config)
          Register a bootstrap with the manager.
 Bootstrap removeBootstrap(String bootstrap)
          Remove the bootstrap of the given name from the group and return it.
 int size()
          Return the number of bootstraps registered in this manager
private  void startBootstrap(Bootstrap bootstrap)
          Starts the given bootstrap.
 int startBootstraps()
          This method will attempt to start all the contains bootstraps that have not yet been started.
 int startBootstrapsStrict()
          This method is the same as startBootstraps() in that it will only attempt to start any bootstraps that have not already been started.
 int stopBootstraps()
          This method will ask all the contained bootstraps to shutdown and cleanup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

group

private com.lbf.commons.component.ComponentGroup<Bootstrap> group

bootstrapHandler

private com.lbf.commons.messaging.IMessageHandler bootstrapHandler

rti

protected RTIExec rti

logger

protected org.apache.log4j.Logger logger
Constructor Detail

BootstrapManager

public BootstrapManager(RTIExec execution)
                 throws JException
Create a new bootstrap manager for the given execution. If the execution is null, an exception will be thrown.

Throws:
JException
Method Detail

getMulticastRegistry

public MulticastRegistry getMulticastRegistry()
Fetch the contained MulticastRegistry.


notifyBootstrapsFederationCreated

public void notifyBootstrapsFederationCreated(Federation theFederation)
Notify all the contained and active bootstraps that a new federation has been created, passing the instance that was started.


notifyBootstrapsFederationDestroyed

public void notifyBootstrapsFederationDestroyed(String federationName)
Notify all the contained and active bootstraps taht a federation with the provided name has been destroyed.


registerBootstrap

public void registerBootstrap(Bootstrap bootstrap,
                              com.lbf.commons.utils.Bag<String,?> config)
                       throws JException
Register a bootstrap with the manager. The given configuration properties will be passed to the bootstrap by the manager on startup, however, if none are required, the config parameter can be null. If the bootstrap is null or the bootstrap component can not be registered, an exception will be thrown.

Parameters:
bootstrap - The bootstrap to register with the manager
config - The set of configuration properties the manager should pass to the bootstrap on startup. NOTE: This *can* be null.
Throws:
JException - If the bootstrap is null or there is a problem registering the bootstrap

removeBootstrap

public Bootstrap removeBootstrap(String bootstrap)
Remove the bootstrap of the given name from the group and return it. If the removal is successful, return the removed component, else, return null.

Parameters:
bootstrap - The name of the bootstrap to remove from the group
Returns:
The bootstrap that was removed (or null if none was removed)

getAllBootstraps

public Set<Bootstrap> getAllBootstraps()
Get a list of all the bootstraps contained in this manager


size

public int size()
Return the number of bootstraps registered in this manager


containsBootstrap

public boolean containsBootstrap(String name)
Returns true if this manager contains a bootstrap by the given name, false otherwise.


startBootstraps

public int startBootstraps()
This method will attempt to start all the contains bootstraps that have not yet been started. This method is safe to call at any time as it will only attempt to start those bootstraps that have not already been started. If any fail to start, a message will be logged, but no exception will be thrown (if you require this, see startBootstrapsStrict().

The number of bootstraps successfully started will be returned (could be 0 if all were already started. 0 does NOT indicate an error).

NOTE: If a bootstrap does not start due to a configuration failure, it will be automatically removed.

Returns:
The number of bootstraps that configured and started happily

startBootstrapsStrict

public int startBootstrapsStrict()
                          throws JException
This method is the same as startBootstraps() in that it will only attempt to start any bootstraps that have not already been started. Like the previous method, if any fail to start, a message will be logged. UNLIKE startBootstraps(), if any fail to start, an exception will be thrown.

Returns:
The number of bootstraps that were started.
Throws:
JException - If *any* of the "unstarted" bootstraps fail to start happily

_startBootstraps

private int _startBootstraps(boolean strict)
                      throws JException
Throws:
JException

startBootstrap

private void startBootstrap(Bootstrap bootstrap)
                     throws com.lbf.commons.config.ConfigurationException,
                            com.lbf.commons.component.ComponentException
Starts the given bootstrap. It will fetch its configuration properties and add to them a link to the bootstrap handler and the RTIExec it is a part of. It will then attempt to configure and execute it.

Parameters:
bootstrap - The bootstrap to start
Throws:
com.lbf.commons.config.ConfigurationException - If there is a problem during the configuration process
com.lbf.commons.component.ComponentException - If there is a problem starting the bootstrap

stopBootstraps

public int stopBootstraps()
                   throws JException
This method will ask all the contained bootstraps to shutdown and cleanup. If any of them fail to shutdown OR cleanup happily, a message will be logged and an exception will be thrown.

This method will return a count of the number of bootstraps that were stopped successfully. NOTE: If a bootstrap fails to cleanup, it is still counted as stopped (thus, all the registered bootstraps could stop "successfully", but an exception could still be thrown if any of them fail to clean up without exception).

If an exception is thrown, the message contains a count of all the bootstraps that did happen to shutdown without error (but not clean up).

Returns:
The number of bootstraps that were stopped
Throws:
JException - If any of the contained bootstraps fail to shutdown or cleanup

convert

private com.lbf.commons.utils.Bag<String,Object> convert(com.lbf.commons.utils.Bag<String,?> bag)
Converts a Bag to a Bag


copyright The Portico Project 2008.