summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-07-15 15:29:27 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-07-15 15:29:27 +0000
commit88b670871cd7ea084300e58fa6c9870683443597 (patch)
treebc70cc4c563a18691248c0d696228b3d0c82c391 /sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java
parent8343c879a235d4200d11ac894e889c80efde359e (diff)
A bit of tidying to remove some chaff and add the async callback pattern into the sample
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@964464 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java')
-rw-r--r--sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculateViaAsyncRef.java7
-rw-r--r--sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculateViaAsyncRefImpl.java26
-rw-r--r--sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncClientLogic.java81
-rw-r--r--sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncHandler.java (renamed from sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorBoot.java)88
-rw-r--r--sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorClient.java4
-rw-r--r--sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorService.java3
-rw-r--r--sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceImpl.java16
7 files changed, 49 insertions, 176 deletions
diff --git a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculateViaAsyncRef.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculateViaAsyncRef.java
index 2d3fc97bb0..7bba2db44c 100644
--- a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculateViaAsyncRef.java
+++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculateViaAsyncRef.java
@@ -3,14 +3,15 @@ package calculator;
import java.util.concurrent.Future;
import javax.xml.ws.AsyncHandler;
-import javax.xml.ws.Response;
+
+import org.oasisopen.sca.annotation.Remotable;
/**
- * client interface for async reference
- * @author kgoodson
+ * Async client version of the CalculatorService interface
*
*/
+@Remotable
public interface CalculateViaAsyncRef {
//public Response<String> calculate( Integer i1);
diff --git a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculateViaAsyncRefImpl.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculateViaAsyncRefImpl.java
deleted file mode 100644
index 589bcab35f..0000000000
--- a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculateViaAsyncRefImpl.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package calculator;
-
-import java.util.concurrent.ExecutionException;
-
-import javax.xml.ws.Response;
-
-import org.oasisopen.sca.annotation.Reference;
-
-public class CalculateViaAsyncRefImpl implements CalculatorService {
-
- @Reference CalculateViaAsyncRef calculatorRef = null;
-
- @Override
- public String calculate(Integer n1) {
- Response<String> r = calculatorRef.calculate(n1);
- String result=null;
- try {
- result = r.get();
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (ExecutionException e) {
- e.printStackTrace();
- }
- return result;
- }
-}
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
deleted file mode 100644
index 562cc87521..0000000000
--- a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncClientLogic.java
+++ /dev/null
@@ -1,81 +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 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<String> 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<String> handler = new AsyncHandler<String>();
-// 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/CalculatorBoot.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorAsyncHandler.java
index 0ddac8e1d2..abaeef8062 100644
--- 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/CalculatorAsyncHandler.java
@@ -1,52 +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 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));
- }
-
-
-}
+/*
+ * 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 CalculatorAsyncHandler implements AsyncHandler<String> {
+ public void handleResponse(Response<String> res) {
+ try {
+ System.out.println("Async client callback patern: result in handler = " + res.get());
+ } catch(Exception ex){
+ System.out.println("Async client callback patern: exception in handler = " + ex.getMessage());
+ }
+ }
+}
diff --git a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorClient.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorClient.java
index fd92647dd1..cc1d1d8d46 100644
--- a/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorClient.java
+++ b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorClient.java
@@ -39,12 +39,8 @@ public class CalculatorClient {
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/CalculatorService.java b/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorService.java
index 6b311f467d..ca9b0397a9 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,8 +21,9 @@ package calculator;
import org.oasisopen.sca.annotation.Remotable;
/**
- * The Calculator service interface.
+ * The sycn Calculator service interface.
*/
+
@Remotable
public interface CalculatorService {
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 c5b0562c65..994ad42d92 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
@@ -43,9 +43,9 @@ public class CalculatorServiceImpl implements CalculatorService {
// sync
String result = calculatorRefSyncService.calculate(1);
- System.out.println(result);
+ System.out.println("Sync client patern: result = " + result);
-// // async poll
+ // async poll
Future<String> future = calculatorRefSyncService.calculateAsync(20);
while (!future.isDone()){
@@ -54,7 +54,7 @@ public class CalculatorServiceImpl implements CalculatorService {
try {
result = future.get();
- System.out.println("Async client patern success: result = " + result);
+ System.out.println("Async client poll patern: result = " + result);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -63,16 +63,14 @@ public class CalculatorServiceImpl implements CalculatorService {
e.printStackTrace();
}
-
-
// async callback
-// AsyncHandler<String> handler = new AsyncHandler<String>();
-// future = calculatorRef.calculateAsync(3, handler);
-/*
+ CalculatorAsyncHandler handler = new CalculatorAsyncHandler();
+ future = calculatorRefSyncService.calculateAsync(3, handler);
+
while (!future.isDone()){
System.out.println("Waiting for callback");
}
-*/
+
return result;
}