diff options
author | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
---|---|---|
committer | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
commit | bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch) | |
tree | 38a92061c0793434c4be189f1d70c3458b6bc41d /sandbox/ant/sample.script.async/src |
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/ant/sample.script.async/src')
7 files changed, 208 insertions, 0 deletions
diff --git a/sandbox/ant/sample.script.async/src/main/java/sample/AsyncClient.java b/sandbox/ant/sample.script.async/src/main/java/sample/AsyncClient.java new file mode 100644 index 0000000000..4115757f88 --- /dev/null +++ b/sandbox/ant/sample.script.async/src/main/java/sample/AsyncClient.java @@ -0,0 +1,40 @@ +/* + * 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 sample; + +import org.osoa.sca.CurrentCompositeContext; + +/** + * This client program shows how to create an SCA runtime, start it, + * locate the OneWayComponent service and invoke it. + */ +public class AsyncClient { + + public static void main(String[] args) throws Exception { + + AsyncService service = CurrentCompositeContext.getContext().locateService( + AsyncService.class, "ClientComponent"); + + System.out.println("Calling service on thread + " + Thread.currentThread()); + service.doitOneWay("foo"); + System.out.println("returned from service"); + Thread.sleep(500); + + } +} diff --git a/sandbox/ant/sample.script.async/src/main/java/sample/AsyncService.java b/sandbox/ant/sample.script.async/src/main/java/sample/AsyncService.java new file mode 100644 index 0000000000..5ca61dc4e8 --- /dev/null +++ b/sandbox/ant/sample.script.async/src/main/java/sample/AsyncService.java @@ -0,0 +1,28 @@ +/* + * 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 sample; + +import org.osoa.sca.annotations.OneWay; + +public interface AsyncService { + + @OneWay + public void doitOneWay(String s); + +} diff --git a/sandbox/ant/sample.script.async/src/main/java/sample/ClientComponent.java b/sandbox/ant/sample.script.async/src/main/java/sample/ClientComponent.java new file mode 100644 index 0000000000..dc806645e3 --- /dev/null +++ b/sandbox/ant/sample.script.async/src/main/java/sample/ClientComponent.java @@ -0,0 +1,38 @@ +/*
+ * 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 sample;
+
+import org.osoa.sca.annotations.Reference;
+
+public class ClientComponent implements AsyncService {
+
+ private AsyncService asyncComponent;
+
+ public void doitOneWay(String s) {
+ System.out.println("ClientComponent calling asyncService on thread + " + Thread.currentThread());
+ asyncComponent.doitOneWay(s);
+ }
+
+ @Reference
+ public void setAsyncComponent(AsyncService asyncComponent) {
+ this.asyncComponent = asyncComponent;
+ }
+
+
+}
diff --git a/sandbox/ant/sample.script.async/src/main/resources/AsyncServiceImpl.componentType b/sandbox/ant/sample.script.async/src/main/resources/AsyncServiceImpl.componentType new file mode 100644 index 0000000000..f6bf9c7752 --- /dev/null +++ b/sandbox/ant/sample.script.async/src/main/resources/AsyncServiceImpl.componentType @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="ASCII"?>
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <service name="OneWayService">
+ <interface.java interface="sample.AsyncService"/>
+ </service>
+
+</componentType>
diff --git a/sandbox/ant/sample.script.async/src/main/resources/AsyncServiceImpl.js b/sandbox/ant/sample.script.async/src/main/resources/AsyncServiceImpl.js new file mode 100644 index 0000000000..fbde7da611 --- /dev/null +++ b/sandbox/ant/sample.script.async/src/main/resources/AsyncServiceImpl.js @@ -0,0 +1,7 @@ +function doitOneWay(s) { + java.lang.System.out.println( + "function doitOneWay received '" + s + "' on thread " + java.lang.Thread.currentThread()); +} + + + diff --git a/sandbox/ant/sample.script.async/src/main/resources/META-INF/sca/default.scdl b/sandbox/ant/sample.script.async/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..1797974c75 --- /dev/null +++ b/sandbox/ant/sample.script.async/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + + name="AsyncSampleComposite"> + + <component name="ClientComponent"> + <implementation.java class="sample.ClientComponent"/> + <reference name="asyncComponent">AsyncComponent</reference> + </component> + + <component name="AsyncComponent"> + <implementation.script script="AsyncServiceImpl.js"/> + </component> + +</composite> diff --git a/sandbox/ant/sample.script.async/src/test/java/sample/AsyncTestCase.java b/sandbox/ant/sample.script.async/src/test/java/sample/AsyncTestCase.java new file mode 100644 index 0000000000..ccb816b121 --- /dev/null +++ b/sandbox/ant/sample.script.async/src/test/java/sample/AsyncTestCase.java @@ -0,0 +1,54 @@ +/* + * 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 sample; + +import java.net.URL; + +import org.apache.tuscany.test.SCATestCase; +import org.osoa.sca.CurrentCompositeContext; + +import sample.AsyncService; + + +/** + * Tests the AsyncService component. + */ +public class AsyncTestCase extends SCATestCase { + + protected void setUp() throws Exception { + URL scdl = getClass().getClassLoader().getResource("META-INF/sca/script.system.scdl"); + addExtension("ScriptContainer", scdl); + setApplicationSCDL(AsyncClient.class, "META-INF/sca/default.scdl"); + super.setUp(); + } + + protected void tearDown() throws Exception { + } + + public void testHelloWorld() throws Exception { + + AsyncService service = CurrentCompositeContext.getContext().locateService( + AsyncService.class, "ClientComponent"); + + System.out.println("Calling async service oneWay on thread + " + Thread.currentThread()); + service.doitOneWay("foo"); + System.out.println("returned from oneWay service"); + Thread.sleep(500); + } +} |