tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sl...@apache.org
Subject svn commit: r782427 - /tuscany/sandbox/travelsample/contributions/travelcatalog-contribution/src/main/java/scatours/travelcatalog/TravelCatalogImpl.java
Date Sun, 07 Jun 2009 18:46:54 GMT
Author: slaws
Date: Sun Jun  7 18:46:54 2009
New Revision: 782427

URL: http://svn.apache.org/viewvc?rev=782427&view=rev
Log:
Use a CountDownLatch instead of a manual count of concurrent threads. Need 1.x change for
TUSCANY-3076 for this to work.

Modified:
    tuscany/sandbox/travelsample/contributions/travelcatalog-contribution/src/main/java/scatours/travelcatalog/TravelCatalogImpl.java

Modified: tuscany/sandbox/travelsample/contributions/travelcatalog-contribution/src/main/java/scatours/travelcatalog/TravelCatalogImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/travelsample/contributions/travelcatalog-contribution/src/main/java/scatours/travelcatalog/TravelCatalogImpl.java?rev=782427&r1=782426&r2=782427&view=diff
==============================================================================
--- tuscany/sandbox/travelsample/contributions/travelcatalog-contribution/src/main/java/scatours/travelcatalog/TravelCatalogImpl.java
(original)
+++ tuscany/sandbox/travelsample/contributions/travelcatalog-contribution/src/main/java/scatours/travelcatalog/TravelCatalogImpl.java
Sun Jun  7 18:46:54 2009
@@ -21,6 +21,7 @@
 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 @@
     
     @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 @@
         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 @@
     
     // 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 @@
             }
         }
         
-        responsesReceived++;
-        try {
-            synchronized (this) {
-                this.notifyAll();
-            }
-        } catch (Exception ex) {
-        }
+        resultsReceivedCountdown.countDown();
     }    
 }



Mime
View raw message