planet.generic.commonapi
Class GenericApp

java.lang.Object
  extended byplanet.generic.commonapi.GenericApp
Direct Known Subclasses:
BroadcastTest, DHTPeerTest, DHTTest, DHTTest, GenSerializedFile, GMLTopologyTest, ScribePeerTest, SerializeNetwork, TestAppFactory, TestEndPointFactory, TestIdFactory, TestNetFactory, TestNodeFactory, TestNodeHandleFactory, TestPool

public class GenericApp
extends java.lang.Object

This class only attemps to help to programmers make more simple the initialization of the simulator context. There are two ways to initialize the context:

One
The new main application has to extend this GenericApp and includes in theirs constructors the sentence super(...) with the desired arguments. For example:

 ....
 
 public NewTest() throws InitializationException {
     super("../conf/master2.properties","TEST_ONE",false,false,false,false);
 
 ....
 
See the constructor description for more details on the arguments.

Two
To include at first these lines (before any other simulator related statement):
   //FIRST: complete Properties initialization
   Properties.init(masterPropertiesFile, masterPropertyName);
   if (activateApplicationLevel)
       Properties.activateApplicationLevelAttributes();
   if (activateEvents)
       Properties.activateEventsAttributes();
   if (activateResults)
       Properties.activateResultsAttributes();
   if (activateSerialization)
       Properties.activateSerializationAttributes();

   //SECOND: GenericFactory initialization
   GenericFactory.init();
 
   //THIRD: making postinitialization
   Properties.postinit();
   GenericFactory.postinit();
 
where the masterPropertiesFile is the main cofiguration file, with the desired properties filename with the current configuration, and masterPropertyName is the key to load the configuration and runs the current test.

Author:
Jordi Pujol 08-jul-2005

Constructor Summary
GenericApp(java.lang.String masterPropertyName, boolean activateApplicationLevel, boolean activateEvents, boolean activateResults, boolean activateSerialization)
          Make the complete initialization of the simulator context, according to the arguments.
GenericApp(java.lang.String masterPropertiesFile, java.lang.String masterPropertyName, boolean activateApplicationLevel, boolean activateEvents, boolean activateResults, boolean activateSerialization)
          Make the complete initialization of the simulator context, according to the arguments.
 
Method Summary
static void printNetwork(Network network)
          Using the attribute planet.util.Properties.simulatorPrintLevel prints out (or not) the whole network.
static void restart(boolean activateApplicationLevel, boolean activateEvents, boolean activateResults, boolean activateSerialization)
          Make an update of the current simulator context using the actual configuration into the planet.util.Properties.
static void start(java.lang.String masterPropertiesFile, java.lang.String masterPropertyName, boolean activateApplicationLevel, boolean activateEvents, boolean activateResults, boolean activateSerialization)
          Make the complete initialization of the simulator context, according to the arguments.
static java.lang.String timeElapsedInSeconds(long firstTime, long lastTime)
          Shows in Y.XXX string format, the seconds elapsed between firstTime and lastTime, where 'Y' are the seconds, and 'XXX' the milliseconds ones.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericApp

public GenericApp(java.lang.String masterPropertiesFile,
                  java.lang.String masterPropertyName,
                  boolean activateApplicationLevel,
                  boolean activateEvents,
                  boolean activateResults,
                  boolean activateSerialization)
           throws InitializationException
Make the complete initialization of the simulator context, according to the arguments. In concrete:
   //FIRST: complete Properties initialization
   Properties.init(masterPropertiesFile);
   if (activateApplicationLevel)
       Properties.activateApplicationLevelAttributes();
   if (activateEvents)
       Properties.activateEventsAttributes();
   if (activateResults)
       Properties.activateResultsAttributes();
   if (activateSerialization)
       Properties.activateSerializationAttributes();

   //SECOND: GenericFactory initialization
   GenericFactory.init();
 
   //THIRD: making postinitialization
   Properties.postinit();
   GenericFactory.postinit();
 
Depending on the masterPropertiesFile specification, you must select the correct directory to run the main application.

Parameters:
masterPropertiesFile - The intermediate file necessary to load the required configuration attributes to run the current test.
masterPropertyName - The key that have to appear in the masterPropertiesFile which identifies the last file with current configuration.
activateApplicationLevel - Flag that shows when to load specific application level attributes for the current test.
activateEvents - Flag that shows when to load specific events attributes for the current test.
activateResults - Flag that shows when to load specific results attributes for the current test.
activateSerialization - Flag that shows when to load specific serialization attributes for the current test.
Throws:
InitializationException - if any error has occurred during initialization of the simulator context.

GenericApp

public GenericApp(java.lang.String masterPropertyName,
                  boolean activateApplicationLevel,
                  boolean activateEvents,
                  boolean activateResults,
                  boolean activateSerialization)
           throws InitializationException
Make the complete initialization of the simulator context, according to the arguments. In concrete:
   //FIRST: complete Properties initialization
   Properties.init("../conf/master.properties");
   if (activateApplicationLevel)
       Properties.activateApplicationLevelAttributes();
   if (activateEvents)
       Properties.activateEventsAttributes();
   if (activateResults)
       Properties.activateResultsAttributes();
   if (activateSerialization)
       Properties.activateSerializationAttributes();

   //SECOND: GenericFactory initialization
   GenericFactory.init();
 
   //THIRD: making postinitialization
   Properties.postinit();
   GenericFactory.postinit();
 
According to the master properties file path, you must run the main application into the bin directory of this distribution.

Parameters:
masterPropertyName - The key that have to appear in the masterPropertiesFile which identifies the last file with current configuration.
activateApplicationLevel - Flag that shows when to load specific application level attributes for the current test.
activateEvents - Flag that shows when to load specific events attributes for the current test.
activateResults - Flag that shows when to load specific results attributes for the current test.
activateSerialization - Flag that shows when to load specific serialization attributes for the current test.
Throws:
InitializationException - if any error has occurred during initialization of the simulator context.
Method Detail

start

public static void start(java.lang.String masterPropertiesFile,
                         java.lang.String masterPropertyName,
                         boolean activateApplicationLevel,
                         boolean activateEvents,
                         boolean activateResults,
                         boolean activateSerialization)
                  throws InitializationException
Make the complete initialization of the simulator context, according to the arguments. In concrete:
   //FIRST: complete Properties initialization
   Properties.init(masterPropertiesFile,masterPropertyName);
   if (activateApplicationLevel)
       Properties.activateApplicationLevelAttributes();
   if (activateEvents)
       Properties.activateEventsAttributes();
   if (activateResults)
       Properties.activateResultsAttributes();
   if (activateSerialization)
       Properties.activateSerializationAttributes();

   //SECOND: GenericFactory initialization
   GenericFactory.init();
   
   //THIRD: making postinitialization
   Properties.postinit();
   GenericFactory.postinit();
 
Depending on the masterPropertiesFile specification, you must select the correct directory to run the main application.

Parameters:
masterPropertiesFile - The intermediate file necessary to load the required configuration attributes to run the current test.
masterPropertyName - The key that have to appear in the masterPropertiesFile which identifies the last file with current configuration.
activateApplicationLevel - Flag that shows when to load specific application level attributes for the current test.
activateEvents - Flag that shows when to load specific events attributes for the current test.
activateResults - Flag that shows when to load specific results attributes for the current test.
activateSerialization - Flag that shows when to load specific serialization attributes for the current test.
Throws:
InitializationException - if any error has occurred during initialization of the simulator context.

restart

public static void restart(boolean activateApplicationLevel,
                           boolean activateEvents,
                           boolean activateResults,
                           boolean activateSerialization)
                    throws InitializationException
Make an update of the current simulator context using the actual configuration into the planet.util.Properties. In concrete:
   if (activateApplicationLevel)
       Properties.activateApplicationLevelAttributes();
   if (activateEvents)
       Properties.activateEventsAttributes();
   if (activateResults)
       Properties.activateResultsAttributes();
   if (activateSerialization)
       Properties.activateSerializationAttributes();
   GenericFactory.init();
   Properties.postinit();
   GenericFactory.postinit();
 

Parameters:
activateApplicationLevel - Flag that shows when to load specific application level attributes for the current test.
activateEvents - Flag that shows when to load specific events attributes for the current test.
activateResults - Flag that shows when to load specific results attributes for the current test.
activateSerialization - Flag that shows when to load specific serialization attributes for the current test.
Throws:
InitializationException - if any error has occurred during initialization of the simulator context.

printNetwork

public static void printNetwork(Network network)
Using the attribute planet.util.Properties.simulatorPrintLevel prints out (or not) the whole network.

Parameters:
network - The network to print out.

timeElapsedInSeconds

public static java.lang.String timeElapsedInSeconds(long firstTime,
                                                    long lastTime)
Shows in Y.XXX string format, the seconds elapsed between firstTime and lastTime, where 'Y' are the seconds, and 'XXX' the milliseconds ones. The time elapsed is obtained as lastTime-firstTime.

Parameters:
firstTime - First logged time.
lastTime - Second logged time.
Returns:
The seconds elapsed between the two logged times, in Y.XXX format.