From 59523e81731bcac1034aceec0de0e65967248cd6 Mon Sep 17 00:00:00 2001 From: slaws Date: Sun, 3 Aug 2008 13:59:39 +0000 Subject: Allow trip items to be removed git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@682175 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/scatours/trip/TripContents.java | 1 + .../src/scatours/trip/TripImpl.java | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'sandbox/travelsample/trip-contribution/src') diff --git a/sandbox/travelsample/trip-contribution/src/scatours/trip/TripContents.java b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripContents.java index 78eb8fdab4..0484dde02e 100644 --- a/sandbox/travelsample/trip-contribution/src/scatours/trip/TripContents.java +++ b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripContents.java @@ -30,5 +30,6 @@ import scatours.common.TripItem; public interface TripContents extends Collection { void addTripItem(String id); + void removeTripItem(String id); double getTotalPrice(); } diff --git a/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java index 53e368f8e6..30d87a283e 100644 --- a/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java +++ b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java @@ -59,6 +59,8 @@ public class TripImpl implements TripSearch, SearchCallback, TripContents{ @Property public String quoteCurrencyCode = "USD"; + private int responsesReceived = 0; + private List searchResults = new ArrayList(); private Map tripItems = new HashMap(); @@ -67,15 +69,22 @@ public class TripImpl implements TripSearch, SearchCallback, TripContents{ public TripItem[] search(TripLeg tripLeg) { searchResults.clear(); + responsesReceived = 0; hotelSearch.searchAsynch(tripLeg); flightSearch.searchAsynch(tripLeg); carSearch.searchAsynch(tripLeg); - // TODO - wait for searches to complete + while (responsesReceived < 3){ + try { + this.wait(); + } catch (InterruptedException ex){ + // do nothing + } + } for (TripItem tripItem : searchResults){ - tripItem.setId(String.valueOf(searchResults.indexOf(tripItem))); + tripItem.setId(UUID.randomUUID().toString()); tripItem.setPrice(currencyConverter.convert(tripItem.getCurrency(), quoteCurrencyCode, tripItem.getPrice())); @@ -91,6 +100,12 @@ public class TripImpl implements TripSearch, SearchCallback, TripContents{ for(int i = 0; i < items.length; i++ ){ searchResults.add(items[i]); } + + responsesReceived++; + try { + this.notifyAll(); + } catch (Exception ex) { + } } // TripContents methods @@ -102,6 +117,9 @@ public class TripImpl implements TripSearch, SearchCallback, TripContents{ } } + public void removeTripItem(String id){ + tripItems.remove(id); + } // Not using the DataCollection iface yet as it seems like a // likely attach vector to be passing complete tripItem records in -- cgit v1.2.3