Doubt about RMI to share object between 2 processes

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

Doubt about RMI to share object between 2 processes

Postby esmetaman » Sun Jun 01, 2014 1:47 am

Hi,

I am thinking about RMI to share data between 2 asyncronous Java processes.

In one side, exist some kind of Server Socket processing web request and in the other side, exist the classic Java program to control the physical robot layer.
I think that it could be interesting to use RMI in this case, but I am not sure.

I am creating a Web tool to show Occupancy grid maps:

Image

And I would like to load maps in the memory using this idea or send commands.

Is RMI the way for this communication purpose?

Cheers

Juan Antonio
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.iloveneutrinos.com/
User avatar
esmetaman
Advanced Member
 
Posts: 290
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Doubt about RMI to share object between 2 processes

Postby lawrie » Sun Jun 01, 2014 5:10 pm

What machines do the two processes run on? Are they both on the EV3?

BTW, It is confusing when you use the word "Doubt" when you mean "Question" or "Query". "Doubt" means uncertainty (Spanish incertidumbre) and never "Question" or "Query". I doubt that it is what you meant.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

Re: Doubt about RMI to share object between 2 processes

Postby esmetaman » Sun Jun 01, 2014 8:57 pm

Hi Lawrie,

Sorry, I wanted to say question. :)

yes, the processes would run in the same brick.

I found 2 examples in the repo:
http://sourceforge.net/p/lejos/ev3/ci/m ... RMIServer/
http://sourceforge.net/p/lejos/ev3/ci/m ... RMIServer/

What is the usage of dBus?

Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.iloveneutrinos.com/
User avatar
esmetaman
Advanced Member
 
Posts: 290
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Doubt about RMI to share object between 2 processes

Postby lawrie » Sun Jun 01, 2014 9:27 pm

If they are on the same brick, why do you want to use separate processes? RMI is designed for distributed applications across multiple machines.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

Re: Doubt about RMI to share object between 2 processes

Postby lawrie » Sun Jun 01, 2014 9:40 pm

I wrote the RMI example in the repository when I was adding Java RMI it to the menu. I will probably delete the example. It won't work unchanged if the menu is running.

I wouldn't recommend dbus for Java apps as the open source project won't work unless you port the C JNI code. I got a partial version working using JNA to support Bluetooth but I did not do a full port of it.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

Re: Doubt about RMI to share object between 2 processes

Postby esmetaman » Mon Jun 02, 2014 7:34 pm

Hi Lawrie,

many thanks for your answer.

I am thinking to isolate the software in 2 isolated processes because in that way, it is easier to maintain the software. In one side, I have the typical LeJOS program running in the brick to execute some task in the robot (Autonomous) and in the other side, some kind of server software to process web forms.

Using this kind of architecture, it is possible to isolate web software and robot's software in a easier way. Using RMI in the same brick, could be interesting to link both parts.

Some months ago, I was testing a Websocket server implemented in Java mixing with a HFSM architecture but that architecture was a bit complex to scale. (Web + Robotics together)
https://github.com/jabrena/liverobots/b ... lTest.java

Now, I will try to use httpd and a minimalistic WebServer development and in Physical layer, I will try to continue working with the API. Some months ago, I had some doubts with with RMI but now, I changed the idea. Besides, I observe BoR project (https://github.com/Asw1n/BoR) and it is a interesting example with RMI.

I will test that example, and I will inform if I have some problem.

Cheers

Juan Antonio
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.iloveneutrinos.com/
User avatar
esmetaman
Advanced Member
 
Posts: 290
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Doubt about RMI to share object between 2 processes

Postby lawrie » Tue Jun 03, 2014 6:06 pm

You don't need RMI to do this sort of thing. Another possibility is to do what the menu does for the menu tools. It dynamically loads the jar file and calls methods from it.
But even that is not necessary. If you have your robot program in one jar file and the web server in another, the web server can just call the methods in the robot program. You can use interfaces to hide implementation details.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

Re: Doubt about RMI to share object between 2 processes

Postby esmetaman » Tue Jun 03, 2014 8:19 pm

Hi Lawrie,

yes, It is a good that you say, but I would like to have a process running in autonomous mode and in some moments, the process receive some command from the web. In that case, I need some mechanics to communicate that parts.
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.iloveneutrinos.com/
User avatar
esmetaman
Advanced Member
 
Posts: 290
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Doubt about RMI to share object between 2 processes

Postby Aswin » Tue Jun 03, 2014 9:01 pm

Hi Juan,

Based on my limited experiences with RMI I know that for RMI to work both server and client side of the software must be in the same JAR for security reasons. Also for this reason it is not a solution for your problem.

Aswin
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 203
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: Doubt about RMI to share object between 2 processes

Postby skoehler » Thu Jun 05, 2014 1:14 pm

Aswin wrote:Based on my limited experiences with RMI I know that for RMI to work both server and client side of the software must be in the same JAR for security reasons. Also for this reason it is not a solution for your problem.

I'm not sure what you mean, Aswin. There are no security issues with having two JARs for server and clients. However, you get into trouble if the server and client are compiled from different sources since
1) unless explicitly defined, the compiler generated a serial number for each class, and RMI checks whether the serial number of the classes on client and server side match. If they don't match, RMI will refuse to de-serialize objects sent from server to client or vice versa. I could be wrong, but the serial number is some kind of "checksum" on the fields and their names in the class.
2) if the serial number is defined manually, the programmer has to take care that the set of fields in the class never change (apart from transient fields, I assume). If the programmer intends to perform changes in the future, read/writeObject methods need to be provided that read/write the same binary format.

Usually, people just use the same source for both sides (client and server) and simply let the compiler determine the serial number. It doesn't matter whether the *.class files are from the same build or not. The serial number generated by the compiler is deterministic, as far as I'm aware.
skoehler
leJOS Team Member
 
Posts: 1422
Joined: Thu Oct 30, 2008 4:54 pm

Re: Doubt about RMI to share object between 2 processes

Postby Aswin » Fri Jun 06, 2014 7:33 am

Hi Sven,

I am glad to hear things are more subtle than I thought.
For what source specifically is the serial number generated and checked? I would suspect that the hub created by RMI needs serialization. But there is no source for that.

Aswin
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 203
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: Doubt about RMI to share object between 2 processes

Postby ryangardner » Tue Jun 24, 2014 12:07 am

Java RMI is pretty heavyweight.

There are lots of alternatives available. Finagle might be interesting to play with: https://blog.twitter.com/2011/finagle-a ... rpc-system
ryangardner
New User
 
Posts: 6
Joined: Sat Jun 21, 2014 12:41 pm


Return to EV3 Software

Who is online

Users browsing this forum: Google [Bot] and 1 guest

more stuff