Wednesday, August 13, 2008

Introducing parameters' factory and registry support

Introducing support classes to create objects, register dynamic parameters:
public class Test extends Observable implements Observer{
public void
init(){
long hearBeatYeldPause = 1000;
long heartBeatsNumber =
100;
String parameterName = "fuel";
DynamicParameter
dynamicParameterDecresingImpl = null;
try{
dynamicParameterDecresingImpl =
DynamicParameterFactory.createObject(DynamicParameterAlgorithms.DECREASING,
heartBeatsNumber,
hearBeatYeldPause,
"fuel",
this);
DynamicParameterRegistry.getInstance().setParameter(parameterName,
dynamicParameterDecresingImpl);
DynamicParameterRegistry.getInstance().registerOnParameter(parameterName,
this);
DynamicParameterRegistry.getInstance().daemonizeParameter(parameterName);
}catch(SimulationLaboratoryGeneralException
slgExc){
slgExc.printStackTrace();
}
try{
Thread.sleep(110000);
}catch(InterruptedException
e){
e.printStackTrace();
}
for(int i =0; i < 102;
i++){
try{
super.setChanged();
super.notifyObservers();
Thread.sleep(hearBeatYeldPause/2);
}catch(InterruptedException
e){
e.printStackTrace();
}
}
}
/**
* @param
args
*/
public static void main(String[] args) {
Test test = new
Test();
test.init();
}
@Override
public void update(Observable
observable, Object arg1) {
System.out.println("UPDATE RECEIVED by " +
observable.toString() + "");
}
}