|
|
| Author |
Message |
|
| jacek99 |
Posted: Fri Jun 12, 2009 1:08 pm |
|
|
|
User
Joined: 26 May 2009
Posts: 27
Location: Montreal, Canada
|
I was looking at all the jinterface docs and they only have examples of Java talking to Erlang.
Is there a way to go the other way: the entry point is Erlang/OTP, but the end recipient of a message may be a running Java app? |
|
|
| Back to top |
|
| vigyana |
Posted: Thu Jun 25, 2009 1:17 am |
|
|
|
Joined: 04 May 2009
Posts: 3
|
see below my log client .....
... 1. create java node & mbox
... (in my experience, one mbox per one node.
... (i'm running Thread.run env.)
...
Code: import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ericsson.otp.erlang.OtpNode;
import com.ericsson.otp.erlang.OtpMbox;
import com.ericsson.otp.erlang.OtpErlangAtom;
import com.ericsson.otp.erlang.OtpErlangPid;
import com.ericsson.otp.erlang.OtpErlangObject;
import com.ericsson.otp.erlang.OtpErlangString;
import com.ericsson.otp.erlang.OtpErlangTuple;
import java.io.IOException;
public class MboxWorker {
// -------------------------------------- Constructor
public MboxWorker(String nodeName, String mboxName) throws IOException {
node = new OtpNode(nodeName);
mbox = node.createMbox(mboxName);
}
// -------------------------------------- Constants
private static final Logger logger =
LoggerFactory.getLogger(MboxWorker.class);
// -------------------------------------- Static Variables
// -------------------------------------- Variables
OtpNode node;
OtpMbox mbox = null;
OtpErlangAtom _logAtom = new OtpErlangAtom("pn0000");
// -------------------------------------- Protected Methods
// -------------------------------------- Public Methods
public void doService() throws Exception {
try {
OtpErlangObject o;
OtpErlangTuple msg;
OtpErlangPid from;
OtpErlangAtom logAtom;
OtpErlangString logstr;
logger.debug("{} : waiting", mbox.getName());
while (true) {
try {
o = mbox.receive();
if (o instanceof OtpErlangTuple) {
msg = (OtpErlangTuple) o;
from = (OtpErlangPid) (msg.elementAt(0));
logAtom = (OtpErlangAtom)(msg.elementAt(1));
logstr = (OtpErlangString)(msg.elementAt(2));
if (logAtom.equals(this._logAtom)) {
logger.info(logstr.stringValue());
logger.debug("{} : write a log", mbox.getName());
mbox.send(from, msg.elementAt(3));
}
else {
logger.warn("{} : Illegal Message received : From["
+ from + "] logstr[" + logstr + "]", mbox.getName());
}
}
}
catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
}
finally {
}
}
}
catch (Exception e) {
throw e;
}
finally {
}
}
}
... 2. send message in erlang node
%%====================================================================
%% API
%%====================================================================
%%--------------------------------------------------------------------
%% Function:
%% Description:
%%--------------------------------------------------------------------
Code:
write_log(LogLine, Target) ->
{Target, mboxName@nodeName} ! {self(), pn0000, LogLine, ok},
receive
ok ->
ok;
Error ->
Error
after 1500 ->
false
end.
|
|
|
| Back to top |
|
| jacek99 |
Posted: Mon Jun 29, 2009 5:08 pm |
|
|
|
User
Joined: 26 May 2009
Posts: 27
Location: Montreal, Canada
|
| Thanks, that's very useful. |
|
|
| Back to top |
|
| timrila |
Posted: Thu Jun 07, 2012 9:59 am |
|
|
|
User
Joined: 28 Mar 2012
Posts: 32
|
|
| Back to top |
|
| trapples |
Posted: Sat Jun 09, 2012 8:15 am |
|
|
|
User
Joined: 02 Apr 2012
Posts: 45
|
| I'm not clear about java. |
_________________ music make our life sounds beautiful

|
|
| Back to top |
|
|
|
All times are GMT
|
|
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
|
|
|