Monday, August 11, 2008

How fuel changes

Fuel decreasing sample starts to run:

Fuel tank collisions, refuelling sample:

Fuel is blinking RED sample:

Links (some in Italian)


Why dynamic parameters ?

It is correct to explain.

A thread running an algorithm to change a value can be whatever in the context of a mechanical (only ?) system simulation. It is feasible to imagine fuel, decreasing, in a "threaded" autonomous way, while time passes, with a define model of variation. With the code done, and the interface foreseeing the capability to receive a "set" of the parameter name (that's the parameter nature of course, eg: fuel), it can be reused. The observer/observable double mutual pattern, collision with fuel tanks can be notified to the parameter thread, and fuel increased. Thus establishing a relation between the value, changing by itself, and what happens in the virtual environment. Every new parameter, with its own meaning add more virtual devices and multiplicity to the simulation scenario, increasing the number of data types.

A virtual parameter with a thread in its soul, to simulate a new range of virtual sensors, based on the changing of a value, like fuel

It is intersting actually, two observer/observable patterns, one against the other, to monitor the ongoing value of a ... value ! That simply thanks to a thread and to the common pattern of the earth beat, to decrease or increase with the time, in its own process, with different color levels, a named floating value. This could be fule, for example, or engine oil. It is self sufficient, not needing nothjing more than jdk runtime, and it is so easy that the few classes involved in this game are posted here to let playing everyone who likes:

Parameters threshold for colors:

DynamicParameter factory (actually only the DEcreasing impl is available):

Paradigm interface for this entity:

The decreasing (and the only written up to now) impl:

To try just use these lines of test class:

import java.util.Observable;
import java.util.Observer;

public class Prova extends Observable implements Observer{
public Prova(){
private void init(){
long hearBeatYeldPause = 1000;
DynamicParameter dynamicParameterDecresingImpl = new DynamicParameterDecreasingImpl(this);
dynamicParameterDecresingImpl.setHeartBeat(100, hearBeatYeldPause);
Thread daemonThread = new Thread(dynamicParameterDecresingImpl);
try {
} catch (InterruptedException e) {
// TODO Auto-generated catch block
for(int i =0; i < 102; i++){
} catch (InterruptedException e) {
// TODO Auto-generated catch block
* @param args
public static void main(String[] args) {
Prova prova = new Prova();
public void update(Observable observable, Object arg1) {
System.out.println("UPDATE RECEIVED by " + observable.toString() + "");