Refactored RadioMediumObservable and added new Observable

Refactored RadioMediumObservable to RadioTransmissionObservable because of its function
Added correct RadioMediumObservable and updating in AbstractRadioMedium, DirectedGraphMedium and MRM
Added some documentation
This commit is contained in:
Sebastian Schinabeck 2013-11-21 18:08:41 +01:00 committed by Moritz 'Morty' Strübe
parent 42077adbb1
commit c1a275f0b2
9 changed files with 69 additions and 20 deletions

View file

@ -230,7 +230,7 @@ public class AreaViewer extends VisPlugin {
// We want to listen to changes both in the channel model as well as in the radio medium
currentChannelModel.addSettingsObserver(channelModelSettingsObserver);
currentRadioMedium.addSettingsObserver(radioMediumSettingsObserver);
currentRadioMedium.addRadioMediumObserver(radioMediumActivityObserver);
currentRadioMedium.addRadioTransmissionObserver(radioMediumActivityObserver);
// Set initial size etc.
setSize(500, 500);
@ -2344,7 +2344,7 @@ public class AreaViewer extends VisPlugin {
}
if (currentRadioMedium != null && radioMediumActivityObserver != null) {
currentRadioMedium.deleteRadioMediumObserver(radioMediumActivityObserver);
currentRadioMedium.deleteRadioTransmissionObserver(radioMediumActivityObserver);
} else {
logger.fatal("Could not remove observer: " + radioMediumActivityObserver);
}

View file

@ -143,6 +143,9 @@ public class MRM extends AbstractRadioMedium {
public void registerRadioInterface(Radio radio, Simulation sim) {
super.registerRadioInterface(radio, sim);
/* Radio Medium changed here so notify Observers */
radioMediumObservable.setChangedAndNotify();
if (WITH_NOISE && radio instanceof NoiseSourceRadio) {
((NoiseSourceRadio)radio).addNoiseLevelListener(noiseListener);
}
@ -150,6 +153,9 @@ public class MRM extends AbstractRadioMedium {
public void unregisterRadioInterface(Radio radio, Simulation sim) {
super.unregisterRadioInterface(radio, sim);
/* Radio Medium changed here so notify Observers */
radioMediumObservable.setChangedAndNotify();
if (WITH_NOISE && radio instanceof NoiseSourceRadio) {
((NoiseSourceRadio)radio).removeNoiseLevelListener(noiseListener);
}

View file

@ -100,24 +100,24 @@ public abstract class RadioMedium {
* Adds an observer which is notified each time a radio connection has finished.
*
* @see #getLastConnection()
* @see #deleteRadioMediumObserver(Observer)
* @see #deleteRadioTransmissionObserver(Observer)
* @param observer New observer
*/
public abstract void addRadioMediumObserver(Observer observer);
public abstract void addRadioTransmissionObserver(Observer observer);
/**
* @return Radio medium observable
*/
public abstract Observable getRadioMediumObservable();
public abstract Observable getRadioTransmissionObservable();
/**
* Deletes an radio medium observer.
*
* @see #addRadioMediumObserver(Observer)
* @see #addRadioTransmissionObserver(Observer)
* @param observer
* Observer to delete
*/
public abstract void deleteRadioMediumObserver(Observer observer);
public abstract void deleteRadioTransmissionObserver(Observer observer);
/**
* @return Last radio connection finished in the radio medium

View file

@ -111,7 +111,7 @@ public class DGRMConfigurator extends VisPlugin {
radioMedium = (DirectedGraphMedium) sim.getRadioMedium();
/* Listen for graph updates */
radioMedium.addRadioMediumObserver(radioMediumObserver = new Observer() {
radioMedium.addRadioTransmissionObserver(radioMediumObserver = new Observer() {
public void update(Observable obs, Object obj) {
model.fireTableDataChanged();
}
@ -500,7 +500,7 @@ public class DGRMConfigurator extends VisPlugin {
};
public void closePlugin() {
radioMedium.deleteRadioMediumObserver(radioMediumObserver);
radioMedium.deleteRadioTransmissionObserver(radioMediumObserver);
}
}

View file

@ -223,7 +223,7 @@ public class EventListener extends VisPlugin {
JCheckBox radioMediumCheckBox = new JCheckBox("Radio medium event", false);
radioMediumCheckBox.putClientProperty("observable", mySimulation
.getRadioMedium().getRadioMediumObservable());
.getRadioMedium().getRadioTransmissionObservable());
radioMediumCheckBox.addActionListener(generalCheckBoxListener);
generalPanel.add(radioMediumCheckBox);

View file

@ -509,7 +509,7 @@ public class RadioLogger extends VisPlugin {
adjuster.setDynamicAdjustment(true);
adjuster.packColumns();
radioMedium.addRadioMediumObserver(radioMediumObserver = new Observer() {
radioMedium.addRadioTransmissionObserver(radioMediumObserver = new Observer() {
@Override
public void update(Observable obs, Object obj) {
RadioConnection conn = radioMedium.getLastConnection();
@ -784,7 +784,7 @@ public class RadioLogger extends VisPlugin {
@Override
public void closePlugin() {
if (radioMediumObserver != null) {
radioMedium.deleteRadioMediumObserver(radioMediumObserver);
radioMedium.deleteRadioTransmissionObserver(radioMediumObserver);
}
}

View file

@ -130,7 +130,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
historyList.clear();
/* Start observing radio medium for transmissions */
radioMedium.addRadioMediumObserver(radioMediumObserver);
radioMedium.addRadioTransmissionObserver(radioMediumObserver);
/* Fade away arrows */
simulation.scheduleEvent(ageArrowsTimeEvent, simulation.getSimulationTime() + 100*Simulation.MILLISECOND);
@ -147,7 +147,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
}
/* Stop observing radio medium */
radioMedium.deleteRadioMediumObserver(radioMediumObserver);
radioMedium.deleteRadioTransmissionObserver(radioMediumObserver);
}
@Override

View file

@ -92,7 +92,13 @@ public abstract class AbstractRadioMedium extends RadioMedium {
public int COUNTER_RX = 0;
public int COUNTER_INTERFERED = 0;
/**
* Two Observables to observe the radioMedium and radioTransmissions
* @see addRadioTransmissionObserver
* @see addRadioMediumObserver
*/
protected ScnObservable radioMediumObservable = new ScnObservable();
protected ScnObservable radioTransmissionObservable = new ScnObservable();
/**
* This constructor should always be called from implemented radio mediums.
@ -280,7 +286,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
/* Notify observers */
lastConnection = null;
radioMediumObservable.setChangedAndNotify();
radioTransmissionObservable.setChangedAndNotify();
}
break;
case TRANSMISSION_FINISHED: {
@ -325,7 +331,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
updateSignalStrengths();
/* Notify observers */
radioMediumObservable.setChangedAndNotify();
radioTransmissionObservable.setChangedAndNotify();
}
break;
case CUSTOM_DATA_TRANSMITTED: {
@ -340,7 +346,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
/* Custom data object */
Object data = ((CustomDataRadio) radio).getLastCustomDataTransmitted();
if (data == null) {
logger.fatal("No custom data object to forward");
logger.fatal("No custom data objecTransmissiont to forward");
return;
}
@ -438,6 +444,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
registeredRadios.add(radio);
radio.addObserver(radioEventsObserver);
radioMediumObservable.setChangedAndNotify();
/* Update signal strengths */
updateSignalStrengths();
@ -454,6 +461,8 @@ public abstract class AbstractRadioMedium extends RadioMedium {
removeFromActiveConnections(radio);
radioMediumObservable.setChangedAndNotify();
/* Update signal strengths */
updateSignalStrengths();
}
@ -520,10 +529,40 @@ public abstract class AbstractRadioMedium extends RadioMedium {
sendRssi.put(radio, rssi);
}
/**
* Register an observer that gets notified when the radiotransmissions changed.
* E.g. creating new connections.
* This does not include changes in the settings and (de-)registration of radios.
* @see addRadioMediumObserver
* @param observer the Observer to register
*/
public void addRadioTransmissionObserver(Observer observer) {
radioTransmissionObservable.addObserver(observer);
}
public Observable getRadioTransmissionObservable() {
return radioTransmissionObservable;
}
public void deleteRadioTransmissionObserver(Observer observer) {
radioTransmissionObservable.deleteObserver(observer);
}
/**
* Register an observer that gets notified when the radio medium changed.
* This includes changes in the settings and (de-)registration of radios.
* This does not include transmissions, etc as these are part of the radio
* and not the radio medium itself.
* @see addRadioTransmissionObserver
* @param observer the Observer to register
*/
public void addRadioMediumObserver(Observer observer) {
radioMediumObservable.addObserver(observer);
}
/**
* @return the radioMediumObservable
*/
public Observable getRadioMediumObservable() {
return radioMediumObservable;
}

View file

@ -93,7 +93,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
edges.add(e);
requestEdgeAnalysis();
radioMediumObservable.setChangedAndNotify();
radioTransmissionObservable.setChangedAndNotify();
}
public void removeEdge(Edge edge) {
@ -104,14 +104,15 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
edges.remove(edge);
requestEdgeAnalysis();
radioMediumObservable.setChangedAndNotify();
radioTransmissionObservable.setChangedAndNotify();
}
public void clearEdges() {
edges.clear();
requestEdgeAnalysis();
radioMediumObservable.setChangedAndNotify();
radioTransmissionObservable.setChangedAndNotify();
}
public Edge[] getEdges() {
@ -221,6 +222,9 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
this.edgesTable = arrTable;
edgesDirty = false;
/* Radio Medium changed here so notify Observers */
radioMediumObservable.setChangedAndNotify();
}
/**