diff options
author | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-15 11:19:14 +0000 |
---|---|---|
committer | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-15 11:19:14 +0000 |
commit | fdfa3d0df9dc79314411bf455cc71c5677925e1b (patch) | |
tree | 408538346626c7b78bd13a4092ae323362ebe124 /sandbox/wjaniszewski/binding-erlang-runtime/src | |
parent | b44951427248e4cf764e2533115272ea17eb9b5f (diff) |
Enabled exposing SCA components as Erlang message boxes.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@754654 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/wjaniszewski/binding-erlang-runtime/src')
38 files changed, 1102 insertions, 440 deletions
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProviderFactory.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProviderFactory.java index f823be2d8f..f4114132c1 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProviderFactory.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProviderFactory.java @@ -32,7 +32,7 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentReference; import org.apache.tuscany.sca.runtime.RuntimeComponentService;
/**
- * @version $Rev: $ $Date: $
+ * @version $Rev$ $Date$
*/
public class ErlangBindingProviderFactory implements
BindingProviderFactory<ErlangBinding> {
@@ -40,9 +40,9 @@ public class ErlangBindingProviderFactory implements private Map<String, ErlangNode> nodes = new HashMap<String, ErlangNode>();
public ErlangBindingProviderFactory(ExtensionPointRegistry registry) {
-
+
}
-
+
/**
* @see org.apache.tuscany.sca.provider.BindingProviderFactory#createReferenceBindingProvider(org.apache.tuscany.sca.runtime.RuntimeComponent,
* org.apache.tuscany.sca.runtime.RuntimeComponentReference,
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java index fd9e89bc2d..9ed3713db4 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java @@ -37,7 +37,7 @@ import com.ericsson.otp.erlang.OtpPeer; import com.ericsson.otp.erlang.OtpSelf;
/**
- * @version $Rev: $ $Date: $
+ * @version $Rev$ $Date$
*/
public class ErlangInvoker implements Invoker {
@@ -59,6 +59,7 @@ public class ErlangInvoker implements Invoker { tmpMbox.send(msg.getOperation().getName(), binding.getNode(),
msgPayload);
if (msg.getOperation().getOutputType() != null) {
+ // TODO: add timeouts, timeout declaration method?
OtpMsg resultMsg = tmpMbox.receiveMsg();
OtpErlangObject result = resultMsg.getMsg();
msg.setBody(TypeHelpersProxy.toJava(result, msg.getOperation()
@@ -92,14 +93,15 @@ public class ErlangInvoker implements Invoker { OtpErlangTuple message = MessageHelper.rpcMessage(self.pid(), self
.createRef(), binding.getModule(), msg.getOperation()
.getName(), params);
- connection.send("rex", message);
+ connection.send(MessageHelper.RPC_MBOX, message);
OtpErlangObject result = connection.receiveRPC();
if (MessageHelper.isfunctionUndefMessage(result)) {
// TODO: externalize message?
Exception e = new ErlangException(
"No such function in referenced Erlang node.");
if (msg.getOperation().getFaultTypes().size() == 0) {
- // TODO: no way to throw exception, log it (temporary as System.out)
+ // TODO: no way to throw exception, log it (temporary as
+ // System.out)
// TODO: do we really want not to throw any exception?
System.out.println("PROBLEM: " + e.getMessage());
// in this case we don't throw occured problem, so we need
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java index a5cfbe6d90..78ffdfaa49 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java @@ -1,25 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.tuscany.sca.binding.erlang.impl; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.apache.tuscany.sca.binding.erlang.ErlangBinding; import org.apache.tuscany.sca.binding.erlang.impl.exceptions.ErlangException; +import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import com.ericsson.otp.erlang.OtpConnection; import com.ericsson.otp.erlang.OtpSelf; +/** + * @version $Rev$ $Date$ + */ public class ErlangNode implements Runnable { - private Map<String, RuntimeComponentService> services = new HashMap<String, RuntimeComponentService>(); - private Map<String, ErlangBinding> bindings = new HashMap<String, ErlangBinding>(); + private Map<String, ErlangNodeElement> erlangModules = new HashMap<String, ErlangNodeElement>(); + private ErlangNodeElement erlangMbox; + private boolean mboxNode; private String name; private OtpSelf self; private ExecutorService executors; private boolean stopRequested; + private Map<String, List<Operation>> groupedOperations; public ErlangNode(String name) throws Exception { this.name = name; @@ -42,8 +69,8 @@ public class ErlangNode implements Runnable { while (!stopRequested) { try { OtpConnection connection = self.accept(); - executors.execute(new RpcExecutor(services, bindings, - connection)); + executors.execute(new ServiceExecutor(connection, + groupedOperations, erlangModules, erlangMbox)); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); @@ -51,30 +78,59 @@ public class ErlangNode implements Runnable { } } - public void registerModule(ErlangBinding binding, + public void registerBinding(ErlangBinding binding, RuntimeComponentService service) throws ErlangException { - if (services.containsKey(binding.getModule())) { - // TODO: externalize message - // TODO: really want to throw exception? Log only? - throw new ErlangException("Module " + binding.getModule() - + " already defined under " + name - + " node. Duplicate module won't be started"); + if (binding.isMbox()) { + if (mboxNode) { + // TODO: externalize message + // TODO: really want to throw exception? Log only? + throw new ErlangException("Node " + binding.getNode() + + " already defined as mbox node"); + } else { + List<Operation> operations = service.getInterfaceContract() + .getInterface().getOperations(); + groupedOperations = new HashMap<String, List<Operation>>(); + for (Operation operation : operations) { + List<Operation> operationsGroup = groupedOperations + .get(operation.getName()); + if (operationsGroup == null) { + operationsGroup = new ArrayList<Operation>(); + groupedOperations.put(operation.getName(), + operationsGroup); + } + operationsGroup.add(operation); + } + mboxNode = true; + erlangMbox = new ErlangNodeElement(); + erlangMbox.setService(service); + erlangMbox.setBinding(binding); + } } else { - if (services.size() == 0) { - // TODO: should ErlangNode manage its thread? - Thread selfThread = new Thread(this); - selfThread.start(); + if (erlangModules.containsKey(binding.getModule())) { + // TODO: externalize message + // TODO: really want to throw exception? Log only? + throw new ErlangException("Module " + binding.getModule() + + " already defined under " + name + + " node. Duplicate module won't be started"); + } else { + if (erlangModules.size() == 0) { + // TODO: should ErlangNode manage its thread? + Thread selfThread = new Thread(this); + selfThread.start(); + } + ErlangNodeElement module = new ErlangNodeElement(); + module.setService(service); + module.setBinding(binding); + erlangModules.put(binding.getModule(), module); } - services.put(binding.getModule(), service); - bindings.put(binding.getModule(), binding); } } - public void unregisterModule(ErlangBinding binding) throws ErlangException { - if (services.containsKey(binding.getModule())) { - services.remove(binding.getModule()); - bindings.remove(binding.getModule()); - if (services.size() == 0) { + public void unregisterBinding(ErlangBinding binding) throws ErlangException { + if (erlangModules.containsKey(binding.getModule())) { + erlangModules.remove(binding.getModule()); + erlangModules.remove(binding.getModule()); + if (erlangModules.size() == 0) { stop(); } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNodeElement.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNodeElement.java new file mode 100644 index 0000000000..f945a841ec --- /dev/null +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNodeElement.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.impl; + +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Holds information (RuntimeComponentService, ErlangBindin) for element (program module, mbox) binded on node. + * @version $Rev$ $Date$ + */ +public class ErlangNodeElement { + + private ErlangBinding binding; + private RuntimeComponentService service; + + public void setBinding(ErlangBinding binding) { + this.binding = binding; + } + + public ErlangBinding getBinding() { + return binding; + } + + public void setService(RuntimeComponentService service) { + this.service = service; + } + + public RuntimeComponentService getService() { + return service; + } + +} diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.java index 0ce9d33238..b96a4524e1 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.java @@ -30,55 +30,58 @@ import org.apache.tuscany.sca.provider.ReferenceBindingProvider; import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
/**
- * @version $Rev: $ $Date: $
+ * @version $Rev$ $Date$
*/
public class ErlangReferenceBindingProvider implements ReferenceBindingProvider {
- private static final Logger logger = Logger.getLogger(ErlangReferenceBindingProvider.class.getName());
- private RuntimeComponentReference reference;
- private ErlangBinding binding;
+ private static final Logger logger = Logger
+ .getLogger(ErlangReferenceBindingProvider.class.getName());
+ private RuntimeComponentReference reference;
+ private ErlangBinding binding;
- public ErlangReferenceBindingProvider(ErlangBinding binding, RuntimeComponentReference reference) {
- this.reference = reference;
- this.binding = binding;
- }
+ public ErlangReferenceBindingProvider(ErlangBinding binding,
+ RuntimeComponentReference reference) {
+ this.reference = reference;
+ this.binding = binding;
+ }
- /**
- * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#createInvoker(org.apache.tuscany.sca.interfacedef.Operation)
- */
- public Invoker createInvoker(Operation operation) {
- try {
- return new ErlangInvoker(binding);
- } catch (Exception e) {
- logger.log(Level.WARNING, "Exception during creating Erlang invoker", e);
- }
- return null;
- }
+ /**
+ * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#createInvoker(org.apache.tuscany.sca.interfacedef.Operation)
+ */
+ public Invoker createInvoker(Operation operation) {
+ try {
+ return new ErlangInvoker(binding);
+ } catch (Exception e) {
+ logger.log(Level.WARNING,
+ "Exception during creating Erlang invoker", e);
+ }
+ return null;
+ }
- /**
- * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#getBindingInterfaceContract()
- */
- public InterfaceContract getBindingInterfaceContract() {
- return reference.getInterfaceContract();
- }
+ /**
+ * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#getBindingInterfaceContract()
+ */
+ public InterfaceContract getBindingInterfaceContract() {
+ return reference.getInterfaceContract();
+ }
- /**
- * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#start()
- */
- public void start() {
- }
+ /**
+ * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#start()
+ */
+ public void start() {
+ }
- /**
- * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#stop()
- */
- public void stop() {
- }
+ /**
+ * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#stop()
+ */
+ public void stop() {
+ }
- /**
- * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#supportsOneWayInvocation()
- */
- public boolean supportsOneWayInvocation() {
- return false;
- }
+ /**
+ * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#supportsOneWayInvocation()
+ */
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
}
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.java index 651067f4e7..38b9b197d6 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.java @@ -26,56 +26,57 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.osoa.sca.ServiceRuntimeException;
/**
- * @version $Rev: 685180 $ $Date: 2008-08-12 16:17:26 +0100 (Tue, 12 Aug 2008) $
+ * @version $Rev$ $Date$
*/
public class ErlangServiceBindingProvider implements ServiceBindingProvider {
- private RuntimeComponentService service;
- private ErlangNode node;
- private ErlangBinding binding;
+ private RuntimeComponentService service;
+ private ErlangNode node;
+ private ErlangBinding binding;
- public ErlangServiceBindingProvider(ErlangNode node, ErlangBinding binding, RuntimeComponentService service) {
- this.service = service;
- this.binding = binding;
- this.node = node;
- }
+ public ErlangServiceBindingProvider(ErlangNode node, ErlangBinding binding,
+ RuntimeComponentService service) {
+ this.service = service;
+ this.binding = binding;
+ this.node = node;
+ }
- /**
- * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#getBindingInterfaceContract()
- */
- public InterfaceContract getBindingInterfaceContract() {
- return service.getInterfaceContract();
- }
+ /**
+ * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#getBindingInterfaceContract()
+ */
+ public InterfaceContract getBindingInterfaceContract() {
+ return service.getInterfaceContract();
+ }
- /**
- * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#start()
- */
- public void start() {
- try {
- node.registerModule(binding, service);
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
+ /**
+ * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#start()
+ */
+ public void start() {
+ try {
+ node.registerBinding(binding, service);
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
- }
+ }
- /**
- * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#stop()
- */
- public void stop() {
- try {
- node.unregisterModule(binding);
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
+ /**
+ * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#stop()
+ */
+ public void stop() {
+ try {
+ node.unregisterBinding(binding);
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
- }
+ }
- /**
- * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#supportsOneWayInvocation()
- */
- public boolean supportsOneWayInvocation() {
- return false;
- }
+ /**
+ * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#supportsOneWayInvocation()
+ */
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
}
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/MessageHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/MessageHelper.java index 55134782d5..ee7957406b 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/MessageHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/MessageHelper.java @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.tuscany.sca.binding.erlang.impl; import com.ericsson.otp.erlang.OtpErlangAtom; @@ -7,34 +26,48 @@ import com.ericsson.otp.erlang.OtpErlangPid; import com.ericsson.otp.erlang.OtpErlangRef; import com.ericsson.otp.erlang.OtpErlangTuple; +/** + * @version $Rev$ $Date$ + */ public class MessageHelper { - private static String ATOM_BADRPC = "badrpc"; - private static String ATOM_EXIT = "EXIT"; - private static String ATOM_UNDEF = "undef"; + /** + * Mbox name used for Remote Procedure Calls + */ + public static String RPC_MBOX = "rex"; + + public static final OtpErlangAtom ATOM_OK = new OtpErlangAtom("ok"); + public static final OtpErlangAtom ATOM_ERROR = new OtpErlangAtom("error"); + public static final OtpErlangAtom ATOM_BADRPC = new OtpErlangAtom("badrpc"); + private static final OtpErlangAtom ATOM_EXIT = new OtpErlangAtom("EXIT"); + private static final OtpErlangAtom ATOM_UNDEF = new OtpErlangAtom("undef"); + private static final OtpErlangAtom ATOM_CALL = new OtpErlangAtom("call"); + private static final OtpErlangAtom ATOM_GEN_CALL = new OtpErlangAtom( + "$gen_call"); - public static OtpErlangObject functionUndefMessage(String module, String function, OtpErlangList args, String tuscanyMsg) { + public static OtpErlangObject functionUndefMessage(String module, + String function, OtpErlangList args, String tuscanyMsg) { OtpErlangObject[] args4 = new OtpErlangObject[3]; args4[0] = new OtpErlangAtom(module); args4[1] = new OtpErlangAtom(function); args4[2] = args; - + OtpErlangObject[] args3 = new OtpErlangObject[2]; args3[0] = new OtpErlangTuple(args4); args3[1] = new OtpErlangAtom(tuscanyMsg); - + OtpErlangObject[] args2 = new OtpErlangObject[2]; - args2[0] = new OtpErlangAtom(ATOM_UNDEF); + args2[0] = ATOM_UNDEF; args2[1] = new OtpErlangList(args3); - + OtpErlangObject[] args1 = new OtpErlangObject[2]; - args1[0] = new OtpErlangAtom(ATOM_EXIT); + args1[0] = ATOM_EXIT; args1[1] = new OtpErlangTuple(args2); - - OtpErlangTuple result = new OtpErlangTuple(args1); + + OtpErlangTuple result = new OtpErlangTuple(args1); return result; } - + public static boolean isfunctionUndefMessage(OtpErlangObject msg) { if (msg.getClass().equals(OtpErlangTuple.class)) { OtpErlangTuple tupleMsg = (OtpErlangTuple) msg; @@ -44,7 +77,7 @@ public class MessageHelper { && tupleMsg.elementAt(1).getClass().equals( OtpErlangTuple.class) && ((OtpErlangAtom) tupleMsg.elementAt(0)).atomValue() - .equals(ATOM_BADRPC)) { + .equals(ATOM_BADRPC.atomValue())) { OtpErlangTuple badrpcTuple = (OtpErlangTuple) tupleMsg .elementAt(1); if (badrpcTuple.arity() == 2 @@ -53,14 +86,14 @@ public class MessageHelper { && badrpcTuple.elementAt(1).getClass().equals( OtpErlangTuple.class) && ((OtpErlangAtom) badrpcTuple.elementAt(0)) - .atomValue().equals(ATOM_EXIT)) { + .atomValue().equals(ATOM_EXIT.atomValue())) { OtpErlangTuple exitTuple = (OtpErlangTuple) badrpcTuple .elementAt(1); if (exitTuple.arity() == 2 && exitTuple.elementAt(0).getClass().equals( OtpErlangAtom.class) && ((OtpErlangAtom) exitTuple.elementAt(0)) - .atomValue().equals(ATOM_UNDEF)) { + .atomValue().equals(ATOM_UNDEF.atomValue())) { return true; } } @@ -69,24 +102,25 @@ public class MessageHelper { } return false; } - - public static OtpErlangTuple rpcMessage(OtpErlangPid senderPid, OtpErlangRef ref, String module, String function, OtpErlangList args) { + + public static OtpErlangTuple rpcMessage(OtpErlangPid senderPid, + OtpErlangRef ref, String module, String function, OtpErlangList args) { OtpErlangObject[] args3 = new OtpErlangObject[5]; - args3[0] = new OtpErlangAtom("call"); + args3[0] = ATOM_CALL; args3[1] = new OtpErlangAtom(module); args3[2] = new OtpErlangAtom(function); args3[3] = args; args3[4] = senderPid; - + OtpErlangObject[] args2 = new OtpErlangObject[2]; args2[0] = senderPid; args2[1] = ref; - + OtpErlangObject[] args1 = new OtpErlangObject[3]; - args1[0] = new OtpErlangAtom("$gen_call"); + args1[0] = ATOM_GEN_CALL; args1[1] = new OtpErlangTuple(args2); args1[2] = new OtpErlangTuple(args3); - + OtpErlangTuple result = new OtpErlangTuple(args1); return result; } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/RpcExecutor.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java index 03e83cec61..63c58cb696 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/RpcExecutor.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java @@ -38,22 +38,30 @@ 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; -public class RpcExecutor implements Runnable { +/** + * @version $Rev$ $Date$ + */ +public class ServiceExecutor implements Runnable { - private Map<String, RuntimeComponentService> services; - private Map<String, ErlangBinding> bindings; - private OtpConnection connection; + private static final long RECEIVE_TIMEOUT = 60000; - private static final OtpErlangAtom OK = new OtpErlangAtom("ok"); - private static final OtpErlangAtom ERROR = new OtpErlangAtom("error"); - private static final OtpErlangAtom BADRPC = new OtpErlangAtom("badrpc"); + private Map<String, ErlangNodeElement> erlangModules; + private ErlangNodeElement erlangMbox; + private OtpConnection connection; + private Map<String, List<Operation>> groupedOperations; - public RpcExecutor(Map<String, RuntimeComponentService> services, Map<String, ErlangBinding> bindings, - OtpConnection connection) { - this.bindings = bindings; - this.services = services; + public ServiceExecutor(OtpConnection connection, + Map<String, List<Operation>> groupedOperations, + Map<String, ErlangNodeElement> erlangModules, + ErlangNodeElement erlangMbox) { + this.erlangModules = erlangModules; this.connection = connection; + this.groupedOperations = groupedOperations; + this.erlangMbox = erlangMbox; } private void sendMessage(OtpConnection connection, OtpErlangPid pid, @@ -66,12 +74,12 @@ public class RpcExecutor implements Runnable { connection.send(pid, msg); } - public void run() { + private void handleRpc(OtpMsg msg) { OtpErlangTuple request = null; OtpErlangPid senderPid = null; OtpErlangRef senderRef = null; try { - OtpErlangTuple call = (OtpErlangTuple) connection.receive(); + OtpErlangTuple call = (OtpErlangTuple) msg.getMsg(); OtpErlangTuple from = (OtpErlangTuple) call.elementAt(1); request = (OtpErlangTuple) call.elementAt(2); senderPid = (OtpErlangPid) from.elementAt(0); @@ -81,20 +89,23 @@ public class RpcExecutor implements Runnable { .atomValue(); OtpErlangObject args = request.elementAt(3); OtpErlangList argsList = null; + // normalize input if (args instanceof OtpErlangList) { argsList = (OtpErlangList) args; } else { argsList = new OtpErlangList(args); } - if (!services.containsKey(module)) { + if (!erlangModules.containsKey(module)) { // TODO: externalize message? OtpErlangObject errorMsg = MessageHelper.functionUndefMessage( module, function, argsList, "Module not found in SCA component."); - sendMessage(connection, senderPid, senderRef, BADRPC, errorMsg); + sendMessage(connection, senderPid, senderRef, + MessageHelper.ATOM_BADRPC, errorMsg); } else { - RuntimeComponentService service = services.get(module); - ErlangBinding binding = bindings.get(module); + RuntimeComponentService service = erlangModules.get(module) + .getService(); + ErlangBinding binding = erlangModules.get(module).getBinding(); List<Operation> operations = service.getInterfaceContract() .getInterface().getOperations(); Operation operation = null; @@ -128,8 +139,8 @@ public class RpcExecutor implements Runnable { Object[] arrArg = new Object[] { result }; response = TypeHelpersProxy.toErlang(arrArg); } - sendMessage(connection, senderPid, senderRef, OK, - response); + sendMessage(connection, senderPid, senderRef, + MessageHelper.ATOM_OK, response); } catch (Exception e) { if ((e.getClass().equals( InvocationTargetException.class) && e @@ -143,7 +154,7 @@ public class RpcExecutor implements Runnable { argsList, "Operation name found in SCA component, but parameters types didn't match."); sendMessage(connection, senderPid, senderRef, - BADRPC, errorMsg); + MessageHelper.ATOM_BADRPC, errorMsg); } else { throw e; } @@ -153,22 +164,97 @@ public class RpcExecutor implements Runnable { OtpErlangObject errorMsg = MessageHelper .functionUndefMessage(module, function, argsList, "Operation name not found in SCA component."); - sendMessage(connection, senderPid, senderRef, BADRPC, - errorMsg); + sendMessage(connection, senderPid, senderRef, + MessageHelper.ATOM_BADRPC, errorMsg); } } } catch (Exception e) { // TODO: distinguish and describe errors! try { e.printStackTrace(); - sendMessage(connection, senderPid, senderRef, ERROR, - new OtpErlangString( + sendMessage(connection, senderPid, senderRef, + MessageHelper.ATOM_ERROR, new OtpErlangString( "Unhandled error while processing request: " + e.getClass().getCanonicalName() + ", message: " + e.getMessage())); } catch (IOException e1) { // error while sending error message. Can't do anything now } + } + } + + private void handleMsg(OtpMsg msg) { + Operation matchedOperation = null; + Object args[] = null; + List<Operation> operations = groupedOperations.get(msg + .getRecipientName()); + if (operations == null) { + // TODO: no such mbox, send error message? + } else { + for (Operation operation : operations) { + List<DataType> iTypes = operation.getInputType().getLogical(); + Class<?>[] forClasses = new Class<?>[iTypes.size()]; + for (int i = 0; i < iTypes.size(); i++) { + forClasses[i] = iTypes.get(i).getPhysical(); + } + try { + args = TypeHelpersProxy.toJavaAsArgs(msg.getMsg(), + forClasses); + matchedOperation = operation; + break; + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + if (matchedOperation != null) { + try { + Object result = erlangMbox.getService().getRuntimeWire( + erlangMbox.getBinding()).invoke(matchedOperation, + args); + OtpErlangObject response = null; + if (matchedOperation.getOutputType() != null + && matchedOperation.getOutputType().getPhysical() + .isArray()) { + response = TypeHelpersProxy.toErlangAsList(result); + } else if (matchedOperation.getOutputType() != null) { + Object[] arrArg = new Object[] { result }; + response = TypeHelpersProxy.toErlang(arrArg); + } + if (response != null) { + OtpNode node = new OtpNode("_response_connector_to_" + + msg.getSenderPid()); + OtpMbox mbox = node.createMbox(); + mbox.send(msg.getSenderPid(), response); + } + } catch (InvocationTargetException e) { + // TODO send some error? + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + // TODO: send some error - no mapping for such arguments + System.out + .println("TODO: send some error - no mapping for such arguments"); + } + } + } + + public void run() { + try { + OtpMsg msg = connection.receiveMsg(RECEIVE_TIMEOUT); + if (msg.getRecipientName().equals(MessageHelper.RPC_MBOX)) { + handleRpc(msg); + } else if (msg != null) { + handleMsg(msg); + } else { + // message receive timeout + } + } catch (Exception e) { + // TODO: log, send error? + e.printStackTrace(); } finally { connection.close(); } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.java index 03b53b60bd..b3562cc413 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.java @@ -19,28 +19,32 @@ package org.apache.tuscany.sca.binding.erlang.impl; +/** + * @version $Rev$ $Date$ + */ public class TypeMismatchException extends Exception { - private static final long serialVersionUID = 1L; - private Class<?> expected; - private Class<?> received; - - public TypeMismatchException(Class<?> expected, Class<?> received) { - super("Received " + received + " cannot be mapped to " + expected.getCanonicalName()); - this.expected = expected; - this.received = received; - } - - public TypeMismatchException() { - super("Arguments don't match"); - } - - public Class<?> getExpected() { - return expected; - } - - public Class<?> getReceived() { - return received; - } + private static final long serialVersionUID = 1L; + private Class<?> expected; + private Class<?> received; + + public TypeMismatchException(Class<?> expected, Class<?> received) { + super("Received " + received + " cannot be mapped to " + + expected.getCanonicalName()); + this.expected = expected; + this.received = received; + } + + public TypeMismatchException() { + super("Arguments don't match"); + } + + public Class<?> getExpected() { + return expected; + } + + public Class<?> getReceived() { + return received; + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/exceptions/ErlangException.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/exceptions/ErlangException.java index cf573def95..587d7a509c 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/exceptions/ErlangException.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/exceptions/ErlangException.java @@ -1,5 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.tuscany.sca.binding.erlang.impl.exceptions; +/** + * @version $Rev$ $Date$ + */ public class ErlangException extends Exception { private static final long serialVersionUID = 1L; @@ -7,9 +29,9 @@ public class ErlangException extends Exception { public ErlangException(String message) { super(message); } - + public ErlangException(String message, Throwable cause) { super(message, cause); } - + } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BooleanTypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BooleanTypeHelper.java index dd9f65b4e9..9463b72eb9 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BooleanTypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BooleanTypeHelper.java @@ -23,18 +23,22 @@ import com.ericsson.otp.erlang.OtpErlangAtom; import com.ericsson.otp.erlang.OtpErlangBoolean; import com.ericsson.otp.erlang.OtpErlangObject; +/** + * @version $Rev$ $Date$ + */ public class BooleanTypeHelper implements TypeHelper { - public OtpErlangObject toErlang(Object object) { - return new OtpErlangBoolean((Boolean)object); - } + public OtpErlangObject toErlang(Object object) { + return new OtpErlangBoolean((Boolean) object); + } - public Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception { - if (object.getClass().equals(OtpErlangAtom.class)) { - return ((OtpErlangAtom)object).booleanValue(); - } else { - return ((OtpErlangBoolean)object).booleanValue(); - } - } + public Object toJava(OtpErlangObject object, Class<?> forClass) + throws Exception { + if (object.getClass().equals(OtpErlangAtom.class)) { + return ((OtpErlangAtom) object).booleanValue(); + } else { + return ((OtpErlangBoolean) object).booleanValue(); + } + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ByteTypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ByteTypeHelper.java index d4a92e768a..c6c8f6690f 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ByteTypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ByteTypeHelper.java @@ -23,13 +23,17 @@ import com.ericsson.otp.erlang.OtpErlangByte; import com.ericsson.otp.erlang.OtpErlangLong; import com.ericsson.otp.erlang.OtpErlangObject; +/** + * @version $Rev$ $Date$ + */ public class ByteTypeHelper implements TypeHelper { - public OtpErlangObject toErlang(Object object) { - return new OtpErlangByte((Byte)object); - } + public OtpErlangObject toErlang(Object object) { + return new OtpErlangByte((Byte) object); + } - public Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception { - return (byte)((OtpErlangLong)object).longValue(); - } + public Object toJava(OtpErlangObject object, Class<?> forClass) + throws Exception { + return (byte) ((OtpErlangLong) object).longValue(); + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/CharTypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/CharTypeHelper.java index 17100c65b8..b0479c9b0c 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/CharTypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/CharTypeHelper.java @@ -23,14 +23,18 @@ import com.ericsson.otp.erlang.OtpErlangChar; import com.ericsson.otp.erlang.OtpErlangLong; import com.ericsson.otp.erlang.OtpErlangObject; +/** + * @version $Rev$ $Date$ + */ public class CharTypeHelper implements TypeHelper { - public OtpErlangObject toErlang(Object object) { - return new OtpErlangChar((Character)object); - } + public OtpErlangObject toErlang(Object object) { + return new OtpErlangChar((Character) object); + } - public Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception { - return (char)((OtpErlangLong)object).longValue(); - } + public Object toJava(OtpErlangObject object, Class<?> forClass) + throws Exception { + return (char) ((OtpErlangLong) object).longValue(); + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/DoubleTypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/DoubleTypeHelper.java index 760fb0723b..92dd4749ac 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/DoubleTypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/DoubleTypeHelper.java @@ -22,14 +22,18 @@ package org.apache.tuscany.sca.binding.erlang.impl.types; import com.ericsson.otp.erlang.OtpErlangDouble; import com.ericsson.otp.erlang.OtpErlangObject; +/** + * @version $Rev$ $Date$ + */ public class DoubleTypeHelper implements TypeHelper { - public OtpErlangObject toErlang(Object object) { - return new OtpErlangDouble((Double)object); - } + public OtpErlangObject toErlang(Object object) { + return new OtpErlangDouble((Double) object); + } - public Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception { - return ((OtpErlangDouble)object).doubleValue(); - } + public Object toJava(OtpErlangObject object, Class<?> forClass) + throws Exception { + return ((OtpErlangDouble) object).doubleValue(); + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/FloatTypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/FloatTypeHelper.java index 851d0982f3..3ee695c3cc 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/FloatTypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/FloatTypeHelper.java @@ -22,14 +22,18 @@ package org.apache.tuscany.sca.binding.erlang.impl.types; import com.ericsson.otp.erlang.OtpErlangDouble; import com.ericsson.otp.erlang.OtpErlangObject; +/** + * @version $Rev$ $Date$ + */ public class FloatTypeHelper implements TypeHelper { - public OtpErlangObject toErlang(Object object) { - return new OtpErlangDouble((Float)object); - } + public OtpErlangObject toErlang(Object object) { + return new OtpErlangDouble((Float) object); + } - public Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception { - return (float)((OtpErlangDouble)object).doubleValue(); - } + public Object toJava(OtpErlangObject object, Class<?> forClass) + throws Exception { + return (float) ((OtpErlangDouble) object).doubleValue(); + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/IntTypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/IntTypeHelper.java index 3e79577b1e..3ee8e7d9ac 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/IntTypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/IntTypeHelper.java @@ -23,14 +23,18 @@ import com.ericsson.otp.erlang.OtpErlangInt; import com.ericsson.otp.erlang.OtpErlangLong; import com.ericsson.otp.erlang.OtpErlangObject; +/** + * @version $Rev$ $Date$ + */ public class IntTypeHelper implements TypeHelper { - public OtpErlangObject toErlang(Object object) { - return new OtpErlangInt((Integer)object); - } + public OtpErlangObject toErlang(Object object) { + return new OtpErlangInt((Integer) object); + } - public Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception { - return (int)((OtpErlangLong)object).longValue(); - } + public Object toJava(OtpErlangObject object, Class<?> forClass) + throws Exception { + return (int) ((OtpErlangLong) object).longValue(); + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ListTypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ListTypeHelper.java index 86dcd4fc0f..adac10bcef 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ListTypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ListTypeHelper.java @@ -26,32 +26,39 @@ import java.util.List; import com.ericsson.otp.erlang.OtpErlangList; import com.ericsson.otp.erlang.OtpErlangObject; +/** + * @version $Rev$ $Date$ + */ public class ListTypeHelper implements TypeHelper { - public OtpErlangObject toErlang(Object object) { - int i = 0; - List<OtpErlangObject> elements = new ArrayList<OtpErlangObject>(); - while (true) { - try { - Object arrElement = Array.get(object, i); - Object[] args = new Object[] {arrElement}; - elements.add(TypeHelpersProxy.toErlang(args)); - i++; - } catch (ArrayIndexOutOfBoundsException e) { - // expected - break; - } - } - return new OtpErlangList(elements.toArray(new OtpErlangObject[elements.size()])); - } + public OtpErlangObject toErlang(Object object) { + int i = 0; + List<OtpErlangObject> elements = new ArrayList<OtpErlangObject>(); + while (true) { + try { + Object arrElement = Array.get(object, i); + Object[] args = new Object[] { arrElement }; + elements.add(TypeHelpersProxy.toErlang(args)); + i++; + } catch (ArrayIndexOutOfBoundsException e) { + // expected + break; + } + } + return new OtpErlangList(elements.toArray(new OtpErlangObject[elements + .size()])); + } - public Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception { - OtpErlangList erlangList = (OtpErlangList)object; - Object result = Array.newInstance(forClass.getComponentType(), erlangList.arity()); - for (int i = 0; i < erlangList.arity(); i++) { - Array.set(result, i, TypeHelpersProxy.toJava(erlangList.elementAt(i), forClass.getComponentType())); - } - return result; - } + public Object toJava(OtpErlangObject object, Class<?> forClass) + throws Exception { + OtpErlangList erlangList = (OtpErlangList) object; + Object result = Array.newInstance(forClass.getComponentType(), + erlangList.arity()); + for (int i = 0; i < erlangList.arity(); i++) { + Array.set(result, i, TypeHelpersProxy.toJava(erlangList + .elementAt(i), forClass.getComponentType())); + } + return result; + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/LongTypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/LongTypeHelper.java index 1437c8f8da..711057569a 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/LongTypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/LongTypeHelper.java @@ -22,14 +22,18 @@ package org.apache.tuscany.sca.binding.erlang.impl.types; import com.ericsson.otp.erlang.OtpErlangLong; import com.ericsson.otp.erlang.OtpErlangObject; +/** + * @version $Rev$ $Date$ + */ public class LongTypeHelper implements TypeHelper { - public OtpErlangObject toErlang(Object object) { - return new OtpErlangLong((Long)object); - } + public OtpErlangObject toErlang(Object object) { + return new OtpErlangLong((Long) object); + } - public Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception { - return ((OtpErlangLong)object).longValue(); - } + public Object toJava(OtpErlangObject object, Class<?> forClass) + throws Exception { + return ((OtpErlangLong) object).longValue(); + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ShortTypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ShortTypeHelper.java index 594875f348..73a68691a4 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ShortTypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ShortTypeHelper.java @@ -23,14 +23,18 @@ import com.ericsson.otp.erlang.OtpErlangLong; import com.ericsson.otp.erlang.OtpErlangObject; import com.ericsson.otp.erlang.OtpErlangShort; +/** + * @version $Rev$ $Date$ + */ public class ShortTypeHelper implements TypeHelper { - public OtpErlangObject toErlang(Object object) { - return new OtpErlangShort((Short)object); - } + public OtpErlangObject toErlang(Object object) { + return new OtpErlangShort((Short) object); + } - public Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception { - return (short)((OtpErlangLong)object).longValue(); - } + public Object toJava(OtpErlangObject object, Class<?> forClass) + throws Exception { + return (short) ((OtpErlangLong) object).longValue(); + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/StringTypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/StringTypeHelper.java index 8a10e1818a..001ec47655 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/StringTypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/StringTypeHelper.java @@ -22,14 +22,18 @@ package org.apache.tuscany.sca.binding.erlang.impl.types; import com.ericsson.otp.erlang.OtpErlangObject; import com.ericsson.otp.erlang.OtpErlangString; +/** + * @version $Rev$ $Date$ + */ public class StringTypeHelper implements TypeHelper { - public OtpErlangObject toErlang(Object object) { - return new OtpErlangString((String)object); - } + public OtpErlangObject toErlang(Object object) { + return new OtpErlangString((String) object); + } - public Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception { - return ((OtpErlangString)object).stringValue(); - } + public Object toJava(OtpErlangObject object, Class<?> forClass) + throws Exception { + return ((OtpErlangString) object).stringValue(); + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TupleTypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TupleTypeHelper.java index 86a78ccf87..3b5b30ac4d 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TupleTypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TupleTypeHelper.java @@ -26,43 +26,49 @@ import java.util.List; import com.ericsson.otp.erlang.OtpErlangObject; import com.ericsson.otp.erlang.OtpErlangTuple; +/** + * @version $Rev$ $Date$ + */ public class TupleTypeHelper implements TypeHelper { - public OtpErlangObject toErlang(Object object) { - Class<?> forClass = object.getClass(); - List<OtpErlangObject> tupleMembers = new ArrayList<OtpErlangObject>(); - Field[] fields = forClass.getFields(); - for (int i = 0; i < fields.length; i++) { - Object[] args; - try { - args = new Object[] {fields[i].get(object)}; - OtpErlangObject member = TypeHelpersProxy.toErlang(args); - tupleMembers.add(member); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - OtpErlangObject result = new OtpErlangTuple(tupleMembers.toArray(new OtpErlangObject[tupleMembers.size()])); - return result; - } + public OtpErlangObject toErlang(Object object) { + Class<?> forClass = object.getClass(); + List<OtpErlangObject> tupleMembers = new ArrayList<OtpErlangObject>(); + Field[] fields = forClass.getFields(); + for (int i = 0; i < fields.length; i++) { + Object[] args; + try { + args = new Object[] { fields[i].get(object) }; + OtpErlangObject member = TypeHelpersProxy.toErlang(args); + tupleMembers.add(member); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + OtpErlangObject result = new OtpErlangTuple(tupleMembers + .toArray(new OtpErlangObject[tupleMembers.size()])); + return result; + } - public Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception { - Object result = null; - OtpErlangTuple tuple = (OtpErlangTuple)object; - Field[] fields = forClass.getFields(); - if (fields.length != tuple.arity()) { - // TODO: received tuple with different element count - wrong - // message, exception! - } - result = forClass.newInstance(); - for (int i = 0; i < tuple.arity(); i++) { - OtpErlangObject tupleMember = tuple.elementAt(i); - Object javaMember = TypeHelpersProxy.toJava(tupleMember, fields[i].getType()); - fields[i].setAccessible(true); - fields[i].set(result, javaMember); - } - return result; - } + public Object toJava(OtpErlangObject object, Class<?> forClass) + throws Exception { + Object result = null; + OtpErlangTuple tuple = (OtpErlangTuple) object; + Field[] fields = forClass.getFields(); + if (fields.length != tuple.arity()) { + // TODO: received tuple with different element count - wrong + // message, exception! + } + result = forClass.newInstance(); + for (int i = 0; i < tuple.arity(); i++) { + OtpErlangObject tupleMember = tuple.elementAt(i); + Object javaMember = TypeHelpersProxy.toJava(tupleMember, fields[i] + .getType()); + fields[i].setAccessible(true); + fields[i].set(result, javaMember); + } + return result; + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelper.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelper.java index 2d32ed586b..add885ef6e 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelper.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelper.java @@ -21,10 +21,13 @@ package org.apache.tuscany.sca.binding.erlang.impl.types; import com.ericsson.otp.erlang.OtpErlangObject;
+/**
+ * @version $Rev$ $Date$
+ */
public interface TypeHelper {
- Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception;
+ Object toJava(OtpErlangObject object, Class<?> forClass) throws Exception;
- OtpErlangObject toErlang(Object object);
+ OtpErlangObject toErlang(Object object);
}
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java index 208216eef2..0d0dd25a41 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java @@ -31,6 +31,9 @@ import com.ericsson.otp.erlang.OtpErlangList; import com.ericsson.otp.erlang.OtpErlangObject;
import com.ericsson.otp.erlang.OtpErlangTuple;
+/**
+ * @version $Rev$ $Date$
+ */
public class TypeHelpersProxy {
private static Map<Class<?>, TypeHelper> primitiveTypes = null;
@@ -72,6 +75,13 @@ public class TypeHelpersProxy { return typeHelper;
}
+ /**
+ * Converts Java objects arrays to Erlang: 1. single object (if array arity
+ * == 1) or 2. tuple (if array arity > 1)
+ *
+ * @param objects
+ * @return
+ */
public static OtpErlangObject toErlang(Object[] objects) {
OtpErlangObject result = null;
if (objects != null) {
@@ -97,12 +107,15 @@ public class TypeHelpersProxy { return result;
}
+ /**
+ * Creates Erlang list basing on unknown Java arrays
+ *
+ * @param array
+ * @return
+ */
public static OtpErlangList toErlangAsList(Object array) {
OtpErlangList result = null;
if (array != null) {
- if (!array.getClass().isArray()) {
- array = new Object[] { array };
- }
List<OtpErlangObject> attrsList = new ArrayList<OtpErlangObject>();
int i = 0;
while (true) {
@@ -123,6 +136,14 @@ public class TypeHelpersProxy { return result;
}
+ /**
+ * Converts single Erlang object to Java
+ *
+ * @param object
+ * @param forClass
+ * @return
+ * @throws Exception
+ */
public static Object toJava(OtpErlangObject object, Class<?> forClass)
throws Exception {
try {
@@ -133,6 +154,14 @@ public class TypeHelpersProxy { }
}
+ /**
+ * Creates array of Java objects from Erlang list
+ *
+ * @param objects
+ * @param forClass
+ * @return
+ * @throws Exception
+ */
public static Object[] toJavaFromList(OtpErlangList objects,
Class<?>[] forClass) throws Exception {
Object[] result = new Object[objects.arity()];
@@ -151,4 +180,41 @@ public class TypeHelpersProxy { return result;
}
+ /**
+ * Converts incoming Erlang message to operation arguments
+ *
+ * @param objects
+ * @param forClass
+ * @return
+ * @throws Exception
+ */
+ public static Object[] toJavaAsArgs(OtpErlangObject objects,
+ Class<?>[] forClass) throws Exception {
+ OtpErlangObject[] args = null;
+ // normalize input
+ if (objects.getClass().equals(OtpErlangTuple.class)) {
+ args = new OtpErlangObject[((OtpErlangTuple) objects).arity()];
+ for (int i = 0; i < ((OtpErlangTuple) objects).arity(); i++) {
+ args[i] = ((OtpErlangTuple) objects).elementAt(i);
+ }
+ } else {
+ args = new OtpErlangObject[1];
+ args[0] = objects;
+ }
+ Object[] result = new Object[args.length];
+ try {
+ for (int i = 0; i < args.length; i++) {
+ TypeHelper helper = getTypeHelper(forClass[i]);
+ result[i] = helper.toJava(args[i], forClass[i]);
+ }
+ } catch (Exception e) {
+ // type mismatch as mismatch of parameters count or parameters type
+ if (e.getClass().equals(ClassCastException.class)
+ || e.getClass()
+ .equals(ArrayIndexOutOfBoundsException.class))
+ throw new TypeMismatchException();
+ }
+ return result;
+ }
+
}
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java index d7ac443055..0f477fe660 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java @@ -1,30 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.tuscany.sca.binding.erlang.testing; +/** + * @version $Rev$ $Date$ + */ public interface MboxInterface { - String sendArgs(String arg) throws Exception; + String sendArgs(String arg) throws Exception; + + boolean sendArgs(boolean arg) throws Exception; + + float sendArgs(float arg) throws Exception; + + double sendArgs(double arg) throws Exception; - boolean sendArgs(boolean arg) throws Exception; + long sendArgs(long arg) throws Exception; - float sendArgs(float arg) throws Exception; + int sendArgs(int arg) throws Exception; - double sendArgs(double arg) throws Exception; + char sendArgs(char arg) throws Exception; - long sendArgs(long arg) throws Exception; + short sendArgs(short arg) throws Exception; - int sendArgs(int arg) throws Exception; + byte sendArgs(byte arg) throws Exception; - char sendArgs(char arg) throws Exception; + void sendArgs(int arg1, String arg2) throws Exception; - short sendArgs(short arg) throws Exception; + StructuredTuple sendArgs(StructuredTuple arg) throws Exception; - byte sendArgs(byte arg) throws Exception; - - void sendArgs(int arg1, String arg2) throws Exception; - - StructuredTuple sendArgs(StructuredTuple arg) throws Exception; + String[] sendArgs(String[] arg) throws Exception; - String[] sendArgs(String[] arg) throws Exception; - - String[][] sendArgs(String[][] arg); + String[][] sendArgs(String[][] arg); } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java index b5d5e67b00..e64728b01e 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java @@ -25,6 +25,9 @@ import com.ericsson.otp.erlang.OtpErlangExit; import com.ericsson.otp.erlang.OtpMbox; import com.ericsson.otp.erlang.OtpMsg; +/** + * @version $Rev$ $Date$ + */ public class MboxListener implements Runnable { private OtpMbox mbox; @@ -39,7 +42,6 @@ public class MboxListener implements Runnable { public void run() { try { msg = mbox.receiveMsg(); - if (response != null) { Object[] args = new Object[1]; args[0] = response; diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ModuleInterface.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ModuleInterface.java index 7d3fc99f26..6fc95ac120 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ModuleInterface.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ModuleInterface.java @@ -1,9 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.tuscany.sca.binding.erlang.testing; +/** + * @version $Rev$ $Date$ + */ public interface ModuleInterface { - String start(String arg1, String arg2) throws Exception; - - String start() throws Exception; + String start(String arg1, String arg2) throws Exception; + + String start() throws Exception; } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java index 34efb04812..2312c5ebea 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java @@ -36,15 +36,21 @@ import org.junit.runner.RunWith; import org.osoa.sca.ServiceRuntimeException; import com.ericsson.otp.erlang.OtpErlangAtom; +import com.ericsson.otp.erlang.OtpErlangBoolean; import com.ericsson.otp.erlang.OtpErlangDouble; +import com.ericsson.otp.erlang.OtpErlangInt; import com.ericsson.otp.erlang.OtpErlangList; import com.ericsson.otp.erlang.OtpErlangLong; +import com.ericsson.otp.erlang.OtpErlangObject; import com.ericsson.otp.erlang.OtpErlangString; import com.ericsson.otp.erlang.OtpErlangTuple; import com.ericsson.otp.erlang.OtpMbox; import com.ericsson.otp.erlang.OtpNode; -//this test runner will ignore tests if epmd is not available +/** + * Test is annotated with test runner, which will ignore tests if epmd is not available + * @version $Rev$ $Date$ + */ @RunWith(IgnorableRunner.class) public class ReferenceServiceTestCase { @@ -53,8 +59,10 @@ public class ReferenceServiceTestCase { private static MboxInterface mboxReference; private static ServiceInterface moduleReference; private static ServiceInterface clonedModuleReference; - private static OtpNode node; - private static OtpMbox mbox; + private static OtpNode serNode; + private static OtpMbox serMbox; + private static OtpNode refNode; + private static OtpMbox refMbox; private static Process epmdProcess; @BeforeClass @@ -69,8 +77,10 @@ public class ReferenceServiceTestCase { mboxReference = component.getMboxReference(); moduleReference = component.getModuleReference(); clonedModuleReference = component.getClonedModuleReference(); - node = new OtpNode("MboxServer"); - mbox = node.createMbox("sendArgs"); + serNode = new OtpNode("MboxServer"); + serMbox = serNode.createMbox("sendArgs"); + refNode = new OtpNode("MboxClient"); + refMbox = refNode.createMbox("connector_to_SCA_mbox"); } catch (IOException e) { System.out.println("Problem executing " + EPMD_COMMAND + ": " + e.getLocalizedMessage() + ". Tests will be IGNORED."); @@ -100,7 +110,7 @@ public class ReferenceServiceTestCase { public void testStrings() throws Exception { String strArg = "Test message"; String strResult = "OK"; - MboxListener mboxListener = new MboxListener(mbox, strResult); + MboxListener mboxListener = new MboxListener(serMbox, strResult); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); String testResult = mboxReference.sendArgs(strArg); @@ -118,7 +128,7 @@ public class ReferenceServiceTestCase { public void testBooleans() throws Exception { boolean booleanArg = true; boolean booleanResult = false; - MboxListener mboxListener = new MboxListener(mbox, booleanResult); + MboxListener mboxListener = new MboxListener(serMbox, booleanResult); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); boolean testResult = mboxReference.sendArgs(booleanArg); @@ -136,7 +146,7 @@ public class ReferenceServiceTestCase { public void testFloats() throws Exception { float floatArg = 1.0f; float floatResult = 2.0f; - MboxListener mboxListener = new MboxListener(mbox, floatResult); + MboxListener mboxListener = new MboxListener(serMbox, floatResult); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); float testResult = mboxReference.sendArgs(floatArg); @@ -154,7 +164,7 @@ public class ReferenceServiceTestCase { public void testDoubles() throws Exception { double doubleArg = 1.0f; double doubleResult = 2.0f; - MboxListener mboxListener = new MboxListener(mbox, doubleResult); + MboxListener mboxListener = new MboxListener(serMbox, doubleResult); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); double testResult = mboxReference.sendArgs(doubleArg); @@ -172,7 +182,7 @@ public class ReferenceServiceTestCase { public void testLongs() throws Exception { long longArg = 1; long longResult = 2; - MboxListener mboxListener = new MboxListener(mbox, longResult); + MboxListener mboxListener = new MboxListener(serMbox, longResult); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); long testResult = mboxReference.sendArgs(longArg); @@ -190,7 +200,7 @@ public class ReferenceServiceTestCase { public void testInts() throws Exception { int intArg = 1; int intResult = 2; - MboxListener mboxListener = new MboxListener(mbox, intResult); + MboxListener mboxListener = new MboxListener(serMbox, intResult); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); int testResult = mboxReference.sendArgs(intArg); @@ -208,7 +218,7 @@ public class ReferenceServiceTestCase { public void testChars() throws Exception { char charArg = 1; char charResult = 2; - MboxListener mboxListener = new MboxListener(mbox, charResult); + MboxListener mboxListener = new MboxListener(serMbox, charResult); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); char testResult = mboxReference.sendArgs(charArg); @@ -226,7 +236,7 @@ public class ReferenceServiceTestCase { public void testShorts() throws Exception { short shortArg = 1; short shortResult = 2; - MboxListener mboxListener = new MboxListener(mbox, shortResult); + MboxListener mboxListener = new MboxListener(serMbox, shortResult); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); short testResult = mboxReference.sendArgs(shortArg); @@ -244,7 +254,7 @@ public class ReferenceServiceTestCase { public void testBytes() throws Exception { byte byteArg = 1; byte byteResult = 2; - MboxListener mboxListener = new MboxListener(mbox, byteResult); + MboxListener mboxListener = new MboxListener(serMbox, byteResult); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); byte testResult = mboxReference.sendArgs(byteArg); @@ -260,7 +270,7 @@ public class ReferenceServiceTestCase { */ @Test(timeout = 1000) public void testMultipleArguments() throws Exception { - MboxListener mboxListener = new MboxListener(mbox, true); + MboxListener mboxListener = new MboxListener(serMbox, true); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); String testString = "TupleString"; @@ -285,7 +295,7 @@ public class ReferenceServiceTestCase { tupleResult.arg1.arg2 = "Tuple inside tuple"; tupleResult.arg2 = "Tuple!"; tupleResult.arg3 = true; - MboxListener mboxListener = new MboxListener(mbox, tupleResult); + MboxListener mboxListener = new MboxListener(serMbox, tupleResult); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); StructuredTuple testArg = new StructuredTuple(); @@ -317,7 +327,7 @@ public class ReferenceServiceTestCase { @Test(timeout = 1000) public void testLists() throws Exception { String[] testArg = new String[] { "One", "Two", "Three" }; - MboxListener mboxListener = new MboxListener(mbox, testArg); + MboxListener mboxListener = new MboxListener(serMbox, testArg); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); String[] testResult = mboxReference.sendArgs(testArg); @@ -342,7 +352,7 @@ public class ReferenceServiceTestCase { public void testMultiDimLists() throws Exception { String[][] testArg = new String[][] { { "One", "Two" }, { "Three", "Four", "Five" }, { "Six" } }; - MboxListener mboxListener = new MboxListener(mbox, testArg); + MboxListener mboxListener = new MboxListener(serMbox, testArg); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); String[][] testResult = mboxReference.sendArgs(testArg); @@ -372,7 +382,7 @@ public class ReferenceServiceTestCase { public void typeMismatch() throws Exception { try { StructuredTuple arg = new StructuredTuple(); - MboxListener mboxListener = new MboxListener(mbox, true); + MboxListener mboxListener = new MboxListener(serMbox, true); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); mboxReference.sendArgs(arg); @@ -383,7 +393,7 @@ public class ReferenceServiceTestCase { try { String[] arg = new String[] { "test" }; - MboxListener mboxListener = new MboxListener(mbox, true); + MboxListener mboxListener = new MboxListener(serMbox, true); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); mboxReference.sendArgs(arg); @@ -394,7 +404,7 @@ public class ReferenceServiceTestCase { try { long arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); + MboxListener mboxListener = new MboxListener(serMbox, true); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); mboxReference.sendArgs(arg); @@ -405,7 +415,7 @@ public class ReferenceServiceTestCase { try { int arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); + MboxListener mboxListener = new MboxListener(serMbox, true); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); mboxReference.sendArgs(arg); @@ -416,7 +426,7 @@ public class ReferenceServiceTestCase { try { short arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); + MboxListener mboxListener = new MboxListener(serMbox, true); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); mboxReference.sendArgs(arg); @@ -427,7 +437,7 @@ public class ReferenceServiceTestCase { try { char arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); + MboxListener mboxListener = new MboxListener(serMbox, true); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); mboxReference.sendArgs(arg); @@ -438,7 +448,7 @@ public class ReferenceServiceTestCase { try { byte arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); + MboxListener mboxListener = new MboxListener(serMbox, true); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); mboxReference.sendArgs(arg); @@ -449,7 +459,7 @@ public class ReferenceServiceTestCase { try { double arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); + MboxListener mboxListener = new MboxListener(serMbox, true); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); mboxReference.sendArgs(arg); @@ -460,7 +470,7 @@ public class ReferenceServiceTestCase { try { float arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); + MboxListener mboxListener = new MboxListener(serMbox, true); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); mboxReference.sendArgs(arg); @@ -471,7 +481,7 @@ public class ReferenceServiceTestCase { try { String arg = "1"; - MboxListener mboxListener = new MboxListener(mbox, true); + MboxListener mboxListener = new MboxListener(serMbox, true); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); mboxReference.sendArgs(arg); @@ -482,7 +492,7 @@ public class ReferenceServiceTestCase { try { boolean arg = true; - MboxListener mboxListener = new MboxListener(mbox, 1); + MboxListener mboxListener = new MboxListener(serMbox, 1); Thread mboxThread = new Thread(mboxListener); mboxThread.start(); mboxReference.sendArgs(arg); @@ -534,6 +544,16 @@ public class ReferenceServiceTestCase { } /** + * Tests RPC with no result + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testRPCWithVoidResult() throws Exception { + moduleReference.doNothing(); + } + + /** * Tests handling requests pointing to unknown functions * * @throws Exception @@ -603,4 +623,65 @@ public class ReferenceServiceTestCase { } } + /** + * Tests mbox with retrieving and answering with basic arguments + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testMbox() throws Exception { + OtpErlangObject[] args = new OtpErlangObject[2]; + args[0] = new OtpErlangString("world"); + args[1] = new OtpErlangString("!"); + OtpErlangTuple tuple = new OtpErlangTuple(args); + refMbox.send("sayHello", "RPCServer", tuple); + OtpErlangString result = (OtpErlangString) refMbox.receiveMsg() + .getMsg(); + assertEquals("Hello world !", result.stringValue()); + } + + /** + * Tests service mbox receiving complex message + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testMboxWithComplexArgs() throws Exception { + int arg1 = 1; + String arg2 = "arg2"; + String arg3 = "arg3"; + boolean arg4 = true; + + OtpErlangObject[] smallTupleContent = new OtpErlangObject[2]; + smallTupleContent[0] = new OtpErlangInt(arg1); + smallTupleContent[1] = new OtpErlangString(arg2); + OtpErlangTuple smallTuple = new OtpErlangTuple(smallTupleContent); + OtpErlangObject[] structuredTupleContent = new OtpErlangObject[3]; + structuredTupleContent[0] = smallTuple; + structuredTupleContent[1] = new OtpErlangString(arg3); + structuredTupleContent[2] = new OtpErlangBoolean(arg4); + OtpErlangTuple structuredTuple = new OtpErlangTuple( + structuredTupleContent); + OtpErlangObject[] secondArg = new OtpErlangObject[2]; + secondArg[0] = new OtpErlangString("in"); + secondArg[1] = new OtpErlangString("array"); + OtpErlangList list = new OtpErlangList(secondArg); + OtpErlangObject[] argsContent = new OtpErlangObject[2]; + argsContent[0] = structuredTuple; + argsContent[1] = list; + OtpErlangTuple args = new OtpErlangTuple(argsContent); + refMbox.send("passComplexArgs", "RPCServer", args); + OtpErlangObject result = refMbox.receiveMsg().getMsg(); + assertEquals(arg1, + ((OtpErlangLong) ((OtpErlangTuple) ((OtpErlangTuple) result) + .elementAt(0)).elementAt(0)).intValue()); + assertEquals(arg2, + ((OtpErlangString) ((OtpErlangTuple) ((OtpErlangTuple) result) + .elementAt(0)).elementAt(1)).stringValue()); + assertEquals(arg3, ((OtpErlangString) ((OtpErlangTuple) result) + .elementAt(1)).stringValue()); + assertEquals(arg4, ((OtpErlangAtom) ((OtpErlangTuple) result) + .elementAt(2)).booleanValue()); + } + } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponent.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponent.java index 0d11b294dc..be43820b0b 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponent.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponent.java @@ -1,5 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.tuscany.sca.binding.erlang.testing; +/** + * @version $Rev$ $Date$ + */ public interface ReferenceTestComponent { } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java index 919ca64568..71041a2be2 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java @@ -1,38 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.tuscany.sca.binding.erlang.testing; import org.osoa.sca.annotations.Reference; +/** + * @version $Rev$ $Date$ + */ public class ReferenceTestComponentImpl implements ReferenceTestComponent { - private MboxInterface mboxReference; - private ServiceInterface moduleReference; - private ServiceInterface clonedModuleReference; - - @Reference - public void setMboxReference(MboxInterface mboxReference) { - this.mboxReference = mboxReference; - } - - @Reference - public void setModuleReference(ServiceInterface moduleReference) { - this.moduleReference = moduleReference; - } - - @Reference - public void setClonedModuleReference(ServiceInterface clonedModuleReference) { - this.clonedModuleReference = clonedModuleReference; - } - - public MboxInterface getMboxReference() { - return mboxReference; - } - - public ServiceInterface getModuleReference() { - return moduleReference; - } - - public ServiceInterface getClonedModuleReference() { - return clonedModuleReference; - } + private MboxInterface mboxReference; + private ServiceInterface moduleReference; + private ServiceInterface clonedModuleReference; + + @Reference + public void setMboxReference(MboxInterface mboxReference) { + this.mboxReference = mboxReference; + } + + @Reference + public void setModuleReference(ServiceInterface moduleReference) { + this.moduleReference = moduleReference; + } + + @Reference + public void setClonedModuleReference(ServiceInterface clonedModuleReference) { + this.clonedModuleReference = clonedModuleReference; + } + + public MboxInterface getMboxReference() { + return mboxReference; + } + + public ServiceInterface getModuleReference() { + return moduleReference; + } + + public ServiceInterface getClonedModuleReference() { + return clonedModuleReference; + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java index 33afcfb53d..95c0ea06f6 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java @@ -1,20 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.tuscany.sca.binding.erlang.testing; +/** + * @version $Rev$ $Date$ + */ public interface ServiceInterface { - String sayHello(String arg1, String arg2); - - String[] sayHellos() throws Exception; - - StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2); - - String sayHello() throws Exception; - - String sayHello(String arg) throws Exception; - - String sayHello(int arg1, int arg2); - - void notExistWithException() throws Exception; - - void notExist(); + void doNothing(); + + String sayHello(String arg1, String arg2); + + String[] sayHellos() throws Exception; + + StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2); + + String sayHello() throws Exception; + + String sayHello(String arg) throws Exception; + + String sayHello(int arg1, int arg2); + + void notExistWithException() throws Exception; + + void notExist(); } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java index f5c03ef281..60650188bc 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java @@ -1,11 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.tuscany.sca.binding.erlang.testing; +/** + * @version $Rev$ $Date$ + */ public interface ServiceTestComponent { - String sayHello(String arg1, String arg2); - - String[] sayHellos() throws Exception; - - StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2); - + String sayHello(String arg1, String arg2); + + String[] sayHellos() throws Exception; + + StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2); + + void doNothing(); + } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java index 4d79005938..551ad3d063 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java @@ -1,19 +1,44 @@ -package org.apache.tuscany.sca.binding.erlang.testing; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.erlang.testing; +/** + * @version $Rev$ $Date$ + */ public class ServiceTestComponentImpl implements ServiceTestComponent { - public String sayHello(String arg1, String arg2) { - return "Hello " + arg1 + " " + arg2; - } + public String sayHello(String arg1, String arg2) { + return "Hello " + arg1 + " " + arg2; + } + + public String[] sayHellos() { + String[] result = new String[] { "1", "2" }; + return result; + } - public String[] sayHellos() { - String[] result = new String[] {"1", "2"}; - return result; - } + public StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2) { + return arg1; + } - public StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2) { - return arg1; - } + public void doNothing() { + // doing nothing + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java index 98921bd24d..b59662551c 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java @@ -1,19 +1,44 @@ -package org.apache.tuscany.sca.binding.erlang.testing; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.erlang.testing; +/** + * @version $Rev$ $Date$ + */ public class ServiceTestComponentImplClone implements ServiceTestComponent { - public String sayHello(String arg1, String arg2) { - return "Bye " + arg1 + " " + arg2; - } + public String sayHello(String arg1, String arg2) { + return "Bye " + arg1 + " " + arg2; + } + + public String[] sayHellos() { + String[] result = new String[] { "-1", "-2" }; + return result; + } + + public StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2) { + return arg1; + } - public String[] sayHellos() { - String[] result = new String[] {"-1", "-2"}; - return result; - } + public void doNothing() { - public StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2) { - return arg1; - } + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/SmallTuple.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/SmallTuple.java index 4b318e4a61..ac8b9e426a 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/SmallTuple.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/SmallTuple.java @@ -19,14 +19,17 @@ package org.apache.tuscany.sca.binding.erlang.testing; +/** + * @version $Rev$ $Date$ + */ public class SmallTuple { - public int arg1; - public String arg2 = ""; - - public boolean equals(Object o) { - SmallTuple comp = (SmallTuple)o; - return arg1 == comp.arg1 && arg2.equals(arg2); - } - + public int arg1; + public String arg2 = ""; + + public boolean equals(Object o) { + SmallTuple comp = (SmallTuple) o; + return arg1 == comp.arg1 && arg2.equals(arg2); + } + } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/StructuredTuple.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/StructuredTuple.java index 736cc2046d..193654172f 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/StructuredTuple.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/StructuredTuple.java @@ -19,15 +19,19 @@ package org.apache.tuscany.sca.binding.erlang.testing; +/** + * @version $Rev$ $Date$ + */ public class StructuredTuple { - public SmallTuple arg1 = new SmallTuple(); - public String arg2 = ""; - public boolean arg3; - - public boolean equals(Object o) { - StructuredTuple comp = (StructuredTuple)o; - return arg2.equals(comp.arg2) && arg3 == comp.arg3 && arg1.equals(comp.arg1); - } - + public SmallTuple arg1 = new SmallTuple(); + public String arg2 = ""; + public boolean arg3; + + public boolean equals(Object o) { + StructuredTuple comp = (StructuredTuple) o; + return arg2.equals(comp.arg2) && arg3 == comp.arg3 + && arg1.equals(comp.arg1); + } + } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java index 81a17ff9dd..33e6d4862b 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java @@ -29,6 +29,9 @@ import org.junit.runner.notification.StoppedByUserException; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.model.InitializationError; +/** + * @version $Rev$ $Date$ + */ public class IgnorableRunner extends Runner { private static final class Notifier extends RunNotifier { diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java index 9a8372051c..3d736da19d 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java @@ -19,6 +19,9 @@ package org.apache.tuscany.sca.binding.erlang.testing.dynaignore; +/** + * @version $Rev$ $Date$ + */ public final class IgnoreTest extends Error { private static final long serialVersionUID = 1L; diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangService.composite b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangService.composite index 441819b95d..ce94340bb6 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangService.composite +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/resources/ErlangService.composite @@ -11,6 +11,10 @@ <interface.java interface="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponent" /> <tuscany:binding.erlang node="RPCServer" module="hello"/> </service> + <service name="ServiceTestMbox" promote="ServiceTest"> + <interface.java interface="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponent" /> + <tuscany:binding.erlang node="RPCServer" mbox="true"/> + </service> <component name="ServiceTestClone"> <implementation.java class="org.apache.tuscany.sca.binding.erlang.testing.ServiceTestComponentImplClone" /> |