Now that I got OtpErlang.jar (see my previous post), my next step was to connect Java to Erlang, if you have been following the book, you would have come across the Name server example in Chapter 10, this java code will connect to the name server
static void store(OtpConnection connection) throws Exception {
OtpErlangObject[] elements = new OtpErlangObject[] {
new OtpErlangString("weather"), new OtpErlangString("very nice") };
OtpErlangList erlangList = new OtpErlangList(elements);
connection.sendRPC("kvs", "store", erlangList);
OtpErlangObject received = connection.receiveRPC();
System.out.println(received);
}
static void lookup(OtpConnection connection) throws Exception {
OtpErlangObject[] elements = new OtpErlangObject[] { new OtpErlangString(
“weather”) };
OtpErlangList erlangList = new OtpErlangList(elements);
connection.sendRPC(“kvs”, “lookup”, erlangList);
OtpErlangObject received = connection.receiveRPC();
System.out.println(received);
}
public static void main(String[] args) throws Exception {
OtpSelf self = new OtpSelf(“client”);
OtpPeer other = new OtpPeer(“gandalf@devender-laptop”);
OtpConnection connection = self.connect(other);
store(connection);
lookup(connection);
}
Interesting.. have you used this in any real projects? Very cool, but seems like it may be a tad complex to maintain and debug
Nop, not yet . I am also concerned about how will I get them to install erlang on production servers.