summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main')
-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/CalculatorAsyncServiceImpl.java11
-rw-r--r--sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorBoot.java52
-rw-r--r--sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorServiceImpl.java12
-rw-r--r--sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/java/calculator/CalculatorSyncServiceImpl.java11
-rw-r--r--sca-java-2.x/trunk/contrib/samples/async/sample-contribution-implementation-java-calculator-async/src/main/resources/Calculator.composite10
6 files changed, 173 insertions, 4 deletions
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<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/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<String> future = calculatorRefAsyncService.calculateAsync(2);
+// // async poll
+ Future<String> 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<String> handler = new AsyncHandler<String>();
// 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 @@
<component name="CalculatorServiceComponent">
<implementation.java class="calculator.CalculatorServiceImpl"/>
+ <reference name="calculatorRefSyncService" target="CalculatorSync"/>
+ <!-- <reference name="calculatorRefAsyncService" target="CalculatorAsync"/> -->
+
</component>
+ <component name="CalculatorSync">
+ <implementation.java class="calculator.CalculatorSyncServiceImpl"/>
+ </component>
+ <!-- <component name="CalculatorAsync">
+ <implementation.java class="calculator.CalculatorAsyncServiceImpl"/>
+ </component> -->
+
</composite>