From 8343c879a235d4200d11ac894e889c80efde359e Mon Sep 17 00:00:00 2001 From: kelvingoodson Date: Thu, 15 Jul 2010 14:51:06 +0000 Subject: git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@964452 13f79535-47bb-0310-9956-ffa450edef68 --- sca-java-2.x/trunk/contrib/samples/async/pom.xml | 2 +- .../calculator/CalculatorAsyncClientLogic.java | 81 ++++++++++++++++++++++ .../calculator/CalculatorAsyncServiceImpl.java | 11 +++ .../src/main/java/calculator/CalculatorBoot.java | 52 ++++++++++++++ .../java/calculator/CalculatorServiceImpl.java | 12 ++-- .../java/calculator/CalculatorSyncServiceImpl.java | 11 +++ .../src/main/resources/Calculator.composite | 10 +++ 7 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncClientLogic.java create mode 100644 sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncServiceImpl.java create mode 100644 sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorBoot.java create mode 100644 sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorSyncServiceImpl.java (limited to 'sca-java-2.x/trunk') diff --git a/sca-java-2.x/trunk/contrib/samples/async/pom.xml b/sca-java-2.x/trunk/contrib/samples/async/pom.xml index 49f58baa34..f44ae33067 100644 --- a/sca-java-2.x/trunk/contrib/samples/async/pom.xml +++ b/sca-java-2.x/trunk/contrib/samples/async/pom.xml @@ -27,7 +27,7 @@ tuscany-sample-async pom - Apache Tuscany SCA Samples for Synchronous/Asynchronous invocation + MYYYYYYYYYYYYYYYYYYY Apache Tuscany SCA Samples for Synchronous/Asynchronous invocation diff --git a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncClientLogic.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncClientLogic.java new file mode 100644 index 0000000000..562cc87521 --- /dev/null +++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncClientLogic.java @@ -0,0 +1,81 @@ +/* + * 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 calculator; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import javax.xml.ws.AsyncHandler; + +import org.oasisopen.sca.annotation.Reference; + + + +/** + * An implementation of the Calculator service. + */ +public class CalculatorAsyncClientLogic implements CalculatorService { + + @Reference + protected CalculateViaAsyncRef calculatorRefSyncService; + + @Reference + protected CalculateViaAsyncRef calculatorRefAsyncService; + + @Override + public String calculate(Integer n1) { + + // sync + String result = calculatorRefSyncService.calculate(1); + + // async poll + Future future = calculatorRefAsyncService.calculateAsync(2); + + while (!future.isDone()){ + System.out.println("Waiting for poll"); + } + + try { + result = future.get(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ExecutionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + // async callback +// AsyncHandler handler = new AsyncHandler(); +// future = calculatorRef.calculateAsync(3, handler); +/* + while (!future.isDone()){ + System.out.println("Waiting for callback"); + } +*/ + return result; + } + + + + + + + +} diff --git a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncServiceImpl.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncServiceImpl.java new file mode 100644 index 0000000000..a01c79c92d --- /dev/null +++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncServiceImpl.java @@ -0,0 +1,11 @@ +package calculator; + +public class CalculatorAsyncServiceImpl implements CalculatorService { + + @Override + public String calculate(Integer n1) { + String retval = "sync service invoked"; + return retval; + } + +} diff --git a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorBoot.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorBoot.java new file mode 100644 index 0000000000..0ddac8e1d2 --- /dev/null +++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorBoot.java @@ -0,0 +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 calculator; + +import org.oasisopen.sca.annotation.EagerInit; +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Scope; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +@Scope("COMPOSITE") @EagerInit +public class CalculatorBoot { + + private CalculatorService calculatorService; + + + @Reference + public void setCalculatorService(CalculatorService calculatorService) { + this.calculatorService = calculatorService; + } + + + @Init + public void calculate() { + + // Calculate + //System.out.println("SCA API ClassLoader: " + print(Reference.class.getClassLoader())); + System.out.println("calculation=" + calculatorService.calculate(20)); + } + + +} diff --git a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceImpl.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceImpl.java index da9963087f..c5b0562c65 100644 --- a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceImpl.java +++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceImpl.java @@ -35,17 +35,18 @@ public class CalculatorServiceImpl implements CalculatorService { @Reference protected CalculateViaAsyncRef calculatorRefSyncService; - @Reference - protected CalculateViaAsyncRef calculatorRefAsyncService; +// @Reference +// protected CalculateViaAsyncRef calculatorRefAsyncService; @Override public String calculate(Integer n1) { // sync String result = calculatorRefSyncService.calculate(1); + System.out.println(result); - // async poll - Future future = calculatorRefAsyncService.calculateAsync(2); +// // async poll + Future future = calculatorRefSyncService.calculateAsync(20); while (!future.isDone()){ System.out.println("Waiting for poll"); @@ -53,6 +54,7 @@ public class CalculatorServiceImpl implements CalculatorService { try { result = future.get(); + System.out.println("Async client patern success: result = " + result); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -61,6 +63,8 @@ public class CalculatorServiceImpl implements CalculatorService { e.printStackTrace(); } + + // async callback // AsyncHandler handler = new AsyncHandler(); // future = calculatorRef.calculateAsync(3, handler); diff --git a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorSyncServiceImpl.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorSyncServiceImpl.java new file mode 100644 index 0000000000..a7b0928a9f --- /dev/null +++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorSyncServiceImpl.java @@ -0,0 +1,11 @@ +package calculator; + +public class CalculatorSyncServiceImpl implements CalculatorService { + + @Override + public String calculate(Integer n1) { + String retval = "sync service invoked"; + return retval; + } + +} diff --git a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/resources/Calculator.composite b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/resources/Calculator.composite index 867b0e6c33..ed02597dc3 100644 --- a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/resources/Calculator.composite +++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/resources/Calculator.composite @@ -24,6 +24,16 @@ + + + + + + + + -- cgit v1.2.3