[erlang-questions] : : First send from JInterface ok, second one blocs??

Raimo Niskanen raimo+erlang-questions@REDACTED
Tue May 13 11:58:18 CEST 2008


Comments inserted at the end.

On Tue, May 13, 2008 at 11:32:08AM +0200, Alexander Lamb wrote:
> 
> Le 13 mai 08 à 10:57, Raimo Niskanen a écrit :
> 
> >Since you gave no example code I give you counterexample code.
> >I have done a simple RPC call example:
> 
> Well, this looks very close to what I am doing I start Erlang like that:
> 
> erl -mnesia -setcookie rodanotech -sname alex
> 
> I start Java (from Eclipse) with those arguments:
> 
> -Djetty.home="/Users/alamb/Library/jetty-5.1.14" -DOtpConnection.trace=4
> 
> When my app starts, I create a node like that:
> 
> 		_otpNode = new OtpNode(OTP_NODE_NAME,OTP_NODE_COOKIE);
> 
> with:
> 
> 	public static final String OTP_NODE_COOKIE = "rodanotech";
> 	public static final String OTP_NODE_NAME = "jnode";
> 
> then I have a class wich creates a mailbox in its constructor:
> 
> 	_mbox = _node.createMbox();
> 
> Finally, I have a function which sends the message to the server:
> 
> private OtpErlangObject callFunctionInModuleOnNodeWithArgs(String  
> functionName,String moduleName,String nodeName,OtpErlangList args)  
> throws SFExceptionTimeout, SFExceptionError {
>     OtpErlangObject[] rpc = new OtpErlangObject[2];
>     OtpErlangObject[] call = new OtpErlangObject[5];
> 
>     call[0] = new OtpErlangAtom("call");
>     call[1] = new OtpErlangAtom(moduleName);
>     call[2] = new OtpErlangAtom(functionName);
>     call[3] = args;
>     call[4] = new OtpErlangAtom("user");
>     rpc[0] = _mbox.self();
>     rpc[1] = new OtpErlangTuple(call);
> 
>     OtpErlangObject response = null;
> 
>     _mbox.send("rex", nodeName, new OtpErlangTuple(rpc));
> 	System.out.println("--- message sent");
>     try {
>     	response = _mbox.receive(_timeout);
>     	System.out.println("--- message received: " + response);
>     } catch(Exception e) {
>     	System.out.println("*** Error receiving message" + e);
>     	e.printStackTrace();
>     	throw new SFExceptionError(e.getMessage());
>     }
>     if(response == null)
>     	throw new SFExceptionTimeout();
>     try {
>     	response =  
> ((com.ericsson.otp.erlang.OtpErlangTuple)response).elementAt(1); //  
> skip "rex"
>     	OtpErlangAtom status = (OtpErlangAtom) 
> ((com.ericsson.otp.erlang.OtpErlangTuple)response).elementAt(0);
>     	response =  
> ((com.ericsson.otp.erlang.OtpErlangTuple)response).elementAt(1);
>     	if(status.atomValue().equals("error"))
>     		throw new SFExceptionError(response.toString());
>     } catch(Exception e) {
>     	System.out.println("*** Error decoding message" + e);
>     	e.printStackTrace();
>     	throw new SFExceptionError(e.getMessage());
>     }
>     return response;
> }
> 
> 
> Now, the problem is that it works fine the FIRST TIME I call this  
> function... but the second time it doesn't and the call doesn't even  
> reach my function in Erlang (I added a trace).
> So it can't be a cookie problem since otherwise it would not even  
> accept a first connection. Something is doing a "close". Should I do  
> somthing special on the Erlang or Java side to make the connection  
> persistent?
> 
> Here is the trace:
> 
> --- TEST START...
> --- INIT OF SESSION...
> --- App module init...
> -> PUBLISH (r4) jnode@REDACTED port=57107
> <- OK
> -> LOOKUP (r4) alex@REDACTED
> <- PORT 57102
> -> MD5 CONNECT TO kirk.local:57102
> -> HANDSHAKE sendName flags=3332 dist=5 local=jnode@REDACTED
> <- HANDSHAKE recvStatus (ok) local=jnode@REDACTED
> <- HANDSHAKE recvChallenge from=alex@REDACTED challenge=-41504799  
> local=jnode@REDACTED
> -> HANDSHAKE sendChallengeReply challenge=-1539340064  
> digest=0f7f9711c77b2b1a28c0fab48b502046 local=jnode@REDACTED
> <- HANDSHAKE recvChallengeAck from=alex@REDACTED  
> digest=b04515d124bdaa99e579ebaaa88079d4 local=jnode@REDACTED
> -> REG_SEND {6,#Pid<jnode@REDACTED>,'',rex}
>    {#Pid<jnode@REDACTED>,{call,profiles,get_default_menus, 
> [[84,79,80]],user}}
> --- message sent
> <- SEND {2,'',#Pid<jnode@REDACTED>}
>    {rex,{ok,[{menu,home,{{home,"Home"},[{login,"Login"}, 
> {logout,"Logout"},{about,"About"}]}},{menu,patients, 
> {{patients,"Patients"},[]}},{menu,centers,{{centers,"Centers"}, 
> [{search,"Search"},{list,"List"}]}},{menu,dashboard, 
> {{dashboard,"Dashboard"},[{enrollment,"Enrollment"}, 
> {statistics,"Statistics"},{initiation,"Initiation"}]}}]}}
> --- message received: {rex,{ok,[{menu,home,{{home,"Home"}, 
> [{login,"Login"},{logout,"Logout"},{about,"About"}]}},{menu,patients, 
> {{patients,"Patients"},[]}},{menu,centers,{{centers,"Centers"}, 
> [{search,"Search"},{list,"List"}]}},{menu,dashboard, 
> {{dashboard,"Dashboard"},[{enrollment,"Enrollment"}, 
> {statistics,"Statistics"},{initiation,"Initiation"}]}}]}}
> --- MSG: [{menu,home,{{home,"Home"},[{login,"Login"},{logout,"Logout"}, 
> {about,"About"}]}},{menu,patients,{{patients,"Patients"},[]}}, 
> {menu,centers,{{centers,"Centers"},[{search,"Search"},{list,"List"}]}}, 
> {menu,dashboard,{{dashboard,"Dashboard"},[{enrollment,"Enrollment"}, 
> {statistics,"Statistics"},{initiation,"Initiation"}]}}]
> -> LOOKUP (r4) alex@REDACTED

As I wrote in my previous mail: I can not understand
this second "-> LOOKUP". It seems like either a new
mbox or a new node is trying to send.

> <- PORT 57102
> -> MD5 CONNECT TO kirk.local:57102
> -> HANDSHAKE sendName flags=3332 dist=5 local=jnode@REDACTED

You get thrown out very early. The erlang node did not
like this node name. I suspect it is a double connection
from the same node name, that is you have created
a new java node with the same name and now tries to
do an RPC call from it.

Check when your objects goes out of scope, how they
get constructed and destructed.

> -> CLOSE
> --- message sent
> --- message received: null
> **** EXCEPTION: ch.rodano.erl_jfoundations.model.SFExceptionTimeout
> 

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list