Commit 6976e2d2 authored by Nils Richerzhagen's avatar Nils Richerzhagen
Browse files

Merge branch 'master' into 'nr/monitoring-model'

Merge Master into nr/monitoring-model

See merge request !4
parents f6a12e49 2ac40564
...@@ -38,8 +38,8 @@ import de.tudarmstadt.maki.simonstrator.api.common.metric.MetricFilter; ...@@ -38,8 +38,8 @@ import de.tudarmstadt.maki.simonstrator.api.common.metric.MetricFilter;
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012 * @version 1.0, 08.08.2012
*/ */
public abstract class AbstractFilter<M extends MetricValue<?>> implements public abstract class AbstractFilter<M extends MetricValue<?>>
MetricFilter { implements MetricFilter {
private final String name; private final String name;
...@@ -67,6 +67,20 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements ...@@ -67,6 +67,20 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements
if (metric.getName().equals(string)) { if (metric.getName().equals(string)) {
return true; return true;
} }
if (string.endsWith("*")) {
// prefix matching
String mName = metric.getName();
if (mName.startsWith(string.substring(0, string.length()-1))) {
return true;
}
}
if (string.startsWith("*")) {
// postfix matching
String mName = metric.getName();
if (mName.endsWith(string.substring(1, string.length()))) {
return true;
}
}
} }
return false; return false;
} }
...@@ -83,7 +97,9 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements ...@@ -83,7 +97,9 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements
incomingMetrics.add(metric); incomingMetrics.add(metric);
} }
if (incomingMetrics.isEmpty()) { if (incomingMetrics.isEmpty()) {
throw new AssertionError("No incoming metrics configured! Available metrics are: "+metrics.toString()); throw new AssertionError(
"No incoming metrics configured! Available metrics are: "
+ metrics.toString());
} }
onInitialize(incomingMetrics); onInitialize(incomingMetrics);
...@@ -233,8 +249,8 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements ...@@ -233,8 +249,8 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 13.08.2012 * @version 1.0, 13.08.2012
*/ */
private class DerivedActiveMetric extends DerivedMetric implements private class DerivedActiveMetric extends DerivedMetric
ActiveMetric<M> { implements ActiveMetric<M> {
private final List<ActiveMetricListener> listeners; private final List<ActiveMetricListener> listeners;
......
/*
* 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.analyzer.metric.filter;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.LifecycleComponent;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Filter a metric usign a {@link LifecycleComponent}s isActive method.
*
* @author Bjoern Richerzhagen
* @version 1.0, Feb 7, 2017
*/
public class ActiveComponentFilter extends AbstractFilter<MetricValue<?>> {
private Class<? extends LifecycleComponent> compClass;
private String description;
private String prefix;
@SuppressWarnings("unchecked")
@XMLConfigurableConstructor({ "clazz", "prefix" })
public ActiveComponentFilter(String clazz, String prefix) {
super("active");
this.prefix = prefix;
description = "only active "+clazz.substring(clazz.lastIndexOf(".") + 1);
// Find class
try {
compClass = (Class<? extends LifecycleComponent>) Class.forName(clazz);
} catch (ClassNotFoundException e) {
throw new AssertionError();
}
}
@Override
protected String getNameForDerivedMetric(List<Metric<?>> inputs) {
assert inputs.size() == 1;
return prefix + "_" + inputs.get(0).getName();
}
@Override
protected void onInitialize(List<Metric<?>> incomingMetrics) {
for (Metric metric : incomingMetrics) {
if (metric.isOverallMetric()) {
continue;
}
createDerivedMetric(metric, false, metric.getUnit(),
description + " of " + metric.getName(), false);
}
}
@Override
public void onStop() {
// nothing to do
}
@Override
protected MetricValue<?> getDerivedMetricValueFor(Metric<?> derivedMetric,
List<Metric<?>> inputs, Host host) {
assert inputs.size() == 1;
assert host != null;
Metric<?> input = inputs.get(0);
if (input.isOverallMetric()) {
throw new AssertionError(
"Only available for per-host input metrics.");
}
try {
LifecycleComponent comp = host.getComponent(compClass);
MetricValue mvIn = input.getPerHostMetric(host.getId());
if (mvIn != null) {
return new ActiveHostMetricValue(input.getPerHostMetric(host.getId()), comp);
}
} catch (ComponentNotAvailableException e) {
//
}
return null; // no derived metric
}
/**
* Computes statistics such as svg, sum, std...
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
private class ActiveHostMetricValue implements MetricValue {
private final MetricValue input;
private final LifecycleComponent comp;
public ActiveHostMetricValue(MetricValue input, LifecycleComponent comp) {
this.input = input;
this.comp = comp;
}
@Override
public Object getValue() {
return input.getValue();
}
@Override
public boolean isValid() {
return comp.isActive() && input.isValid();
}
}
}
...@@ -46,6 +46,20 @@ public abstract class AbstractOutput implements MetricOutput { ...@@ -46,6 +46,20 @@ public abstract class AbstractOutput implements MetricOutput {
if (metric.getName().equals(string)) { if (metric.getName().equals(string)) {
return true; return true;
} }
if (string.endsWith("*")) {
// prefix matching
String mName = metric.getName();
if (mName.startsWith(string.substring(0, string.length()-1))) {
return true;
}
}
if (string.startsWith("*")) {
// postfix matching
String mName = metric.getName();
if (mName.endsWith(string.substring(1, string.length()))) {
return true;
}
}
} }
return false; return false;
} }
......
...@@ -25,6 +25,7 @@ import java.util.LinkedHashSet; ...@@ -25,6 +25,7 @@ import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
...@@ -56,6 +57,8 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -56,6 +57,8 @@ public class MetricOutputDAO extends AbstractOutput {
protected Set<String> metricsToAggregate = new LinkedHashSet<>(); protected Set<String> metricsToAggregate = new LinkedHashSet<>();
protected List<MetricDaoAdapter> daoAdapters = new LinkedList<>();
/** /**
* *
* @param table * @param table
...@@ -94,6 +97,29 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -94,6 +97,29 @@ public class MetricOutputDAO extends AbstractOutput {
} }
} }
public boolean isToAggregate(Metric metric) {
for (String string : metricsToAggregate) {
if (metric.getName().equals(string)) {
return true;
}
if (string.endsWith("*")) {
// prefix matching
String mName = metric.getName();
if (mName.startsWith(string.substring(0, string.length()-1))) {
return true;
}
}
if (string.startsWith("*")) {
// postfix matching
String mName = metric.getName();
if (mName.endsWith(string.substring(1, string.length()))) {
return true;
}
}
}
return false;
}
@Override @Override
public void onInitialize(List<Metric> metrics) { public void onInitialize(List<Metric> metrics) {
for (Metric metric : metrics) { for (Metric metric : metrics) {
...@@ -103,13 +129,18 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -103,13 +129,18 @@ public class MetricOutputDAO extends AbstractOutput {
*/ */
if (metric instanceof ActiveMetric) { if (metric instanceof ActiveMetric) {
ActiveMetric am = (ActiveMetric) metric; ActiveMetric am = (ActiveMetric) metric;
am.addActiveMetricListener(new MetricDaoAdapter(am)); MetricDaoAdapter adapter = new MetricDaoAdapter(am);
am.addActiveMetricListener(adapter);
daoAdapters.add(adapter);
} }
} }
} }
@Override @Override
public void onStop() { public void onStop() {
for (MetricDaoAdapter adapter : daoAdapters) {
adapter.onStop();
}
/* /*
* Commit missing values * Commit missing values
*/ */
...@@ -136,6 +167,8 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -136,6 +167,8 @@ public class MetricOutputDAO extends AbstractOutput {
private final Map<String, List<SimHost>> hostsByGroup; private final Map<String, List<SimHost>> hostsByGroup;
private final Map<String, DescriptiveStatistics> globalStatsByGroup;
private long timestampLastEvent = -1; private long timestampLastEvent = -1;
public MetricDaoAdapter(ActiveMetric metric) { public MetricDaoAdapter(ActiveMetric metric) {
...@@ -144,17 +177,33 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -144,17 +177,33 @@ public class MetricOutputDAO extends AbstractOutput {
metric.getName(), metric.getDescription(), metric.getName(), metric.getDescription(),
metric.getUnit().toString()); metric.getUnit().toString());
this.hosts = GlobalOracle.getHosts(); this.hosts = GlobalOracle.getHosts();
writeAggregates = metricsToAggregate.contains(metric.getName()); this.writeAggregates = isToAggregate(metric);
this.hostsByGroup = new LinkedHashMap<>(); this.hostsByGroup = new LinkedHashMap<>();
this.globalStatsByGroup = new LinkedHashMap<>();
for (SimHost simHost : hosts) { for (SimHost simHost : hosts) {
String groupId = simHost.getProperties().getGroupID(); String groupId = simHost.getProperties().getGroupID();
if (!this.hostsByGroup.containsKey(groupId)) { if (!this.hostsByGroup.containsKey(groupId)) {
this.hostsByGroup.put(groupId, new LinkedList<>()); this.hostsByGroup.put(groupId, new LinkedList<>());
this.globalStatsByGroup.put(groupId,
new DescriptiveStatistics());
} }
this.hostsByGroup.get(groupId).add(simHost); this.hostsByGroup.get(groupId).add(simHost);
} }
} }
public void onStop() {
if (writeAggregates) {
for (Entry<String, DescriptiveStatistics> groupData : globalStatsByGroup
.entrySet()) {
MeasurementDAO.storeGroupStatisticsMeasurement(md,
groupData.getKey(), Time.getCurrentTime(),
groupData.getValue(),
Time.getCurrentTime() - timeEnableDao, true);
}
globalStatsByGroup.clear();
}
}
@Override @Override
public void onMetricUpdate(ActiveMetric metric) { public void onMetricUpdate(ActiveMetric metric) {
long time = Time.getCurrentTime(); long time = Time.getCurrentTime();
...@@ -184,6 +233,8 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -184,6 +233,8 @@ public class MetricOutputDAO extends AbstractOutput {
// Iterate over groups // Iterate over groups
for (String group : hostsByGroup.keySet()) { for (String group : hostsByGroup.keySet()) {
DescriptiveStatistics stats = new DescriptiveStatistics(); DescriptiveStatistics stats = new DescriptiveStatistics();
DescriptiveStatistics globalStats = globalStatsByGroup
.get(group);
for (SimHost host : hostsByGroup.get(group)) { for (SimHost host : hostsByGroup.get(group)) {
MetricValue mv = metric MetricValue mv = metric
.getPerHostMetric(host.getId()); .getPerHostMetric(host.getId());
...@@ -198,14 +249,17 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -198,14 +249,17 @@ public class MetricOutputDAO extends AbstractOutput {
} }
// Add value // Add value
stats.addValue(vd); stats.addValue(vd);
globalStats.addValue(vd);
} }
} }
} }
} }
// Write Group stats // Write Group stats
long observationDuration = Time.getCurrentTime() - timestampLastEvent; long observationDuration = Time.getCurrentTime()
- timestampLastEvent;
if (timestampLastEvent == -1) { if (timestampLastEvent == -1) {
observationDuration = Time.getCurrentTime() - timeEnableDao; observationDuration = Time.getCurrentTime()
- timeEnableDao;
} }
MeasurementDAO.storeGroupStatisticsMeasurement(md, MeasurementDAO.storeGroupStatisticsMeasurement(md,
group, time, stats, observationDuration, false); group, time, stats, observationDuration, false);
......
...@@ -85,8 +85,10 @@ public class DefaultMonitor implements MonitorComponent, EventHandler, ...@@ -85,8 +85,10 @@ public class DefaultMonitor implements MonitorComponent, EventHandler,
@Override @Override
public <A extends Analyzer> void registerAnalyzer(A analyzer) { public <A extends Analyzer> void registerAnalyzer(A analyzer) {
if (!analyzers.contains(analyzer)) {
analyzers.add(analyzer); analyzers.add(analyzer);
} }
}
@Override @Override
public void log(Class<?> subject, Level level, String msg, Object... data) { public void log(Class<?> subject, Level level, String msg, Object... data) {
......
...@@ -92,6 +92,8 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -92,6 +92,8 @@ public class DefaultTopologyComponent implements TopologyComponent {
private PlacementModel placementModel; private PlacementModel placementModel;
private final boolean registerAsInformationProviderInSiS;
/** /**
* Create a TopologyComponent for the current host. * Create a TopologyComponent for the current host.
* *
...@@ -100,7 +102,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -100,7 +102,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
* @param movementModel * @param movementModel
*/ */
public DefaultTopologyComponent(SimHost host, Topology topology, public DefaultTopologyComponent(SimHost host, Topology topology,
MovementModel movementModel, PlacementModel placementModel) { MovementModel movementModel, PlacementModel placementModel, boolean registerAsInformationProviderInSiS) {
this.topology = topology; this.topology = topology;
this.host = host; this.host = host;
this.position = new PositionVector(0, 0); this.position = new PositionVector(0, 0);
...@@ -114,6 +116,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -114,6 +116,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
if (this.placementModel != null) { if (this.placementModel != null) {
this.placementModel.addComponent(this); this.placementModel.addComponent(this);
} }
this.registerAsInformationProviderInSiS = registerAsInformationProviderInSiS;
} }
@Override @Override
...@@ -132,6 +135,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -132,6 +135,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
position.set(placementModel.place(this)); position.set(placementModel.place(this));
} }
if (registerAsInformationProviderInSiS) {
try { try {
final SiSComponent sis = host.getComponent(SiSComponent.class); final SiSComponent sis = host.getComponent(SiSComponent.class);
sis.provide().nodeState(SiSTypes.PHY_LOCATION, sis.provide().nodeState(SiSTypes.PHY_LOCATION,
...@@ -180,6 +184,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -180,6 +184,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
// OK // OK
} }
} }
}
@Override @Override
public void shutdown() { public void shutdown() {
......
...@@ -72,6 +72,8 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -72,6 +72,8 @@ public class TopologyFactory implements HostComponentFactory {
private ObstacleModel obstacleModel; private ObstacleModel obstacleModel;
private boolean registerAsInformationProviderInSiS = false;
private static NetMeasurementDB measurementDB = null; private static NetMeasurementDB measurementDB = null;
private static Map<SimHost, NetMeasurementDB.Host> measurementDBHosts = new LinkedHashMap<SimHost, NetMeasurementDB.Host>(); private static Map<SimHost, NetMeasurementDB.Host> measurementDBHosts = new LinkedHashMap<SimHost, NetMeasurementDB.Host>();
...@@ -125,7 +127,7 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -125,7 +127,7 @@ public class TopologyFactory implements HostComponentFactory {
* movement model. * movement model.
*/ */
TopologyComponent toCo = new DefaultTopologyComponent(host, topo, TopologyComponent toCo = new DefaultTopologyComponent(host, topo,
movement, placement); 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
...@@ -228,6 +230,17 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -228,6 +230,17 @@ public class TopologyFactory implements HostComponentFactory {
TopologyFactory.useRegionGroups = useRegionGroups; TopologyFactory.useRegionGroups = useRegionGroups;
} }
/**
* Option to disable the default behavior of nodes registering as
* topology providers.
*
* @param registerAsLocationProviderInSiS
*/
public void setRegisterAsInformationProviderInSiS(
boolean registerAsInformationProviderInSiS) {
this.registerAsInformationProviderInSiS = registerAsInformationProviderInSiS;
}
/** /**
* Allows GNP-based strategies to retrieve the unique * Allows GNP-based strategies to retrieve the unique
* {@link NetMeasurementDB.Host} - as this object should only be created * {@link NetMeasurementDB.Host} - as this object should only be created
......
...@@ -22,6 +22,7 @@ package de.tud.kom.p2psim.impl.topology.movement.local; ...@@ -22,6 +22,7 @@ package de.tud.kom.p2psim.impl.topology.movement.local;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.UUID;
import com.graphhopper.GHRequest; import com.graphhopper.GHRequest;
import com.graphhopper.GHResponse; import com.graphhopper.GHResponse;
...@@ -38,6 +39,8 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation; ...@@ -38,6 +39,8 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.util.Either; import de.tud.kom.p2psim.impl.util.Either;
import de.tud.kom.p2psim.impl.util.Left; import de.tud.kom.p2psim.impl.util.Left;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
/** /**
* This movement strategy uses the data from osm and navigates the nodes throught streets to the destination * This movement strategy uses the data from osm and navigates the nodes throught streets to the destination
...@@ -61,6 +64,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -61,6 +64,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private double latRight; //Values from -90 to 90 private double latRight; //Values from -90 to 90
private double lonLeft; //Values from -180 to 180; Always smaller than lonRight private double lonLeft; //Values from -180 to 180; Always smaller than lonRight
private double lonRight; //Values from -180 to 180 private double lonRight; //Values from -180 to 180
private boolean uniqueFolders;
/** /**
* Tolerance in meters (if the node reached a waypoint up to "tolerance" * Tolerance in meters (if the node reached a waypoint up to "tolerance"
...@@ -81,7 +85,16 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -81,7 +85,16 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
hopper = new GraphHopper().forServer(); hopper = new GraphHopper().forServer();
hopper.setOSMFile(osmFileLocation); hopper.setOSMFile(osmFileLocation);
// where to store graphhopper files? // where to store graphhopper files?
hopper.setGraphHopperLocation(graphFolderFiles+"/"+osmFileLocation.hashCode()+movementType); if (uniqueFolders) {
Monitor.log(RealWorldStreetsMovement.class, Level.WARN,
"Using per-simulation unique folders for GraphHopper temporary data in %s. Remember to delete them to prevent your disk from filling up.",
graphFolderFiles);
hopper.setGraphHopperLocation(graphFolderFiles + "/"
+ UUID.randomUUID().toString());
} else {
hopper.setGraphHopperLocation(graphFolderFiles + "/"
+ osmFileLocation.hashCode() + movementType);
}
hopper.setEncodingManager(new EncodingManager(movementType)); hopper.setEncodingManager(new EncodingManager(movementType));
hopper.importOrLoad(); hopper.importOrLoad();
init = true; init = true;
...@@ -190,4 +203,16 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -190,4 +203,16 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
public void setWaypointTolerance(double tolerance) { public void setWaypointTolerance(double tolerance) {
this.tolerance = tolerance; this.tolerance = tolerance;
} }
/**
* For large batch simulations, we need to prevent same-time access to
* garphhopper temp data. Therefore, this flag creates unique folders for
* each run (which, obviously, wastes a lot of space and comp-resources and
* should not be used in standalone, single-threaded demo mode...)
*
* @param uniqueFolders
*/
public void setCreateUniqueFolders(boolean uniqueFolders) {
this.uniqueFolders = uniqueFolders;
}
} }
...@@ -240,14 +240,18 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac ...@@ -240,14 +240,18 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
*/ */
PositionVector attractionCenter = (PositionVector) newAssignment; PositionVector attractionCenter = (PositionVector) newAssignment;
PositionVector destination = null; PositionVector destination = null;
/*
* Even if an AP does not have a radius, we slightly offset
*/
double apRadius = Math.max(newAssignment.getRadius(), 25.0);
int tries = 0; int tries = 0;
do { do {
destination = new PositionVector(attractionCenter); destination = new PositionVector(attractionCenter);
// Gaussian with std = 1 --> >99% of nodes // Gaussian with std = 1 --> >99% of nodes
PositionVector offset = new PositionVector( PositionVector offset = new PositionVector(
rand.nextGaussian() * newAssignment.getRadius() / 3, rand.nextGaussian() * apRadius / 3,
rand.nextGaussian() * newAssignment.getRadius() / 3); rand.nextGaussian() * apRadius / 3);
destination.add(offset); destination.add(offset);
// Check constraints // Check constraints
if (destination.getX() < 0.0 if (destination.getX() < 0.0
......
...@@ -260,7 +260,11 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, ...@@ -260,7 +260,11 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
* FIXME add @Override lateron, as soon as the API is updated globally. * FIXME add @Override lateron, as soon as the API is updated globally.
*/ */
public void removeTransportMessageListener() { public void removeTransportMessageListener() {
assert listener != null; // assert listener != null;
if (listener == null) {
Monitor.log(ModularTransLayer.class, Level.DEBUG, "Trying tor remove a non-existing transport message listener.");
return;
}
removeTransMsgListener(listener, localPort); removeTransMsgListener(listener, localPort);
listener = null; listener = null;
} }
......
...@@ -169,6 +169,41 @@ public class MeasurementDAO extends DAO { ...@@ -169,6 +169,41 @@ public class MeasurementDAO extends DAO {
addToPersistQueue(measurement); addToPersistQueue(measurement);
} }
/**
* Stores a statistical description of a series of values for group of
* hosts and a given spatial coordinate.
*
* @param metricDesc
* The {@link MetricDescription} which describes the metric.
* @param groupName
* The host group
* @param time
* A time for the measurement in simulation time
* @param stats
* the {@link DescriptiveStatistics} object used as input
* @param observationDuration
* duration of this observation in simulation time
* @param describesWholeSimulation
* true, if this measurement is a description of the WHOLE
* simulation
* @param locationX
* x coordinate for spatial sampling
* @param locationY
* y coordinate for spatial sampling
*/
public static void storeSpatialGroupStatisticsMeasurement(
MetricDescription metricDesc, String groupName, long time,
DescriptiveStatistics stats, long observationDuration,
boolean describesWholeSimulation, int locationX, int locationY) {
Metric metric = MetricDAO.lookupStatisticsMetric(metricDesc);
GroupMetric groupMetric = GroupMetricDAO.lookupGroupMetric(metric,
groupName);
MeasurementStatistic measurement = new MeasurementStatistic(time, stats,
groupMetric, observationDuration, describesWholeSimulation, locationX, locationY);
addToPersistQueue(measurement);
}
/** /**
* Store a list-based measurement with a key (i.e., as a * Store a list-based measurement with a key (i.e., as a
* {@link MeasurementPairList}). * {@link MeasurementPairList}).
......
...@@ -74,6 +74,9 @@ public class MeasurementStatistic implements GroupMetricBound { ...@@ -74,6 +74,9 @@ public class MeasurementStatistic implements GroupMetricBound {
@Column(nullable = true, name = "[values]") @Column(nullable = true, name = "[values]")
private Double values; private Double values;
@Column(nullable = true, name = "[std]")
private Double std;
@Column(nullable = true, name = "[sum]") @Column(nullable = true, name = "[sum]")
private Double sum; private Double sum;
...@@ -116,11 +119,14 @@ public class MeasurementStatistic implements GroupMetricBound { ...@@ -116,11 +119,14 @@ public class MeasurementStatistic implements GroupMetricBound {
@Column(nullable = true, name = "[perc5]") @Column(nullable = true, name = "[perc5]")
private Double perc5; // 5 private Double perc5; // 5
@Column(nullable = true, name = "[skewness]") @Column(nullable = true, name = "[locationX]")
private Double skewness; private Integer locationX;
@Column(nullable = true, name = "[locationY]")
private Integer locationY;
@Column(nullable = true, name = "[kurtosis]") @Column(nullable = true, name = "[isSpatial]")
private Double kurtosis; private boolean isSpatial;
/** /**
* Mapping to group metric * Mapping to group metric
...@@ -152,6 +158,36 @@ public class MeasurementStatistic implements GroupMetricBound { ...@@ -152,6 +158,36 @@ public class MeasurementStatistic implements GroupMetricBound {
this.groupMetric = groupMetric; this.groupMetric = groupMetric;
} }
/**
* Creates a {@link Measurement}-Object using the provided
* {@link DescriptiveStatistics} object, with spatial data attached.
*
* @param time
* The simulation time for to this measurement as Date
* @param stats
* the {@link DescriptiveStatistics} object
* @param hostMetric
* The reference to the {@link HostMetric}-Object, which
* describes this metric. Is used for the mapping.
* @param observationDuration
* duration of the observation
* @param describesWholeSimulation
* true, if this measurement describes the whole simulation
* @param locationX
* x coordinate for spatial sampling
* @param locationY
* y coordinate for spatial sampling
*/
public MeasurementStatistic(long time, DescriptiveStatistics stats,
GroupMetric groupMetric, long observationDuration,
boolean describesWholeSimulation, int locationX, int locationY) {
this(time, stats, observationDuration, describesWholeSimulation);
this.groupMetric = groupMetric;
this.locationX = locationX;
this.locationY = locationY;
this.isSpatial = true;
}
/** /**
* Internal - write statistics * Internal - write statistics
* *
...@@ -179,8 +215,8 @@ public class MeasurementStatistic implements GroupMetricBound { ...@@ -179,8 +215,8 @@ public class MeasurementStatistic implements GroupMetricBound {
this.perc97 = checkForSpecialNumbers(stats.getPercentile(97.7)); this.perc97 = checkForSpecialNumbers(stats.getPercentile(97.7));
this.perc5 = checkForSpecialNumbers(stats.getPercentile(5)); this.perc5 = checkForSpecialNumbers(stats.getPercentile(5));
this.perc95 = checkForSpecialNumbers(stats.getPercentile(95)); this.perc95 = checkForSpecialNumbers(stats.getPercentile(95));
this.skewness = checkForSpecialNumbers(stats.getSkewness()); this.std = checkForSpecialNumbers(stats.getStandardDeviation());
this.kurtosis = checkForSpecialNumbers(stats.getKurtosis()); this.isSpatial = false;
} }
/** /**
......
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