Commit d8bfa8aa authored by Julian Zobel's avatar Julian Zobel
Browse files

Topology Factory now uses Topology Component Factories to define the type of...

Topology Factory now uses Topology Component Factories to define the type of topology component to be used.
parent b5862a04
...@@ -38,6 +38,7 @@ import de.tud.kom.p2psim.impl.network.modular.DBHostListManager; ...@@ -38,6 +38,7 @@ import de.tud.kom.p2psim.impl.network.modular.DBHostListManager;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB; import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.topology.component.BaseTopologyComponent; import de.tud.kom.p2psim.impl.topology.component.BaseTopologyComponent;
import de.tud.kom.p2psim.impl.topology.component.DefaultTopologyComponent; import de.tud.kom.p2psim.impl.topology.component.DefaultTopologyComponent;
import de.tud.kom.p2psim.impl.topology.component.TopologyComponentFactory;
import de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent; import de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent;
import de.tud.kom.p2psim.impl.topology.movement.AbstractWaypointMovementModel; import de.tud.kom.p2psim.impl.topology.movement.AbstractWaypointMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.NoMovement; import de.tud.kom.p2psim.impl.topology.movement.NoMovement;
...@@ -48,6 +49,7 @@ import de.tudarmstadt.maki.simonstrator.api.Binder; ...@@ -48,6 +49,7 @@ import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory; import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
...@@ -76,6 +78,8 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -76,6 +78,8 @@ public class TopologyFactory implements HostComponentFactory {
private ObstacleModel obstacleModel; private ObstacleModel obstacleModel;
private TopologyComponentFactory topologyComponentFactory = null;
private boolean registerAsInformationProviderInSiS = false; private boolean registerAsInformationProviderInSiS = false;
private static NetMeasurementDB measurementDB = null; private static NetMeasurementDB measurementDB = null;
...@@ -90,11 +94,6 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -90,11 +94,6 @@ public class TopologyFactory implements HostComponentFactory {
private boolean alreadyAddedMovement = false; private boolean alreadyAddedMovement = false;
// FIXME this can be inconsistent (both true e.g) and should be refactored
private boolean isUAVComponent = false;
private boolean isBaseStationComponent = false;
/** /**
* *
*/ */
...@@ -135,22 +134,12 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -135,22 +134,12 @@ public class TopologyFactory implements HostComponentFactory {
* Create a TopologyComponent and register it with the Topology and its * Create a TopologyComponent and register it with the Topology and its
* movement model. * movement model.
*/ */
TopologyComponent toCo;
/* if(topologyComponentFactory == null) {
* Choose the UAV topology component, if this host is part of the UAV group! throw new UnsupportedOperationException("[TopologyFactory] Cannot create topology component, topology component factory is NULL");
*
*/
if(isUAVComponent) {
toCo = new UAVTopologyComponent(host, topo, movement, placement, registerAsInformationProviderInSiS);
}
else if(isBaseStationComponent) {
toCo = new BaseTopologyComponent(host, topo, movement, placement, registerAsInformationProviderInSiS);
}
else {
toCo = new DefaultTopologyComponent(host, topo, movement, placement, registerAsInformationProviderInSiS);
} }
TopologyComponent toCo = topologyComponentFactory.createTopologyComponent(host, topo, movement, placement, registerAsInformationProviderInSiS);
/* /*
* Need to register TopoViews as movement listeners, as they might need * Need to register TopoViews as movement listeners, as they might need
...@@ -295,11 +284,8 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -295,11 +284,8 @@ public class TopologyFactory implements HostComponentFactory {
return obstacleModel; return obstacleModel;
} }
public void setIsUAVComponent(boolean uav) { public void setTopologyComponentFactory(TopologyComponentFactory factory) {
this.isUAVComponent = uav; this.topologyComponentFactory = factory;
} }
public void setIsBaseStationComponent(boolean uav) {
this.isBaseStationComponent = uav;
}
} }
...@@ -24,6 +24,7 @@ import java.util.Set; ...@@ -24,6 +24,7 @@ import java.util.Set;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel; import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.energy.UAVReplacementCharger; import de.tud.kom.p2psim.impl.energy.UAVReplacementCharger;
...@@ -118,4 +119,16 @@ public class BaseTopologyComponent extends AbstractTopologyComponent { ...@@ -118,4 +119,16 @@ public class BaseTopologyComponent extends AbstractTopologyComponent {
public void disconnectUAVFromBase(UAVToBaseInterface uav) { public void disconnectUAVFromBase(UAVToBaseInterface uav) {
this.controllerInterface.disconnectUAV(uav); this.controllerInterface.disconnectUAV(uav);
} }
public static class Factory implements TopologyComponentFactory {
@Override
public TopologyComponent createTopologyComponent(SimHost host,
Topology topology, MovementModel movementModel,
PlacementModel placementModel,
boolean registerAsInformationProviderInSiS) {
return new BaseTopologyComponent(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
}
}
} }
...@@ -117,4 +117,15 @@ public class DefaultTopologyComponent extends AbstractTopologyComponent { ...@@ -117,4 +117,15 @@ public class DefaultTopologyComponent extends AbstractTopologyComponent {
return movementModel.getAllAttractionPoints(); return movementModel.getAllAttractionPoints();
} }
public static class Factory implements TopologyComponentFactory {
@Override
public TopologyComponent createTopologyComponent(SimHost host,
Topology topology, MovementModel movementModel,
PlacementModel placementModel,
boolean registerAsInformationProviderInSiS) {
return new DefaultTopologyComponent(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
}
}
} }
/*
* Copyright (c) 2005-2010 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.component;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
public interface TopologyComponentFactory {
public TopologyComponent createTopologyComponent(SimHost host, Topology topology, MovementModel movementModel, PlacementModel placementModel, boolean registerAsInformationProviderInSiS);
}
...@@ -28,6 +28,7 @@ import de.tud.kom.p2psim.api.energy.ComponentType; ...@@ -28,6 +28,7 @@ import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyModel; import de.tud.kom.p2psim.api.energy.EnergyModel;
import de.tud.kom.p2psim.api.network.SimNetInterface; import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.SimUAVLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimUAVLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.UAVMovementModel; import de.tud.kom.p2psim.api.topology.movement.UAVMovementModel;
...@@ -370,5 +371,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S ...@@ -370,5 +371,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
} }
public static class Factory implements TopologyComponentFactory {
@Override
public TopologyComponent createTopologyComponent(SimHost host,
Topology topology, MovementModel movementModel,
PlacementModel placementModel,
boolean registerAsInformationProviderInSiS) {
return new UAVTopologyComponent(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
}
}
} }
...@@ -227,10 +227,6 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac ...@@ -227,10 +227,6 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
throw new ConfigurationException( throw new ConfigurationException(
"TransitionStrategy is missing in ModularMovementModel!"); "TransitionStrategy is missing in ModularMovementModel!");
} }
if (attractionGenerator == null) {
throw new ConfigurationException(
"AttractionGenerator is missing in ModularMovementModel!");
}
} }
@Override @Override
......
...@@ -43,6 +43,7 @@ import com.graphhopper.util.shapes.GHPoint3D; ...@@ -43,6 +43,7 @@ import com.graphhopper.util.shapes.GHPoint3D;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.local.AbstractLocalMovementStrategy; import de.tud.kom.p2psim.impl.topology.movement.local.AbstractLocalMovementStrategy;
import de.tud.kom.p2psim.impl.topology.movement.local.RealWorldStreetsMovement; import de.tud.kom.p2psim.impl.topology.movement.local.RealWorldStreetsMovement;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.util.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
...@@ -303,7 +304,7 @@ public class ModularMovementModelViz extends JComponent ...@@ -303,7 +304,7 @@ public class ModularMovementModelViz extends JComponent
{ {
Composite gc = g2.getComposite(); Composite gc = g2.getComposite();
for (IAttractionPoint aPoint : movementModel.getAttractionPoints()) { for (IAttractionPoint aPoint : IAttractionGenerator.attractionPoints) {
Point point = ((PositionVector) aPoint).asPoint(); Point point = ((PositionVector) aPoint).asPoint();
// draw border // draw border
g2.setColor(Color.BLACK); g2.setColor(Color.BLACK);
......
...@@ -389,16 +389,4 @@ public class SocialGroupMovementModel extends ModularMovementModel { ...@@ -389,16 +389,4 @@ public class SocialGroupMovementModel extends ModularMovementModel {
public Map<SimLocationActuator, PositionVector> getCurrentTargets(){ public Map<SimLocationActuator, PositionVector> getCurrentTargets(){
return currentTargets; return currentTargets;
} }
/**
* Only for visualization!
*
* @return
*/
public List<IAttractionPoint> getAttractionPoints() {
return new Vector<IAttractionPoint>(IAttractionGenerator.attractionPoints);
}
} }
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