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 ded892d1 authored by Petyo Bogdanov Ilov's avatar Petyo Bogdanov Ilov

Initial commit

parent a67da6f1
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
/target/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RMIModelServer</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
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
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>montisim</groupId>
<artifactId>rmi-model-server</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>rmi-model-server</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Set up profiles -->
<profiles>
<profile>
<id>Windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<script.extension>.bat</script.extension>
</properties>
</profile>
<profile>
<id>Unix</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<properties>
<script.extension>.sh</script.extension>
</properties>
</profile>
</profiles>
<build>
<plugins>
<!-- Exec plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>Launch</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${project.basedir}/scripts/run${script.extension}</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
start rmiregistry 10101
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
#run rmi registry on port 10101
rmiregistry 10101 &
#run rmi server
java -classpath ./target/rmi-model-server.jar -Djava.rmi.server.codebase=./target/rmi-model-server-1.0.0.jar rwth.rmi.model.server.RMIServer &
package rwth.rmi.model.server;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.util.HashMap;
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;
public class ModelManager implements RMIManager {
private int lastModelId = -1;
private Map<Integer, VehicleModel> models;
//Served models
private VehicleModel[] supportedModels = new VehicleModel[] {
new Autopilot()
};
public ModelManager() {
this.models = new HashMap<Integer, VehicleModel>();
}
@Override
/**
* Adds a VehicleModel to list of served models and returns the modelId, with which this model is accessible.
*
* @param model - the class name of the model, requested to be registered
* @return the model Id or -1 if incorrect model has been requested
* @throws RemoteException
* @throws AlreadyBoundException
*/
public int registerModel(String modelClass) throws RemoteException, AlreadyBoundException {
VehicleModel model = getCorrespondingModel(modelClass);
if(model == null) return -1;
this.models.put(++lastModelId, model);
System.out.println("Model [" + model.getClass().getName() + "] created with ID: " + this.lastModelId);
return this.lastModelId;
}
private VehicleModel getCorrespondingModel(String modelClass) {
for(VehicleModel model : this.supportedModels) {
if(model.getClass().getName() == modelClass) {
return model;
}
}
return null;
}
@Override
public VehicleModel getModel(int modelId) throws RemoteException {
return this.models.get(modelId);
}
@Override
public void removeModel(int modelId) throws RemoteException {
System.out.println("Removed model: " + this.models.get(modelId).getClass().getName());
this.models.remove(modelId);
}
}
package rwth.rmi.model.server;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class RMIServer {
private final static int INIT_PORT = 10101;
public static void main(String[] args) {
ModelManager manager = new ModelManager();
try {
Registry registry = LocateRegistry.getRegistry(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));
} catch (RemoteException | AlreadyBoundException e) {
e.printStackTrace();
}
}
}
package rwth.rmi.model.server.interfaces;
import java.rmi.AlreadyBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RMIManager extends Remote {
public int registerModel(String modelClass) throws RemoteException, AlreadyBoundException;
public VehicleModel getModel(int modelId) throws RemoteException;
void removeModel(int modelId) throws RemoteException;
}
package rwth.rmi.model.server.interfaces;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Map;
public interface VehicleModel extends Remote {
public Map<String, Object> execute(Map<String, Object> inputs) throws RemoteException;
}
\ No newline at end of file
package rwth.rmi.model.server.models;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Map;
import rwth.rmi.model.server.interfaces.VehicleModel;
/**
* JNI binding to a CPP class generated for the native model.
*/
public class Autopilot implements VehicleModel {
static {
// make sure the corresponding DLL is on the classpath
// when the java app with simulation is started
System.loadLibrary("AutopilotAdapter");
}
private boolean isInitialized = false;
public void execute() {
initialize();
exec();
}
public void initialize() {
if (!isInitialized) {
init();
isInitialized = true;
}
}
public native void set_timeIncrement(double timeIncrement);
public native void set_currentVelocity(double currentVelocity);
public native void set_x(double currentGpsLat);
public native void set_y(double currentGpsLon);
public native void set_compass(double compass);
public native void set_currentEngine(double currentEngine);
public native void set_currentSteering(double currentSteering);
public native void set_currentBrakes(double currentBrakes);
public native void set_trajectory_length(int length);
public native void set_trajectory_x(double[] x);
public native void set_trajectory_y(double[] y);
public native double get_engine();
public native double get_steering();
public native double get_brakes();
private native void exec();
private native void init();
@Override
/**
* Implementation of RMI interface of 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 {
//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);
}
}
}
//fill in outputs
Map<String, Object> outputs = new HashMap<String, Object>();
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;
}
}
package montisim.rmi_model_server;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
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