|
copyright The Portico Project 2008. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lbf.commons.component.AbstractComponent
org.portico.core.Bootstrap
public abstract class Bootstrap
A Bootstrap
is a component that is notified when the Portico RTI server is starting up
and shutting down. Generally speaking, Bootstrap
subclasses have been used by the
communications bindings as a way to do any setup and cleanup they require as the RTI is starting
or stopping. For example, a socket-based binding would need to start a Server Socket on startup
to listen for incoming connections. As Bootstrap
s are notified when the RTI starts and
stops, this is the perfect place to create/destroy the socket.
Bootstrap
facility was created,
they are not the only use. Rather, a Bootstrap
could be used for ANY facility that need
to startup or shutdown with the RTI server.
Bootstraps
Each Bootstrap
has a defined lifecycle. All bootstraps *MUST* extend from this class and
provide implementations of the startBootstrap()
and stopBootstrap()
methods.
Although it is not mandatory, Bootstrap
s can also provide an implementation of the
configureBootstrap(Bag)
methods. The bag of properties passed to that method will
contain with them the XML properties provided with the bootstrap configuration (if it was XML
based).
The lifecycle of a bootstrap is (this is the same as an IComponent):
configureBootstrap(Bag)
startBootstrap()
stopBootstrap()
ServerSocket
for incoming connections) are
long-lived, requiring a dedicated thread. Under no circumstances should the
startBootstrap()
method block for any serious length of time. If such behaviour is
needed, use startBootstrap()
to start a new worker thread (or worker threads).
Configuration
Bootstraps are declared in XML within the Portic configuration file or a plugin configuration
file and they look something like this:
<portico> <bootstraps> <bootstrap name="jsop" class="org.portico.binding.jsop.rti.JSOPBootstrap"/> </bootstraps> </portico>However, should additional configuration parameters be needed, they can be passed to the
Bootstrap
in one of two ways.
Firstly, they could be provided as system properties, which the Bootstrap
could then
look for during either configureBootstrap(Bag)
or startBootstrap()
. This
approach is clean and requires no real extra effort beyond setting the system properties.
The second approach is to provide the information as part of the bootstrap XML declaration. The
listing below shows how this would be done for the bootstrap declaration above:
<portico> <bootstraps> <bootstrap name="jsop" class="org.portico.binding.jsop.rti.JSOPBootstrap"> <configuration> <endpoint port="20913"/> </configuration> </bootstrap> </bootstraps> </portico>Here, a child element of the bootstrap called
configuration
is provided. Beneath
it can be any well-formed XML. If this information exists, it is turned into name-value pairs
and put into the Bag of information passed to the configureBootstrap(Bag)
method. Using
the example above, the following code would print out the string "20913":
public void configureBootstrap( BagIMPORTANT NOTE Bootstrap implementations must provide a no-arg constructor so that they can be easily instantiated via reflection. The no-arg constructor should pass a default bootstrap name to the constructor of this abstract class.properties ) throws ConfigurationException { System.out.println( properties.get( "configuration.endpoint.port" ); }
Field Summary | |
---|---|
protected com.lbf.commons.messaging.IMessageHandler |
bootstrapHandler
|
static String |
CONFIG_HANDLER
|
static String |
CONFIG_RTIEXEC
|
protected RTIExec |
execution
|
protected org.apache.log4j.Logger |
logger
|
Fields inherited from class com.lbf.commons.component.AbstractComponent |
---|
executing, name, shutdown |
Constructor Summary | |
---|---|
protected |
Bootstrap(String name)
Create a new bootstrap with the given name. |
Method Summary | |
---|---|
void |
configure(com.lbf.commons.utils.Bag<String,?> properties)
This method extracts from the given properties a number of requsite components (such as the bootstrap handler, to which create/join/destroy requests should be passed). |
void |
configureBootstrap(com.lbf.commons.utils.Bag<String,?> properties)
Called when the Bootstrap is being configured. |
void |
execute()
This method will invoke the startBootstrap() method, the implementation of which
has to be provided by the concrete class. |
void |
federationCreated(Federation theFederation)
This method is called by the RTI when a new Federation has been created. |
void |
federationDestroyed(String federationName)
This method is called by the RTI when a federation has been destroyed. |
com.lbf.commons.messaging.IMessageHandler |
getBootstrapHandler()
Get the bootstrap handler. |
RTIExec |
getExecution()
Gets the RTIExec that this bootstrap is contained within. |
org.apache.log4j.Logger |
getLogger()
Get the logger that should be used for all messages. |
void |
shutdown()
This method will invoke the stopBootstrap() method, the implementation of which
has to be provided by the concrete class. |
abstract void |
startBootstrap()
This method tells the component that it is time to start up. |
abstract void |
stopBootstrap()
This method tells the component that it is time to shut down. |
Methods inherited from class com.lbf.commons.component.AbstractComponent |
---|
cleanup, getName, isExecuting, isShutdown, setName |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String CONFIG_HANDLER
public static final String CONFIG_RTIEXEC
protected com.lbf.commons.messaging.IMessageHandler bootstrapHandler
protected RTIExec execution
protected org.apache.log4j.Logger logger
Constructor Detail |
---|
protected Bootstrap(String name)
Method Detail |
---|
public abstract void startBootstrap() throws com.lbf.commons.component.ComponentException
ComponentException
should be thrown to indicate that the bootstrap didn't
start. This method is mandatory in all Bootstrap
s
com.lbf.commons.component.ComponentException
public abstract void stopBootstrap() throws com.lbf.commons.component.ComponentException
ComponentException
should be thrown to indicate that the bootstrap didn't
stop properly. This method is mandatory in all Bootstrap
s
com.lbf.commons.component.ComponentException
public void configureBootstrap(com.lbf.commons.utils.Bag<String,?> properties) throws com.lbf.commons.config.ConfigurationException
Bootstrap
is being configured. If a Bootstrap
is created from
an XML configuration file and additional configuration data is provided, the contained
properties will have that information (but it will be flattened). See the class-level
comments for more details. Overriding this method is NOT mandatory.
com.lbf.commons.config.ConfigurationException
public com.lbf.commons.messaging.IMessageHandler getBootstrapHandler()
RTIExec
.
public RTIExec getExecution()
RTIExec
that this bootstrap is contained within.
public org.apache.log4j.Logger getLogger()
public void federationCreated(Federation theFederation)
Federation
has been created. The
Federation
instance that was created is provided. Override this method in your
Bootstrap implementations if you want to receive notifications when a federation is created.
The implementation in this class takes no action on this event (it is empty).
public void federationDestroyed(String federationName)
federationCreated(Federation)
method. As the federation has been destroyed,
only the name of the federation is provided (you really shouldn't be accessing the destoryed
federation instance. If you want to receive these notifications, override this method.
The implementation in this class takes no action on this event (it is empty).
public final void configure(com.lbf.commons.utils.Bag<String,?> properties) throws com.lbf.commons.config.ConfigurationException
configureBootstrap(Bag)
, passing the properties it was given.
NOTE: You cannot provide an implementation of this method. If you want to fetch
configuration properties, use configureBootstrap(Bag)
.
configure
in interface com.lbf.commons.component.IComponent
configure
in class com.lbf.commons.component.AbstractComponent
com.lbf.commons.config.ConfigurationException
public final void execute() throws com.lbf.commons.component.ComponentException
startBootstrap()
method, the implementation of which
has to be provided by the concrete class. It will catch any exceptions that are thrown and
treat such a condition as a failure to start. It also performs the necessary management
logic for the IComponent.
execute
in interface com.lbf.commons.component.IComponent
execute
in class com.lbf.commons.component.AbstractComponent
com.lbf.commons.component.ComponentException
public final void shutdown() throws com.lbf.commons.component.ComponentException
stopBootstrap()
method, the implementation of which
has to be provided by the concrete class. It will catch any exceptions that are thrown and
treat such a condition as a failure to shutdown. It also performs the necessary management
logic for the IComponent.
shutdown
in interface com.lbf.commons.component.IComponent
shutdown
in class com.lbf.commons.component.AbstractComponent
com.lbf.commons.component.ComponentException
|
copyright The Portico Project 2008. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |