diff options
author | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-13 09:41:00 +0000 |
---|---|---|
committer | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-13 09:41:00 +0000 |
commit | adcd82c520cafe5744c4256c245c3930955d3491 (patch) | |
tree | ab039112b0fbe1c1ce5186afa1e6c7a41d859452 /branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java | |
parent | 0aafa12010ca496809a7fa7e5327d1f90556d399 (diff) |
General improvements for messaging, fixed some issues regarding communication with real Erlang nodes
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@764382 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java index 001256f5f0..696447feef 100644 --- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java +++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java @@ -43,9 +43,7 @@ import com.ericsson.otp.erlang.OtpErlangPid; import com.ericsson.otp.erlang.OtpErlangRef; import com.ericsson.otp.erlang.OtpErlangString; import com.ericsson.otp.erlang.OtpErlangTuple; -import com.ericsson.otp.erlang.OtpMbox; import com.ericsson.otp.erlang.OtpMsg; -import com.ericsson.otp.erlang.OtpNode; /** * @version $Rev$ $Date$ @@ -72,17 +70,18 @@ public class ServiceExecutor implements Runnable { private void sendMessage(OtpConnection connection, OtpErlangPid pid, OtpErlangRef ref, OtpErlangAtom head, OtpErlangObject message) throws IOException { - OtpErlangTuple tResult = new OtpErlangTuple(new OtpErlangObject[] { - head, message }); + OtpErlangObject tResult = null; + if (head != null) { + tResult = new OtpErlangTuple( + new OtpErlangObject[] { head, message }); + } else { + tResult = message; + } OtpErlangObject msg = null; msg = new OtpErlangTuple(new OtpErlangObject[] { ref, tResult }); connection.send(pid, msg); } - private String getResponseClientNodeName(OtpErlangPid pid) { - return "_response_connector_to_" + pid + System.currentTimeMillis(); - } - private void handleRpc(OtpMsg msg) { OtpErlangTuple request = null; OtpErlangPid senderPid = null; @@ -148,8 +147,8 @@ public class ServiceExecutor implements Runnable { Object[] arrArg = new Object[] { result }; response = TypeHelpersProxy.toErlang(arrArg); } - sendMessage(connection, senderPid, senderRef, - MessageHelper.ATOM_OK, response); + sendMessage(connection, senderPid, senderRef, null, + response); } catch (Exception e) { if ((e.getClass().equals( InvocationTargetException.class) && e @@ -207,8 +206,24 @@ public class ServiceExecutor implements Runnable { private void handleMsg(OtpMsg msg) { Operation matchedOperation = null; Object args[] = null; + OtpErlangPid senderPid = null; + OtpErlangObject msgNoSender = null; List<Operation> operations = groupedOperations.get(msg .getRecipientName()); + try { + if (msg.getMsg().getClass().equals(OtpErlangTuple.class) + && (((OtpErlangTuple) msg.getMsg()).elementAt(0)) + .getClass().equals(OtpErlangPid.class)) { + senderPid = (OtpErlangPid) ((OtpErlangTuple) msg.getMsg()) + .elementAt(0); + msgNoSender = ((OtpErlangTuple) msg.getMsg()).elementAt(1); + } else { + msgNoSender = msg.getMsg(); + } + } catch (Exception e) { + + } + if (operations == null) { // TODO: externalize message? // NOTE: I assume in Erlang sender doesn't get confirmation so @@ -224,7 +239,7 @@ public class ServiceExecutor implements Runnable { forClasses[i] = iTypes.get(i).getPhysical(); } try { - args = TypeHelpersProxy.toJavaAsArgs(msg.getMsg(), + args = TypeHelpersProxy.toJavaAsArgs(msgNoSender, forClasses); matchedOperation = operation; break; @@ -247,11 +262,12 @@ public class ServiceExecutor implements Runnable { Object[] arrArg = new Object[] { result }; response = TypeHelpersProxy.toErlang(arrArg); } - if (response != null) { - OtpNode node = new OtpNode( - getResponseClientNodeName(msg.getSenderPid())); - OtpMbox mbox = node.createMbox(); - mbox.send(msg.getSenderPid(), response); + if (response != null && senderPid != null) { + connection.send(senderPid, response); + } else if (response != null && senderPid == null) { + // FIXME: cannot send reply - sender didn't provided + // pid. Use PID obtained by jinteface or log this error? + // connection.send(msg.getSenderPid(), response); } } catch (InvocationTargetException e) { // FIXME: use linking feature? send some error? @@ -262,17 +278,11 @@ public class ServiceExecutor implements Runnable { e.printStackTrace(); } } else { - try { - // TODO: externalize message? - // NOTE: don't send error message if mapping not found - logger.log(Level.WARNING, - "No mapping for such arguments in '" - + msg.getRecipientName() - + "' operation in '" + name - + "' node. Recevied arguments: " - + msg.getMsg()); - } catch (OtpErlangDecodeException e) { - } + // TODO: externalize message? + // NOTE: don't send error message if mapping not found + logger.log(Level.WARNING, "No mapping for such arguments in '" + + msg.getRecipientName() + "' operation in '" + name + + "' node. Recevied arguments: " + msgNoSender); } } } |