minor bugfixes + more debug logging
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>1.4.4</version>
|
<version>1.4.5</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
</encoder>
|
</encoder>
|
||||||
<filter class="de.srsoftware.web4rail.ThreadFilter">
|
<filter class="de.srsoftware.web4rail.ThreadFilter">
|
||||||
<level>DEBUG</level>
|
<level>DEBUG</level>
|
||||||
<keywords>Brake, Contact, Feed, Route, Train, e</keywords>
|
<keywords>Brake, Contact, Feed, Route, Train</keywords>
|
||||||
</filter>
|
</filter>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import java.util.Collections;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -70,7 +69,7 @@ public abstract class BaseClass implements Constants{
|
|||||||
private Contact contact;
|
private Contact contact;
|
||||||
private Direction direction;
|
private Direction direction;
|
||||||
private Integer waitTime;
|
private Integer waitTime;
|
||||||
List<EventListener> invalidationListeners = new LinkedList<>();
|
EventListener invalidationListener = null;
|
||||||
|
|
||||||
public Context(BaseClass object) {
|
public Context(BaseClass object) {
|
||||||
setMain(object);
|
setMain(object);
|
||||||
@@ -149,7 +148,7 @@ public abstract class BaseClass implements Constants{
|
|||||||
|
|
||||||
public void invalidate() {
|
public void invalidate() {
|
||||||
setMain(null);
|
setMain(null);
|
||||||
invalidationListeners.forEach(EventListener::fire);
|
if (isSet(invalidationListener)) invalidationListener.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean invalidated() {
|
public boolean invalidated() {
|
||||||
@@ -157,7 +156,7 @@ public abstract class BaseClass implements Constants{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onInvalidate(EventListener listener) {
|
public void onInvalidate(EventListener listener) {
|
||||||
invalidationListeners.add(listener);
|
invalidationListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ public class Plan extends BaseClass{
|
|||||||
}
|
}
|
||||||
tile.position(x, y);
|
tile.position(x, y);
|
||||||
if (tile instanceof TileWithShadow) ((TileWithShadow)tile).placeShadows();
|
if (tile instanceof TileWithShadow) ((TileWithShadow)tile).placeShadows();
|
||||||
|
tile.parent(this);
|
||||||
place(tile);
|
place(tile);
|
||||||
return t("Added {}",tile.getClass().getSimpleName());
|
return t("Added {}",tile.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -374,6 +374,9 @@ public class Route extends BaseClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Route dropNextPreparedRoute() {
|
public Route dropNextPreparedRoute() {
|
||||||
|
if (isSet(nextRoutePrepper)) nextRoutePrepper.stop();
|
||||||
|
nextRoutePrepper = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return nextPreparedRoute;
|
return nextPreparedRoute;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -387,6 +390,7 @@ public class Route extends BaseClass {
|
|||||||
|
|
||||||
public void finish(Train train) {
|
public void finish(Train train) {
|
||||||
LOG.debug("{}.finish()",this);
|
LOG.debug("{}.finish()",this);
|
||||||
|
context.onInvalidate(null); // do in invalidate context of route's nextRoute
|
||||||
context.invalidate();
|
context.invalidate();
|
||||||
train.endRoute(this);
|
train.endRoute(this);
|
||||||
setSignals(Signal.RED);
|
setSignals(Signal.RED);
|
||||||
@@ -690,8 +694,10 @@ public class Route extends BaseClass {
|
|||||||
nextRoutePrepper.onRoutePrepared(() -> {
|
nextRoutePrepper.onRoutePrepared(() -> {
|
||||||
nextPreparedRoute = nextRoutePrepper.route();
|
nextPreparedRoute = nextRoutePrepper.route();
|
||||||
nextRoutePrepper = null;
|
nextRoutePrepper = null;
|
||||||
|
LOG.debug("prepared route after {}: {}",this,nextPreparedRoute);
|
||||||
});
|
});
|
||||||
nextRoutePrepper.onFail(() -> {
|
nextRoutePrepper.onFail(() -> {
|
||||||
|
LOG.debug("preparing route next to {} failed, resetting.",this);
|
||||||
Route rt = nextRoutePrepper.route(); // Nachfolgeroute kann ja schon reserviert sein, oder gar schon teilweise vorbereitet!
|
Route rt = nextRoutePrepper.route(); // Nachfolgeroute kann ja schon reserviert sein, oder gar schon teilweise vorbereitet!
|
||||||
if (isSet(rt)) rt.resetIgnoring(this); // angefangene Route freigeben ohne Teile der aktuellen Route freizugeben
|
if (isSet(rt)) rt.resetIgnoring(this); // angefangene Route freigeben ohne Teile der aktuellen Route freizugeben
|
||||||
nextRoutePrepper = null;
|
nextRoutePrepper = null;
|
||||||
@@ -843,10 +849,16 @@ public class Route extends BaseClass {
|
|||||||
|
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
LOG.debug("{}.start()",this);
|
LOG.debug("{}.start()",this);
|
||||||
if (isNull(context) || context.invalidated()) return false;
|
if (isNull(context) || context.invalidated()) {
|
||||||
|
LOG.debug("Invalid context: {}",context);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Train train = context.train();
|
Train train = context.train();
|
||||||
if (isNull(train)) return false; // can't set route's train to null
|
if (isNull(train)) {
|
||||||
|
LOG.debug("Context does not contain train: {}",context);
|
||||||
|
return false; // can't set route's train to null
|
||||||
|
}
|
||||||
train.setRoute(this); // set new train
|
train.setRoute(this); // set new train
|
||||||
|
|
||||||
triggeredContacts.clear();
|
triggeredContacts.clear();
|
||||||
@@ -856,7 +868,10 @@ public class Route extends BaseClass {
|
|||||||
if (isSet(startActions)) {
|
if (isSet(startActions)) {
|
||||||
context.route(this);
|
context.route(this);
|
||||||
String cause = this+".start("+train.name()+")";
|
String cause = this+".start("+train.name()+")";
|
||||||
if (!startActions.fire(context,cause)) return false; // start actions failed
|
if (!startActions.fire(context,cause)) {
|
||||||
|
LOG.debug("Failed to execute {}",startActions);
|
||||||
|
return false; // start actions failed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context.waitTime(endBlock.getWaitTime(train, endDirection).random());
|
context.waitTime(endBlock.getWaitTime(train, endDirection).random());
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ public class BrakeStart extends Action {
|
|||||||
public boolean fire(Context context,Object cause) {
|
public boolean fire(Context context,Object cause) {
|
||||||
if (isNull(context.train())) return false;
|
if (isNull(context.train())) return false;
|
||||||
context.train().startBrake();
|
context.train().startBrake();
|
||||||
LOG.debug("Started brake process...");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -443,6 +443,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void endRoute(Route endedRoute) {
|
public void endRoute(Route endedRoute) {
|
||||||
|
LOG.debug("{}.endRoute({})",this,endedRoute);
|
||||||
BrakeProcess brake = endBrake();
|
BrakeProcess brake = endBrake();
|
||||||
direction = endedRoute.endDirection; // muss vor der Auswertung des Destination-Tags stehen!
|
direction = endedRoute.endDirection; // muss vor der Auswertung des Destination-Tags stehen!
|
||||||
Block endBlock = endedRoute.endBlock();
|
Block endBlock = endedRoute.endBlock();
|
||||||
@@ -494,6 +495,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if (isSet(brake)) brake.updateTime();
|
if (isSet(brake)) brake.updateTime();
|
||||||
Integer waitTime = route.waitTime();
|
Integer waitTime = route.waitTime();
|
||||||
nextPreparedRoute = route.dropNextPreparedRoute();
|
nextPreparedRoute = route.dropNextPreparedRoute();
|
||||||
|
if (isSet(nextPreparedRoute)) LOG.debug("nextPreparedRoute is now {}",nextPreparedRoute);
|
||||||
if ((!autopilot)|| isNull(nextPreparedRoute) || (isSet(waitTime) && waitTime > 0)) setSpeed(0);
|
if ((!autopilot)|| isNull(nextPreparedRoute) || (isSet(waitTime) && waitTime > 0)) setSpeed(0);
|
||||||
route = null;
|
route = null;
|
||||||
endBlock.setTrain(this);
|
endBlock.setTrain(this);
|
||||||
@@ -632,13 +634,14 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
public void afterLoad() {
|
public void afterLoad() {
|
||||||
if (json.has(TRACE)) json.getJSONArray(TRACE).forEach(elem -> {
|
if (json.has(TRACE)) json.getJSONArray(TRACE).forEach(elem -> {
|
||||||
Tile tile = plan.get(new Id(elem.toString()), false);
|
Tile tile = plan.get(new Id(elem.toString()), false);
|
||||||
tile.setTrain(Train.this);
|
tile.setTrain(Train.this);
|
||||||
trace.add(tile);
|
trace.add(tile);
|
||||||
});
|
});
|
||||||
if (json.has(BLOCK)) {// do not move this up! during set, other fields will be referenced!
|
if (json.has(BLOCK)) {// do not move this up! during set, other fields will be referenced!
|
||||||
currentBlock = (Block) plan.get(Id.from(json, BLOCK), false);
|
currentBlock = (Block) plan.get(Id.from(json, BLOCK), false);
|
||||||
if (isSet(currentBlock)) {
|
if (isSet(currentBlock)) {
|
||||||
currentBlock.setTrain(Train.this);
|
currentBlock.setTrain(Train.this);
|
||||||
|
trace.add(currentBlock);
|
||||||
// currentBlock.add(Train.this, direction);
|
// currentBlock.add(Train.this, direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -969,21 +972,31 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
|
|
||||||
public String start(boolean auto) {
|
public String start(boolean auto) {
|
||||||
|
LOG.debug("{}.start({})",this,auto?"auto":"");
|
||||||
autopilot |= auto;
|
autopilot |= auto;
|
||||||
if (isSet(nextPreparedRoute) && nextPreparedRoute.start()) {
|
if (isSet(nextPreparedRoute)) {
|
||||||
nextPreparedRoute = null;
|
LOG.debug("starting nextPreparedRoute: {}",nextPreparedRoute);
|
||||||
return null;
|
if (nextPreparedRoute.start()) {
|
||||||
|
LOG.debug("dropped nextPreparedRoute (was {})",nextPreparedRoute);
|
||||||
|
nextPreparedRoute = null;
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
LOG.debug("was not able to start {}", nextPreparedRoute);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isSet(routePrepper)) return t("Already searching route for {}",this);
|
if (isSet(routePrepper)) return t("Already searching route for {}",this);
|
||||||
routePrepper = new RoutePrepper(new Context(this).block(currentBlock).direction(direction));
|
routePrepper = new RoutePrepper(new Context(this).block(currentBlock).direction(direction));
|
||||||
|
|
||||||
routePrepper.onRoutePrepared(() -> {
|
routePrepper.onRoutePrepared(() -> {
|
||||||
routePrepper.route().start();
|
Route newRoute = routePrepper.route();
|
||||||
|
LOG.debug("prepared route {} for {}",newRoute,this);
|
||||||
|
newRoute.start();
|
||||||
routePrepper = null;
|
routePrepper = null;
|
||||||
plan.stream(t("Started {}",Train.this));
|
plan.stream(t("Started {}",Train.this));
|
||||||
});
|
});
|
||||||
|
|
||||||
routePrepper.onFail(() -> {
|
routePrepper.onFail(() -> {
|
||||||
|
LOG.debug("preparing route for {} failed, resetting.",this);
|
||||||
Route failedRoute = routePrepper.route();
|
Route failedRoute = routePrepper.route();
|
||||||
routePrepper = null;
|
routePrepper = null;
|
||||||
if (isSet(failedRoute)) failedRoute.reset();
|
if (isSet(failedRoute)) failedRoute.reset();
|
||||||
@@ -1005,7 +1018,10 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
public void startBrake() {
|
public void startBrake() {
|
||||||
LOG.debug("{}.startBrake()",this);
|
LOG.debug("{}.startBrake()",this);
|
||||||
if (autopilot && isSet(nextPreparedRoute)) return;
|
if (autopilot && isSet(nextPreparedRoute)) {
|
||||||
|
LOG.debug("not braking, because autopilot is active and next roue is prepared, already");
|
||||||
|
return;
|
||||||
|
}
|
||||||
brake = new BrakeProcess(this);
|
brake = new BrakeProcess(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ public class BrakeProcess extends BaseClass implements Runnable{
|
|||||||
long dist = 0;
|
long dist = 0;
|
||||||
int s = startSpeed;
|
int s = startSpeed;
|
||||||
while (s > Train.defaultEndSpeed) {
|
while (s > Train.defaultEndSpeed) {
|
||||||
s -= SPEED_STEP;
|
|
||||||
dist += s*ts;
|
dist += s*ts;
|
||||||
|
s -= SPEED_STEP;
|
||||||
}
|
}
|
||||||
LOG.debug("Estimated distamce with {} ms timestep: {}",ts,dist);
|
LOG.debug("Estimated distamce with {} ms timestep: {}",ts,dist);
|
||||||
return dist;
|
return dist;
|
||||||
@@ -56,6 +56,7 @@ public class BrakeProcess extends BaseClass implements Runnable{
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
timeStep = train.route().brakeTime(train.brakeId());
|
timeStep = train.route().brakeTime(train.brakeId());
|
||||||
|
LOG.debug("{}.run() with timestep = {} ms",this,timeStep);
|
||||||
if (timeStep == null) timeStep = defaultTimeStep;
|
if (timeStep == null) timeStep = defaultTimeStep;
|
||||||
startSpeed = train.speed;
|
startSpeed = train.speed;
|
||||||
lastTime = timestamp();
|
lastTime = timestamp();
|
||||||
@@ -100,7 +101,7 @@ public class BrakeProcess extends BaseClass implements Runnable{
|
|||||||
if (!newTimeStep.equals(timeStep)) {
|
if (!newTimeStep.equals(timeStep)) {
|
||||||
route.brakeTime(brakeId,newTimeStep);
|
route.brakeTime(brakeId,newTimeStep);
|
||||||
calculated = calcDistance(newTimeStep);
|
calculated = calcDistance(newTimeStep);
|
||||||
LOG.debug("Corrected brake timestep for {} @ {} from {} to {} ms.",train,route,timeStep,newTimeStep);
|
LOG.debug("Corrected brake timestep from {} to {} ms for {} @ {}.",timeStep,newTimeStep,train,route);
|
||||||
LOG.debug("Differemce from estimated distance: {} ({}%)",distance-calculated,100*(distance-calculated)/(float)distance);
|
LOG.debug("Differemce from estimated distance: {} ({}%)",distance-calculated,100*(distance-calculated)/(float)distance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,10 @@ public class RoutePrepper extends BaseClass implements Runnable{
|
|||||||
private List<EventListener> failListeners = new LinkedList<>();
|
private List<EventListener> failListeners = new LinkedList<>();
|
||||||
private List<EventListener> foundListeners = new LinkedList<>();
|
private List<EventListener> foundListeners = new LinkedList<>();
|
||||||
private List<EventListener> lockedListeners = new LinkedList<>();
|
private List<EventListener> lockedListeners = new LinkedList<>();
|
||||||
private List<EventListener> preparedListeners= new LinkedList<>();
|
private EventListener preparedListener = null;
|
||||||
|
|
||||||
public RoutePrepper(Context c) {
|
public RoutePrepper(Context c) {
|
||||||
|
LOG.debug("new RoutePrepper({})",c);
|
||||||
List<String> errors = new LinkedList<>();
|
List<String> errors = new LinkedList<>();
|
||||||
if (isNull(c.train())) errors.add(t("No train in context for {}",getClass().getSimpleName()));
|
if (isNull(c.train())) errors.add(t("No train in context for {}",getClass().getSimpleName()));
|
||||||
if (isNull(c.block())) errors.add(t("No block in context for {}",getClass().getSimpleName()));
|
if (isNull(c.block())) errors.add(t("No block in context for {}",getClass().getSimpleName()));
|
||||||
@@ -182,7 +183,7 @@ public class RoutePrepper extends BaseClass implements Runnable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onRoutePrepared(EventListener l) {
|
public void onRoutePrepared(EventListener l) {
|
||||||
preparedListeners.add(l);
|
preparedListener = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -196,7 +197,7 @@ public class RoutePrepper extends BaseClass implements Runnable{
|
|||||||
if (!route.reserveFor(context)) return fail();
|
if (!route.reserveFor(context)) return fail();
|
||||||
notify(lockedListeners);
|
notify(lockedListeners);
|
||||||
if (!route.prepareAndLock()) return fail();
|
if (!route.prepareAndLock()) return fail();
|
||||||
notify(preparedListeners);
|
if (isSet(preparedListener)) preparedListener.fire();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,6 +208,7 @@ public class RoutePrepper extends BaseClass implements Runnable{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
LOG.debug("{}.run()",this);
|
||||||
prepareRoute();
|
prepareRoute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,4 +219,9 @@ public class RoutePrepper extends BaseClass implements Runnable{
|
|||||||
public void stop() {
|
public void stop() {
|
||||||
context.invalidate();
|
context.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName()+"("+context+")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,9 @@ public abstract class Block extends StretchableTile{
|
|||||||
@Override
|
@Override
|
||||||
protected HashSet<String> classes() {
|
protected HashSet<String> classes() {
|
||||||
HashSet<String> classes = super.classes();
|
HashSet<String> classes = super.classes();
|
||||||
if (!parkedTrains.isEmpty()) classes.add(OCCUPIED);
|
if (!isNull(occupyingTrain()) || !parkedTrains.isEmpty()) classes.add(OCCUPIED);
|
||||||
|
if (!isNull(lockingTrain())) classes.add(LOCKED);
|
||||||
|
if (isDisabled()) classes.add(DISABLED);
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,8 +458,8 @@ public abstract class Block extends StretchableTile{
|
|||||||
if (isNull(replacements)) replacements = new HashMap<String, Object>();
|
if (isNull(replacements)) replacements = new HashMap<String, Object>();
|
||||||
replacements.put("%text%",name);
|
replacements.put("%text%",name);
|
||||||
Vector<String> trainNames = new Vector<String>();
|
Vector<String> trainNames = new Vector<String>();
|
||||||
Train lockingTrain = lockingTrain();
|
Train lockingTrain = occupyingTrain();
|
||||||
if (isSet(lockingTrain) /*&& !parkedTrains.contains(lockingTrain)*/) trainNames.add(lockingTrain.directedName());
|
if (isSet(lockingTrain)) trainNames.add(lockingTrain.directedName());
|
||||||
for (Train train: parkedTrains) trainNames.add(train.directedName());
|
for (Train train: parkedTrains) trainNames.add(train.directedName());
|
||||||
if (!trainNames.isEmpty())replacements.put("%text%",String.join(" | ", trainNames));
|
if (!trainNames.isEmpty())replacements.put("%text%",String.join(" | ", trainNames));
|
||||||
Tag tag = super.tag(replacements);
|
Tag tag = super.tag(replacements);
|
||||||
|
|||||||
@@ -120,11 +120,10 @@ public abstract class Tile extends BaseClass implements Comparable<Tile> {
|
|||||||
return new Id(x + "-" + y);
|
return new Id(x + "-" + y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void inflate(String clazz, JSONObject json,
|
private static void inflate(String clazz, JSONObject json, Plan plan) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException, IOException {
|
||||||
Plan plan) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException, IOException {
|
|
||||||
clazz = Tile.class.getName().replace(".Tile", "." + clazz);
|
clazz = Tile.class.getName().replace(".Tile", "." + clazz);
|
||||||
Tile tile = (Tile) Tile.class.getClassLoader().loadClass(clazz).getDeclaredConstructor().newInstance();
|
Tile tile = (Tile) Tile.class.getClassLoader().loadClass(clazz).getDeclaredConstructor().newInstance();
|
||||||
tile.load(json).register();
|
tile.load(json).parent(plan).register();
|
||||||
if (tile instanceof TileWithShadow) ((TileWithShadow) tile).placeShadows();
|
if (tile instanceof TileWithShadow) ((TileWithShadow) tile).placeShadows();
|
||||||
plan.place(tile);
|
plan.place(tile);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user