Commit 667f2308 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Removed SimLogger-dependency

parent 7d3a9810
......@@ -30,11 +30,10 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import de.tud.kom.p2psim.impl.util.db.dao.metric.ExperimentDAO;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
/**
* This class represents a simple access to persist objects with Hibernate. It
......@@ -50,10 +49,6 @@ import de.tud.kom.p2psim.impl.util.logging.SimLogger;
*/
public class DAO {
/**
* Logger for this class
*/
private final static Logger log = SimLogger.getLogger(DAO.class);
/**
* The actually session for all DAOs
......@@ -162,13 +157,15 @@ public class DAO {
try {
getEntityManager().getTransaction().rollback();
} catch (HibernateException e) {
log.warn("The Rollback could not executed", e);
Monitor.log(DAO.class, Level.WARN,
"The Rollback could not be executed! %s", e);
}
try {
getEntityManager().close();
} catch (HibernateException e) {
log.warn("The session could not closed", e);
Monitor.log(DAO.class, Level.WARN,
"The session could not be closed! %s", e);
}
DAO.entityManager.set(null);
}
......@@ -224,15 +221,20 @@ public class DAO {
objectCount += persistQueue.size();
if (threads.size() >= maxConnections) {
log.info("Waiting for commitThreads to finish, to not exceeed the maximum of "+maxConnections+ "Connections to the Database.");
Monitor.log(DAO.class, Level.INFO,
"Waiting for commitThreads to finish, to not exceeed the maximum of "
+ maxConnections + "Connections to the Database.");
while (!threads.isEmpty()) {
Thread thread = threads.peek();
try {
log.info("Waiting for thread " + thread.getName()+" to finish");
Monitor.log(DAO.class, Level.INFO, "Waiting for thread "
+ thread.getName() + " to finish");
thread.join();
log.info("Thread " + thread.getName()+" finished");
Monitor.log(DAO.class, Level.INFO,
"Thread " + thread.getName() + " finished");
} catch (InterruptedException e) {
log.warn("got interrupted while waiting for commit threads");
Monitor.log(DAO.class, Level.WARN,
"got interrupted while waiting for commit threads");
continue;
}
threads.poll();
......@@ -250,22 +252,25 @@ public class DAO {
* Wait for all queue committing threads to finish.
*/
public static void finishCommits() {
log.info("waiting for commit threads to finish");
while (threads.size() > 0) {
while (!threads.isEmpty()) {
Thread thread = threads.peek();
try {
log.info("Waiting for thread " + thread.getName()+" to finish");
Monitor.log(DAO.class, Level.INFO, "Waiting for thread "
+ thread.getName() + " to finish");
thread.join();
log.info("Thread " + thread.getName()+" finished");
Monitor.log(DAO.class, Level.INFO, "Thread " + thread.getName()
+ " finished");
} catch (InterruptedException e) {
log.warn("got interrupted while waiting for commit threads");
Monitor.log(DAO.class, Level.WARN,
"got interrupted while waiting for commit threads");
continue;
}
threads.poll();
}
log.info("commit threads finished");
log.info("stored "+objectCount+" objects in "+commitCount+" threaded transactions taking "+commitTime+" ms");
log.info("experiment id: "+ExperimentDAO.getExperiment().getId());
Monitor.log(DAO.class, Level.INFO,
"commit threads finished. \n stored " + objectCount
+ " objects in " + commitCount
+ " threaded transactions taking " + commitTime + " ms");
}
/**
......
......@@ -47,13 +47,13 @@ import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.log4j.Logger;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tud.kom.p2psim.impl.util.toolkits.SAXToolkit;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
/**
* <p>
......@@ -121,8 +121,6 @@ public abstract class RelationalDB implements XMLSerializable {
public static String XML_URI = "urn:simulation:pfs:relational";
private static Logger log = SimLogger.getLogger(RelationalDB.class);
int ARRAY_LIST_START_SZ = 100;
static final boolean DISALLOW_NULL_REFS = true;
......@@ -384,7 +382,11 @@ public abstract class RelationalDB implements XMLSerializable {
checkReleased();
DBIDTypeMeta instList = idObjectInstances.get(tblClass);
if (instList == null) {
log.warn("Instance table of class " + tblClass.getName() + " shall be serialized but is not existing or empty.");
Monitor.log(
RelationalDB.class,
Level.WARN,
"Instance table of class %s shall be serialized but is not existing or empty.",
tblClass.getName());
return;
}
wr.writeStartElement(tblClass.getSimpleName());
......@@ -807,11 +809,7 @@ public abstract class RelationalDB implements XMLSerializable {
DefaultHandler hdlr = getXMLHandler(1);
f.setNamespaceAware(true);
SAXParser parser = f.newSAXParser();
//log.info("Loading DB from in " + in);
long startTime = System.nanoTime();
parser.parse(in, hdlr);
long timeDiff = System.nanoTime() - startTime;
log.info("Loaded DB in " + (timeDiff * 0.000001d) + " milliseconds.");
}
public void readFromXMLFile(InputStream in) throws SAXException, IOException, ParserConfigurationException {
......
......@@ -24,11 +24,8 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.impl.util.functiongenerator.exceptions.FunctionNotLoadedException;
import de.tud.kom.p2psim.impl.util.functiongenerator.functions.Function;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
......@@ -42,7 +39,6 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
*
*/
public class FunctionGenerator {
private static Logger log = SimLogger.getLogger(FunctionGenerator.class);
private static FunctionGenerator instance;
......@@ -54,7 +50,6 @@ public class FunctionGenerator {
public static FunctionGenerator getInstance() {
if (FunctionGenerator.instance == null) {
log.debug("Instantiating new FunctionGenerator");
FunctionGenerator.instance = new FunctionGenerator();
}
......@@ -70,7 +65,6 @@ public class FunctionGenerator {
*/
public final void setFunction(Function function) {
if (!this.functions.values().contains(function)) {
log.debug("Added " + function.toString());
this.functions.put(function.getClass(), function);
}
}
......
......@@ -20,12 +20,11 @@
package de.tud.kom.p2psim.impl.util.functiongenerator.frequencyadjuster;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.impl.util.functiongenerator.functions.Function;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
......@@ -36,7 +35,6 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
*
*/
public abstract class FrequencyAdjuster implements EventHandler {
private static final Logger log = SimLogger.getLogger(FrequencyAdjuster.class);
private long start = 0;
private Function function = null;
private long interval = 0;
......@@ -88,12 +86,11 @@ public abstract class FrequencyAdjuster implements EventHandler {
if (this.function != null) {
adjustFrequency();
this.executionCounter++;
} else {
log.warn(new StringBuilder("Missing function, couldn't adjust frequency at ")
.append(this.start)
.append(" with ")
.append(this.getClass().getSimpleName())
.toString());
} else {
Monitor.log(FrequencyAdjuster.class, Level.WARN,
"Missing function, couldn't adjust frequency at "
+ this.start + " with "
+ this.getClass().getSimpleName());
}
}
......
......@@ -23,10 +23,7 @@ package de.tud.kom.p2psim.impl.util.functiongenerator.functions;
import java.util.LinkedList;
import java.util.List;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.impl.util.functiongenerator.frequencyadjuster.FrequencyAdjuster;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
/**
* The Function class can be used to implement different functions for the
......@@ -36,7 +33,6 @@ import de.tud.kom.p2psim.impl.util.logging.SimLogger;
*
*/
public abstract class Function {
private static Logger log = SimLogger.getLogger(Function.class);
private List<FrequencyAdjuster> frequencyAdjusters = new LinkedList<FrequencyAdjuster>();
......@@ -129,8 +125,6 @@ public abstract class Function {
this.frequencyAdjusters.add(adjuster);
adjuster.schedule();
log.debug("Added " + adjuster.toString());
}
/**
......
......@@ -20,8 +20,6 @@
package de.tud.kom.p2psim.impl.util.geo.maps;
import org.apache.log4j.Logger;
import com.google.common.collect.Maps;
import de.tud.kom.p2psim.api.util.geo.maps.Map;
......@@ -29,12 +27,12 @@ import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView;
import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap.Axis;
import de.tud.kom.p2psim.impl.util.geo.maps.osm.OSMMap;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.Component;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class MapLoader implements Component {
private static final Logger log = SimLogger.getLogger(MapLoader.class);
private java.util.Map<String, Map> maps = Maps.newHashMap();
private PositionVector dimensions = null;
......@@ -78,7 +76,8 @@ public class MapLoader implements Component {
private void configureToScenario(Map map) {
// Map the longitude and latitude to width and height of the simulated world
if (map instanceof AbstractMap) {
log.info("Map " + map .getName() + " is being scaled to " + dimensions);
Monitor.log(MapLoader.class, Level.INFO, "Map " + map.getName()
+ " is being scaled to " + dimensions);
((AbstractMap)map).mapToWorld(dimensions);
}
if (map instanceof OSMMap) {
......
......@@ -28,8 +28,6 @@ import java.util.Map;
import java.util.Stack;
import java.util.Vector;
import org.apache.log4j.Logger;
import com.google.common.collect.Maps;
import de.tud.kom.p2psim.api.util.geo.maps.Node;
......@@ -39,10 +37,8 @@ import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
import de.tud.kom.p2psim.impl.util.Tuple;
import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
public class OSMMap extends AbstractMap {
private Logger log = SimLogger.getLogger(OSMMap.class);
private FuzzyWaypointCache waypointCache = new FuzzyWaypointCache();
......
......@@ -31,7 +31,6 @@ import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.log4j.Logger;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
......@@ -40,10 +39,10 @@ import de.tud.kom.p2psim.api.scenario.ConfigurationException;
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.topology.PositionVector;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
public class OSMReader extends DefaultHandler {
private static Logger log = SimLogger.getLogger(OSMReader.class);
private static HashMap<String, OSMMap> loadedMaps = new HashMap<String, OSMMap>();
private OSMMap map;
......@@ -74,7 +73,6 @@ public class OSMReader extends DefaultHandler {
throw new ConfigurationException("Couldn't find OSM file: " + filename);
try {
log.info("Loading " + filename);
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser parser;
......@@ -93,7 +91,6 @@ public class OSMReader extends DefaultHandler {
reader.postProcessing();
log.info("Original map dimensions: " + map.getDimensions());
} catch (Exception e) {
e.printStackTrace();
}
......@@ -120,7 +117,8 @@ public class OSMReader extends DefaultHandler {
}
}
log.info("Removed " + (size - map.getWays().size()) + " of " + size + " ways.");
Monitor.log(OSMReader.class, Level.INFO, "Removed "
+ (size - map.getWays().size()) + " of " + size + " ways.");
}
private boolean checkBounds(OSMMap map, PositionVector pos) {
......@@ -239,7 +237,6 @@ public class OSMReader extends DefaultHandler {
throw new ConfigurationException("Couldn't find OSM file: " + args[0]);
try {
log.info("Loading " + args[0]);
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser parser;
......
......@@ -37,7 +37,6 @@ import javax.xml.parsers.SAXParserFactory;
import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
import org.apache.batik.parser.AWTPathProducer;
import org.apache.batik.parser.PathParser;
import org.apache.log4j.Logger;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
......@@ -55,7 +54,6 @@ import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
/**
* This map generates waypoints and obstacles based on a given SVG file.
......@@ -78,7 +76,6 @@ import de.tud.kom.p2psim.impl.util.logging.SimLogger;
* @version 1.0, 22.10.2012
*/
public class SVGMap extends AbstractMap {
private static Logger log = SimLogger.getLogger(SVGMap.class);
private Map<PositionVector, Waypoint> waypointCache = Maps.newHashMap();
......@@ -91,7 +88,6 @@ public class SVGMap extends AbstractMap {
+ getFilename());
try {
log.info("Loading " + getFilename());
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser parser;
......
......@@ -24,17 +24,13 @@ package de.tud.kom.p2psim.impl.util.guirunner.impl;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.util.Tuple;
import de.tud.kom.p2psim.impl.util.guirunner.progress.ProgressUIEventNotifier;
import de.tud.kom.p2psim.impl.util.guirunner.progress.SimulationProgressView;
import de.tud.kom.p2psim.impl.util.livemon.LivemonCommonAnalyzer;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
public class SimulationThread extends Thread {
private static final Logger log = SimLogger.getLogger(SimulationThread.class);
int seed;
private ConfigFile f;
......@@ -54,10 +50,8 @@ public class SimulationThread extends Thread {
Simulator sim = Simulator.getInstance();
Map<String, String> variables = new LinkedHashMap<String, String>();
variables.put("seed", String.valueOf(seed));
log.debug("Modifying variables changed in the GUI:");
for (Tuple<String, String> t : f.getModifiedVariables()) {
variables.put(t.getA(), t.getB());
log.debug("- " + t.getA() + ": " + t.getB());
}
String filename = f.getFile().getAbsolutePath();
......
/*
* Copyright (c) 2005-2011 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.util.logging;
import org.apache.log4j.Logger;
/**
* This is a wrapper class for log4j. Log4j is a logging package for printing
* log output to different local and remote destinations. <strong>See
* <code>log4j.properties</code> for configuration</strong>. Be sure to include
* the path to log4j.jar in your CLASSPATH. See <a
* href="http://logging.apache.org/log4j/1.2/index.html">log4j documentation</a>
* for more details.
*
* @author Andre Mink
*
*/
public class SimLogger {
private static SimLogger simLogger;
private SimLogger() {
//
}
/**
* The common and encouraged way to obtain loggers in the simulator. The
* usage of this method will ensure that all loggers are configured from the
* same configuration file, <code>log4j.properties</code> in the root dir of
* the distribution dir.
*
* @param c
* - class for which the logger is required
* @return logger instance
*/
public static Logger getLogger(Class c) {
Logger l = Logger.getLogger(c);
l.trace("Initialized logger");
return l;
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
@(#)package.html 1.60 98/01/27
Copyright 1998
-->
</head>
<body bgcolor="white">
Provides classes required to log events in the simulator. These event outputs are typically used
for two purposes: debugging and obtaining basic information about the simulation progress.
</body>
</html>
......@@ -9,9 +9,8 @@ import java.util.Map.Entry;
import java.util.Random;
import java.util.TreeMap;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
......@@ -27,8 +26,6 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
*
*/
public class CustomDistribution implements Distribution {
private final static Logger log = SimLogger
.getLogger(CustomDistribution.class);
private Random rand = Randoms.getRandom(this);
......@@ -67,7 +64,8 @@ public class CustomDistribution implements Distribution {
.ceilingEntry(randomDouble);
if (greaterOrEqualEntry == null) {
log.warn("No entry with a key greater or equal to " + randomDouble
Monitor.log(CustomDistribution.class, Level.WARN,
"No entry with a key greater or equal to " + randomDouble
+ " has been found. (Has the data been loaded?)");
return 0;
} else {
......@@ -85,7 +83,8 @@ public class CustomDistribution implements Distribution {
*/
private void readCDFData(String csvFilename) {
log.debug("Reading CDF data from CSV file " + csvFilename);
Monitor.log(CustomDistribution.class, Level.INFO,
"Reading CDF data from CSV file %s", csvFilename);
cdfData.clear();
boolean entrySuccessfullyRead = false;
......@@ -114,7 +113,9 @@ public class CustomDistribution implements Distribution {
} catch (NumberFormatException e) {
// Ignore leading comments
if (entrySuccessfullyRead) {
log.warn("Couldn't parse cdf entry " + line);
Monitor.log(CustomDistribution.class,
Level.WARN,
"Couldn't parse cdf entry %s", line);
}
}
} else {
......@@ -124,13 +125,10 @@ public class CustomDistribution implements Distribution {
}
} catch (FileNotFoundException e) {
log.error("Could not open CSV file with CDF data (\"" + csvFilename
+ "\")");
throw new RuntimeException(
"Could not open CSV file with CDF data (\"" + csvFilename
+ "\")");
} catch (IOException e) {
log.error("Failed to read the CDF data (\"" + csvFilename + "\")");
throw new RuntimeException("Failed to read the CDF data (\""
+ csvFilename + "\")");
} finally {
......@@ -142,9 +140,10 @@ public class CustomDistribution implements Distribution {
}
}
log.warn("Read " + cdfData.size() + " unique entries from "
+ csvFilename + "with " + counter
+ " and got a scaling factor of " + scaleFactor);
Monitor.log(CustomDistribution.class, Level.INFO,
"Read " + cdfData.size() + " unique entries from "
+ csvFilename + "with " + counter
+ " and got a scaling factor of " + scaleFactor);
/*
* Scale entries to a value range of ]0,1] if scale == true. This has to
......
......@@ -26,15 +26,13 @@ import java.util.Random;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.NormalDistributionImpl;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class NormalDistribution implements Distribution {
private static final Logger log = SimLogger.getLogger(NormalDistribution.class);
private NormalDistributionImpl normal;
private Random randomGen = Randoms.getRandom(this);
......
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