@Provides @LazySingleton public CloudFilesApi getCloudFilesApi(final CloudFilesAccountConfig config) { log.info("Building Cloud Files Api..."); Iterable<com.google.inject.Module> modules; if (config.getUseServiceNet()) { log.info("Configuring Cloud Files Api to use the internal service network..."); modules = ImmutableSet.of(new SLF4JLoggingModule(), new InternalUrlModule()); } else { log.info("Configuring Cloud Files Api to use the public network..."); modules = ImmutableSet.of(new SLF4JLoggingModule()); } ProviderRegistry.registerProvider(CloudFilesUSProviderMetadata.builder().build()); ProviderRegistry.registerProvider(CloudFilesUKProviderMetadata.builder().build()); ContextBuilder cb = ContextBuilder.newBuilder(config.getProvider()) .credentials(config.getUserName(), config.getApiKey()).modules(modules); CloudFilesApi cfa = cb.buildApi(CloudFilesApi.class); log.info("Cloud Files Api built."); return cfa; }
@Test public void testRegisteredProvider() throws Exception { String id = "my-example-provider"; assertFalse(JcloudsProviderAndApiLoader.isProvider(id)); ProviderMetadata provider = new BaseProviderMetadata.Builder() .id(id) .name("My Example Provider") .apiMetadata(new AWSEC2ApiMetadata()) .build(); ProviderRegistry.registerProvider(provider); try { assertIsProvider(id); ProviderRegistry.unregisterProvider(provider); assertFalse(JcloudsProviderAndApiLoader.isProvider(id)); } finally { ProviderRegistry.unregisterProvider(provider); } }
/** * Searches for {@link ProviderMetadata} and {@link ApiMetadata} registered under the {@link Bundle} id. If metadata * are found they are removed the {@link ProviderRegistry} and {@link ApiRegistry}. Also the {@link ProviderListener} * and {@link ApiListener} are notified. * * @param bundle */ private synchronized void removeBundle(Bundle bundle) { for (ProviderMetadata providerMetadata : providerMetadataMap.removeAll(bundle.getBundleId())) { ProviderRegistry.unregisterProvider(providerMetadata); for (ProviderListener listener : providerListeners) { listener.removed(providerMetadata); } } for (ApiMetadata apiMetadata : apiMetadataMap.removeAll(bundle.getBundleId())) { ApiRegistry.unRegisterApi(apiMetadata); for (ApiListener listener : apiListeners) { listener.removed(apiMetadata); } } }
/** * Returns all available providers. * * @return all available providers */ public static Iterable<ProviderMetadata> all() { return ImmutableSet.<ProviderMetadata>builder() .addAll(fromServiceLoader()) .addAll(ProviderRegistry.fromRegistry()).build(); }
/** * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop * the bundle. In general, this method should undo the work that the <code>BundleActivator.start</code> method * started. There should be no active threads that were started by this bundle when this bundle returns. A stopped * bundle must not call any Framework objects. * <p/> * <p/> * This method must complete and return to its caller in a timely manner. * * @param context * The execution context of the bundle being stopped. * @throws Exception * If this method throws an exception, the bundle is still marked as stopped, and the Framework will * remove the bundle's listeners, unregister all services registered by the bundle, and release all * services used by the bundle. */ @Override public void stop(BundleContext context) throws Exception { bundleListener.stop(context); ProviderRegistry.clear(); ApiRegistry.clear(); if (apiListenerTracker != null) { apiListenerTracker.close(); } if (providerListenerTracker != null) { providerListenerTracker.close(); } } }
@Test public void testRenamedRegisteredProvider() throws Exception { String newId = "my-example-provider2"; String oldId = "my-example-provider-renamed"; assertFalse(JcloudsProviderAndApiLoader.isProvider(newId)); ProviderMetadata provider = new BaseProviderMetadata.Builder() .id(newId) .name("My Example Provider 2") .apiMetadata(new AWSEC2ApiMetadata()) .build(); ProviderRegistry.registerProvider(provider); try { assertIsProvider(newId); assertFalse(JcloudsProviderAndApiLoader.isProvider(oldId)); DeserializingJcloudsRenamesProvider.INSTANCE.loadDeserializingMapping().put(oldId,newId); assertIsProvider(oldId, newId); ProviderRegistry.unregisterProvider(provider); assertFalse(JcloudsProviderAndApiLoader.isProvider(newId)); assertFalse(JcloudsProviderAndApiLoader.isProvider(oldId)); } finally { ProviderRegistry.unregisterProvider(provider); } }
/** * Searches for {@link ProviderMetadata} and {@link ApiMetadata} registered under the {@link Bundle} id. If metadata * are found they are removed the {@link ProviderRegistry} and {@link ApiRegistry}. Also the {@link ProviderListener} * and {@link ApiListener} are notified. * * @param bundle */ private synchronized void removeBundle(Bundle bundle) { for (ProviderMetadata providerMetadata : providerMetadataMap.removeAll(bundle.getBundleId())) { ProviderRegistry.unregisterProvider(providerMetadata); for (ProviderListener listener : providerListeners) { listener.removed(providerMetadata); } } for (ApiMetadata apiMetadata : apiMetadataMap.removeAll(bundle.getBundleId())) { ApiRegistry.unRegisterApi(apiMetadata); for (ApiListener listener : apiListeners) { listener.removed(apiMetadata); } } }
/** * Returns all available providers. * * @return all available providers */ public static Iterable<ProviderMetadata> all() { return ImmutableSet.<ProviderMetadata>builder() .addAll(fromServiceLoader()) .addAll(ProviderRegistry.fromRegistry()).build(); }
/** * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop * the bundle. In general, this method should undo the work that the <code>BundleActivator.start</code> method * started. There should be no active threads that were started by this bundle when this bundle returns. A stopped * bundle must not call any Framework objects. * <p/> * <p/> * This method must complete and return to its caller in a timely manner. * * @param context * The execution context of the bundle being stopped. * @throws Exception * If this method throws an exception, the bundle is still marked as stopped, and the Framework will * remove the bundle's listeners, unregister all services registered by the bundle, and release all * services used by the bundle. */ @Override public void stop(BundleContext context) throws Exception { bundleListener.stop(context); ProviderRegistry.clear(); ApiRegistry.clear(); if (apiListenerTracker != null) { apiListenerTracker.close(); } if (providerListenerTracker != null) { providerListenerTracker.close(); } } }
/** * Searches for {@link ProviderMetadata} and {@link ApiMetadata} inside the {@link Bundle}. If metadata are found * they are registered in the {@link ProviderRegistry} and {@link ApiRegistry}. Also the {@link ProviderListener} and * {@link ApiListener} are notified. * * @param bundle */ private synchronized void addBundle(Bundle bundle) { for (ProviderMetadata providerMetadata : listProviderMetadata(bundle)) { if (providerMetadata != null) { ProviderRegistry.registerProvider(providerMetadata); providerMetadataMap.put(bundle.getBundleId(), providerMetadata); for (ProviderListener listener : providerListeners) { listener.added(providerMetadata); } } } for (ApiMetadata apiMetadata : listApiMetadata(bundle)) { if (apiMetadata != null) { ApiRegistry.registerApi(apiMetadata); apiMetadataMap.put(bundle.getBundleId(), apiMetadata); for (ApiListener listener : apiListeners) { listener.added(apiMetadata); } } } }
/** * Searches for {@link ProviderMetadata} and {@link ApiMetadata} registered under the {@link Bundle} id. If metadata * are found they are removed the {@link ProviderRegistry} and {@link ApiRegistry}. Also the {@link ProviderListener} * and {@link ApiListener} are notified. * * @param bundle */ private synchronized void removeBundle(Bundle bundle) { for (ProviderMetadata providerMetadata : providerMetadataMap.removeAll(bundle.getBundleId())) { ProviderRegistry.unregisterProvider(providerMetadata); for (ProviderListener listener : providerListeners) { listener.removed(providerMetadata); } } for (ApiMetadata apiMetadata : apiMetadataMap.removeAll(bundle.getBundleId())) { ApiRegistry.unRegisterApi(apiMetadata); for (ApiListener listener : apiListeners) { listener.removed(apiMetadata); } } }
/** * Returns all available providers. * * @return all available providers */ public static Iterable<ProviderMetadata> all() { return ImmutableSet.<ProviderMetadata>builder() .addAll(fromServiceLoader()) .addAll(ProviderRegistry.fromRegistry()).build(); }
/** * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop * the bundle. In general, this method should undo the work that the <code>BundleActivator.start</code> method * started. There should be no active threads that were started by this bundle when this bundle returns. A stopped * bundle must not call any Framework objects. * <p/> * <p/> * This method must complete and return to its caller in a timely manner. * * @param context * The execution context of the bundle being stopped. * @throws Exception * If this method throws an exception, the bundle is still marked as stopped, and the Framework will * remove the bundle's listeners, unregister all services registered by the bundle, and release all * services used by the bundle. */ @Override public void stop(BundleContext context) throws Exception { bundleListener.stop(context); ProviderRegistry.clear(); ApiRegistry.clear(); if (apiListenerTracker != null) { apiListenerTracker.close(); } if (providerListenerTracker != null) { providerListenerTracker.close(); } } }
/** * Searches for {@link ProviderMetadata} and {@link ApiMetadata} inside the {@link Bundle}. If metadata are found * they are registered in the {@link ProviderRegistry} and {@link ApiRegistry}. Also the {@link ProviderListener} and * {@link ApiListener} are notified. * * @param bundle */ private synchronized void addBundle(Bundle bundle) { for (ProviderMetadata providerMetadata : listProviderMetadata(bundle)) { if (providerMetadata != null) { ProviderRegistry.registerProvider(providerMetadata); providerMetadataMap.put(bundle.getBundleId(), providerMetadata); for (ProviderListener listener : providerListeners) { listener.added(providerMetadata); } } } for (ApiMetadata apiMetadata : listApiMetadata(bundle)) { if (apiMetadata != null) { ApiRegistry.registerApi(apiMetadata); apiMetadataMap.put(bundle.getBundleId(), apiMetadata); for (ApiListener listener : apiListeners) { listener.added(apiMetadata); } } } }
/** * Searches for {@link ProviderMetadata} and {@link ApiMetadata} registered under the {@link Bundle} id. If metadata * are found they are removed the {@link ProviderRegistry} and {@link ApiRegistry}. Also the {@link ProviderListener} * and {@link ApiListener} are notified. * * @param bundle */ private synchronized void removeBundle(Bundle bundle) { for (ProviderMetadata providerMetadata : providerMetadataMap.removeAll(bundle.getBundleId())) { ProviderRegistry.unregisterProvider(providerMetadata); for (ProviderListener listener : providerListeners) { listener.removed(providerMetadata); } } for (ApiMetadata apiMetadata : apiMetadataMap.removeAll(bundle.getBundleId())) { ApiRegistry.unRegisterApi(apiMetadata); for (ApiListener listener : apiListeners) { listener.removed(apiMetadata); } } }
/** * Returns all available providers. * * @return all available providers */ public static Iterable<ProviderMetadata> all() { return ImmutableSet.<ProviderMetadata>builder() .addAll(fromServiceLoader()) .addAll(ProviderRegistry.fromRegistry()).build(); }
/** * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop * the bundle. In general, this method should undo the work that the <code>BundleActivator.start</code> method * started. There should be no active threads that were started by this bundle when this bundle returns. A stopped * bundle must not call any Framework objects. * <p/> * <p/> * This method must complete and return to its caller in a timely manner. * * @param context * The execution context of the bundle being stopped. * @throws Exception * If this method throws an exception, the bundle is still marked as stopped, and the Framework will * remove the bundle's listeners, unregister all services registered by the bundle, and release all * services used by the bundle. */ @Override public void stop(BundleContext context) throws Exception { bundleListener.stop(context); ProviderRegistry.clear(); ApiRegistry.clear(); if (apiListenerTracker != null) { apiListenerTracker.close(); } if (providerListenerTracker != null) { providerListenerTracker.close(); } } }
/** * Searches for {@link ProviderMetadata} and {@link ApiMetadata} inside the {@link Bundle}. If metadata are found * they are registered in the {@link ProviderRegistry} and {@link ApiRegistry}. Also the {@link ProviderListener} and * {@link ApiListener} are notified. * * @param bundle */ private synchronized void addBundle(Bundle bundle) { for (ProviderMetadata providerMetadata : listProviderMetadata(bundle)) { if (providerMetadata != null) { ProviderRegistry.registerProvider(providerMetadata); providerMetadataMap.put(bundle.getBundleId(), providerMetadata); for (ProviderListener listener : providerListeners) { listener.added(providerMetadata); } } } for (ApiMetadata apiMetadata : listApiMetadata(bundle)) { if (apiMetadata != null) { ApiRegistry.registerApi(apiMetadata); apiMetadataMap.put(bundle.getBundleId(), apiMetadata); for (ApiListener listener : apiListeners) { listener.added(apiMetadata); } } } }
/** * Searches for {@link ProviderMetadata} and {@link ApiMetadata} registered under the {@link Bundle} id. If metadata * are found they are removed the {@link ProviderRegistry} and {@link ApiRegistry}. Also the {@link ProviderListener} * and {@link ApiListener} are notified. * * @param bundle */ private synchronized void removeBundle(Bundle bundle) { for (ProviderMetadata providerMetadata : providerMetadataMap.removeAll(bundle.getBundleId())) { ProviderRegistry.unregisterProvider(providerMetadata); for (ProviderListener listener : providerListeners) { listener.removed(providerMetadata); } } for (ApiMetadata apiMetadata : apiMetadataMap.removeAll(bundle.getBundleId())) { ApiRegistry.unRegisterApi(apiMetadata); for (ApiListener listener : apiListeners) { listener.removed(apiMetadata); } } }
/** * Returns all available providers. * * @return all available providers */ public static Iterable<ProviderMetadata> all() { return ImmutableSet.<ProviderMetadata>builder() .addAll(fromServiceLoader()) .addAll(ProviderRegistry.fromRegistry()).build(); }