diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-07 18:46:54 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-07 18:46:54 +0000 |
commit | 8c95399e018199d989fd6eef12475c32d13e74c5 (patch) | |
tree | 7813dd96be7d7f0cce22d46c1605f5e9e50920e7 /sandbox | |
parent | 968d35ff3272da65a7efb42e99187af0fa435ec3 (diff) |
Use a CountDownLatch instead of a manual count of concurrent threads. Need 1.x change for TUSCANY-3076 for this to work.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@782427 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox')
-rw-r--r-- | sandbox/travelsample/contributions/travelcatalog-contribution/src/main/java/scatours/travelcatalog/TravelCatalogImpl.java | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/sandbox/travelsample/contributions/travelcatalog-contribution/src/main/java/scatours/travelcatalog/TravelCatalogImpl.java b/sandbox/travelsample/contributions/travelcatalog-contribution/src/main/java/scatours/travelcatalog/TravelCatalogImpl.java index 4919d2a629..68eb3c38a2 100644 --- a/sandbox/travelsample/contributions/travelcatalog-contribution/src/main/java/scatours/travelcatalog/TravelCatalogImpl.java +++ b/sandbox/travelsample/contributions/travelcatalog-contribution/src/main/java/scatours/travelcatalog/TravelCatalogImpl.java @@ -21,6 +21,7 @@ package scatours.travelcatalog; import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
import org.osoa.sca.ComponentContext;
import org.osoa.sca.RequestContext;
@@ -64,17 +65,17 @@ public class TravelCatalogImpl implements TravelCatalogSearch, SearchCallback{ @Context
protected ComponentContext componentContext;
-
- private int responsesReceived = 0;
-
+
private List<TripItem> searchResults = new ArrayList<TripItem>();
+ CountDownLatch resultsReceivedCountdown;
+
// TravelSearch methods
public TripItem[] search(TripLeg tripLeg) {
+ resultsReceivedCountdown = new CountDownLatch(4);
searchResults.clear();
- responsesReceived = 0;
ServiceReference<Search> dynamicHotelSearch =
componentContext.getServiceReference(Search.class, "hotelSearch");
@@ -82,34 +83,16 @@ public class TravelCatalogImpl implements TravelCatalogSearch, SearchCallback{ dynamicHotelSearch.setCallbackID("HotelSearchCallbackID-" + tripLeg.getId());
dynamicHotelSearch.getService().searchAsynch(tripLeg);
- flightSearch.searchAsynch(tripLeg);
-
- while (responsesReceived < 2){
- try {
- synchronized (this) {
- this.wait();
- }
- } catch (InterruptedException ex){
- // do nothing
- System.out.println("waiting for response");
- }
- }
-
+ flightSearch.searchAsynch(tripLeg);
carSearch.searchAsynch(tripLeg);
tripSearch.searchAsynch(tripLeg);
System.out.println("going into wait");
- while (responsesReceived < 4){
- try {
- synchronized (this) {
- this.wait();
- }
- } catch (InterruptedException ex){
- // do nothing
- System.out.println("waiting for response");
- }
- }
+ try {
+ resultsReceivedCountdown.await();
+ } catch (InterruptedException ex){
+ }
for (TripItem tripItem : searchResults){
tripItem.setId(UUID.randomUUID().toString());
@@ -125,7 +108,7 @@ public class TravelCatalogImpl implements TravelCatalogSearch, SearchCallback{ // SearchCallback methods
- public void searchResults(TripItem[] items){
+ public synchronized void searchResults(TripItem[] items){
RequestContext requestContext = componentContext.getRequestContext();
Object callbackID = requestContext.getServiceReference().getCallbackID();
System.out.println("Asynch response - " + callbackID);
@@ -136,12 +119,6 @@ public class TravelCatalogImpl implements TravelCatalogSearch, SearchCallback{ }
}
- responsesReceived++;
- try {
- synchronized (this) {
- this.notifyAll();
- }
- } catch (Exception ex) {
- }
+ resultsReceivedCountdown.countDown();
}
}
|