diff --git a/.classpath b/.classpath
deleted file mode 100644
index af1430be15836d78425a795565a49fcd23d562b4..0000000000000000000000000000000000000000
--- a/.classpath
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.gitignore b/.gitignore
index b83d22266ac8aa2f8df2edef68082c789727841d..68b057c62b49a80b142c9fd471762bf74454bdc8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,6 @@
/target/
+/.idea
+.project
+*.iml
+.classpath
+/.settings
\ No newline at end of file
diff --git a/.project b/.project
deleted file mode 100644
index d90778cd1e9e035f21cac77f1bfe0e6bcf426881..0000000000000000000000000000000000000000
--- a/.project
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
- RMIModelServer
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.eclipse.m2e.core.maven2Builder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
- org.eclipse.m2e.core.maven2Nature
-
-
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
deleted file mode 100644
index f9fe34593fcd3624a964478aeb438b0d44fe7237..0000000000000000000000000000000000000000
--- a/.settings/org.eclipse.core.resources.prefs
+++ /dev/null
@@ -1,4 +0,0 @@
-eclipse.preferences.version=1
-encoding//src/main/java=UTF-8
-encoding//src/test/java=UTF-8
-encoding/=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 714351aec195a9a572640e6844dcafd51565a2a5..0000000000000000000000000000000000000000
--- a/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,5 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.8
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
deleted file mode 100644
index f897a7f1cb2389f85fe6381425d29f0a9866fb65..0000000000000000000000000000000000000000
--- a/.settings/org.eclipse.m2e.core.prefs
+++ /dev/null
@@ -1,4 +0,0 @@
-activeProfiles=
-eclipse.preferences.version=1
-resolveWorkspaceProjects=true
-version=1
diff --git a/install/run_with_zookeeper.sh b/install/run_with_zookeeper.sh
index b1782f328b4241eb9588fc7836c92beb4c5a2e6f..f5e127d67a5879c622540b6a38faf8a6cc50df35 100755
--- a/install/run_with_zookeeper.sh
+++ b/install/run_with_zookeeper.sh
@@ -1,4 +1,25 @@
#!/usr/bin/env bash
+#
+#
+# ******************************************************************************
+# MontiCAR Modeling Family, www.se-rwth.de
+# Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
+# All rights reserved.
+#
+# This project is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3.0 of the License, or (at your option) any later version.
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this project. If not, see .
+# *******************************************************************************
+#
+
if [ -z "$1" ]; then
PORT=10101
diff --git a/pom.xml b/pom.xml
index effbc6d8a58d7d00b3ecb566cb0a61b16c10b30a..8a1c9432d90dc50e8ca7fd13f106aac8be0600a8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@
montisim
rmi-model-server
- 1.1.1
+ 1.1.2
jar
rmi-model-server
@@ -71,6 +71,11 @@
zkclient
0.2
+
+ montisim
+ commons
+ 1.0.7
+
diff --git a/src/main/java/rwth/rmi/model/server/RMIServer.java b/src/main/java/rwth/rmi/model/server/RMIServer.java
index 2e3dfe05a605f7e5c8d4875ef84facb2d37257c6..756019390cdf7aa30d7532e9d5ce8cce7ceb0a60 100644
--- a/src/main/java/rwth/rmi/model/server/RMIServer.java
+++ b/src/main/java/rwth/rmi/model/server/RMIServer.java
@@ -35,50 +35,87 @@ import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Arrays;
+import java.util.HashMap;
public class RMIServer {
public final static String MODEL_MANAGER = "ModelManager";
public final static String ZK_NODE = "/rmi-servers/all";
+ public static void parse_args(String[] args, HashMap options){
+ String default_config = "";
+ boolean add_to_default_config = false;
+ for (String arg : args){
+ if (add_to_default_config){
+ default_config += arg + "\n";
+ } else {
+ String sub_args[] = arg.split("=");
+ if (arg.equals("no-zookeeper")){
+ options.put("no-zookeeper", "true");
+ } else if (arg.equals("default_config")){
+ add_to_default_config = true;
+ } else if (sub_args.length > 1) {
+ if (sub_args[0].equals("port")){
+ options.put("port", sub_args[1]);
+ } else if (sub_args[0].equals("autopilots_folder")){
+ options.put("autopilots_folder", sub_args[1]);
+ }
+ }
+ }
+ }
+ options.put("default_config", default_config);
+ }
+
+
public static void main(String[] args) throws UnknownHostException {
- if (args.length < 2){
- System.out.println("Please assign a port that the RMI server need to bind, also the path to the autopilot(s)");
+ HashMap options = new HashMap();
+ parse_args(args, options);
+ if (!options.containsKey("port")){
+ System.out.println("Please assign a port that the RMI server need to bind (port=...)");
return;
}
-
- if (!isPortAvailable(args[0])){
- System.out.printf("Port %s is currently unavailable, please use another port.\n", args[0]);
+ String port = options.get("port");
+ if (!isPortAvailable(port)){
+ System.out.printf("Port %s is currently unavailable, please use another port.\n", port);
return;
}
- File autopilot_folder = new File(args[1]);
+ File autopilot_folder = new File(options.containsKey("autopilots_folder") ? options.get("autopilots_folder") : "autopilots");
if (!autopilot_folder.exists()){
System.out.printf("The autopilot folder %s does not exist\n", autopilot_folder);
return;
}
- boolean use_zookeeper = true;
- int configIndex = 2;
- if (args.length >= 3){
- if (args[2].equals("--no-zookeeper")){
- use_zookeeper = false;
- configIndex++;
- System.out.println("Not using Zookeeper.");
- }
- }
+ boolean use_zookeeper = !options.containsKey("no-zookeeper");
+ if (!use_zookeeper)
+ System.out.println("Not using Zookeeper.");
+
+ String default_config = options.get("default_config");
+ String emu_config = "";
+ try {// Load AutopilotAdapter.dll from libraryPath
+ emu_config += "autopilots_folder=" + autopilot_folder.getCanonicalPath() + "\n";
+ } catch (IOException e) {
+ e.printStackTrace();
+ System.out.println("Could not resolve the Hardware Emulator autopilots path.");
+ }
- HardwareEmulatorInterface manager = new HardwareEmulatorInterface(args, configIndex);
+ HardwareEmulatorInterface manager = null;
+ try {
+ manager = new HardwareEmulatorInterface(emu_config, default_config);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(-2);
+ }
String host = InetAddress.getLocalHost().getHostName();
- int port = Integer.valueOf(args[0]);
+ int port_id = Integer.valueOf(port);
try {
- Registry registry = LocateRegistry.createRegistry(port);
+ Registry registry = LocateRegistry.createRegistry(port_id);
System.out.println("RMIRegistry serving on port: " + port);
//bind the ModelManager to a stub, representing the remote object
- registry.bind(MODEL_MANAGER, UnicastRemoteObject.exportObject(manager, port));
+ registry.bind(MODEL_MANAGER, UnicastRemoteObject.exportObject(manager, port_id));
if (use_zookeeper){
String zoo_servers;
@@ -87,11 +124,11 @@ public class RMIServer {
zoo_servers = "localhost:2181";
}
ZkClient zk = new ZkClient(zoo_servers, 1000, 5000);
- register(zk, host, port);
+ register(zk, host, port_id);
Runtime.getRuntime().addShutdownHook(new Thread(){
@Override
public void run(){
- unregister(zk, host, port);
+ unregister(zk, host, port_id);
}
});
}
diff --git a/src/main/java/simulator/integration/HardwareEmulatorInterface.java b/src/main/java/simulator/integration/HardwareEmulatorInterface.java
index 0265b5fb226e9ffa80a088ec0973f8b9ca6e947b..a9ea1f095a61219929f2e9a08f3be8c35a395ee1 100644
--- a/src/main/java/simulator/integration/HardwareEmulatorInterface.java
+++ b/src/main/java/simulator/integration/HardwareEmulatorInterface.java
@@ -25,37 +25,32 @@ import java.io.IOException;
import java.util.HashMap;
import java.io.Serializable;
import rwth.rmi.model.server.interfaces.RMIManager;
+import commons.utils.LibraryService;
public class HardwareEmulatorInterface implements RMIManager {
- public HardwareEmulatorInterface(String[] args, int configIndex) {
+ String lib_path = "";
+ public HardwareEmulatorInterface(String emu_config, String default_config) throws LibraryService.LibraryException, Exception {
super();
- String default_config = "";
- for (int i = configIndex; i < args.length; i++){
- default_config += args[i] + "\n";
+ load_library();
+ if (!init(emu_config, default_config)){
+ String error_msg = query("get_error_msg");
+ throw new Exception("Error initializing the HardwareEmulator: " + error_msg);
}
- String libraryPath = args[1];
- String emu = System.getProperty("user.dir") + "/HardwareEmulator";
- String OS = System.getProperty("os.name").toLowerCase();
- if (OS.contains("win")){
- System.load(emu+".dll");
- } else if (OS.contains("nix")|| OS.contains("nux")|| OS.contains("aix")){
- System.load(emu+".so");
- } else {
- System.out.println("Could not deduce Operating System for loading the HardwareEmulator.");
- }
- try {// Load AutopilotAdapter.dll from libraryPath
- File b = new File(libraryPath);
- String absolute = b.getCanonicalPath();
-
-
+ }
- init("autopilots_folder=" + absolute, default_config);
- } catch (IOException e) {
- e.printStackTrace();
- System.out.println("Could not initiate the Hardware Emulator");
- init("", default_config);
- }
+ public void load_library() throws LibraryService.LibraryException {
+ //Use LibraryService to get the library from resources to the working directory (if not already there)
+ String working_dir = LibraryService.getWorkingDirectory();
+ String system_library_name = LibraryService.getSystemLibraryName("HardwareEmulator");
+ LibraryService.prepareLibrary(working_dir, system_library_name);
+ lib_path = working_dir + system_library_name;
+ //Load the library
+ System.load(lib_path);
+ //System.out.println("LibPath: " + lib_path);
+ }
+ public File get_library(){
+ return new File(lib_path);
}
private native boolean init(String config, String default_config);
diff --git a/install/HardwareEmulator.dll b/src/main/resources/HardwareEmulator.dll
similarity index 68%
rename from install/HardwareEmulator.dll
rename to src/main/resources/HardwareEmulator.dll
index f195ba92385a130dae381446a81c3454b2e3cf75..758597fe5921fc21180c4551088bb8e21316d217 100644
Binary files a/install/HardwareEmulator.dll and b/src/main/resources/HardwareEmulator.dll differ
diff --git a/install/HardwareEmulator.so b/src/main/resources/HardwareEmulator.so
similarity index 100%
rename from install/HardwareEmulator.so
rename to src/main/resources/HardwareEmulator.so
diff --git a/src/test/java/simulator/integration/HardwareEmulatorTest.java b/src/test/java/simulator/integration/HardwareEmulatorTest.java
index 9fc4241aa9c77fe491d25acb5071589cd1582952..2aa756c0f680b05cc103cf11ea6f42419a8d187b 100644
--- a/src/test/java/simulator/integration/HardwareEmulatorTest.java
+++ b/src/test/java/simulator/integration/HardwareEmulatorTest.java
@@ -23,14 +23,15 @@ package simulator.integration;
import org.junit.Test;
import org.junit.Assert;
+import java.io.File;
import java.io.Serializable;
import java.util.HashMap;
public class HardwareEmulatorTest {
@Test
- public void basic_test(){
+ public void basic_test() throws Exception {
System.out.println("Current test directory: " + System.getProperty("user.dir"));
- HardwareEmulatorInterface manager = new HardwareEmulatorInterface(new String[]{"10101", "autopilots"}, 2);
+ HardwareEmulatorInterface manager = new HardwareEmulatorInterface("autopilots_folder=autopilots", "");
String querry = "get_available_autopilots\nget_available_threads";
String res = manager.query(querry);
@@ -78,5 +79,11 @@ public class HardwareEmulatorTest {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
manager.free_autopilot(id);
+
+ //Try to clear up the library from the test directory
+ File lib = manager.get_library();
+ manager = null;
+ System.gc();
+ lib.delete();
}
}