*/
private static ServiceReference getBlueprintContainerRef(Bundle b) throws ServiceUnavailableException
{
ServiceReference result = findBPCRef(b);
if (result == null) {
Semaphore s = new Semaphore(0);
AtomicReference<ServiceReference> bpcRef = new AtomicReference<ServiceReference>();
ServiceTracker st = new ServiceTracker (b.getBundleContext(), BlueprintContainer.class.getName(),
new BlueprintContainerServiceTrackerCustomizer (b, s, bpcRef));
st.open();
// Make another check for the BlueprintContainer service in case it came up just before our tracker engaged
int graceperiod = getGracePeriod(b);
result = findBPCRef(b);
if (result == null && graceperiod >= 0) {
if (graceperiod == 0) { // Wait for an unlimited period
try {
s.acquire();
} catch (InterruptedException ix) {}
} else {
try {
s.tryAcquire(graceperiod, TimeUnit.MILLISECONDS);
} catch (InterruptedException ix) {}
}
}
result = bpcRef.get();
st.close();