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

Alexander Lamb <>
Tue May 13 11:33:47 CEST 2008


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)  port=57107
<- OK
-> LOOKUP (r4) 
<- PORT 57102
-> MD5 CONNECT TO kirk.local:57102
-> HANDSHAKE sendName flags=3332 dist=5 local=
<- HANDSHAKE recvStatus (ok) local=
<- HANDSHAKE recvChallenge from= challenge=-41504799  
local=
-> HANDSHAKE sendChallengeReply challenge=-1539340064  
digest=0f7f9711c77b2b1a28c0fab48b502046 local=
<- HANDSHAKE recvChallengeAck from=  
digest=b04515d124bdaa99e579ebaaa88079d4 local=
-> REG_SEND {6,#Pid<>,'',rex}
   {#Pid<>,{call,profiles,get_default_menus, 
[[84,79,80]],user}}
--- message sent
<- SEND {2,'',#Pid<>}
   {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) 
<- PORT 57102
-> MD5 CONNECT TO kirk.local:57102
-> HANDSHAKE sendName flags=3332 dist=5 local=
-> CLOSE
--- message sent
--- message received: null
**** EXCEPTION: ch.rodano.erl_jfoundations.model.SFExceptionTimeout



More information about the erlang-questions mailing list