mirror of https://github.com/apache/jclouds.git
Providers and APIs in OSGi can be discovered even if they are installed prior to the installation of jclouds-core.
This commit is contained in:
parent
c0e23d4460
commit
ff2c2fb3e3
|
@ -44,6 +44,7 @@ public class Activator implements BundleActivator {
|
|||
*/
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception {
|
||||
bundleListener.start(context);
|
||||
context.addBundleListener(bundleListener);
|
||||
}
|
||||
|
||||
|
@ -66,6 +67,7 @@ public class Activator implements BundleActivator {
|
|||
*/
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
bundleListener.stop(context);
|
||||
context.removeBundleListener(bundleListener);
|
||||
ProviderRegistry.clear();
|
||||
ApiRegistry.clear();
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.jclouds.apis.ApiRegistry;
|
|||
import org.jclouds.providers.ProviderMetadata;
|
||||
import org.jclouds.providers.ProviderRegistry;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.BundleEvent;
|
||||
import org.osgi.framework.BundleListener;
|
||||
|
||||
|
@ -43,6 +44,31 @@ public class MetadataBundleListener implements BundleListener {
|
|||
private Map<Long, ProviderMetadata> providerMetadataMap = new HashMap<Long, ProviderMetadata>();
|
||||
private Map<Long, ApiMetadata> apiMetadataMap = new HashMap<Long, ApiMetadata>();
|
||||
|
||||
|
||||
public void start(BundleContext bundleContext) {
|
||||
bundleContext.addBundleListener(this);
|
||||
for (Bundle bundle : bundleContext.getBundles()) {
|
||||
if (bundle.getState() == Bundle.ACTIVE) {
|
||||
ProviderMetadata providerMetadata = getProviderMetadata(bundle);
|
||||
ApiMetadata apiMetadata = getApiMetadata(bundle);
|
||||
|
||||
if (providerMetadata != null) {
|
||||
ProviderRegistry.registerProvider(providerMetadata);
|
||||
providerMetadataMap.put(bundle.getBundleId(), providerMetadata);
|
||||
}
|
||||
if (apiMetadata != null) {
|
||||
ApiRegistry.registerApi(apiMetadata);
|
||||
apiMetadataMap.put(bundle.getBundleId(), apiMetadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(BundleContext bundleContext) {
|
||||
providerMetadataMap.clear();
|
||||
apiMetadataMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bundleChanged(BundleEvent event) {
|
||||
ProviderMetadata providerMetadata;
|
||||
|
|
Loading…
Reference in New Issue