Class Babel

java.lang.Object
pt.unl.fct.di.novasys.babel.core.Babel

public class Babel extends Object
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 Details

    • getInstance

      public static Babel 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

      public void registerProtocol(GenericProtocol p) throws ProtocolAlreadyExistsException
      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 name
      initializer - 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 file
      args - console parameters
      Returns:
      the configurations built
      Throws:
      IOException - if the provided file does not exist
      InvalidParameterException - if the console parameters are not in the format: prop=value
    • getMillisSinceStart

      public long getMillisSinceStart()