diff options
author | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-16 08:44:36 +0000 |
---|---|---|
committer | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-16 08:44:36 +0000 |
commit | cc8390a108db502b965721392f1df0a7be221754 (patch) | |
tree | b5d7e298439386edc47957605928e98fec098e36 /branches/sca-java-1.x | |
parent | ce604976d31aba76df48dfd271a3e0c8a1bcac18 (diff) |
Messaging improvements
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@765512 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
3 files changed, 51 insertions, 8 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 696447feef..e42b93c313 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 @@ -214,14 +214,17 @@ public class ServiceExecutor implements Runnable { if (msg.getMsg().getClass().equals(OtpErlangTuple.class) && (((OtpErlangTuple) msg.getMsg()).elementAt(0)) .getClass().equals(OtpErlangPid.class)) { + // PID provided by client senderPid = (OtpErlangPid) ((OtpErlangTuple) msg.getMsg()) .elementAt(0); msgNoSender = ((OtpErlangTuple) msg.getMsg()).elementAt(1); } else { + // PID obtained from jinterface + senderPid = msg.getSenderPid(); msgNoSender = msg.getMsg(); } } catch (Exception e) { - + e.printStackTrace(); } if (operations == null) { @@ -265,13 +268,32 @@ public class ServiceExecutor implements Runnable { 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); + // TODO: externalize message? + // TODO: do we need to send this reply? + logger + .log( + Level.WARNING, + "Cannot send reply - Erlang client didn't provide it's PID and couldn't obtain sender PID from jinterface"); } } catch (InvocationTargetException e) { - // FIXME: use linking feature? send some error? - e.printStackTrace(); + if (e.getCause() != null + && e.getCause().getClass().equals( + IllegalArgumentException.class)) { + // arguments number or type mismatch + try { + // TODO: externalize message? + connection + .send( + senderPid, + new OtpErlangString( + "Operation name found in SCA component, but parameters types didn't match.")); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } else { + e.printStackTrace(); + } // } catch (IOException e) { } catch (Exception e) { // FIXME: log this problem? use linking feature? send error? diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java index 817ba2cefa..fe643fcff6 100644 --- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java +++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.binding.erlang.testing; import org.apache.tuscany.sca.binding.erlang.impl.types.TypeHelpersProxy; import com.ericsson.otp.erlang.OtpErlangObject; +import com.ericsson.otp.erlang.OtpErlangPid; import com.ericsson.otp.erlang.OtpErlangTuple; import com.ericsson.otp.erlang.OtpMbox; import com.ericsson.otp.erlang.OtpMsg; @@ -50,10 +51,16 @@ public class MboxListener implements Runnable { try { msg = mbox.receiveMsg(); Thread.sleep(duration); + OtpErlangPid senderPid = null; if (response != null) { Object[] args = new Object[1]; args[0] = response; - mbox.send(msg.getSenderPid(), TypeHelpersProxy.toErlang(args)); + if (msg.getMsg().getClass().equals(OtpErlangTuple.class) && ((OtpErlangTuple) msg.getMsg()).elementAt(0).getClass().equals(OtpErlangPid.class)) { + senderPid = (OtpErlangPid) ((OtpErlangTuple) msg.getMsg()).elementAt(0); + } else { + senderPid = msg.getSenderPid(); + } + mbox.send(senderPid, TypeHelpersProxy.toErlang(args)); } } catch (Exception e) { e.printStackTrace(); diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java index 1d349888e6..3e0a60725e 100644 --- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java +++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java @@ -649,6 +649,21 @@ public class ReferenceServiceTestCase { .getMsg(); assertEquals("Hello world !", result.stringValue()); } + + /** + * Tests receiving reply without sending self PID + * @throws Exception + */ + @Test(timeout = 1000) + public void testMsgWithoutPid() throws Exception { + OtpErlangObject[] args = new OtpErlangObject[2]; + args[0] = new OtpErlangString("world"); + args[1] = new OtpErlangString("!"); + refMbox.send("sayHello", "RPCServerMbox", new OtpErlangTuple(args)); + OtpErlangString result = (OtpErlangString) refMbox.receiveMsg() + .getMsg(); + assertEquals("Hello world !", result.stringValue()); + } /** * Tests service mbox receiving complex message @@ -814,7 +829,6 @@ public class ReferenceServiceTestCase { // testing correct cookie cookieModuleReference.sayHellos(); - } } |