diff options
Diffstat (limited to 'sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java')
-rw-r--r-- | sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java index 63c58cb696..a03d522860 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; import org.apache.tuscany.sca.binding.erlang.ErlangBinding; import org.apache.tuscany.sca.binding.erlang.impl.types.TypeHelpersProxy; @@ -30,8 +32,10 @@ import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import com.ericsson.otp.erlang.OtpAuthException; import com.ericsson.otp.erlang.OtpConnection; import com.ericsson.otp.erlang.OtpErlangAtom; +import com.ericsson.otp.erlang.OtpErlangExit; import com.ericsson.otp.erlang.OtpErlangList; import com.ericsson.otp.erlang.OtpErlangObject; import com.ericsson.otp.erlang.OtpErlangPid; @@ -47,21 +51,25 @@ import com.ericsson.otp.erlang.OtpNode; */ public class ServiceExecutor implements Runnable { + private static final Logger logger = Logger.getLogger(ServiceExecutor.class + .getName()); private static final long RECEIVE_TIMEOUT = 60000; private Map<String, ErlangNodeElement> erlangModules; private ErlangNodeElement erlangMbox; private OtpConnection connection; private Map<String, List<Operation>> groupedOperations; + private String name; public ServiceExecutor(OtpConnection connection, Map<String, List<Operation>> groupedOperations, Map<String, ErlangNodeElement> erlangModules, - ErlangNodeElement erlangMbox) { + ErlangNodeElement erlangMbox, String name) { this.erlangModules = erlangModules; this.connection = connection; this.groupedOperations = groupedOperations; this.erlangMbox = erlangMbox; + this.name = name; } private void sendMessage(OtpConnection connection, OtpErlangPid pid, @@ -123,7 +131,8 @@ public class ServiceExecutor implements Runnable { forClasses[i] = iTypes.get(i).getPhysical(); } try { - Object result = service.getRuntimeWire(binding).invoke( + Object result = service.getRuntimeWire(binding, + service.getInterfaceContract()).invoke( operation, TypeHelpersProxy.toJavaFromList(argsList, forClasses)); @@ -169,9 +178,7 @@ public class ServiceExecutor implements Runnable { } } } catch (Exception e) { - // TODO: distinguish and describe errors! try { - e.printStackTrace(); sendMessage(connection, senderPid, senderRef, MessageHelper.ATOM_ERROR, new OtpErlangString( "Unhandled error while processing request: " @@ -179,6 +186,9 @@ public class ServiceExecutor implements Runnable { + ", message: " + e.getMessage())); } catch (IOException e1) { // error while sending error message. Can't do anything now + logger.log(Level.WARNING, "Error during sending error message", + e); + e.printStackTrace(); } } } @@ -189,7 +199,12 @@ public class ServiceExecutor implements Runnable { List<Operation> operations = groupedOperations.get(msg .getRecipientName()); if (operations == null) { - // TODO: no such mbox, send error message? + // TODO: externalize message? + // NOTE: I assume in Erlang sender doesn't get confirmation so + // message will be send + logger.log(Level.WARNING, "Node '" + name + + "' received message addressed to non exising mbox: " + + msg.getRecipientName()); } else { for (Operation operation : operations) { List<DataType> iTypes = operation.getInputType().getLogical(); @@ -203,8 +218,8 @@ public class ServiceExecutor implements Runnable { matchedOperation = operation; break; } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + // this exception is expected while processing operation + // version with mismatched arguments } } if (matchedOperation != null) { @@ -228,22 +243,25 @@ public class ServiceExecutor implements Runnable { mbox.send(msg.getSenderPid(), response); } } catch (InvocationTargetException e) { - // TODO send some error? + // FIXME: use linking feature? send some error? e.printStackTrace(); } catch (IOException e) { - // TODO Auto-generated catch block + // FIXME: log this problem? use linking feature? send error? e.printStackTrace(); } } else { - // TODO: send some error - no mapping for such arguments - System.out - .println("TODO: send some error - no mapping for such arguments"); + // 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."); } } } public void run() { try { + // TODO: should receive timeout be configured in .composite file? OtpMsg msg = connection.receiveMsg(RECEIVE_TIMEOUT); if (msg.getRecipientName().equals(MessageHelper.RPC_MBOX)) { handleRpc(msg); @@ -252,8 +270,16 @@ public class ServiceExecutor implements Runnable { } else { // message receive timeout } - } catch (Exception e) { - // TODO: log, send error? + } catch (IOException e) { + // TODO: externalize message? + logger.log(Level.WARNING, "Problem while receiving message", e); + } catch (OtpErlangExit e) { + // TODO: linking? + e.printStackTrace(); + } catch (OtpAuthException e) { + // TODO: cookies? + } catch (InterruptedException e) { + // TODO: when it could happen? e.printStackTrace(); } finally { connection.close(); |