Package pt.unl.fct.di.novasys.babel.core
Class Babel
java.lang.Object
pt.unl.fct.di.novasys.babel.core.Babel
The Babel class provides applications with a Runtime that supports
the execution of protocols.
An example of how to use the class follows:
Babel babel = Babel.getInstance(); //initialize babel Properties configProps = babel.loadConfig("network_config.properties", args); INetwork net = babel.getNetworkInstance(); //Define protocols ProtocolA protoA = new ProtocolA(net); protoA.init(configProps); ProtocolB protoB = new ProtocolB(net); protoB.init(configProps); //Register protocols babel.registerProtocol(protoA); babel.registerProtocol(protoB); //subscribe to notifications protoA.subscribeNotification(protoA.NOTIFICATION_ID, this); //start babel runtime babel.start(); //Application Logic
For more information on protocol implementation with Babel:
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Babel
Returns the instance of the Babel Runtimelong
static Properties
loadConfig
(String[] args, String defaultConfigFile) Reads either the default or the given properties file (the file can be given with the argument -config) Builds a configuration file with the properties from the file and then merges ad-hoc properties given in the arguments.void
registerChannelInitializer
(String name, ChannelInitializer<? extends IChannel<BabelMessage>> initializer) Registers a new channel in babelvoid
Register a protocol in Babelvoid
start()
Begins the execution of all protocols registered in Babel
-
Method Details
-
getInstance
Returns the instance of the Babel Runtime- Returns:
- the Babel instance
-
start
public void start()Begins the execution of all protocols registered in Babel -
registerProtocol
Register a protocol in Babel- Parameters:
p
- the protocol to registered- Throws:
ProtocolAlreadyExistsException
- if a protocol with the same id or name has already been registered
-
registerChannelInitializer
public void registerChannelInitializer(String name, ChannelInitializer<? extends IChannel<BabelMessage>> initializer) Registers a new channel in babel- Parameters:
name
- the channel nameinitializer
- the channel initializer
-
loadConfig
public static Properties loadConfig(String[] args, String defaultConfigFile) throws IOException, InvalidParameterException Reads either the default or the given properties file (the file can be given with the argument -config) Builds a configuration file with the properties from the file and then merges ad-hoc properties given in the arguments.Argument properties should be provided as: propertyName=value
- Parameters:
defaultConfigFile
- the path to the default properties fileargs
- console parameters- Returns:
- the configurations built
- Throws:
IOException
- if the provided file does not existInvalidParameterException
- if the console parameters are not in the format: prop=value
-
getMillisSinceStart
public long getMillisSinceStart()
-