Commit 0001f6eb authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

MovementSupported: Removed AfterComponentsMoved

parent 5080829c
......@@ -32,14 +32,6 @@ package de.tud.kom.p2psim.api.topology.movement;
*/
public interface MovementListener {
/**
* As most {@link MovementModel}s are round-based we add this callback. It
* is triggered after all componentMoved-Calls are triggered for this round.
* If a model is not round based, it will trigger this method every time a
* component moves
*/
public void afterComponentsMoved();
/**
* Triggered, after the respective component moved.
*
......
......@@ -193,13 +193,6 @@ public class DefaultTopologyComponent implements TopologyComponent {
}
}
@Override
public void afterComponentsMoved() {
for (MovementListener moveListener : movementListeners) {
moveListener.afterComponentsMoved();
}
}
@Override
public boolean movementActive() {
/*
......@@ -598,14 +591,9 @@ public class DefaultTopologyComponent implements TopologyComponent {
return currentView;
}
@Override
public void afterComponentsMoved() {
this.isInvalid = true;
}
@Override
public void afterComponentMoved(MovementSupported comp) {
// don't care, we calculate based on global knowledge.
this.isInvalid = true;
}
@Override
......
/*
* Copyright (c) 2005-2013 KOM - Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*/
package de.tud.kom.p2psim.impl.topology.events;
/**
* This event is posted when a component scales
* the map to a specific size.
*
* Posted by
* - AppJobberDataLoader
* - AbstractWaypointMovementModel
*
* @author Fabio Zöllner
* @version 1.0, 09.02.13
*/
public class ScaleWorldEvent {
private double scaleFactor = 1.0;
public ScaleWorldEvent(double scaleFactor) {
this.scaleFactor = scaleFactor;
}
public double getFactor() {
return scaleFactor;
}
}
......@@ -106,15 +106,6 @@ public abstract class AbstractMovementModel implements MovementModel {
listeners.remove(listener);
}
/**
* Notify Listeners
*/
protected void notifyRoundEnd() {
for (MovementListener listener : listeners) {
listener.afterComponentsMoved();
}
}
protected void notifyPositionChange(MovementSupported comp) {
for (MovementListener listener : listeners) {
listener.afterComponentMoved(comp);
......
......@@ -27,8 +27,6 @@ import java.util.Random;
import java.util.Set;
import java.util.WeakHashMap;
import com.google.common.eventbus.Subscribe;
import de.tud.kom.p2psim.api.topology.movement.MovementListener;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
......@@ -37,7 +35,6 @@ import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.After;
import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.Configure;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.events.ScaleWorldEvent;
import de.tud.kom.p2psim.impl.util.Either;
import de.tud.kom.p2psim.impl.util.geo.maps.MapLoader;
import de.tudarmstadt.maki.simonstrator.api.Event;
......@@ -116,18 +113,6 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
return true;
}
@Subscribe
public void scaleWorld(ScaleWorldEvent event) {
double scaleFactor = event.getFactor();
speedLimit = unscaledSpeedLimit * scaleFactor;
Monitor.log(
AbstractWaypointMovementModel.class,
Level.INFO,
"Movement speed of the local movement strategy has been adjusted for the waypoint model scale and is now "
+ speedLimit + "m/s");
}
/**
* Gets called periodically (after timeBetweenMoveOperations) or by an
* application and should be used to recalculate positions
......@@ -138,8 +123,6 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
for (int i = 0; i < nrOfSteps; i++) {
step();
}
notifyRoundEnd();
}
private void step() {
......@@ -322,16 +305,7 @@ public abstract class AbstractWaypointMovementModel implements MovementModel {
public void removeMovementListener(MovementListener listener) {
listeners.remove(listener);
}
/**
* Notify Listeners
*/
protected void notifyRoundEnd() {
for (MovementListener listener : listeners) {
listener.afterComponentsMoved();
}
}
protected void notifyPositionChange(MovementSupported comp) {
for (MovementListener listener : listeners) {
listener.afterComponentMoved(comp);
......
......@@ -298,11 +298,6 @@ public class BonnMotionMovementModel extends AbstractMovementModel implements
// log.warn(Simulator.getFormattedTime(Simulator.getCurrentTime())+" ID = " + bme.getHostID() +" pos = " + pos);
}
}
if (lastNotificationTime + movementInterval < Simulator
.getCurrentTime()) {
notifyRoundEnd();
lastNotificationTime = Simulator.getCurrentTime();
}
}
}
......
......@@ -106,7 +106,6 @@ public class CsvMovement extends AbstractMovementModel {
if (info.getRemainingSteps() == 0 || info.getDelta() == null) {
// assign next delta and next steps for next path point
if (!assignNextMovementInfo(comp)) {
notifyRoundEnd();
return;
}
}
......@@ -114,7 +113,6 @@ public class CsvMovement extends AbstractMovementModel {
info.setRemainingSteps(info.getRemainingSteps() - 1);
comp.positionChanged();
}
notifyRoundEnd();
}
protected boolean assignNextMovementInfo(MovementSupported comp) {
......
......@@ -166,7 +166,6 @@ public class GaussMarkovMovement extends AbstractMovementModel {
notifyPositionChange(comp);
}
}
notifyRoundEnd();
}
@Override
......
......@@ -36,7 +36,6 @@ public class NoMovement extends AbstractMovementModel {
@Override
public void move() {
// nothing to do
notifyRoundEnd();
}
}
......@@ -48,8 +48,6 @@ public class RandomMovement extends AbstractMovementModel {
comp.getMaxMovementSpeed()));
notifyPositionChange(comp);
}
notifyRoundEnd();
}
......
......@@ -75,7 +75,6 @@ public class RandomPathMovement extends AbstractMovementModel {
info.setRemainingSteps(info.getRemainingSteps() - 1);
notifyPositionChange(comp);
}
notifyRoundEnd();
}
protected void assignNewMovementInfo(MovementSupported comp) {
......
......@@ -72,7 +72,6 @@ public class TargetMovement extends AbstractMovementModel {
pos.add(vec);
notifyPositionChange(comp);
}
notifyRoundEnd();
}
public void setX(double x) {
......
......@@ -252,8 +252,6 @@ public class ModularMovementModel implements MovementModel, EventHandler {
Event.scheduleWithDelay(timeBetweenMoveOperation, this, null,
EVENT_MOVE);
notifyRoundEnd();
}
/**
......@@ -276,15 +274,6 @@ public class ModularMovementModel implements MovementModel, EventHandler {
}
}
/**
* Notify Listeners
*/
protected void notifyRoundEnd() {
for (MovementListener listener : movementListeners) {
listener.afterComponentsMoved();
}
}
protected void notifyPositionChange(MovementSupported comp) {
for (MovementListener listener : movementListeners) {
listener.afterComponentMoved(comp);
......
......@@ -226,8 +226,6 @@ public class ModularMovementModel implements MovementModel, EventHandler {
Event.scheduleWithDelay(timeBetweenMoveOperation, this, null,
EVENT_MOVE);
notifyRoundEnd();
}
/**
......@@ -257,15 +255,6 @@ public class ModularMovementModel implements MovementModel, EventHandler {
}
}
/**
* Notify Listeners
*/
protected void notifyRoundEnd() {
for (MovementListener listener : movementListeners) {
listener.afterComponentsMoved();
}
}
protected void notifyPositionChange(MovementSupported comp) {
for (MovementListener listener : movementListeners) {
listener.afterComponentMoved(comp);
......
......@@ -43,6 +43,7 @@ import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Rate;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/**
......@@ -317,35 +318,32 @@ public abstract class AbstractTopologyView<L extends DefaultLink> implements
public Collection<MacLayer> getAllMacs() {
return macs.values();
}
long timeLastMovement = 0;
@Override
public void afterComponentsMoved() {
/*
* again, topologies might or might not support movement. We do not
* force handling of this callback. The default implementation does
* nothing. If a topology uses this callback is should mark
* neighborhoods as outdated and re-calculate them on-demand as soon as
* the hosts first requests the neighborhood again.
*/
if (movementSupported) {
public void afterComponentMoved(MovementSupported comp) {
if (Time.getCurrentTime() != timeLastMovement) {
timeLastMovement = Time.getCurrentTime();
/*
* mark all neighborhoods as outdated
* again, topologies might or might not support movement. We do not
* force handling of this callback. The default implementation does
* nothing. If a topology uses this callback is should mark
* neighborhoods as outdated and re-calculate them on-demand as soon as
* the hosts first requests the neighborhood again.
*/
for (Entry<MacAddress, Boolean> entry : neighborsOutdated
.entrySet()) {
entry.setValue(true);
if (movementSupported) {
/*
* mark all neighborhoods as outdated
*/
for (Entry<MacAddress, Boolean> entry : neighborsOutdated
.entrySet()) {
entry.setValue(true);
}
}
}
}
@Override
public void afterComponentMoved(MovementSupported comp) {
/*
* don't care. One might optimize handling here when compared to a
* global recalculation.
*/
}
@Override
public final L getLinkBetween(MacAddress source, MacAddress destination) {
return getCachedLink(source, destination);
......
......@@ -30,6 +30,7 @@ import de.tud.kom.p2psim.api.linklayer.mac.Link;
import de.tud.kom.p2psim.api.linklayer.mac.MacAddress;
import de.tud.kom.p2psim.api.linklayer.mac.MacLayer;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
......@@ -39,6 +40,7 @@ import de.tud.kom.p2psim.impl.topology.views.fiveg.FiveGTopologyDatabase.Entry;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.handover.HandoverSensor;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
import edu.emory.mathcs.backport.java.util.Arrays;
......@@ -131,7 +133,7 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
Event.scheduleImmediately(new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
afterComponentsMoved();
checkAPAssociations();
}
}, null, 0);
}
......@@ -210,16 +212,14 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
null);
}
}
@Override
public void afterComponentsMoved() {
super.afterComponentsMoved();
/*
* Check, if a node moved into a new segment. If so, we need to update
* the HandoverSensor to trigger the listeners. We only need to check
* nodes that are included in the list of ap-enabled nodes (i.e., they
* already have a HandoverSensor-instance).
*/
/**
* Check, if a node moved into a new segment. If so, we need to update
* the HandoverSensor to trigger the listeners. We only need to check
* nodes that are included in the list of ap-enabled nodes (i.e., they
* already have a HandoverSensor-instance).
*/
protected void checkAPAssociations() {
for (HandoverSensor5G sensor : handoverSensors) {
PositionVector pos = getCachedPosition(sensor.macAddr);
int segId = databaseAccessPoints.getSegmentID(pos.getX(),
......@@ -238,7 +238,17 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
for (MacAddress mobileClient : mobileClientsList) {
updateMaxMacBandwidth(mobileClient);
}
}
long lastMovementTimestamp = 0;
@Override
public void afterComponentMoved(MovementSupported comp) {
super.afterComponentMoved(comp);
if (lastMovementTimestamp != Time.getCurrentTime()) {
lastMovementTimestamp = Time.getCurrentTime();
checkAPAssociations();
}
}
/**
......
......@@ -33,11 +33,13 @@ import de.tud.kom.p2psim.api.linklayer.mac.Link;
import de.tud.kom.p2psim.api.linklayer.mac.MacAddress;
import de.tud.kom.p2psim.api.linklayer.mac.MacLayer;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.obstacles.Obstacle;
import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.util.LiveMonitoring;
import de.tud.kom.p2psim.impl.util.LiveMonitoring.ProgressValue;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
......@@ -210,20 +212,24 @@ public class RangedTopologyView extends AbstractTopologyView<RangedLink> {
}
return updatedNeighbors;
}
long lastMovementTime = 0;
@Override
public void afterComponentsMoved() {
super.afterComponentsMoved();
/*
* mark all links as outdated
*/
synchronized (linkList) {
for (RangedLink link : linkList) {
link.setOutdated(true);
}
for (Dijkstra dijkstra : dijkstras.values()) {
dijkstra.afterComponentsMoved();
public void afterComponentMoved(MovementSupported comp) {
super.afterComponentMoved(comp);
if (lastMovementTime != Time.getCurrentTime()) {
lastMovementTime = Time.getCurrentTime();
/*
* mark all links as outdated
*/
synchronized (linkList) {
for (RangedLink link : linkList) {
link.setOutdated(true);
}
for (Dijkstra dijkstra : dijkstras.values()) {
dijkstra.afterComponentsMoved();
}
}
}
}
......
......@@ -78,6 +78,7 @@ import de.tud.kom.p2psim.impl.topology.views.visualization.world.TopologyCompone
import de.tud.kom.p2psim.impl.topology.views.visualization.world.WeakWaypointComponentVis;
import de.tud.kom.p2psim.impl.util.NotSupportedException;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
......@@ -262,14 +263,15 @@ public class VisualizationTopologyView extends JFrame implements TopologyView,
* obstacle); worldPanel.add(obsVis); } }
*/
@Override
public void afterComponentsMoved() {
worldPanel.invalidate();
}
long lastMove = 0;
@Override
public void afterComponentMoved(MovementSupported comp) {
// don't care
if (lastMove != Time.getCurrentTime()) {
worldPanel.invalidate();
lastMove = Time.getCurrentTime();
}
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment