import org.apache.karaf.features.FeaturesService; //導入方法依賴的package包/類
private void waitForFeatures( List requiredFeatures, FeaturesService featuresService ) throws Exception {
long entryTime = System.currentTimeMillis();
// Loop through to see if features are all installed
while ( true ) {
List uninstalledFeatures = new ArrayList();
for ( String requiredFeature : requiredFeatures ) {
requiredFeature = requiredFeature.trim();
Feature feature = featuresService.getFeature( requiredFeature );
if ( feature != null && featuresService.isInstalled( feature ) == false ) {
uninstalledFeatures.add( requiredFeature );
}
}
if ( uninstalledFeatures.size() > 0 ) {
if ( System.currentTimeMillis() - timeout > entryTime ) {
IServiceBarrier serviceBarrier =
IServiceBarrierManager.LOCATOR.getManager().getServiceBarrier( "KarafFeatureWatcherBarrier" );
if ( serviceBarrier == null || serviceBarrier.isAvailable() ) {
logger.debug( getFeaturesReport( featuresService, uninstalledFeatures ) );
throw new FeatureWatcherException( "Timed out waiting for Karaf features to install: " + StringUtils
.join( uninstalledFeatures, "," ) );
} else {
entryTime = System.currentTimeMillis();
}
}
logger.debug( "KarafFeatureWatcher is waiting for the following features to install: " + StringUtils.join(
uninstalledFeatures, "," ) );
Thread.sleep( 100 );
continue;
}
break;
}
}