summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample/contributions/interaction-client-contribution/src/main
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-06-14 15:45:33 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-06-14 15:45:33 +0000
commit6222ba67f2fd06e34dde842a82e553d3280acaaa (patch)
tree5ebf9d891df80d8b5fb46ab62655543048a38b9b /sandbox/travelsample/contributions/interaction-client-contribution/src/main
parentf7cdb52f0e6c981a78eb4c9c4787688023685b8f (diff)
Extend the launcher for the interaction examples based on components from the travel sample
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@784575 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/travelsample/contributions/interaction-client-contribution/src/main')
-rw-r--r--sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionClient.java119
-rw-r--r--sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionConversationClient.java78
-rw-r--r--sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionLocalClient.java2
-rw-r--r--sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionOneWayCallbackClient.java78
-rw-r--r--sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionRemoteClient.java6
-rw-r--r--sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionRequestResponseClient.java2
-rw-r--r--sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionStatefulCallbackClient.java98
-rw-r--r--sandbox/travelsample/contributions/interaction-client-contribution/src/main/resources/META-INF/sca-contribution.xml1
-rw-r--r--sandbox/travelsample/contributions/interaction-client-contribution/src/main/resources/client.composite57
9 files changed, 309 insertions, 132 deletions
diff --git a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionClient.java b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionClient.java
deleted file mode 100644
index 9953d4b1a5..0000000000
--- a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionClient.java
+++ /dev/null
@@ -1,119 +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 scatours.client;
-
-import org.osoa.sca.annotations.Reference;
-import org.osoa.sca.annotations.Service;
-
-import calendar.Calendar;
-
-import scatours.common.Search;
-import scatours.common.SearchCallback;
-import scatours.common.TripItem;
-import scatours.common.TripLeg;
-
-@Service(Runnable.class)
-public class InteractionClient implements Runnable, SearchCallback {
- @Reference
- protected Search hotelSearchRemoteRequestResponse;
-
- @Reference
- protected Calendar calendarLocalRequestResponse;
-
- public InteractionClient() {
- }
-
- // Runnable method
-
- public void run() {
- System.out.println("Calling hotel component over remote binding");
- runRemoteRequestResponse();
-
- System.out.println("Calling calendar component over local binding");
- runLocalRequestReponse();
- }
-
- private void runRemoteRequestResponse() {
- TripLeg tripLeg = getTestTripLeg();
- TripItem[] tripItems = hotelSearchRemoteRequestResponse.searchSynch(tripLeg);
- for (TripItem tripItem : tripItems){
- System.out.println("Found hotel - " + tripItem.getName());
- }
- }
-
- private void runLocalRequestReponse() {
- TripLeg tripLeg = getTestTripLeg();
- String toDate = calendarLocalRequestResponse.getEndDate(tripLeg.getFromDate(), 10);
- tripLeg.setToDate(toDate);
- System.out.println("Calculated trip end date - " + toDate);
- }
-
- private void runRemoteOneWay() {
-
- }
-
- private void runConversational() {
-
- }
-
- private void runCallback() {
-
- }
-
- private void runStatefulCallback() {
-
- }
-
- private TripLeg getTestTripLeg(){
- TripLeg tripLeg = new TripLeg();
- tripLeg.setFromLocation("LGW");
- tripLeg.setToLocation("FLR");
- tripLeg.setFromDate("06/12/09 00:00");
- tripLeg.setToDate("13/12/09 00:00");
- tripLeg.setNoOfPeople("1");
- tripLeg.setId("TRIP27");
-
- return tripLeg;
- }
-
- // SearchCallback methods
-
- public void searchResults(TripItem[] items){
-/*
- RequestContext requestContext = componentContext.getRequestContext();
- Object callbackID = requestContext.getServiceReference().getCallbackID();
- System.out.println(callbackID);
-
- if (items != null) {
- for(int i = 0; i < items.length; i++ ){
- searchResults.add(items[i]);
- }
- }
-
- responsesReceived++;
- try {
- synchronized (this) {
- this.notifyAll();
- }
- } catch (Exception ex) {
- }
-*/
- }
-}
diff --git a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionConversationClient.java b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionConversationClient.java
new file mode 100644
index 0000000000..c013cd63fb
--- /dev/null
+++ b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionConversationClient.java
@@ -0,0 +1,78 @@
+/*
+ * 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 scatours.client;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.Service;
+
+import scatours.common.Search;
+import scatours.common.SearchCallback;
+import scatours.common.TripItem;
+import scatours.common.TripLeg;
+import scatours.shoppingcart.CartStore;
+
+@Scope("COMPOSITE")
+@Service(Runnable.class)
+public class InteractionConversationClient implements Runnable{
+
+ @Reference
+ protected CartStore cartStoreConversation;
+
+ public void run() {
+ System.out.println("\nCalling cart store using the conversational interaction pattern");
+
+ // add some trip items to the cart store
+ TripItem tripItem = getTestTripItem();
+ cartStoreConversation.addTrip(tripItem);
+
+ tripItem.setDescription("2nd trip item");
+ cartStoreConversation.addTrip(tripItem);
+
+ tripItem.setDescription("3rd trip item");
+ cartStoreConversation.addTrip(tripItem);
+
+ System.out.println("Trip items now in cart");
+ TripItem[] tripItems = cartStoreConversation.getTrips();
+ for (TripItem item : tripItems){
+ System.out.println("Item - " + item.getDescription());
+ }
+
+ System.out.println("Reset the cart");
+ cartStoreConversation.reset();
+
+ System.out.println("Trip items now in cart");
+ tripItems = cartStoreConversation.getTrips();
+ for (TripItem item : tripItems){
+ System.out.println("Item - " + item.getDescription());
+ }
+ }
+
+ private TripItem getTestTripItem(){
+ TripItem tripItem = new TripItem();
+ tripItem.setLocation("FLR");
+ tripItem.setFromDate("06/12/09 00:00");
+ tripItem.setToDate("13/12/09 00:00");
+ tripItem.setDescription("1st trip item");
+ return tripItem;
+ }
+}
diff --git a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionLocalClient.java b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionLocalClient.java
index fb1a7c29d5..4ada5ab47f 100644
--- a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionLocalClient.java
+++ b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionLocalClient.java
@@ -33,7 +33,7 @@ public class InteractionLocalClient implements Runnable {
protected Calendar calendarLocal;
public void run() {
- System.out.println("\nCalling calendar component over local binding");
+ System.out.println("\nCalling calendar component over a local binding");
TripLeg tripLeg = getTestTripLeg();
String toDate = calendarLocal.getEndDate(tripLeg.getFromDate(), 10);
tripLeg.setToDate(toDate);
diff --git a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionOneWayCallbackClient.java b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionOneWayCallbackClient.java
new file mode 100644
index 0000000000..94ef5ef284
--- /dev/null
+++ b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionOneWayCallbackClient.java
@@ -0,0 +1,78 @@
+/*
+ * 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 scatours.client;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.Service;
+
+import scatours.common.Search;
+import scatours.common.SearchCallback;
+import scatours.common.TripItem;
+import scatours.common.TripLeg;
+
+@Scope("COMPOSITE")
+@Service(Runnable.class)
+public class InteractionOneWayCallbackClient implements Runnable, SearchCallback{
+
+ @Reference
+ protected Search hotelSearchOneWayCallback;
+
+ CountDownLatch resultsReceivedCountdown;
+
+ public void run() {
+ System.out.println("\nCalling hotel component using both one way and callback interation patterns");
+ resultsReceivedCountdown = new CountDownLatch(1);
+ TripLeg tripLeg = getTestTripLeg();
+ hotelSearchOneWayCallback.searchAsynch(tripLeg);
+
+ // start other searched here while the hotel search progresses
+
+ // wait for responses to come back
+ try {
+ resultsReceivedCountdown.await();
+ } catch (InterruptedException ex){
+ }
+ }
+
+ public void searchResults(TripItem[] items){
+ for (TripItem tripItem : items){
+ System.out.println("Found hotel - " + tripItem.getName());
+ }
+ resultsReceivedCountdown.countDown();
+ }
+
+ public void setPercentComplete(String searchComponent, int percentComplete){
+ // Not used in this sample
+ }
+
+ private TripLeg getTestTripLeg(){
+ TripLeg tripLeg = new TripLeg();
+ tripLeg.setFromLocation("LGW");
+ tripLeg.setToLocation("FLR");
+ tripLeg.setFromDate("06/12/09 00:00");
+ tripLeg.setToDate("13/12/09 00:00");
+ tripLeg.setNoOfPeople("1");
+ tripLeg.setId("TRIP27");
+ return tripLeg;
+ }
+}
diff --git a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionRemoteClient.java b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionRemoteClient.java
index 2f198797a1..278c7bb08f 100644
--- a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionRemoteClient.java
+++ b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionRemoteClient.java
@@ -34,7 +34,7 @@ public class InteractionRemoteClient implements Runnable, SearchCallback{
protected Search hotelSearchRemote;
public void run() {
- System.out.println("\nCalling hotel component over remote binding");
+ System.out.println("\nCalling hotel component over a remote binding");
TripLeg tripLeg = getTestTripLeg();
TripItem[] tripItems = hotelSearchRemote.searchSynch(tripLeg);
for (TripItem tripItem : tripItems){
@@ -47,6 +47,10 @@ public class InteractionRemoteClient implements Runnable, SearchCallback{
// so the callback interface is not used
}
+ public void setPercentComplete(String searchComponent, int percentComplete){
+ // Not used in this sample
+ }
+
private TripLeg getTestTripLeg(){
TripLeg tripLeg = new TripLeg();
tripLeg.setFromLocation("LGW");
diff --git a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionRequestResponseClient.java b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionRequestResponseClient.java
index 20cb8fd740..0ca001fd9b 100644
--- a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionRequestResponseClient.java
+++ b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionRequestResponseClient.java
@@ -34,7 +34,7 @@ public class InteractionRequestResponseClient implements Runnable {
protected CurrencyConverter currencyConverterRequestResponse;
public void run() {
- System.out.println("\nCalling currency converter component using request response pattern");
+ System.out.println("\nCalling currency converter component using request response interation pattern");
double convertedAmount = currencyConverterRequestResponse.convert("GBP", "USD", 10.0);
System.out.println("10 GBP = " + convertedAmount + " USD");
}
diff --git a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionStatefulCallbackClient.java b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionStatefulCallbackClient.java
new file mode 100644
index 0000000000..690c99373e
--- /dev/null
+++ b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/java/scatours/client/InteractionStatefulCallbackClient.java
@@ -0,0 +1,98 @@
+/*
+ * 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 scatours.client;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.Context;
+import org.osoa.sca.annotations.ConversationID;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.Service;
+
+import scatours.common.Search;
+import scatours.common.SearchCallback;
+import scatours.common.TripItem;
+import scatours.common.TripLeg;
+
+@Scope("CONVERSATION")
+@Service(Runnable.class)
+public class InteractionStatefulCallbackClient implements Runnable, SearchCallback{
+
+ @Reference
+ protected Search flightSearchStatefulCallback;
+
+ @Context
+ protected ComponentContext componentContext;
+
+ CountDownLatch resultsReceivedCountdown;
+
+ public void run() {
+ System.out.println("\nCalling flight component using stateful callback interation pattern");
+ resultsReceivedCountdown = new CountDownLatch(1);
+ TripLeg tripLeg = getTestTripLeg();
+
+ ServiceReference<Search> dynamicFlightSearchStatefulCallback =
+ componentContext.getServiceReference(Search.class, "flightSearchStatefulCallback");
+ dynamicFlightSearchStatefulCallback.setConversationID("SomeUniqeID");
+ Search flightSearch = dynamicFlightSearchStatefulCallback.getService();
+
+ flightSearch.searchAsynch(tripLeg);
+
+ // wait for a while and see how the flight search is getting one
+ try {
+ Thread.sleep(1200);
+ } catch(Exception ex){
+ // do nothing
+ }
+ System.out.println("Flight search is " + flightSearch.getPercentComplete() + "% complete");
+
+ // wait for responses to come back
+ try {
+ resultsReceivedCountdown.await();
+ } catch (InterruptedException ex){
+ }
+ }
+
+ public void searchResults(TripItem[] items){
+ System.out.println("Received results in conversation - " + componentContext.getRequestContext().getServiceReference().getConversation().getConversationID());
+ for (TripItem tripItem : items){
+ System.out.println("Found flight - " + tripItem.getName());
+ }
+ resultsReceivedCountdown.countDown();
+ }
+
+ public void setPercentComplete(String searchComponent, int percentComplete){
+ System.out.println(searchComponent + " search is " + percentComplete + "% complete");
+ }
+
+ private TripLeg getTestTripLeg(){
+ TripLeg tripLeg = new TripLeg();
+ tripLeg.setFromLocation("LGW");
+ tripLeg.setToLocation("FLR");
+ tripLeg.setFromDate("06/12/09");
+ tripLeg.setToDate("13/12/09");
+ tripLeg.setNoOfPeople("1");
+ tripLeg.setId("TRIP27");
+ return tripLeg;
+ }
+}
diff --git a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/resources/META-INF/sca-contribution.xml b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/resources/META-INF/sca-contribution.xml
index 848e0bea5b..bc47b4de2e 100644
--- a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/resources/META-INF/sca-contribution.xml
+++ b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/resources/META-INF/sca-contribution.xml
@@ -22,5 +22,6 @@
<import.java package="calendar"/>
<import.java package="scatours.common"/>
<import.java package="scatours.currencyconverter"/>
+ <import.java package="scatours.shoppingcart"/>
<deployable composite="client:Client" />
</contribution>
diff --git a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/resources/client.composite b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/resources/client.composite
index c2ff2c9a89..f6483bb55f 100644
--- a/sandbox/travelsample/contributions/interaction-client-contribution/src/main/resources/client.composite
+++ b/sandbox/travelsample/contributions/interaction-client-contribution/src/main/resources/client.composite
@@ -21,7 +21,7 @@
targetNamespace="http://client.scatours/"
name="Client">
- <!-- Local interaction -->
+ <!-- Local interaction -->
<component name="InteractionLocalClient">
<implementation.java class="scatours.client.InteractionLocalClient" />
<reference name="calendarLocal"
@@ -32,22 +32,59 @@
<implementation.java class="calendar.CalendarImpl"/>
</component>
- <!-- Remote interaction -->
+ <!-- Remote interaction -->
<component name="InteractionRemoteClient">
<implementation.java class="scatours.client.InteractionRemoteClient" />
<reference name="hotelSearchRemote">
- <binding.ws uri="http://localhost:8081/HotelComponent/Search"/>
+ <binding.ws uri="http://localhost:8081/Hotel/Search"/>
</reference>
- </component>
+ </component>
- <!-- Request response interaction -->
- <component name="InteractionRequestResponseClient">
+ <!-- Request response interaction -->
+ <component name="InteractionRequestResponseClient">
<implementation.java class="scatours.client.InteractionRequestResponseClient" />
- <reference name="currencyConverterRequestResponse" target="CurrencyConverterComponent"/>
- </component>
+ <reference name="currencyConverterRequestResponse" target="CurrencyConverter"/>
+ </component>
- <component name="CurrencyConverterComponent">
+ <component name="CurrencyConverter">
<implementation.java class="scatours.currencyconverter.CurrencyConverterImpl"/>
- </component>
+ </component>
+
+ <!-- One way and callback interaction -->
+ <component name="InteractionOneWayCallbackClient">
+ <implementation.java class="scatours.client.InteractionOneWayCallbackClient" />
+ <reference name="hotelSearchOneWayCallback">
+ <interface.java interface="scatours.common.Search"
+ callbackInterface="scatours.common.SearchCallback"/>
+ <binding.ws uri="http://localhost:8081/Hotel/Search"/>
+ <callback>
+ <binding.ws uri="http://localhost:8080/Client/SearchCallback"/>
+ </callback>
+ </reference>
+ </component>
+
+ <!-- Conversational interaction -->
+ <component name="InteractionConversationClient">
+ <implementation.java class="scatours.client.InteractionConversationClient" />
+ <reference name="cartStoreConversation" target="CartStore"/>
+ </component>
+
+ <component name="CartStore">
+ <implementation.java class="scatours.shoppingcart.CartStoreImpl"/>
+ <service name="CartStore"/>
+ </component>
+
+ <!-- Stateful callback interaction -->
+ <component name="InteractionStatefulCallbackClient">
+ <implementation.java class="scatours.client.InteractionStatefulCallbackClient" />
+ <reference name="flightSearchStatefulCallback">
+ <interface.java interface="scatours.common.Search"
+ callbackInterface="scatours.common.SearchCallback"/>
+ <binding.ws uri="http://localhost:8081/Hotel/SearchConversational"/>
+ <callback>
+ <binding.ws uri="http://localhost:8080/Client/SearchCallbackConversational"/>
+ </callback>
+ </reference>
+ </component>
</composite>