Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
simulators
RMIModelServer
Commits
8cc1b83e
Commit
8cc1b83e
authored
May 02, 2018
by
Petyo Bogdanov Ilov
Browse files
Update
parent
9d3d0cf1
Changes
8
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
8cc1b83e
...
...
@@ -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>
...
...
scripts/run.bat
View file @
8cc1b83e
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
scripts/run.sh
View file @
8cc1b83e
#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
src/main/java/rwth/rmi/model/server/ModelManager.java
View file @
8cc1b83e
...
...
@@ -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
Autopilot
Adapter
()
};
public
ModelManager
()
{
super
();
this
.
models
=
new
HashMap
<
Integer
,
VehicleModel
>();
}
...
...
@@ -32,7 +36,7 @@ public class ModelManager implements RMIManager {
* @throws RemoteException
* @throws AlreadyBoundException
*/
public
i
nt
registerModel
(
String
modelClass
)
throws
RemoteException
,
AlreadyBoundException
{
public
I
nt
eger
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
().
get
Name
()
==
modelClass
)
{
if
(
model
.
getClass
().
get
SimpleName
().
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
(
i
nt
modelId
)
throws
RemoteException
{
public
void
removeModel
(
I
nt
eger
modelId
)
throws
RemoteException
{
System
.
out
.
println
(
"Removed model: "
+
this
.
models
.
get
(
modelId
).
getClass
().
getName
());
this
.
models
.
remove
(
modelId
);
}
...
...
src/main/java/rwth/rmi/model/server/RMIServer.java
View file @
8cc1b83e
...
...
@@ -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
.
get
Registry
(
INIT_PORT
);
Registry
registry
=
LocateRegistry
.
create
Registry
(
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
();
}
...
...
src/main/java/rwth/rmi/model/server/interfaces/RMIManager.java
View file @
8cc1b83e
...
...
@@ -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
i
nt
registerModel
(
String
modelClass
)
throws
RemoteException
,
AlreadyBoundException
;
public
I
nt
eger
registerModel
(
String
modelClass
)
throws
RemoteException
,
AlreadyBoundException
;
public
VehicleModel
get
Model
(
i
nt
modelId
)
throws
RemoteException
;
public
HashMap
<
String
,
Serializable
>
execute
Model
(
I
nt
eger
modelId
,
HashMap
<
String
,
Serializable
>
inputs
)
throws
RemoteException
;
public
void
removeModel
(
i
nt
modelId
)
throws
RemoteException
;
public
void
removeModel
(
I
nt
eger
modelId
)
throws
RemoteException
;
}
src/main/java/rwth/rmi/model/server/interfaces/VehicleModel.java
View file @
8cc1b83e
...
...
@@ -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
Hash
Map
<
String
,
Serializable
>
execute
(
Hash
Map
<
String
,
Serializable
>
inputs
)
throws
RemoteException
;
}
\ No newline at end of file
src/main/java/
rwth/rmi/model/server/models
/Autopilot.java
→
src/main/java/
simulator/integration
/Autopilot
Adapter
.java
View file @
8cc1b83e
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
Autopilot
Adapter
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
Hash
Map
<
String
,
Serializable
>
execute
(
Hash
Map
<
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
>();
Hash
Map
<
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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment