<br><div class="gmail_quote">On Mon, Jan 9, 2012 at 5:44 PM, ilya goberman <span dir="ltr"><<a href="mailto:goberman@msn.com">goberman@msn.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div dir="ltr">
<div>Hello,</div>We are a market data API vendor. We have APIs to consume market data in Java, .Net, and C++. One of the clients indicated interest in using our API from Erlang.<div>So I would like to find out if it is possible to interface with any of these language APIs from Erlang.<br>
<div><br></div><div>I looked briefly at jinterface, but it appears to be designed to make calls from Java to Erlang, but not in the other directions.</div><div>I have found a post <a href="http://www.javalimit.com/2010/06/a-java-api-for-erjang.html" style="font-size:10pt" target="_blank">http://www.javalimit.com/2010/06/a-java-api-for-erjang.html</a> for the Erlang-java calls, but it does not seem to be a finished product.</div>
<div><br></div><div>What is the best bet to accomplish the integration?
</div><div>Any advice is appreciated.</div><div>Thanks</div><div><br></div></div></div></div></blockquote><div><br>Erlang uses message passing as it's primary communication mechanism. Thus you could write a small Java program utilising the Jinterface library to enable it to receive messages from Erlang, marshalling to your API and sending results back using the messaging again.<br>
<br>This is pretty straightforward.<br><br>Untested Java-like "pseudo"-code without any error checking:<br><br>public static void main(String[] args)<br>{<br> String node_name = args[0];<br> String mbox_name = args[1];<br>
String cookie = args[2];<br><br> OtpNode node = new OtpNode(node_name, cookie);<br> OtpMbox mbox = = node.createMbox(mbox_name);<br><br> while (true) {<br> OtpErlangTuple msg = (OtpErlangTuple) mbox.receive();<br>
OtpErlangPid from = (OtpErlangPid) msg.elementAt(0);<br> OtpErlangAtom request = (OtpErlangAtom) msg.elementAt(1);<br> OtpErlangObject args = msg.elementAt(2);<br> if (request.atomValue().equals("stop")) {<br>
break;<br> } else {<br> handle_request_and_send_result_back_to_requestor(from, request, args);<br> }<br> }<br><br> node.closeMbox(mbox);<br> node.close();<br>}<br><br>In Erlang, you'd have a gen_server that launches this Java server (for example, as a port program) and uses the defined node and mbox names to communicate with it.<br>
<br>Robby<br><br></div></div>