Erlang/OTP Forums

Author Message

<  Open Telecom Platform (OTP)  ~  Create mulitple mailboxes in Jinterface

adamprisa
Posted: Mon Jan 19, 2009 3:08 pm Reply with quote
Joined: 21 Nov 2008 Posts: 7
I want to create two processes Process1 and Process2 each of these should have one mailbox each.

Code:
public class Process1
{   
   public static void main(String[] args) throws IOException
   {
   OtpNode oNode = new OtpNode("jnode2");
   oNode.setCookie("abc");      
   OtpMbox mbox1 = oNode.createMbox("process1");

      ...

      while (true)
      {
         try
         {
            System.out.println("before receive..");
       receivedObject1 =   mbox1.receive();            
            System.out.println("after receive..");

            ...

         }catch(Exception e){}
       }
    }
}
}


and similarly Process2

Code:
public class Process2
{   
   public static void main(String[] args) throws IOException
   {
   OtpNode oNode = new OtpNode("jnode2");
   oNode.setCookie("abc");      
   OtpMbox mbox1 = oNode.createMbox("process2");

      ...

      while (true)
      {
         try
         {
            System.out.println("before receive..");
       receivedObject2 =   mbox1.receive();            
            System.out.println("after receive..");

            ...

         }catch(Exception e){}
       }
    }
}
}


I am not able to call these processes individually using a client

Code:
mbox.send("process1", "jnode2@host-machine", tuple);
mbox2.send("process2", "jnode2@host-machine", tuple);


For me only one process(whichever is started first) is working.

Help highly appreciated. The entire code files are attached along with.



Files.zip
 Description:
Files Attached:

Process1.java
Process2.java
EchoClient.java

Download
 Filename:  Files.zip
 Filesize:  2.1 KB
 Downloaded:  885 Time(s)

View user's profile Send private message
Mazen
Posted: Mon Jan 19, 2009 3:26 pm Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
Try creating otp nodes with different names. I suspect there is a clash there.

/M
View user's profile Send private message
adamprisa
Posted: Tue Jan 20, 2009 5:24 am Reply with quote
Joined: 21 Nov 2008 Posts: 7
I do not want to create OTP Nodes with different names. I want to have the node names same.
View user's profile Send private message
Mazen
Posted: Tue Jan 20, 2009 1:30 pm Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
you can't have 2 nodes with the same -sname or -name AFAIK. Try it in the shell you will see.

run:
Code:

erl -sname test

twice

I mean how else would you know to which of the two nodes a message should be sent to? probably the second node fails to start and all messages go to the first (which is pretty logical).
View user's profile Send private message
adamprisa
Posted: Thu Jan 22, 2009 9:30 am Reply with quote
Joined: 21 Nov 2008 Posts: 7
Quote:
I do not want to create OTP Nodes with different names. I want to have the node names same.


Thats what i am saying. I want to have nodes with he same name. but mailboxes with different names.
View user's profile Send private message
Matrim
Posted: Fri Jan 23, 2009 4:16 pm Reply with quote
Joined: 13 Jan 2009 Posts: 4
adamprisa wrote:
Thats what i am saying. I want to have nodes with he same name. but mailboxes with different names.
You would have to create two mailboxes in Java:

Code:
OtpMbox mbox1 = new OtpMbox("process1");
OtpMbox mbox2 = new OtpMbox("process2");


Making them concurrent is where the problem lies. You may have to use Java threads to do that, which would be a pain. (i.e., create a wrapper class that implements Runnable [I think]... constructor takes mailbox name as a parameter.)
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum