doc: updated Logger messages
This commit is contained in:
parent
9ec801690f
commit
c9fa49e10f
@ -72,9 +72,13 @@ public class Lobby {
|
|||||||
badRequests = 0;
|
badRequests = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.info("got {} requests from participant {}", requests.length, source);
|
Logger.info("{}: got {} requests from participant {}",
|
||||||
|
Thread.currentThread().getName(),
|
||||||
|
requests.length,
|
||||||
|
source);
|
||||||
|
|
||||||
Logger.trace("Processing requests through pipeline");
|
Logger.trace("{}: Processing requests through pipeline",
|
||||||
|
Thread.currentThread().getName());
|
||||||
Optional<Event[]> resultingEvents = pipeline.processRequests(requests, source);
|
Optional<Event[]> resultingEvents = pipeline.processRequests(requests, source);
|
||||||
Logger.debug("generated {} events from the pipeline", resultingEvents.map(x -> x.length).orElse(0));
|
Logger.debug("generated {} events from the pipeline", resultingEvents.map(x -> x.length).orElse(0));
|
||||||
|
|
||||||
|
@ -20,15 +20,21 @@ public class GameStateSegment implements Segment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
Logger.trace("GameStateSegment received {} requests.", packet.size());
|
Logger.trace("{}: GameStateSegment received {} requests.",
|
||||||
|
Thread.currentThread().getName(),
|
||||||
|
packet.size());
|
||||||
var result = game.checkRequestsAndApply(packet);
|
var result = game.checkRequestsAndApply(packet);
|
||||||
Logger.trace("GameLogic generated {} events", result.map(List::size).orElse(0));
|
Logger.trace("{}: GameLogic generated {} events",
|
||||||
|
Thread.currentThread().getName(),
|
||||||
|
result.map(List::size).orElse(0));
|
||||||
if (result.isPresent()) {
|
if (result.isPresent()) {
|
||||||
Logger.trace("Result from GameLogic is present. Adding requests to carrier.");
|
Logger.trace("{}: Result from GameLogic is present. Adding requests to carrier.",
|
||||||
|
Thread.currentThread().getName());
|
||||||
carrier.addAll(result.get());
|
carrier.addAll(result.get());
|
||||||
packet.clear();
|
packet.clear();
|
||||||
} else {
|
} else {
|
||||||
Logger.debug("Result from GameLogic is invalid. Triggering error.");
|
Logger.debug("{}: Result from GameLogic is invalid. Triggering error.",
|
||||||
|
Thread.currentThread().getName());
|
||||||
abort.set(true);
|
abort.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,15 @@ public class PauseSegment implements Segment {
|
|||||||
public void pauseGame(){
|
public void pauseGame(){
|
||||||
if(!paused) {
|
if(!paused) {
|
||||||
paused = true;
|
paused = true;
|
||||||
Logger.debug("Game paused.");
|
Logger.debug("{}: Game paused.",
|
||||||
|
Thread.currentThread().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void pauseEnd(){
|
public void pauseEnd(){
|
||||||
if(paused) {
|
if(paused) {
|
||||||
paused = false;
|
paused = false;
|
||||||
Logger.debug("Game unpaused.");
|
Logger.debug("{}: Game unpaused.",
|
||||||
|
Thread.currentThread().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,42 +57,52 @@ public class PauseSegment implements Segment {
|
|||||||
* <li>If a mistake is made (request is sent while pause active), the client will get an error</li>
|
* <li>If a mistake is made (request is sent while pause active), the client will get an error</li>
|
||||||
* <li>If there is a PauseStopRequest the game will be unpaused</li>
|
* <li>If there is a PauseStopRequest the game will be unpaused</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* @param packet
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
Logger.trace("PauseSegment received {} requests. PausedState is {}", packet.size(), paused);
|
Logger.trace("{}: PauseSegment received {} requests. PausedState is {}",
|
||||||
|
Thread.currentThread().getName(),
|
||||||
|
packet.size(),
|
||||||
|
paused);
|
||||||
// check if there is a pause request (either start or stop)
|
// check if there is a pause request (either start or stop)
|
||||||
if (packet.contains(new RequestBuilder(RequestType.PauseStartRequest).buildGameRequest())) {
|
if (packet.contains(new RequestBuilder(RequestType.PauseStartRequest).buildGameRequest())) {
|
||||||
Logger.trace("PauseStartRequest found");
|
Logger.trace("{}: PauseStartRequest found",
|
||||||
|
Thread.currentThread().getName());
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
// pause the game
|
// pause the game
|
||||||
pauseGame();
|
pauseGame();
|
||||||
// create a new PauseStartEvent
|
// create a new PauseStartEvent
|
||||||
carrier.add(new EventBuilder(EventType.PauseStartEvent).buildGameEvent());
|
carrier.add(new EventBuilder(EventType.PauseStartEvent).buildGameEvent());
|
||||||
Logger.trace("Added PauseStartEvent to pipeline carrier");
|
Logger.trace("{}: Added PauseStartEvent to pipeline carrier",
|
||||||
|
Thread.currentThread().getName());
|
||||||
} else { // if the game is already paused
|
} else { // if the game is already paused
|
||||||
Logger.info("PauseStartRequest sent even though the game wasn't paused. Error triggered.");
|
Logger.info("{}: PauseStartRequest sent even though the game wasn't paused. Error triggered.",
|
||||||
|
Thread.currentThread().getName());
|
||||||
abort.set(true);
|
abort.set(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (packet.contains(new RequestBuilder(RequestType.PauseStopRequest).buildGameRequest())) {
|
} else if (packet.contains(new RequestBuilder(RequestType.PauseStopRequest).buildGameRequest())) {
|
||||||
Logger.trace("PauseStopRequest found");
|
Logger.trace("{}: PauseStopRequest found",
|
||||||
|
Thread.currentThread().getName());
|
||||||
if (paused) {
|
if (paused) {
|
||||||
pauseEnd();
|
pauseEnd();
|
||||||
Logger.debug("Game unpaused.");
|
Logger.debug("{}: Game unpaused.",
|
||||||
|
Thread.currentThread().getName());
|
||||||
// create a new PauseStartRequest
|
// create a new PauseStartRequest
|
||||||
carrier.add(new EventBuilder(EventType.PauseStopEvent).buildGameEvent());
|
carrier.add(new EventBuilder(EventType.PauseStopEvent).buildGameEvent());
|
||||||
Logger.trace("Added PauseStopEvent to pipeline carrier");
|
Logger.trace("{}: Added PauseStopEvent to pipeline carrier",
|
||||||
|
Thread.currentThread().getName());
|
||||||
} else { // if the game is not paused
|
} else { // if the game is not paused
|
||||||
Logger.info("PauseStopRequest sent even though the game wasn't paused. Error triggered.");
|
Logger.info("{}: PauseStopRequest sent even though the game wasn't paused. Error triggered.",
|
||||||
|
Thread.currentThread().getName());
|
||||||
abort.set(true);
|
abort.set(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paused) {
|
if (paused) {
|
||||||
Logger.trace("As the game is paused, Requests are removed.");
|
Logger.trace("{}: As the game is paused, Requests are removed.",
|
||||||
|
Thread.currentThread().getName());
|
||||||
packet.removeRequestsOfTypes(
|
packet.removeRequestsOfTypes(
|
||||||
RequestType.MeleeAttackRequest,
|
RequestType.MeleeAttackRequest,
|
||||||
RequestType.RangedAttackRequest,
|
RequestType.RangedAttackRequest,
|
||||||
|
@ -38,7 +38,8 @@ public class Pipeline {
|
|||||||
* {@link Optional#isEmpty()} or {@link Optional#isPresent()}, and act accordingly.
|
* {@link Optional#isEmpty()} or {@link Optional#isPresent()}, and act accordingly.
|
||||||
*/
|
*/
|
||||||
public Optional<Event[]> processRequests(Request[] requests, Participant origin) {
|
public Optional<Event[]> processRequests(Request[] requests, Participant origin) {
|
||||||
Logger.trace("Pipeline started RequestProcessing");
|
Logger.trace("{}: Pipeline started RequestProcessing",
|
||||||
|
Thread.currentThread().getName());
|
||||||
// The packet carries the requests, and gets smaller per segment
|
// The packet carries the requests, and gets smaller per segment
|
||||||
Packet packet = new Packet(requests, origin);
|
Packet packet = new Packet(requests, origin);
|
||||||
// The packet is filled by the requests resulting from events per segment
|
// The packet is filled by the requests resulting from events per segment
|
||||||
@ -46,7 +47,8 @@ public class Pipeline {
|
|||||||
// The abort boolean describes whether an abort happened in a segment
|
// The abort boolean describes whether an abort happened in a segment
|
||||||
AtomicBoolean abort = new AtomicBoolean(false);
|
AtomicBoolean abort = new AtomicBoolean(false);
|
||||||
|
|
||||||
Logger.trace("Iterating through segments");
|
Logger.trace("{}: Iterating through segments",
|
||||||
|
Thread.currentThread().getName());
|
||||||
// Loop through all segments
|
// Loop through all segments
|
||||||
for (Segment segment: segments) {
|
for (Segment segment: segments) {
|
||||||
// Give the segment the packet, carrier and abort, and let it process requests
|
// Give the segment the packet, carrier and abort, and let it process requests
|
||||||
@ -56,10 +58,13 @@ public class Pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (abort.get()) { // if abort is true, return empty optional
|
if (abort.get()) { // if abort is true, return empty optional
|
||||||
Logger.debug("Abort triggered in Pipeline");
|
Logger.debug("{}: Abort triggered in Pipeline",
|
||||||
|
Thread.currentThread().getName());
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
} else { // else return an optional of the array
|
} else { // else return an optional of the array
|
||||||
Logger.trace("Pipeline executed normally. Returning {} events.", carrier.size());
|
Logger.trace("{}: Pipeline executed normally. Returning {} events.",
|
||||||
|
Thread.currentThread().getName(),
|
||||||
|
carrier.size());
|
||||||
return Optional.of(carrier.toArray(new Event[0]));
|
return Optional.of(carrier.toArray(new Event[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,12 @@ public class RequestGameStateSegment implements Segment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
||||||
Logger.trace("RequestGameStateSegment received {} requests", packet.size());
|
Logger.trace("{}: RequestGameStateSegment received {} requests",
|
||||||
|
Thread.currentThread().getName(),
|
||||||
|
packet.size());
|
||||||
if (packet.containsRequestOfType(RequestType.Req)) {
|
if (packet.containsRequestOfType(RequestType.Req)) {
|
||||||
Logger.trace("Req event found. Returning Gamestate, and clearing entire RequestList");
|
Logger.trace("{}: Req event found. Returning Gamestate, and clearing entire RequestList",
|
||||||
|
Thread.currentThread().getName());
|
||||||
carrier.add(game.getGameStateEvent());
|
carrier.add(game.getGameStateEvent());
|
||||||
packet.clear();
|
packet.clear();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user