Commit eff5d429 authored by Julian Zobel's avatar Julian Zobel 🦄
Browse files

Merge branch 'master' into 'cherry-pick-7698d9d7'

# Conflicts:
#   src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputDAO.java
#   src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java
parents 1c7f20ec 37020b44
......@@ -30,6 +30,8 @@ import javax.swing.border.BevelBorder;
import com.google.common.collect.Maps;
import de.tud.kom.p2psim.impl.util.guirunner.Config;
/**
* JFrame which holds all the live plots.
*
......@@ -42,9 +44,16 @@ import com.google.common.collect.Maps;
* they will stay add a minimum height of 250 px and a scrollbar will be added instead.
*/
public class PlottingView extends JFrame {
private static final int VIEW_WIDTH = 900;
private static final int VIEW_HEIGHT = 800;
/*
* Configuration paths
*/
static final String CONF_PATH = "GUIRunner/LivePlotWindow/";
static final String CONF_PATH_POSX = CONF_PATH + "PosX";
static final String CONF_PATH_POSY = CONF_PATH + "PosY";
static final String CONF_PATH_WIDTH = CONF_PATH + "Width";
static final String CONF_PATH_HEIGHT = CONF_PATH + "Height";
private static final int PLOT_HEIGHT_MIN = 250;
private static final Color PLOT_BACKGROUND_COLOR = Color.WHITE;
......@@ -69,8 +78,16 @@ public class PlottingView extends JFrame {
spane = new JScrollPane(plotBox);
add(spane);
setSize(VIEW_WIDTH, VIEW_HEIGHT);
setPreferredSize(new Dimension(VIEW_WIDTH, VIEW_HEIGHT));
int locationX = Config.getValue(CONF_PATH_POSX, 0);
int locationY = Config.getValue(CONF_PATH_POSY, 0);
setLocation(locationX, locationY);
int winWidth = Config.getValue(CONF_PATH_WIDTH, 900);
int winHeight = Config.getValue(CONF_PATH_HEIGHT, 800);
setSize(winWidth, winHeight);
setPreferredSize(new Dimension(winWidth, winHeight));
}
public XYChart createPlot(String name, String seriesName) {
......@@ -170,7 +187,7 @@ public class PlottingView extends JFrame {
private class PlotBox extends JPanel implements Scrollable
{
private boolean enableScroll = false;
private Dimension preferredSize = new Dimension(VIEW_WIDTH, 800);
private Dimension preferredSize = new Dimension( Config.getValue(CONF_PATH_WIDTH, 900), 800);
@Override
public Component add(Component comp)
......
......@@ -166,10 +166,10 @@ public class SimControlPanel extends JMenuBar implements ActionListener, ChangeL
}
protected JSlider getSpeedSlider() {
if (speedslider == null) {
speedslider = new JSlider(SwingConstants.HORIZONTAL, 1, 30, 5);
speedslider.addChangeListener(this);
// speedslider.setValue(speedslider.getMaximum());
if (speedslider == null) {
int simskew = ((int)Simulator.getScheduler().getTimeSkew() + 4 > 50 ? simskew = 50 : (int)Simulator.getScheduler().getTimeSkew() + 4);
speedslider = new JSlider(SwingConstants.HORIZONTAL, 1, 50, simskew);
speedslider.addChangeListener(this);
}
return speedslider;
}
......@@ -223,7 +223,7 @@ public class SimControlPanel extends JMenuBar implements ActionListener, ChangeL
protected JLabel getSpeedLabel() {
if (speedlabel == null) {
speedlabel = new JLabel("max");
speedlabel = new JLabel(Simulator.getScheduler().getTimeSkew() + "x");
}
return speedlabel;
}
......@@ -275,7 +275,7 @@ public class SimControlPanel extends JMenuBar implements ActionListener, ChangeL
}
protected void changeSimulationSkew(double skew) {
if (skew == 30) {
if (skew == 50) {
getSpeedLabel().setText("max");
Simulator.getScheduler().setTimeSkew(0);
} else {
......
......@@ -26,6 +26,9 @@ import java.awt.Point;
import java.awt.Polygon;
import java.awt.geom.Point2D;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.util.Triple;
/**
* Helpers for your own visualization components
*
......@@ -76,4 +79,24 @@ public class VisHelper {
drawArrow(g2, from.getX(), from.getY(), to.getX(), to.getY(), thickness);
}
/**
* uses the start-/end position and the percentage and determines with
* vector addition the new position on the line between start and end
* according to the percentage of already traveled distance.
*
* @param messageBall
* @return the current position of the message.
*/
public static PositionVector determineNewMessageBallPosition(
Triple<PositionVector, PositionVector, Integer> messageBall) {
double distance = messageBall.getA().distanceTo(messageBall.getB());
PositionVector differenceVector = messageBall.getB()
.minus(messageBall.getA());
differenceVector.normalize();
differenceVector.multiplyScalar(
messageBall.getC().doubleValue() / 100d * distance);
PositionVector pos = messageBall.getA().clone();
pos.add(differenceVector);
return pos;
}
}
......@@ -38,7 +38,7 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisNodeInformation;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.VisualizationComponent;
......@@ -218,12 +218,22 @@ implements VisualizationComponent {
float hue = i / (float) dimensionSize;
// colors[dim][i] = Color.getHSBColor(hue, hsbVals[1],
// hsbVals[2]);
colors[dim][i] = tuColors[i];
colors[dim][i] = getColor(i);
}
}
}
private Color getColor(int i) {
if(i < tuColors.length) {
return tuColors[i];
}
else {
return new Color(255, 0, 0);
}
}
/**
* Called on one of the nodes to draw global objects such as a legend.
* Called before draw.
......
......@@ -43,7 +43,7 @@ import javax.swing.event.ChangeListener;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.topology.social.SocialView;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector.MouseClickListener;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.VisualizationComponent;
......
......@@ -34,9 +34,9 @@ import javax.swing.JComponent;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModelListener;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdge;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.StrongWaypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
......@@ -137,7 +137,7 @@ public class StrongWaypointComponentVis extends JComponent
}
@Override
public void addedPath(Path path) {
public void addedPath(PathEdge path) {
needsRedraw = true;
}
......
......@@ -35,12 +35,13 @@ import java.util.Set;
import javax.swing.JComponent;
import org.jgrapht.Graph;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModelListener;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.DefaultWeightedEdgeRetrievableGraph;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdge;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
......@@ -125,11 +126,11 @@ public class WeakWaypointComponentVis extends JComponent implements WaypointMode
}
protected void drawColoredGraph(Graphics2D g2) {
ArrayList<Path> usedWaypoints = new ArrayList<Path>();
ArrayList<PathEdge> usedWaypoints = new ArrayList<PathEdge>();
ArrayList<Waypoint> starts = new ArrayList<Waypoint>();
Collection<Waypoint> waypoints = model.getWaypoints();
DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> graph = model.getGraph();
Graph<Waypoint, PathEdge> graph = model.getGraph();
if (waypoints == null || waypoints.isEmpty() || graph == null) {
throw new RuntimeException() {
......@@ -141,13 +142,13 @@ public class WeakWaypointComponentVis extends JComponent implements WaypointMode
if (starts.contains(wp)) continue;
starts.add(wp);
ArrayList<Path> workList = new ArrayList<Path>();
ArrayList<PathEdge> workList = new ArrayList<PathEdge>();
workList.addAll(graph.edgesOf(wp));
Color pathColor = getRandomColor();
while (!workList.isEmpty()) {
Path p = workList.remove(0);
PathEdge p = workList.remove(0);
Waypoint target = p.getTarget();
starts.add(target);
......@@ -173,8 +174,8 @@ public class WeakWaypointComponentVis extends JComponent implements WaypointMode
}
}
private boolean containsPath(ArrayList<Path> workList, Path p1) {
for (Path p : workList) {
private boolean containsPath(ArrayList<PathEdge> workList, PathEdge p1) {
for (PathEdge p : workList) {
if (p.equals(p1)) {
return true;
}
......@@ -187,7 +188,7 @@ public class WeakWaypointComponentVis extends JComponent implements WaypointMode
}
protected void drawPaths(Graphics2D g2) {
Set<Path> paths = model.getPaths();
Set<PathEdge> paths = model.getPaths();
if (paths.isEmpty()) {
throw new RuntimeException() {
......@@ -195,7 +196,7 @@ public class WeakWaypointComponentVis extends JComponent implements WaypointMode
};
}
for (Path p : paths) {
for (PathEdge p : paths) {
PositionVector sourcePos = p.getSource().getPosition();
PositionVector targetPos = p.getTarget().getPosition();
......@@ -227,7 +228,7 @@ public class WeakWaypointComponentVis extends JComponent implements WaypointMode
}
@Override
public void addedPath(Path path) {
public void addedPath(PathEdge path) {
needsRedraw = true;
}
......
......@@ -121,6 +121,10 @@ public class LogDistancePropagationLossModel extends PropagationLossModel {
return exponent;
}
protected double getReferenceLoss() {
return referenceLoss;
}
/**
* The lamba and the referenceLoss is depending of the frequency and the
* referenceDistance. If one of this values changed, then should be updated
......
package de.tud.kom.p2psim.impl.topology.views.wifi.phy.propagation.loss;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/**
* A model suited for connections between antennas at heights of 0.5-3m. Defined
* in:
* <p>
* Konstantinou, K., Kang, S., & Tzaras, C. (2007). A measurement-based model for
* mobile-to-mobile UMTS links. IEEE Vehicular Technology Conference, 529–533.
* http://doi.org/10.1109/VETECS.2007.120
* <p>
* The model defines path loss for line of sight (LOS) and non light of sight (NLOS)
* propagation.
* <pre>
* PLOS = 4.62 + 20 * log10(4π/λ) - 2.24ht - 4.9hr + 29.6 * log10(d)
* PNLOS = 20 * log10(4π/λ) - 2 *hr + 40 * log10(d) + C
*
* C = 0 if dense urban (HB > 18m), -4 else (HB < 12m)
* </pre>
* <p>
* with λ the wavelength, HB average building height, ht and hr the height of
* the transmitting and receiving antenna above ground, d the distance.
* <p>
* The average path loss is estimated as <code>PL = α PLLOS + (1-α)PLNLOS</code>, where
* α is the probability that there is a LOS connection between transmitter and
* receiver.
*
* @author Tim Feuerbach
*/
public class SurreyPropagationLossModel extends LogDistancePropagationLossModel {
private double C = 0;
private double alpha = 0.098601797632;
private double transmitterHeight = 1.6;
private double receiverHeight = 1.6;
/**
* Distance below which the model will always return the TX power.
*/
private double minDistance = 0.5d;
@Override
public double getRxPowerDbm(double txPowerDbm, Location a, Location b) {
return getRxPowerDbm(txPowerDbm, a.distanceTo(b));
}
@Override
public double getRxPowerDbm(double txPowerDbm, double distance) {
if (distance < minDistance) return txPowerDbm;
double pLOS = 4.62 + getReferenceLoss() - 2.24 * transmitterHeight - 4.9 * receiverHeight + 29.6 *
Math.log10(distance);
double pNLOS = getReferenceLoss() - 2 * receiverHeight + 40 * Math.log10(distance) + C;
double loss = alpha * pLOS + (1 - alpha) * pNLOS;
return txPowerDbm - Math.max(0, loss);
}
@Override
public double getDistance(double txPowerDbm, double rxPowerDbm) {
double p = Math.abs(rxPowerDbm - txPowerDbm);
// TODO use less obscure formulation, this one was obtained from Wolfram Alpha by solving for d
return Math.exp((-285379588546205536L * alpha * C - 827600806783996032L * alpha *
receiverHeight - 639250278343500416L * alpha * transmitterHeight + 1318453699083469568L
* alpha + 285379588546205536L * C - 285379588546205536L * p - 570759177092411072L *
receiverHeight + 285379588546205536L * getReferenceLoss()) / (1288963317755749376L *
alpha - 4957551222137499648L));
}
public void setIsUrban(boolean isUrban) {
C = (isUrban) ? 0 : -4;
}
public void setLosProbability(double losProbability) {
this.alpha = losProbability;
}
public void setTransmitterHeight(double transmitterHeight) {
this.transmitterHeight = transmitterHeight;
}
public void setReceiverHeight(double receiverHeight) {
this.receiverHeight = receiverHeight;
}
}
......@@ -25,7 +25,9 @@ import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.jgrapht.alg.DijkstraShortestPath;
import org.jgrapht.Graph;
import org.jgrapht.GraphPath;
import org.jgrapht.alg.shortestpath.DijkstraShortestPath;
import com.google.common.collect.Sets;
......@@ -37,9 +39,8 @@ import de.tud.kom.p2psim.api.topology.waypoints.WaypointModelListener;
import de.tud.kom.p2psim.api.util.geo.maps.Map;
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.waypoints.graph.DefaultWeightedEdgeRetrievableGraph;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdge;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.util.Tuple;
import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener;
......@@ -221,26 +222,26 @@ public abstract class AbstractWaypointModel implements WaypointModel {
}
@Override
public List<Tuple<Waypoint, Path>> getConnectedWaypoints(Waypoint waypoint) {
public List<Tuple<Waypoint, PathEdge>> getConnectedWaypoints(Waypoint waypoint) {
return getConnectedWaypoints(waypoint, Waypoint.class);
}
@Override
public List<Tuple<Waypoint, Path>> getConnectedWaypoints(Waypoint waypoint,
public List<Tuple<Waypoint, PathEdge>> getConnectedWaypoints(Waypoint waypoint,
Class type) {
Set<Path> paths = map.getGraph().edgesOf(waypoint);
ArrayList<Tuple<Waypoint, Path>> waypointsAndPaths = new ArrayList<Tuple<Waypoint, Path>>();
Set<PathEdge> paths = map.getGraph().edgesOf(waypoint);
ArrayList<Tuple<Waypoint, PathEdge>> waypointsAndPaths = new ArrayList<Tuple<Waypoint, PathEdge>>();
for (Path p : paths) {
for (PathEdge p : paths) {
Waypoint destinationWaypoint = null;
if (p.getSource().equals(waypoint))
destinationWaypoint = p.getTarget();
else if (p.getTarget().equals(waypoint))
destinationWaypoint = p.getSource();
if (map.getGraph().getEdgeSource(p).equals(waypoint))
destinationWaypoint = map.getGraph().getEdgeTarget(p);
else if (map.getGraph().getEdgeTarget(p).equals(waypoint))
destinationWaypoint = map.getGraph().getEdgeSource(p);
if (destinationWaypoint.getClass().equals(type))
waypointsAndPaths.add(new Tuple<Waypoint, Path>(
waypointsAndPaths.add(new Tuple<Waypoint, PathEdge>(
destinationWaypoint, p));
}
......@@ -278,7 +279,7 @@ public abstract class AbstractWaypointModel implements WaypointModel {
}
}
private void notifyAddedPath(Path path) {
private void notifyAddedPath(PathEdge path) {
for (WaypointModelListener l : listeners) {
l.addedPath(path);
}
......@@ -302,19 +303,18 @@ public abstract class AbstractWaypointModel implements WaypointModel {
}
@Override
public Set<Path> getPaths() {
return map.getGraph().getAllEdges();
public Set<PathEdge> getPaths() {
return map.getGraph().edgeSet();
}
@Override
public List<Path> getShortestPath(Waypoint start, Waypoint end) {
DijkstraShortestPath<Waypoint, Path> dijkstrashortestpath = new DijkstraShortestPath<Waypoint, Path>(
map.getGraph(), start, end);
public List<PathEdge> getShortestPath(Waypoint start, Waypoint end) {
DijkstraShortestPath<Waypoint, PathEdge> dijkstrashortestpath = new DijkstraShortestPath<Waypoint, PathEdge>(map.getGraph());
GraphPath gp = dijkstrashortestpath.getPath(start, end);
List<Path> paths = dijkstrashortestpath.getPathEdgeList();
return dijkstrashortestpath.getPathEdgeList();
return dijkstrashortestpath.getPath(start, end).getEdgeList();
}
@Override
......@@ -323,7 +323,7 @@ public abstract class AbstractWaypointModel implements WaypointModel {
}
@Override
public DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> getGraph() {
public Graph<Waypoint, PathEdge> getGraph() {
if (map == null)
return null;
......
......@@ -20,7 +20,7 @@
package de.tud.kom.p2psim.impl.topology.waypoints;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
public class DefaultWaypointModel extends AbstractWaypointModel {
public DefaultWaypointModel() {
......
/*
* 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.waypoints;
import java.util.Random;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.DefaultTopology;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
public class RandomWaypointGenerator {
private Random rand;
private PositionVector worldDimension;
public RandomWaypointGenerator() {
super();
this.worldDimension = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
this.rand = Randoms.getRandom(RandomWaypointGenerator.class);
}
public PositionVector getRandomPoint() {
double x = rand.nextDouble() * Math.nextUp(worldDimension.getX());
double y = rand.nextDouble() * Math.nextUp(worldDimension.getY());
PositionVector pos = new PositionVector(x, y);
if(!DefaultTopology.isWithinWorldBoundaries(pos)) {
throw new UnsupportedOperationException("[RandomWaypointGenerator] The random generated point must be inside the simulation area!");
}
return pos;
}
}
\ No newline at end of file
......@@ -30,12 +30,12 @@ import org.jgrapht.graph.DefaultWeightedEdge;
* @author Fabio Zöllner
* @version 1.0, 27.03.2012
*/
public class Path extends DefaultWeightedEdge {
public class PathEdge extends DefaultWeightedEdge {
private Waypoint source;
private Waypoint target;
private double weight = 1;
public Path(Waypoint source, Waypoint target) {
public PathEdge(Waypoint source, Waypoint target) {
this.source = source;
this.target = target;
......@@ -73,7 +73,7 @@ public class Path extends DefaultWeightedEdge {
if (getClass() != obj.getClass())
return false;
Path other = (Path) obj;
PathEdge other = (PathEdge) obj;
if (getWeight() != other.getWeight() ||
!source.equals(other.getSource()) ||
!target.equals(other.getTarget()))
......
......@@ -20,7 +20,7 @@
package de.tud.kom.p2psim.impl.topology.waypoints.graph;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
/**
* The strong waypoint is intended for the movement through a
......
......@@ -20,7 +20,7 @@
package de.tud.kom.p2psim.impl.topology.waypoints.graph;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
/**
* Represents a node in the map graph.
......
......@@ -20,7 +20,7 @@
package de.tud.kom.p2psim.impl.topology.waypoints.graph;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
/**
* The weak waypoint is intended to provide additional movement
......
......@@ -51,7 +51,7 @@ import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.api.util.geo.maps.Node;
import de.tud.kom.p2psim.api.util.geo.maps.Way;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector.DisplayString;
import de.tud.kom.p2psim.impl.topology.waypoints.StrongWaypointSupport;
......
......@@ -39,7 +39,7 @@ public abstract class CSVReader<T>
while (csv.ready()) {
String line = csv.readLine();
if (line.contains(SEP)) {
if (line != null && line.contains(SEP)) {
String[] parts = line.split(SEP);
T entry = parse(parts);
......
......@@ -21,23 +21,25 @@
package de.tud.kom.p2psim.impl.util.db.dao;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.apache.commons.math3.analysis.function.Exp;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;
import org.hibernate.service.ServiceRegistry;
import org.omg.CORBA.CustomMarshal;
import de.tud.kom.p2psim.impl.util.db.metric.CustomMeasurement;
import de.tud.kom.p2psim.impl.util.db.metric.Experiment;
import de.tud.kom.p2psim.impl.util.db.metric.GroupMetric;
......@@ -50,10 +52,12 @@ import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSpatial;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatisticMsgType;
import de.tud.kom.p2psim.impl.util.db.metric.Metric;
import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.web.WebConfigurationManager;
/**
* This class represents a simple access to persist objects with Hibernate. It
......@@ -100,27 +104,27 @@ public class DAO {
// public static Map<String, Object> configOverwrites = new HashMap<String, Object>();
private static ArrayList<Class<?>> daoClasses = new ArrayList<Class<?>>();
public static String address = "localhost";
public static String port = "3306";
public static String database;
public static String username;
public static String password;
public static String password;
private static SessionFactory sessionFactory;
private static final ThreadLocal<Session> session = new ThreadLocal<Session>();
private static ServiceRegistry serviceRegistry;
/**
* Hibernate-only implementation to support annotated classes without active
* binding
*
*
* @return
*/
public static Session getSession() {
......@@ -138,17 +142,17 @@ public class DAO {
cfg.setProperty("hibernate.connection.url", "jdbc:mysql://"+ address + ":" + port + "/" + database);
cfg.setProperty("hibernate.connection.username", username);
cfg.setProperty("hibernate.connection.password", password);
// mySQL 5
cfg.setProperty("hibernate.dialect",
"org.hibernate.dialect.MySQL5InnoDBDialect");
cfg.setProperty("hibernate.transaction.factory_class",
"org.hibernate.transaction.JDBCTransactionFactory");
cfg.setProperty("hibernate.pool_size", "1");
cfg.setProperty("hibernate.hbm2ddl.auto", "update");
cfg.setProperty("hibernate.current_session_context_class", "thread");
// Add core classes
cfg.addAnnotatedClass(CustomMeasurement.class);
cfg.addAnnotatedClass(Experiment.class);
......@@ -162,9 +166,10 @@ public class DAO {
cfg.addAnnotatedClass(MeasurementSingle.class);
cfg.addAnnotatedClass(MeasurementSpatial.class);
cfg.addAnnotatedClass(MeasurementStatistic.class);
cfg.addAnnotatedClass(MeasurementStatisticMsgType.class);
cfg.addAnnotatedClass(Metric.class);
cfg.addAnnotatedClass(MetricDescription.class);
for (Class<?> clazz : daoClasses) {
cfg.addAnnotatedClass(clazz);
}
......@@ -183,6 +188,30 @@ public class DAO {
return currSession;
}
public static void setDatabase(String pDatabase) {
if (!WebConfigurationManager.isActive()) {
database = pDatabase;
} else {
database = WebConfigurationManager.getConfig().getOptions().getDatabase().getDatabase();
}
}
public static void setUsername(String pUsername) {
if (!WebConfigurationManager.isActive()) {
username = pUsername;
} else {
username = WebConfigurationManager.getConfig().getOptions().getDatabase().getUsername();
}
}
public static void setPassword(String pPassword) {
if (!WebConfigurationManager.isActive()) {
password = pPassword;
} else {
password = WebConfigurationManager.getConfig().getOptions().getDatabase().getPassword();
}
}
/**
* Gets the session
*
......@@ -290,6 +319,15 @@ public class DAO {
DAO.session.remove();
}
public static <T extends Object> List<T> retrieve(Class<T> pClass) {
begin();
Criteria criteria = getSession().createCriteria(pClass);
List<T> objects = criteria.list();
commit();
return objects;
}
/**
* Persist the given POJO directly to the DB. Should be make, if it exists
* relationships between tables.
......@@ -405,7 +443,7 @@ public class DAO {
*
* @param o
* The same object, which is already used to persist.
*
*
* @return The object attached to the persistence context
*/
public static <T> T update(T o) {
......
......@@ -25,6 +25,10 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.util.db.dao.DAO;
......@@ -85,6 +89,22 @@ public class ExperimentDAO extends DAO {
return experiment;
}
public static Experiment retrieveExperiment(long pSeed, Map<String, String> pVariables) {
begin();
Criteria criteria = getSession().createCriteria(Experiment.class);
criteria = criteria.add(Restrictions.eq("seed", pSeed));
for (Entry<String, String> entry : pVariables.entrySet()) {
criteria = criteria.add(Restrictions.like("workload", "%" + entry.getKey() + "=" + entry.getValue() + "%"));
}
List<Experiment> experiments = criteria.list();
commit();
if (experiments.size() > 0) {
return experiments.get(experiments.size() - 1);
}
return null;
}
/** Called by the {@link Time} when the simulation is shut down. */
public static void simulationFinished() {
// If there is no experiment object, no measurements have been made,
......
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