Java Reference
In-Depth Information
System.out.println("Cheese returned after "
+ (System.currentTimeMillis() - start) + " ms.");
Food leastPopularCheese = cheeses.get(0);//
return leastPopularCheese;
Rebuild the cheese bundle, and drop it into the load directory. Also update the
OfferAggregator to disable the sorting of the offer list for the moment (so that you
get the persistence call at the right time) and rebuild the business bundle. Hit the web
page, and then stop the persistence bundle when you see your first message appearing
in the console. You'll see that instead of returning after the five-second pause you
introduced, the load request on the web page hasn't returned. What's going on? The
call on the inventory object will block until a persistence provider becomes available
again, or until the Blueprint timeout happens after five minutes (see figure 6.9).
The nice thing about the Blueprint damping is that the disappearance of a service
need not be fatal. If you restart the persistence bundle before the five-minute timeout
expires, the cheese offer will miraculously kick back into life. But you may get more
than you bargained for, as figure 6.10 shows.
What's going on? You certainly didn't expect that the removal of the cheese offer
service would give you two cheese offers.
The list of offers is injected into the OfferAggregator , which passes a reference to
the same list to the servlet. When the servlet starts iterating over the list, there are two
elements in the list. It requests the details for the chocolate offer, and then it requests
the details for the cheese offer, which is where you disable the persistence bundle,
causing the cheese offer to block when asked for its details. Re-enabling the persis-
tence bundle unblocks the call and allows the servlet to see the details of the cheese
offer. Meanwhile, however, the cheese offer has been removed from the aggregator's
reference list and then added back to it. When the iterator finishes printing out the
Figure 6.9 If a Blueprint service is unregistered after services that depend on it have been invoked, the
proxy to the service will block for five minutes before throwing a ServiceUnavailableException .
Search WWH ::




Custom Search