Skip to content

Commit

Permalink
Merge pull request #67 from marty30/9-theoretical-tactic
Browse files Browse the repository at this point in the history
9 theoretical tactic
  • Loading branch information
Tim108 authored Dec 21, 2017
2 parents 311940c + 819d567 commit ca3ee24
Show file tree
Hide file tree
Showing 90 changed files with 1,678 additions and 1,107 deletions.
33 changes: 22 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,38 @@ services:
rabbitmq:
condition: service_healthy
ports:
- "8000:8000"
- "8001:8000"
environment:
DRONE_NAME: "drone-thales-1"
DRONE_TEAM: "teamthales"
DRONE_COMPONENTS: "gps,radar,radio"
DRONE_COMPONENTS: "gps,gun,radio"
DRONE_TACTIC: "org.inaetics.dronessimulator.drone.tactic.example.utility.TheoreticalTactic"
drone-thales_2:
build: ./docker_images/drone
env_file: config.env
depends_on:
rabbitmq:
condition: service_healthy
ports:
- "8002:8000"
environment:
DRONE_NAME: "drone-thales-2"
DRONE_TEAM: "teamthales"
DRONE_COMPONENTS: "gps,radio,gun"
DRONE_COMPONENTS: "gps,radio,radar"
DRONE_TACTIC: "org.inaetics.dronessimulator.drone.tactic.example.utility.TheoreticalTactic"
drone-thales_3:
build: ./docker_images/drone
env_file: config.env
depends_on:
rabbitmq:
condition: service_healthy
environment:
DRONE_TEAM: "teamthales"
DRONE_COMPONENTS: "gps,radio,gun"
build: ./docker_images/drone
env_file: config.env
depends_on:
rabbitmq:
condition: service_healthy
ports:
- "8003:8000"
environment:
DRONE_NAME: "drone-thales-3"
DRONE_TEAM: "teamthales"
DRONE_COMPONENTS: "gps,radio,gun"
DRONE_TACTIC: "org.inaetics.dronessimulator.drone.tactic.example.utility.TheoreticalTactic"


drone-student_1:
Expand All @@ -80,3 +90,4 @@ services:
environment:
DRONE_TEAM: "teamstudent"
DRONE_COMPONENTS: "gps,radar,radio,gun"
DRONE_TACTIC: "org.inaetics.dronessimulator.drone.tactic.example.SimpleTactic"
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

public class MockDiscoverer implements Discoverer {
@Getter
private List<NodeEventHandler<AddedNode>> addedHandlers = new LinkedList<>();
private final List<NodeEventHandler<AddedNode>> addedHandlers = new LinkedList<>();
@Getter
private List<NodeEventHandler<ChangedValue>> changedHandlers = new LinkedList<>();
private final List<NodeEventHandler<ChangedValue>> changedHandlers = new LinkedList<>();
@Getter
private List<NodeEventHandler<RemovedNode>> removedHandlers = new LinkedList<>();
private final List<NodeEventHandler<RemovedNode>> removedHandlers = new LinkedList<>();

private List<NodeEvent> happenedEvents = new LinkedList<>();
private final List<NodeEvent> happenedEvents = new LinkedList<>();

@Override
public void register(Instance instance) throws DuplicateName, IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.inaetics.dronessimulator.architecturemanager;

import org.apache.log4j.Logger;
import lombok.extern.log4j.Log4j;
import org.inaetics.dronessimulator.common.architecture.SimulationAction;
import org.inaetics.dronessimulator.common.architecture.SimulationState;
import org.inaetics.dronessimulator.common.protocol.MessageTopic;
import org.inaetics.dronessimulator.common.protocol.RequestArchitectureStateChangeMessage;
import org.inaetics.dronessimulator.discovery.api.Discoverer;
import org.inaetics.dronessimulator.discovery.api.DuplicateName;
import org.inaetics.dronessimulator.discovery.api.Instance;
import org.inaetics.dronessimulator.discovery.api.discoverynode.Group;
import org.inaetics.dronessimulator.discovery.api.discoverynode.Type;
import org.inaetics.dronessimulator.discovery.api.instances.ArchitectureInstance;
import org.inaetics.dronessimulator.pubsub.api.Message;
import org.inaetics.dronessimulator.pubsub.api.subscriber.Subscriber;
Expand All @@ -24,6 +22,7 @@
* Currently this only consists of the current lifecycle state of the architecture
* Uses Discovery and Subscriber to publish current state and receive requested state updates
*/
@Log4j
public class ArchitectureManager {
/**
* Reference to discovery bundle to publish state information
Expand All @@ -34,11 +33,6 @@ public class ArchitectureManager {
*/
private volatile Subscriber m_subscriber;

/**
* The logger
*/
private final static Logger logger = Logger.getLogger(ArchitectureManager.class);

/**
* The instance published in Discovery
*/
Expand Down Expand Up @@ -90,15 +84,15 @@ public ArchitectureManager(Discoverer discoverer, Subscriber subscriber) {
*/
public void start() {
while (!m_subscriber.hasConnection()){
logger.warn("Architecture Manager does not yet have a connection to the subscriber implementation... Retrying now!");
log.warn("Architecture Manager does not yet have a connection to the subscriber implementation... Retrying now!");
try {
m_subscriber.connect();
logger.debug("Connection with the subscriber created");
log.debug("Connection with the subscriber created");
} catch (IOException e) {
logger.error(e);
log.error(e);
}
}
logger.info("Starting Architecture Manager...");
log.info("Starting Architecture Manager...");
try {
// Register instance with discovery
m_discoverer.register(this.instance);
Expand All @@ -116,38 +110,43 @@ public void start() {
this.previousAction = action;
this.currentState = nextState;

logger.info("New transition: (" + this.previousState + ", " + this.previousAction + ", " + this.currentState + ")");
log.info("New transition: (" + this.previousState + ", " + this.previousAction + ", " + this.currentState + ")");

try {
instance = m_discoverer.updateProperties(instance, getCurrentProperties());
} catch (IOException e) {
logger.fatal(e);
}
instance = safeUpdateProperties(instance, getCurrentProperties());

} else {
logger.error(String.format("Received an action which did not led to next state! Current state: %s. Action: %s", currentState, action));
log.error(String.format("Received an action which did not led to next state! Current state: %s. Action: %s", currentState, action));
}
});

} catch(IOException | DuplicateName e) {
logger.fatal(e);
log.fatal(e);
}

logger.info("Started Architecture Manager!");
log.info("Started Architecture Manager!");
}

private Instance safeUpdateProperties(final Instance instance, final Map<String, String> properties) {
try {
return m_discoverer.updateProperties(instance, properties);
} catch (IOException e) {
log.fatal(e);
}
return instance;
}

/**
* Stops the Architecture Manager service
* Unregisters the current state in Discovery
*/
public void stop() {
logger.info("Stopping Architecture Manager...");
log.info("Stopping Architecture Manager...");
try {
m_discoverer.unregister(instance);
} catch (IOException e) {
logger.error(e);
log.error(e);
}
logger.info("Stopped Architecture Manager!");
log.info("Stopped Architecture Manager!");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
package org.inaetics.dronessimulator.architecturemanager;

import com.rabbitmq.client.ConnectionFactory;
import org.inaetics.dronessimulator.architectureevents.ArchitectureEventController;
import org.inaetics.dronessimulator.architectureevents.ArchitectureEventControllerService;
import org.inaetics.dronessimulator.architectureevents.ArchitectureEventHandler;
import org.inaetics.dronessimulator.common.architecture.SimulationAction;
import org.inaetics.dronessimulator.common.architecture.SimulationState;
import org.inaetics.dronessimulator.common.protocol.MessageTopic;
import org.inaetics.dronessimulator.common.protocol.RequestArchitectureStateChangeMessage;
import org.inaetics.dronessimulator.discovery.api.Discoverer;
import org.inaetics.dronessimulator.discovery.api.Instance;
import org.inaetics.dronessimulator.discovery.api.discoverynode.DiscoveryStoredNode;
import org.inaetics.dronessimulator.discovery.api.discoverynode.Group;
import org.inaetics.dronessimulator.discovery.api.discoverynode.Type;
import org.inaetics.dronessimulator.discovery.api.instances.ArchitectureInstance;
import org.inaetics.dronessimulator.discovery.etcd.EtcdDiscoverer;
import org.inaetics.dronessimulator.discovery.etcd.EtcdDiscovererService;
import org.inaetics.dronessimulator.pubsub.api.Message;
import org.inaetics.dronessimulator.pubsub.api.publisher.Publisher;
import org.inaetics.dronessimulator.pubsub.api.serializer.Serializer;
import org.inaetics.dronessimulator.pubsub.api.subscriber.Subscriber;
import org.inaetics.dronessimulator.pubsub.javaserializer.JavaSerializer;
import org.inaetics.dronessimulator.pubsub.rabbitmq.common.RabbitConnectionInfo;
import org.inaetics.dronessimulator.pubsub.rabbitmq.publisher.RabbitPublisher;
Expand All @@ -33,7 +24,7 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;

public class LifecycleUpdateIT {

Expand Down Expand Up @@ -66,9 +57,7 @@ public void testLifecycleUpdates() throws Exception {
ArchitectureManager manager = new ArchitectureManager(discoverer, subscriber);
ArchitectureEventControllerService controller = new ArchitectureEventControllerService(discoverer);
AtomicBoolean isReceived = new AtomicBoolean(false);
ArchitectureEventHandler handler = (SimulationState fromState, SimulationAction action, SimulationState toState) -> {
isReceived.set(toState == SimulationState.CONFIG);
};
ArchitectureEventHandler handler = (SimulationState fromState, SimulationAction action, SimulationState toState) -> isReceived.set(toState == SimulationState.CONFIG);

controller.addHandler(SimulationState.INIT, SimulationAction.CONFIG, SimulationState.CONFIG, handler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static org.junit.Assert.assertEquals;

public class StateTransitionTest {
SimulationState[] validCurrentStates = new SimulationState[]{
final SimulationState[] validCurrentStates = new SimulationState[]{
SimulationState.NOSTATE,
SimulationState.INIT,
SimulationState.CONFIG,
Expand All @@ -19,7 +19,7 @@ public class StateTransitionTest {
SimulationState.PAUSED,
SimulationState.DONE,
};
SimulationAction[] validActions = new SimulationAction[]{
final SimulationAction[] validActions = new SimulationAction[]{
SimulationAction.INIT,
SimulationAction.CONFIG,
SimulationAction.STOP,
Expand All @@ -31,7 +31,7 @@ public class StateTransitionTest {
SimulationAction.RESUME,
SimulationAction.STOP,
};
SimulationState[] validFinalStates = new SimulationState[]{
final SimulationState[] validFinalStates = new SimulationState[]{
SimulationState.INIT,
SimulationState.CONFIG,
SimulationState.INIT,
Expand All @@ -44,17 +44,17 @@ public class StateTransitionTest {
SimulationState.INIT,
};

int numActions = 10;
final int numActions = 10;

SimulationState[] allStates = new SimulationState[]{
final SimulationState[] allStates = new SimulationState[]{
SimulationState.NOSTATE,
SimulationState.INIT,
SimulationState.CONFIG,
SimulationState.RUNNING,
SimulationState.PAUSED,
SimulationState.DONE,
};
SimulationAction[] allActions = new SimulationAction[]{
final SimulationAction[] allActions = new SimulationAction[]{
SimulationAction.INIT,
SimulationAction.CONFIG,
SimulationAction.START,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.inaetics.dronessimulator.common;

import org.inaetics.dronessimulator.common.vector.D3Vector;

import java.time.temporal.ChronoUnit;

public class Settings {
Expand All @@ -8,6 +10,7 @@ public class Settings {
public static final double ARENA_HEIGHT = Float.parseFloat(v("ARENA_HEIGHT", "100"));
public static final double ARENA_DEPTH = Float.parseFloat(v("ARENA_DEPTH", "800"));
public static final double ARENA_WIDTH = Float.parseFloat(v("ARENA_WIDTH", "800"));
public static final D3Vector ARENA = new D3Vector(ARENA_WIDTH, ARENA_DEPTH, ARENA_HEIGHT);
public static final GameMode GAME_MODE = GameMode.valueOf(v("GAME_MODE", "DEATHMATCH"));
public static final long TICK_TIME = 33;//ms
/**
Expand All @@ -26,6 +29,10 @@ private static String v(String variableName, String defaultValue) {
return value != null ? value : defaultValue;
}

private Settings() {
throw new IllegalStateException("Utility class");
}

public static double getTickTime(ChronoUnit temporalUnit) {
switch (temporalUnit) {
case NANOS:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class TimeoutTimer {
* @return true if the timeout has been exceeded, false otherwise.
*/
public static boolean isTimeExceeded(long startTime, double timeout) {

return (startTime + timeout) < System.currentTimeMillis();
}

Expand All @@ -34,6 +33,22 @@ public static boolean isTimeExceeded(LocalDateTime startTime, long timeout) {
return startTime.plusSeconds(timeout).isBefore(LocalDateTime.now());
}

/**
* Check if a timeout has exceeded since the given starttime
*
* @param startTime a LocalDateTime object with the time since when the timeout must be counted
* @param timeout a timeout in seconds (note that it will be compared up-to nano second accuracy).
* @return true if the timeout has been exceeded, false otherwise.
*/
public static boolean isTimeExceeded(LocalDateTime startTime, double timeout) {
LocalDateTime test = startTime.plusNanos((long) (timeout * 1e9));
LocalDateTime nu = LocalDateTime.now();
return test.isBefore(nu);
}

/**
* Reset the timer. You must call this everytime a new measurement should start.
*/
public synchronized void reset() {
lastTime = System.currentTimeMillis();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.inaetics.dronessimulator.common.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

/**
* 3-tuple with arbitrary types.
*
* @param <A> Type of the first value.
* @param <B> Type of the second value.
* @param <C> Type of the third value.
*/
@EqualsAndHashCode
@RequiredArgsConstructor
@ToString
@Getter
public class Triple<A, B, C> {
private final A a;
private final B b;
private final C c;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class FireBulletMessage extends CreateEntityMessage {
*/
private String firedById;

@Override
public String toString() {
return String.format("(FireBulletMessage %s fired by %s, %s)", this.getIdentifier(), this.getFiredById(), this.getDamage());
}
Expand Down
Loading

0 comments on commit ca3ee24

Please sign in to comment.