From b5c0d648cf147d3709eb78d98011f38e07aee723 Mon Sep 17 00:00:00 2001 From: lresende Date: Fri, 13 Nov 2009 01:25:44 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835694 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca-java-1.5.2/samples/callbacks-jms/README | 73 +++++++++++++++ .../sca-java-1.5.2/samples/callbacks-jms/build.xml | 72 ++++++++++++++ .../sca-java-1.5.2/samples/callbacks-jms/pom.xml | 103 +++++++++++++++++++++ .../src/main/java/callbacks/CallbackJMSClient.java | 44 +++++++++ .../src/main/java/callbacks/OrderCallback.java | 30 ++++++ .../src/main/java/callbacks/OrderRequest.java | 24 +++++ .../src/main/java/callbacks/OrderResponse.java | 24 +++++ .../src/main/java/callbacks/OrderService.java | 33 +++++++ .../main/java/callbacks/OrderServiceClient.java | 59 ++++++++++++ .../src/main/java/callbacks/OrderServiceImpl.java | 51 ++++++++++ .../src/main/resources/callbacks.composite | 44 +++++++++ .../src/main/resources/jndi.properties | 30 ++++++ .../src/test/java/callbacks/CallbacksTestCase.java | 64 +++++++++++++ 13 files changed, 651 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/README create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/build.xml create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/CallbackJMSClient.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderCallback.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderRequest.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderResponse.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderService.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderServiceClient.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/resources/callbacks.composite create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/resources/jndi.properties create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/test/java/callbacks/CallbacksTestCase.java (limited to 'sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms') diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/README b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/README new file mode 100644 index 0000000000..b5e130e2fc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/README @@ -0,0 +1,73 @@ +Callback JMS Sample +=================== +This sample demonstrates SCA callbacks over the JMS binding. It implements the example +described in the INFOQ article: + + "Can I call you back about that?" Building Asynchronous Services using Service Component Architecture + See: http://www.infoq.com/articles/async-sca + +It implements a service for placing an order for some widgets, where the service is asynchronous +and the client is informed of progress via a callback interface. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-callbacks-jms.jar callbacks.CallbacksTestCase + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-callbacks-jms.jar callbacks.CallbacksTestCase + +Sample Overview +--------------- + +The only changes over the sample code described in the INFOQ article are to add the @Remotable annotation +to the service and callback interfaces, add the @Oneway annotation to the placeOrder and placeOrderResponse +methods, and the composite XML is changed to use instead of . + + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd callbacks-jms +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] client placing order: callbacks.OrderRequest@c72243 + [java] service received order: callbacks.OrderRequest@1f94884 + [java] client callback received order response: callbacks.OrderResponse@14ab51b + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd callbacks-jms +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running callbacks.CallbacksTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.272 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/build.xml b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/build.xml new file mode 100644 index 0000000000..bc2c191fc2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/pom.xml b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/pom.xml new file mode 100644 index 0000000000..d45114ed1d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/pom.xml @@ -0,0 +1,103 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.5.2-SNAPSHOT + ../../pom.xml + + sample-callbacks-jms + Apache Tuscany SCA Sample Callbacks with JMS + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.5.2-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.5.2-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-jms-runtime + 1.5.2-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-host-jms-asf + 1.5.2-SNAPSHOT + + + + junit + junit + 4.2 + test + + + + org.apache.activemq + activemq-core + 5.1.0 + test + + + backport-util-concurrent + backport-util-concurrent + 3.1 + + + + + + ${artifactId} + + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/CallbackJMSClient.java b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/CallbackJMSClient.java new file mode 100644 index 0000000000..c2e62ab8bd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/CallbackJMSClient.java @@ -0,0 +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 callbacks; + +import org.apache.tuscany.sca.node.SCAClient; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; + +public class CallbackJMSClient { + + public static void main(String[] args) throws Exception { + + SCANodeFactory factory = SCANodeFactory.newInstance(); + SCANode node = factory.createSCANodeFromClassLoader("callbacks.composite", CallbackJMSClient.class.getClassLoader()); + node.start(); + + OrderServiceClient orderServiceClient = ((SCAClient)node).getService(OrderServiceClient.class, "ClientComponent"); + + // do something + orderServiceClient.doSomeOrdering(); + + // wait to give the service time to respond + Thread.sleep(500); + + node.stop(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderCallback.java b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderCallback.java new file mode 100644 index 0000000000..775663cdff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderCallback.java @@ -0,0 +1,30 @@ +/* + * 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 callbacks; + +import org.osoa.sca.annotations.OneWay; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface OrderCallback { + + @OneWay + public void placeOrderResponse(OrderResponse orderResponse); +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderRequest.java b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderRequest.java new file mode 100644 index 0000000000..69f5751379 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderRequest.java @@ -0,0 +1,24 @@ +/* + * 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 callbacks; + +public class OrderRequest { + +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderResponse.java b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderResponse.java new file mode 100644 index 0000000000..882bcf8479 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderResponse.java @@ -0,0 +1,24 @@ +/* + * 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 callbacks; + +public class OrderResponse { + +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderService.java b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderService.java new file mode 100644 index 0000000000..9f6d90577c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderService.java @@ -0,0 +1,33 @@ +/* + * 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 callbacks; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.OneWay; +import org.osoa.sca.annotations.Remotable; + +@Remotable +@Callback(OrderCallback.class) +public interface OrderService { + + @OneWay + public void placeOrder(OrderRequest orderRequest); + +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderServiceClient.java b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderServiceClient.java new file mode 100644 index 0000000000..3393ae5dca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderServiceClient.java @@ -0,0 +1,59 @@ +/* + * 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 callbacks; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +@Service(OrderServiceClient.class) +public class OrderServiceClient implements OrderCallback { + + // A field to hold the reference to the order service + + private OrderService orderService; + public static OrderResponse oResponse; + + public void doSomeOrdering() { + + OrderRequest oRequest = new OrderRequest(); + + // … fill in the details of the order … + + System.out.println("client placing order: " + oRequest); + + orderService.placeOrder(oRequest); + + // …the client code can continue to do processing + } + + public void placeOrderResponse(OrderResponse oResponse) { + + // …handle the response as needed + + System.out.println("client callback received order response: " + oResponse); + OrderServiceClient.oResponse = oResponse; + } + + // A setter method for the order service reference + @Reference + public void setOrderService(OrderService theService) { + orderService = theService; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderServiceImpl.java b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderServiceImpl.java new file mode 100644 index 0000000000..dd963bc1b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/java/callbacks/OrderServiceImpl.java @@ -0,0 +1,51 @@ +/* + * 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 callbacks; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.Service; + +@Service(OrderService.class) +public class OrderServiceImpl implements OrderService { + + // A field for the callback reference object + private OrderCallback callbackReference; + + // The place order operation itself + public void placeOrder(OrderRequest oRequest) { + + // …do the work to process the order… + // …which may take some time… + + System.out.println("service received order: " + oRequest); + + // when ready to respond… + + OrderResponse theResponse = new OrderResponse(); + + callbackReference.placeOrderResponse(theResponse); + } + + // A setter method for the callback reference + @Callback + public void setCallbackReference(OrderCallback theCallback) { + callbackReference = theCallback; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/resources/callbacks.composite b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/resources/callbacks.composite new file mode 100644 index 0000000000..94dd29c45d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/resources/callbacks.composite @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/resources/jndi.properties b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/resources/jndi.properties new file mode 100644 index 0000000000..698aeb1711 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/main/resources/jndi.properties @@ -0,0 +1,30 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# START SNIPPET: jndi + +java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory + +# use the following property to configure the default connector +java.naming.provider.url = vm://localhost?broker.persistent=false&broker.useJmx=false + +# use the following property to specify the JNDI name the connection factory should appear as. +connectionFactoryNames = ConnectionFactory + +# register some queues in JNDI using the form +# queue.[jndiName] = [physicalName] +queue.OrderService = OrderServiceQueue diff --git a/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/test/java/callbacks/CallbacksTestCase.java b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/test/java/callbacks/CallbacksTestCase.java new file mode 100644 index 0000000000..967fc42c64 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/samples/callbacks-jms/src/test/java/callbacks/CallbacksTestCase.java @@ -0,0 +1,64 @@ +/* + * 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 callbacks; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This shows how to test the Calculator service component. + */ +public class CallbacksTestCase extends TestCase { + + private OrderServiceClient orderServiceClient; + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("callbacks.composite"); + orderServiceClient = scaDomain.getService(OrderServiceClient.class, "ClientComponent"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testOderClient() throws Exception { + + orderServiceClient.doSomeOrdering(); + + // wait to give the service time to respond + Thread.sleep(500); + } + + public static void main(String[] args) { + try { + + CallbacksTestCase runner = new CallbacksTestCase(); + runner.setUp(); + runner.testOderClient(); + runner.tearDown(); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} -- cgit v1.2.3