protected void waitOnContextCreation(BundleContext context, String forBundleWithSymbolicName, long timeout) {
// translate from seconds to milliseconds
long time = timeout * SECOND;
// use the counter to make sure the threads block
final Counter counter = new Counter("waitForContext on bnd=" + forBundleWithSymbolicName);
counter.increment();
String filter = "(org.springframework.context.service.name=" + forBundleWithSymbolicName + ")";
ServiceListener listener = new ServiceListener() {
public void serviceChanged(ServiceEvent event) {
if (event.getType() == ServiceEvent.REGISTERED)
counter.decrement();
}
};
OsgiListenerUtils.addServiceListener(context, listener, filter);
if (logger.isDebugEnabled())
logger.debug("Start waiting for Spring/OSGi bundle=" + forBundleWithSymbolicName);
try {
if (counter.waitForZero(time)) {
waitingFailed(forBundleWithSymbolicName);
}
else if (logger.isDebugEnabled()) {
logger.debug("Found applicationContext for bundle=" + forBundleWithSymbolicName);
}