Commit ddd8791a authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

apply code formatting to VadereManager module

parent 9a5a86ea
Pipeline #212870 passed with stages
in 132 minutes and 2 seconds
......@@ -13,9 +13,9 @@ import java.util.concurrent.locks.ReentrantLock;
public class RemoteScenarioRun extends ScenarioRun implements RemoteRunListener {
private List<Subscription> subscriptions;
private final Object waitForLoopEnd;
private final ReentrantLock lock;
private List<Subscription> subscriptions;
private boolean lastSimulationStep;
......
......@@ -15,6 +15,33 @@ public class ServerView extends JFrame implements SingleScenarioFinishedListener
private static ServerView mainWindow;
private ServerView() throws HeadlessException {
ServerView.mainWindow = this;
setTitle("Vadere GUI - Server");
setBounds(100, 100, 1000, 600);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
public static void close() {
EventQueue.invokeLater(() -> {
mainWindow.setVisible(false);
mainWindow.dispose();
});
}
public static void startServerGui(OnlineVisualization onlineVisualization) {
EventQueue.invokeLater(() -> {
ServerView frame = new ServerView();
frame.setVisible(true);
frame.setSize(1200, 800);
frame.add(onlineVisualization.getVisualizationPanel());
onlineVisualization.getMainPanel().setVisible(true);
});
}
@Override
public void preScenarioRun(Scenario scenario, int scenariosLeft) {
......@@ -45,32 +72,4 @@ public class ServerView extends JFrame implements SingleScenarioFinishedListener
}
private ServerView() throws HeadlessException {
ServerView.mainWindow = this;
setTitle("Vadere GUI - Server");
setBounds(100, 100, 1000, 600);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
public static void close() {
EventQueue.invokeLater(() -> {
mainWindow.setVisible(false);
mainWindow.dispose();
});
}
public static void startServerGui(OnlineVisualization onlineVisualization) {
EventQueue.invokeLater(() -> {
ServerView frame = new ServerView();
frame.setVisible(true);
frame.setSize(1200, 800);
frame.add(onlineVisualization.getVisualizationPanel());
onlineVisualization.getMainPanel().setVisible(true);
});
}
}
......@@ -38,7 +38,7 @@ public class TraCIException extends RuntimeException {
+ "not supported in API: " + cmd.getTraCICmd().toString());
}
public String getMessageForClient(){
public String getMessageForClient() {
return getMessage();
}
......
package org.vadere.manager;
/**
* Use this Exception if the message produces has no mean for a TraCI client.
* The stacktrace is printed but the client gets a static response.
* Use this Exception if the message produces has no mean for a TraCI client. The stacktrace is
* printed but the client gets a static response.
*/
public class TraCIExceptionInternal extends TraCIException {
......
......@@ -17,9 +17,8 @@ import java.nio.ByteBuffer;
*/
public class TraCISocket implements Closeable {
private static Logger logger = Logger.getLogger(TraCISocket.class);
private final static int TRACI_LEN_LENGTH = 4;
private static Logger logger = Logger.getLogger(TraCISocket.class);
private final Socket socket;
private final DataOutputStream outStream;
private final DataInputStream inStream;
......@@ -27,7 +26,7 @@ public class TraCISocket implements Closeable {
private String host;
private int port;
public TraCISocket(Socket socket, boolean tracePackets) throws IOException{
public TraCISocket(Socket socket, boolean tracePackets) throws IOException {
this.socket = socket;
this.host = this.socket.getInetAddress().toString();
this.port = this.socket.getPort();
......
......@@ -27,6 +27,25 @@ public class ConsoleReader implements Runnable {
addCommand("help", "Print this Help", this::cmd_help);
}
public static void main(String[] args) {
ConsoleReader r = new ConsoleReader();
r.addCommand("do-shit", "guess..",
args1 -> System.out.println("do-shit with " + Arrays.toString(args1)));
Thread thread = new Thread(r);
System.out.println("start..");
thread.start();
try {
thread.join();
System.out.println("joined");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void cmd_help(String[] args) {
if (!args[0].equals("help"))
System.out.println("Unknown command: " + args[0]);
......@@ -81,25 +100,6 @@ public class ConsoleReader implements Runnable {
running = false;
}
public static void main(String[] args) {
ConsoleReader r = new ConsoleReader();
r.addCommand("do-shit", "guess..",
args1 -> System.out.println("do-shit with " + Arrays.toString(args1)));
Thread thread = new Thread(r);
System.out.println("start..");
thread.start();
try {
thread.join();
System.out.println("joined");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void run() {
commandLoop();
......
......@@ -31,12 +31,6 @@ public class TestClient extends org.vadere.manager.client.AbstractTestClient imp
private String defaultScenario;
private boolean running;
public static void main(String[] args) throws IOException, InterruptedException {
TestClient testClient = new TestClient(9999, args);
testClient.run();
}
public TestClient(int port, String basePath, String defaultScenario) {
this.port = port;
this.running = false;
......@@ -44,6 +38,7 @@ public class TestClient extends org.vadere.manager.client.AbstractTestClient imp
this.defaultScenario = defaultScenario;
}
public TestClient(int port, String[] args) {
this.port = port;
this.running = false;
......@@ -61,6 +56,10 @@ public class TestClient extends org.vadere.manager.client.AbstractTestClient imp
}
}
public static void main(String[] args) throws IOException, InterruptedException {
TestClient testClient = new TestClient(9999, args);
testClient.run();
}
private void addCommands(ConsoleReader consoleReader) {
consoleReader.addCommand("ctr.getVersion", "", this::getVersion);
......
......@@ -7,13 +7,11 @@ import java.net.ServerSocket;
import java.nio.file.Path;
public abstract class AbstractVadereServer implements Runnable {
protected static Logger logger = Logger.getLogger(VadereServer.class);
public static int SUPPORTED_TRACI_VERSION = 20;
// public static int SUPPORTED_TRACI_VERSION = 1;
public static String SUPPORTED_TRACI_VERSION_STRING = "Vadere Simulator. Supports subset of commands based von TraCI Version " + SUPPORTED_TRACI_VERSION;
public static TraCIVersion currentVersion = TraCIVersion.V20_0_2;
protected static Logger logger = Logger.getLogger(VadereServer.class);
protected final ServerSocket serverSocket;
protected final Path baseDir;
protected final boolean guiSupport;
......
......@@ -114,7 +114,7 @@ public enum TraCICmd {
return String.format("TraCICmd{%s: id=0x%02X, type=%s}", name(), id, type);
}
public String logShort(){
public String logShort() {
return String.format("{%s:0x%02X%s}", name(), id, type);
}
}
......@@ -53,7 +53,7 @@ public class CommandExecutor {
try {
logger.debugf("execute cmd: %s", cmd.getTraCICmd().logShort());
cmd = handler.handel(cmd, remoteManager);
}catch (TraCIException e){
} catch (TraCIException e) {
logger.errorf("Error handling cmd: %s", cmd.getTraCICmd().logShort());
e.printStackTrace();
return TraCIPacket.createErr(cmd.getTraCICmd().id, e.getMessageForClient());
......@@ -61,7 +61,7 @@ public class CommandExecutor {
try {
logger.debugf("build response for: %s", cmd.getTraCICmd().logShort());
response = cmd.buildResponsePacket();
} catch (TraCIException e){
} catch (TraCIException e) {
logger.errorf("error building response for: %s", cmd.getTraCICmd().logShort());
e.printStackTrace();
return TraCIPacket.createErr(cmd.getTraCICmd().id, e.getMessageForClient());
......
......@@ -31,8 +31,6 @@ import java.util.List;
*/
public abstract class CommandHandler<VAR extends Enum> {
private static Logger logger = Logger.getLogger(CommandHandler.class);
public static final String ELEMENT_ID_NOT_FOUND = "No element found with given object id ";
public static final String ELEMENT_ID_NOT_FREE = "There is already an element with the given object id ";
public static final String FILE_NOT_FOUND = "No file with given path ";
......@@ -40,8 +38,9 @@ public abstract class CommandHandler<VAR extends Enum> {
public static final String COULD_NOT_MAP_OBJECT_FROM_JSON = "Could not map object from given json ";
public static final String COULD_NOT_SERIALIZE_OBJECT = "Could not serialize object ";
public static final String NO_MAIN_MODEL = "Main Model is not present.";
protected HashMap<Pair<TraCICmd, VAR>, Method> handler;
private static Logger logger = Logger.getLogger(CommandHandler.class);
private final Method processNotImplemented;
protected HashMap<Pair<TraCICmd, VAR>, Method> handler;
public CommandHandler() {
handler = new HashMap<>();
......
......@@ -28,9 +28,8 @@ import java.lang.reflect.Method;
*/
public class ControlCommandHandler extends CommandHandler<ControlVar> {
private static Logger logger = Logger.getLogger(ControlCommandHandler.class);
public static ControlCommandHandler instance;
private static Logger logger = Logger.getLogger(ControlCommandHandler.class);
static {
instance = new ControlCommandHandler();
......
......@@ -38,9 +38,8 @@ import java.util.stream.Collectors;
public class PolygonCommandHandler extends CommandHandler<PolygonVar> {
private static Logger logger = Logger.getLogger(PersonCommandHandler.class);
public static PolygonCommandHandler instance;
private static Logger logger = Logger.getLogger(PersonCommandHandler.class);
static {
instance = new PolygonCommandHandler();
......
......@@ -43,8 +43,8 @@ import java.util.ArrayList;
)
public class SimulationCommandHandler extends CommandHandler<SimulationVar> {
private static Logger logger = Logger.getLogger(SimulationCommandHandler.class);
public static SimulationCommandHandler instance;
private static Logger logger = Logger.getLogger(SimulationCommandHandler.class);
static {
instance = new SimulationCommandHandler();
......
......@@ -81,7 +81,7 @@ public class VadereCommandHandler extends CommandHandler<VadereVar> {
@VadereHandler(cmd = TraCICmd.SET_VADERE_STATE, var = VadereVar.ADD_TARGET_CHANGER, dataTypeStr = "String", name = "createTargetChanger", ignoreElementId = true)
public TraCICommand process_addTargetChanger(TraCISetCommand cmd, RemoteManager remoteManager) {
String data = (String) cmd.getVariableValue();
AttributesTargetChanger atc;
AttributesTargetChanger atc;
try {
atc = (AttributesTargetChanger) StateJsonConverter.deserializeScenarioElementType(data, ScenarioElementType.TARGET_CHANGER);
remoteManager.accessState((manager, state) -> {
......@@ -105,7 +105,7 @@ public class VadereCommandHandler extends CommandHandler<VadereVar> {
@VadereHandler(cmd = TraCICmd.SET_VADERE_STATE, var = VadereVar.ADD_STIMULUS_INFOS, dataTypeStr = "String", name = "addStimulusInfos", ignoreElementId = true)
public TraCICommand process_addStimulusInfos(TraCISetCommand cmd, RemoteManager remoteManager) {
String data = (String) cmd.getVariableValue();
StimulusInfoStore sis;
StimulusInfoStore sis;
try {
sis = StateJsonConverter.deserializeStimuli(data);
} catch (IOException e) {
......
......@@ -65,7 +65,7 @@ public enum PersonVar {
'}';
}
public String logShort(){
public String logShort() {
return String.format("{%s:0x%02X}", name(), id);
}
}
......@@ -38,6 +38,10 @@ public abstract class TraCICommand {
protected TraCICmd traCICmd;
protected TraCIPacket NOK_response = null;
protected TraCICommand(TraCICmd traCICmd) {
this.traCICmd = traCICmd;
}
public static TraCICommand create(ByteBuffer rawCmd) {
TraCICommandBuffer cmdBuffer = TraCICommandBuffer.wrap(rawCmd);
......@@ -83,11 +87,6 @@ public abstract class TraCICommand {
}
protected TraCICommand(TraCICmd traCICmd) {
this.traCICmd = traCICmd;
}
public TraCICmd getTraCICmd() {
return traCICmd;
}
......
......@@ -34,6 +34,20 @@ public class TraCIGetCommand extends TraCICommand {
private TraCIGetResponse response;
public TraCIGetCommand(TraCICmd traCICmd, int variableIdentifier, String elementIdentifier) {
super(traCICmd);
this.variableIdentifier = variableIdentifier;
this.elementIdentifier = elementIdentifier;
this.cmdBuffer = TraCICommandBuffer.empty();
}
public TraCIGetCommand(TraCICmd traCICmd, TraCICommandBuffer cmdBuffer) {
super(traCICmd);
this.variableIdentifier = cmdBuffer.readUnsignedByte();
this.elementIdentifier = cmdBuffer.readString();
this.cmdBuffer = cmdBuffer;
}
public static TraCIPacket build(TraCICmd commandIdentifier, int variableIdentifier, String elementIdentifier) {
int cmdLen = 1 + 1 + 1 + 4 + elementIdentifier.getBytes(StandardCharsets.US_ASCII).length;
TraCIPacket packet = TraCIPacket.create();
......@@ -51,21 +65,6 @@ public class TraCIGetCommand extends TraCICommand {
dataType, data);
}
public TraCIGetCommand(TraCICmd traCICmd, int variableIdentifier, String elementIdentifier) {
super(traCICmd);
this.variableIdentifier = variableIdentifier;
this.elementIdentifier = elementIdentifier;
this.cmdBuffer = TraCICommandBuffer.empty();
}
public TraCIGetCommand(TraCICmd traCICmd, TraCICommandBuffer cmdBuffer) {
super(traCICmd);
this.variableIdentifier = cmdBuffer.readUnsignedByte();
this.elementIdentifier = cmdBuffer.readString();
this.cmdBuffer = cmdBuffer;
}
public int getVariableIdentifier() {
return variableIdentifier;
}
......
......@@ -33,12 +33,6 @@ public class TraCISetCommand extends TraCICommand {
private StatusResponse statusResponse;
public static TraCIPacket build(TraCICmd commandIdentifier, String elementIdentifier, int variableIdentifier, TraCIDataType dataType, Object data) {
return TraCIPacket.create()
.wrapCommand(commandIdentifier, elementIdentifier, variableIdentifier,
dataType, data);
}
public TraCISetCommand(TraCICmd traCICmd, TraCICommandBuffer cmdBuffer) {
super(traCICmd);
variableId = cmdBuffer.readUnsignedByte();
......@@ -48,6 +42,12 @@ public class TraCISetCommand extends TraCICommand {
}
public static TraCIPacket build(TraCICmd commandIdentifier, String elementIdentifier, int variableIdentifier, TraCIDataType dataType, Object data) {
return TraCIPacket.create()
.wrapCommand(commandIdentifier, elementIdentifier, variableIdentifier,
dataType, data);
}
public Object getVariableValue() {
return variableValue;
}
......
......@@ -11,6 +11,13 @@ public class TraCICloseCommand extends TraCICommand {
private TraCIResponse response;
public TraCICloseCommand() {
super(TraCICmd.CLOSE);
this.response = new TraCIResponse(
new StatusResponse(TraCICmd.CLOSE, TraCIStatusResponse.OK, ""),
TraCICmd.CLOSE);
}
public static TraCIPacket build() {
TraCIPacket packet = TraCIPacket.create(6); // 4
......@@ -20,13 +27,6 @@ public class TraCICloseCommand extends TraCICommand {
return packet;
}
public TraCICloseCommand() {
super(TraCICmd.CLOSE);
this.response = new TraCIResponse(
new StatusResponse(TraCICmd.CLOSE, TraCIStatusResponse.OK, ""),
TraCICmd.CLOSE);
}
public TraCIResponse getResponse() {
return response;
}
......
Supports Markdown
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