Aufgrund von Umarbeiten des s3 Storage wird es in GitLab, in nächster Zeit, mögliche Performance-Einbußen geben. Näheres dazu unter: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/43/show_ticket/6670

Commit 8cc1b83e authored by Petyo Bogdanov Ilov's avatar Petyo Bogdanov Ilov

Update

parent 9d3d0cf1
......@@ -4,7 +4,7 @@
<groupId>montisim</groupId>
<artifactId>rmi-model-server</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>
<name>rmi-model-server</name>
......
start rmiregistry 10101
pushd %~dp0
set AUTOPILOT_HOME=..\..\emam-model-showcase
popd
set JAVA_HOME=%AUTOPILOT_HOME%\jdk
set MINGW_HOME=%AUTOPILOT_HOME%\mingw64
set OCTAVE_HOME=%AUTOPILOT_HOME%\octave-4.2.1
set AUTOPILOT_DLL_DIR=%AUTOPILOT_HOME%\dll
set PATH=%AUTOPILOT_DLL_DIR%;%JAVA_HOME%\bin;%MINGW_HOME%\bin;%OCTAVE_HOME%\bin;%PATH%
start java -classpath ./target/rmi-model-server.jar -Djava.rmi.server.codebase=./target/rmi-model-server-1.0.0.jar rwth.rmi.model.server.RMIServer &
\ No newline at end of file
java "-Djava.library.path=%PATH%" "-Djava.rmi.server.codebase=file:\C:\Users\Administrator\MontiSim\RMIModelServer\target\rmi-model-server-1.0.0.jar" "-Djava.rmi.server.hostname=127.0.0.1" -cp ..\target\rmi-model-server-1.0.1.jar rwth.rmi.model.server.RMIServer
pause
\ No newline at end of file
#run rmi registry on port 10101
rmiregistry 10101 &
#run rmi server
java -cp ./target/rmi-model-server-1.0.0.jar -Djava.rmi.server.codebase=./target/rmi-model-server-1.0.0.jar -Djava.rmi.server.hostname=server.rmi -Djava.security.policy=server.policy rwth.rmi.model.server.RMIServer
#run rmi server and registry
java -cp ../target/rmi-model-server-1.0.0.jar -Djava.rmi.server.codebase=../target/rmi-model-server-1.0.1.jar -Djava.rmi.server.hostname=127.0.0.1 rwth.rmi.model.server.RMIServer
......@@ -7,19 +7,23 @@ import java.util.Map;
import rwth.rmi.model.server.interfaces.RMIManager;
import rwth.rmi.model.server.interfaces.VehicleModel;
import rwth.rmi.model.server.models.Autopilot;
import simulator.integration.AutopilotAdapter;
import java.io.Serializable;
public class ModelManager implements RMIManager {
private int lastModelId = -1;
private int lastModelId = 0;
private Map<Integer, VehicleModel> models;
//Served models
private VehicleModel[] supportedModels = new VehicleModel[] {
new Autopilot()
new AutopilotAdapter()
};
public ModelManager() {
super();
this.models = new HashMap<Integer, VehicleModel>();
}
......@@ -32,7 +36,7 @@ public class ModelManager implements RMIManager {
* @throws RemoteException
* @throws AlreadyBoundException
*/
public int registerModel(String modelClass) throws RemoteException, AlreadyBoundException {
public Integer registerModel(String modelClass) throws RemoteException, AlreadyBoundException {
VehicleModel model = getCorrespondingModel(modelClass);
if(model == null) return -1;
......@@ -44,7 +48,7 @@ public class ModelManager implements RMIManager {
private VehicleModel getCorrespondingModel(String modelClass) {
for(VehicleModel model : this.supportedModels) {
if(model.getClass().getName() == modelClass) {
if(model.getClass().getSimpleName().contentEquals(modelClass)) {
return model;
}
}
......@@ -52,12 +56,17 @@ public class ModelManager implements RMIManager {
}
@Override
public VehicleModel getModel(int modelId) throws RemoteException {
return this.models.get(modelId);
public HashMap<String, Serializable> executeModel(Integer modelId, HashMap<String, Serializable> inputs) throws RemoteException {
VehicleModel model = this.models.get(modelId);
if(model == null) {
return new HashMap<String, Serializable>(); //fallback to empty map
}
return model.execute(inputs);
}
@Override
public void removeModel(int modelId) throws RemoteException {
public void removeModel(Integer modelId) throws RemoteException {
System.out.println("Removed model: " + this.models.get(modelId).getClass().getName());
this.models.remove(modelId);
}
......
......@@ -8,17 +8,19 @@ import java.rmi.server.UnicastRemoteObject;
public class RMIServer {
public final static String MODEL_MANAGER = "ModelManager";
private final static int INIT_PORT = 10101;
public static void main(String[] args) {
ModelManager manager = new ModelManager();
try {
Registry registry = LocateRegistry.getRegistry(INIT_PORT);
Registry registry = LocateRegistry.createRegistry(INIT_PORT);
System.out.println("RMIRegistry serving on port: " + INIT_PORT);
//bind the ModelManager to a stub, representing the remote object
registry.bind(manager.getClass().getName(), UnicastRemoteObject.exportObject(manager, INIT_PORT + 1));
System.out.println("RMIManager listening on port: " + (INIT_PORT + 1));
registry.bind(MODEL_MANAGER, UnicastRemoteObject.exportObject(manager, 0));
System.out.println("RMIManager listening");
} catch (RemoteException | AlreadyBoundException e) {
e.printStackTrace();
}
......
......@@ -4,12 +4,15 @@ import java.rmi.AlreadyBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.io.Serializable;
import java.util.HashMap;
public interface RMIManager extends Remote {
public int registerModel(String modelClass) throws RemoteException, AlreadyBoundException;
public Integer registerModel(String modelClass) throws RemoteException, AlreadyBoundException;
public VehicleModel getModel(int modelId) throws RemoteException;
public HashMap<String, Serializable> executeModel(Integer modelId, HashMap<String, Serializable> inputs) throws RemoteException;
public void removeModel(int modelId) throws RemoteException;
public void removeModel(Integer modelId) throws RemoteException;
}
......@@ -2,10 +2,12 @@ package rwth.rmi.model.server.interfaces;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Map;
import java.util.HashMap;
import java.io.Serializable;
public interface VehicleModel extends Remote {
public Map<String, Object> execute(Map<String, Object> inputs) throws RemoteException;
public HashMap<String, Serializable> execute(HashMap<String, Serializable> inputs) throws RemoteException;
}
\ No newline at end of file
package rwth.rmi.model.server.models;
package simulator.integration;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Map;
import java.io.Serializable;
import rwth.rmi.model.server.interfaces.VehicleModel;
/**
* JNI binding to a CPP class generated for the native model.
*/
public class Autopilot implements VehicleModel {
public class AutopilotAdapter implements VehicleModel {
static {
// make sure the corresponding DLL is on the classpath
// when the java app with simulation is started
System.loadLibrary("AutopilotAdapter");
}
public AutopilotAdapter() {
super();
initialize();
}
private boolean isInitialized = false;
......@@ -58,35 +62,43 @@ public class Autopilot implements VehicleModel {
* @param inputs - a map denoting the methods to be executed and their params as a single object
* @return a map containing the outputs of the model
*/
public Map<String, Object> execute(Map<String, Object> inputs) throws RemoteException {
public HashMap<String, Serializable> execute(HashMap<String, Serializable> inputs) throws RemoteException {
//set inputs
for(String key : inputs.keySet()) {
Method method = getMethod(key);
if(method != null) {
try {
method.invoke(this, inputs.get(key));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
System.err.println("Problem invoking method [" + key + "]: " + e);
}
if(key.contentEquals("timeIncrement")) {
set_timeIncrement((double) inputs.get(key));
}else if(key.contentEquals("currentVelocity")) {
set_currentVelocity((double)inputs.get(key));
}else if(key.contentEquals("x")) {
set_x((double)inputs.get(key));
}else if(key.contentEquals("y")) {
set_y((double)inputs.get(key));
}else if(key.contentEquals("compass")) {
set_compass((double)inputs.get(key));
}else if(key.contentEquals("currentEngine")) {
set_currentEngine((double)inputs.get(key));
}else if(key.contentEquals("currentSteering")) {
set_currentSteering((double)inputs.get(key));
}else if(key.contentEquals("currentBrakes")) {
set_currentBrakes((double)inputs.get(key));
}else if(key.contentEquals("trajectory_length")) {
set_trajectory_length((int)inputs.get(key));
}else if(key.contentEquals("trajectory_x")) {
set_trajectory_x((double[])inputs.get(key));
}else if(key.contentEquals("trajectory_y")) {
set_trajectory_y((double[])inputs.get(key));
}
}
//execute model
execute();
//fill in outputs
Map<String, Object> outputs = new HashMap<String, Object>();
HashMap<String, Serializable> outputs = new HashMap<String, Serializable>();
outputs.put("engine", get_engine());
outputs.put("steering", get_steering());
outputs.put("brakes", get_brakes());
return outputs;
}
private Method getMethod(String name) {
Method[] methods = this.getClass().getDeclaredMethods();
for(int i=0; i<methods.length; ++i)
//strip "get_" or "set_" prefixes before comparing method names to inputs
if(methods[i].getName().substring(0, 4) == name)
return methods[i];
return null;
}
}
Markdown is supported
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