From 04c6f646cf7eb5fc4f9d859b583a4dbd349e84f2 Mon Sep 17 00:00:00 2001 From: slaws Date: Thu, 15 Jul 2010 16:19:24 +0000 Subject: Trying to get the async version of the service working. However it's failing with a policy error that I think is caused by the recent policy changes. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@964477 13f79535-47bb-0310-9956-ffa450edef68 --- .../calculator/CalculatorAsyncServiceImpl.java | 11 --- .../main/java/calculator/CalculatorService.java | 3 +- .../java/calculator/CalculatorServiceAsync.java | 33 ++++++++ .../calculator/CalculatorServiceAsyncImpl.java | 15 ++++ .../java/calculator/CalculatorServiceImpl.java | 83 -------------------- .../calculator/CalculatorServiceProxyImpl.java | 89 ++++++++++++++++++++++ .../java/calculator/CalculatorServiceSyncImpl.java | 12 +++ .../java/calculator/CalculatorSyncServiceImpl.java | 11 --- .../src/main/resources/Calculator.composite | 18 +++-- 9 files changed, 161 insertions(+), 114 deletions(-) delete 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/CalculatorServiceAsync.java create mode 100644 sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceAsyncImpl.java delete mode 100644 sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceProxyImpl.java create mode 100644 sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceSyncImpl.java delete 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/contrib/samples/async') 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 deleted file mode 100644 index a01c79c92d..0000000000 --- a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncServiceImpl.java +++ /dev/null @@ -1,11 +0,0 @@ -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/CalculatorService.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorService.java index ca9b0397a9..45bdd265d4 100644 --- a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorService.java +++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorService.java @@ -21,11 +21,10 @@ package calculator; import org.oasisopen.sca.annotation.Remotable; /** - * The sycn Calculator service interface. + * The sync Calculator service interface. */ @Remotable public interface CalculatorService { - String calculate(Integer n1); } diff --git a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceAsync.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceAsync.java new file mode 100644 index 0000000000..3979529595 --- /dev/null +++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceAsync.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 calculator; + +import org.oasisopen.sca.ResponseDispatch; +import org.oasisopen.sca.annotation.AsyncInvocation; +import org.oasisopen.sca.annotation.Remotable; + +/** + * The async Calculator service interface. + */ + +@Remotable +@AsyncInvocation +public interface CalculatorServiceAsync { + void calculateAsync(Integer n1, ResponseDispatch response); +} diff --git a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceAsyncImpl.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceAsyncImpl.java new file mode 100644 index 0000000000..18a982f4d6 --- /dev/null +++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceAsyncImpl.java @@ -0,0 +1,15 @@ +package calculator; + +import org.oasisopen.sca.ResponseDispatch; + +public class CalculatorServiceAsyncImpl implements CalculatorServiceAsync { + + @Override + public void calculateAsync(Integer n1, ResponseDispatch response) { + int result = n1 + n1; + String retval = "async service invoked: " + n1 + " + " + n1 + " = " + result; + + response.sendResponse(retval); + } + +} 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 deleted file mode 100644 index 994ad42d92..0000000000 --- a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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 CalculatorServiceImpl implements CalculatorService { - - @Reference - protected CalculateViaAsyncRef calculatorRefSyncService; - -// @Reference -// protected CalculateViaAsyncRef calculatorRefAsyncService; - - @Override - public String calculate(Integer n1) { - - // sync - String result = calculatorRefSyncService.calculate(1); - System.out.println("Sync client patern: result = " + result); - - // async poll - Future future = calculatorRefSyncService.calculateAsync(20); - - while (!future.isDone()){ - System.out.println("Waiting for poll"); - } - - try { - result = future.get(); - System.out.println("Async client poll patern: result = " + result); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - // async callback - CalculatorAsyncHandler handler = new CalculatorAsyncHandler(); - future = calculatorRefSyncService.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/CalculatorServiceProxyImpl.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceProxyImpl.java new file mode 100644 index 0000000000..69c96fe892 --- /dev/null +++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceProxyImpl.java @@ -0,0 +1,89 @@ +/* + * 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 org.oasisopen.sca.annotation.Reference; + +/** + * An implementation of the Calculator service which just proxies + * to sync and asyn versions of the calculator service. This proxy + * exercises the various async interface alternatives + */ +public class CalculatorServiceProxyImpl implements CalculatorService { + + @Reference + protected CalculateViaAsyncRef calculatorServiceRefSync; + + @Reference + protected CalculateViaAsyncRef calculatorServiceRefAsync; + + @Override + public String calculate(Integer n1) { + String result = null; + + // calculate using a sync service + System.out.println("Calling sync service"); + result = calculate(calculatorServiceRefSync, n1); + + // calculate using an aycn service + System.out.println("Calling async service"); + result += calculate(calculatorServiceRefAsync, n1); + + return result; + } + + // exercise sync and async versions of a service interface method + private String calculate(CalculateViaAsyncRef calculatorRef, Integer n1) { + + // sync + String result = calculatorRef.calculate(1); + System.out.println("Sync client patern: result = " + result); + + // async poll + Future future = calculatorRef.calculateAsync(20); + + while (!future.isDone()){ + System.out.println("Waiting for poll"); + } + + try { + result = future.get(); + System.out.println("Async client poll patern: result = " + result); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ExecutionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + // async callback + CalculatorAsyncHandler handler = new CalculatorAsyncHandler(); + 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/CalculatorServiceSyncImpl.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceSyncImpl.java new file mode 100644 index 0000000000..95bf2c9eec --- /dev/null +++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceSyncImpl.java @@ -0,0 +1,12 @@ +package calculator; + +public class CalculatorServiceSyncImpl implements CalculatorService { + + @Override + public String calculate(Integer n1) { + int result = n1 + n1; + String retval = "sync service invoked: " + n1 + " + " + n1 + " = " + result; + return retval; + } + +} 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 deleted file mode 100644 index a7b0928a9f..0000000000 --- a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorSyncServiceImpl.java +++ /dev/null @@ -1,11 +0,0 @@ -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 3e6799612a..6117d436db 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 @@ -20,20 +20,24 @@ - - - + + + - + - + + + + + + -- cgit v1.2.3