User Tools

Site Tools


zalozeni:logika:observers

Observers

V teto casti je popsano, jak vytvorit tridy pro vycitani udaju z regulatoru. Je to pro pohodlnejsi volani vycitani ze tridy ExperimentLogic. Observer se stara o vycitani udaju, encapsuluje vycitani ze souvisejicich Component (kdyz napr. ctu polohu hlavice, tak potrebuju cist zaroven ze dvou kanalu - zda je hlava nahore nebo dole) do jedne tridy a pri vycteni raisuje patricny event. Rovnez si vyctenou hodnotu uchovava v pameti pro dalsi pouziti.

Prakticky se mi osvedcilo definovat tridu DokuwikiGenericObserver a oddedit

public class DokuwikiGenericObserver {
 
	protected ExperimentInstance expInstance;
	protected DokuwikiInstrument instrument;
 
	public DokuwikiGenericObserver(ExperimentInstance expInstance) {
		this.expInstance = expInstance;
		this.instrument = (DokuwikiInstrument) expInstance.getInstrument();
	}
 
}

a jednotlive vycitani pak implementovat naslednym zpusobem. Teprve tridy DokuwikiTempObserver a DokuwikiCounterObserver jsou pouzity v DokuwikiExpLogic.

public class DokuwikiTempObserver extends DokuwikiGenericObserver {
 
	private double temp;
 
	public DokuwikiTempObserver(ExperimentInstance expInstance) {
		super(expInstance);
	}
 
	public void readValue() throws IOException, GetValueException, Exception {
		temp = instrument.getTemperature();
		ServiceLocator.getInstance().getLogicModuleManager().raiseEvent(new TempReadOutEvent(temp), expInstance);
	}
 
	public double getTemp() {
		return temp;
	}
 
	public void setTemp(double temp) {
		this.temp = temp;
	}
 
}
public class DokuwikiCounterObserver extends DokuwikiGenericObserver {
 
	private int counter;
 
	public DokuwikiCounterObserver(ExperimentInstance expInstance) {
		super(expInstance);
	}
 
	public void readValue() throws IOException, GetValueException, Exception {
		counter = instrument.getCounter();
		ServiceLocator.getInstance().getLogicModuleManager().raiseEvent(new CounterReadOutEvent(counter), expInstance);
	}
 
	public int getCounter() {
		return counter;
	}
 
	public void setCounter(int counter) {
		this.counter = counter;
	}
 
}
zalozeni/logika/observers.txt · Last modified: 2016/07/29 11:36 by jlochman