From 77ee1e713a1a4df51ba73ca1e0249eff4edbd7c0 Mon Sep 17 00:00:00 2001 From: slaws Date: Wed, 27 Oct 2010 15:00:38 +0000 Subject: TUSCANY-3757 - add code (commented out currently) to demonstrate void return type scenario. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1027990 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/calculator/CalculateReferenceAsync.java | 14 +++++++-- .../src/main/java/calculator/CalculatorClient.java | 4 +++ .../calculator/CalculatorPrintAsyncHandler.java | 36 ++++++++++++++++++++++ .../java/calculator/CalculatorServiceAsync.java | 3 ++ .../calculator/CalculatorServiceAsyncImpl.java | 10 ++++++ .../calculator/CalculatorServiceProxyImpl.java | 35 +++++++++++++++++++-- .../java/calculator/CalculatorServiceSync.java | 1 + .../java/calculator/CalculatorServiceSyncImpl.java | 7 +++++ 8 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorPrintAsyncHandler.java (limited to 'sca-java-2.x/trunk/samples') diff --git a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculateReferenceAsync.java b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculateReferenceAsync.java index c07e5d2d65..a8a323ba04 100644 --- a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculateReferenceAsync.java +++ b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculateReferenceAsync.java @@ -33,8 +33,6 @@ import org.oasisopen.sca.annotation.Remotable; @Remotable public interface CalculateReferenceAsync { - - //public Response calculate( Integer i1); // Sync public String calculate(Integer i1); @@ -44,6 +42,16 @@ public interface CalculateReferenceAsync { // Async Callback public Future calculateAsync(Integer i1, AsyncHandler handler); - + +/* TUSCANY-3757 + // Sync + public void print(Integer i1); + + // Aysnc Poll + public Response printAsync(Integer i1); + + // Async Callback + public Future printAsync(Integer i1, AsyncHandler handler); +*/ } diff --git a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorClient.java b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorClient.java index fd7cfcf1e2..6f4ffc0ca7 100644 --- a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorClient.java +++ b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorClient.java @@ -42,6 +42,10 @@ public class CalculatorClient { @Init public void calculate() { System.out.println("calculation=" + calculatorService.calculate(20)); + System.out.println("print"); + /* TUSCANY-3757 + calculatorService.print(27); + */ } diff --git a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorPrintAsyncHandler.java b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorPrintAsyncHandler.java new file mode 100644 index 0000000000..8faf390974 --- /dev/null +++ b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorPrintAsyncHandler.java @@ -0,0 +1,36 @@ +/* + * 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 javax.xml.ws.AsyncHandler; +import javax.xml.ws.Response; + +/** + * Handles callbacks to the async client + */ + +public class CalculatorPrintAsyncHandler implements AsyncHandler { + public void handleResponse(Response res) { + try { + System.out.println("Async client callback patern: result in print handler = " + res.get()); + } catch(Exception ex){ + System.out.println("Async client callback patern: exception in print handler = " + ex.getMessage()); + } + } +} diff --git a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceAsync.java b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceAsync.java index 3979529595..bcb931e418 100644 --- a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceAsync.java +++ b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceAsync.java @@ -30,4 +30,7 @@ import org.oasisopen.sca.annotation.Remotable; @AsyncInvocation public interface CalculatorServiceAsync { void calculateAsync(Integer n1, ResponseDispatch response); + /* TUSCANY-3757 + void printAsync(Integer n1, ResponseDispatch response); + */ } diff --git a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceAsyncImpl.java b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceAsyncImpl.java index 1906f46f5b..d865bcf454 100644 --- a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceAsyncImpl.java +++ b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceAsyncImpl.java @@ -30,5 +30,15 @@ public class CalculatorServiceAsyncImpl implements CalculatorServiceAsync { response.sendResponse(retval); } + +/* TUSCANY-3757 + @Override + + public void printAsync(Integer n1, ResponseDispatch response) { + int result = n1 + n1; + String retval = "async service invoked: " + n1 + " + " + n1 + " = " + result; + System.out.println(retval); + } +*/ } diff --git a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceProxyImpl.java b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceProxyImpl.java index 351ba9c5ef..45e23b8e93 100644 --- a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceProxyImpl.java +++ b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceProxyImpl.java @@ -43,11 +43,11 @@ public class CalculatorServiceProxyImpl implements CalculatorServiceSync { String result = null; // calculate using a sync service - System.out.println("Calling sync service"); + System.out.println("Calling sync service for calculate"); result = calculate(calculatorServiceRefSync, n1); // calculate using an aycn service - System.out.println("Calling async service"); + System.out.println("Calling async service for calculate"); result += calculate(calculatorServiceRefAsync, n1); return result; @@ -98,4 +98,35 @@ public class CalculatorServiceProxyImpl implements CalculatorServiceSync { return result; } + +/* TUSCANY-3757 + @Override +*/ + public void print(Integer n1) { + + // calculate using a sync service + System.out.println("Calling sync service for print"); + //print(calculatorServiceRefSync, n1); + + // calculate using an asycn service + System.out.println("Calling async service for print"); + //print(calculatorServiceRefAsync, n1); + } + +/* TUSCANY-3757 + // exercise sync and async versions of a service interface method + private void print(CalculateReferenceAsync calculatorRef, Integer n1) { + + // sync + calculatorRef.print(1); + + // async poll + Response response = calculatorRef.printAsync(20); + + // async callback + CalculatorPrintAsyncHandler handler = new CalculatorPrintAsyncHandler(); + Future future = calculatorRef.printAsync(3, handler); + + } +*/ } diff --git a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceSync.java b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceSync.java index c0ed1fa798..cded310a15 100644 --- a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceSync.java +++ b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceSync.java @@ -27,4 +27,5 @@ import org.oasisopen.sca.annotation.Remotable; @Remotable public interface CalculatorServiceSync { String calculate(Integer n1); + void print(Integer n1); } diff --git a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceSyncImpl.java b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceSyncImpl.java index a5ab67c086..01e0d9f414 100644 --- a/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceSyncImpl.java +++ b/sca-java-2.x/trunk/samples/learning-more/async/calculator-contribution/src/main/java/calculator/CalculatorServiceSyncImpl.java @@ -27,5 +27,12 @@ public class CalculatorServiceSyncImpl implements CalculatorServiceSync { String retval = "sync service invoked: " + n1 + " + " + n1 + " = " + result; return retval; } + + @Override + public void print(Integer n1) { + int result = n1 + n1; + String retval = "sync service invoked: " + n1 + " + " + n1 + " = " + result; + System.out.println(retval); + } } -- cgit v1.2.3