-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OSGi condition which is satisfied once the default Ehcache services
are registered This allows to defer starting of custom OSGi DS component which rely on the EhcacheManager in their activate() method until the Ehcache services are registered This closes #3232
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
ehcache-impl/src/main/java/org/ehcache/impl/osgi/EhcacheReadyCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Terracotta, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.ehcache.impl.osgi; | ||
|
||
import org.ehcache.core.EhcacheManager; | ||
import org.ehcache.core.events.CacheEventDispatcherFactory; | ||
import org.ehcache.core.events.CacheEventListenerProvider; | ||
import org.ehcache.core.spi.service.ServiceFactory; | ||
import org.ehcache.core.spi.store.Store; | ||
import org.ehcache.impl.internal.spi.resilience.DefaultResilienceStrategyProvider; | ||
import org.ehcache.impl.internal.store.tiering.TieredStore; | ||
import org.ehcache.impl.internal.store.tiering.TieredStoreProviderFactory; | ||
import org.ehcache.spi.loaderwriter.CacheLoaderWriterProvider; | ||
import org.ehcache.spi.loaderwriter.WriteBehindProvider; | ||
import org.ehcache.spi.resilience.ResilienceStrategyProvider; | ||
import org.osgi.service.component.ComponentConstants; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
import org.osgi.service.condition.Condition; | ||
|
||
/** | ||
* The condition is satisfied once all default {@link ServiceFactory} objects mentioned in {@link EhcacheManager} are registered. | ||
* Those are | ||
* <ol> | ||
* <li>{@link Store.Provider} provided through DS component {@link TieredStoreProviderFactory}</li> | ||
* <li>{@link CacheLoaderWriterProvider} provided through DS component {@link DefaultCacheLoaderWriterProviderFactory}</li> | ||
* <li>{@link WriteBehindProvider} provided through DS component {@link WriteBehindProviderFactory}</li> | ||
* <li>{@link CacheEventDispatcherFactory} provided through DS component {@link CacheEventNotificationListenerServiceProviderFactory}</li> | ||
* <li>{@link CacheEventListenerProvider} provided through DS component {@link DefaultCacheEventListenerProviderFactory}</li> | ||
* <li>{@link ResilienceStrategyProvider} provided through DS component {@link DefaultResilienceStrategyProvider}</li> | ||
* </ol> | ||
* Because those services are not provided directly but through {@link ServiceFactory} this condition references directly the responsible default factories (via their component name) | ||
*/ | ||
@Component(property = Condition.CONDITION_ID + "=ehcache") | ||
public class EhcacheReadyCondition implements Condition { | ||
|
||
@Reference(target = "("+ComponentConstants.COMPONENT_NAME+"=org.ehcache.impl.internal.store.tiering.TieredStoreProviderFactory)") | ||
private ServiceFactory<TieredStore.Provider> storeProviderFactory; | ||
|
||
@Reference(target = "("+ComponentConstants.COMPONENT_NAME+"=org.ehcache.impl.internal.spi.loaderwriter.DefaultCacheLoaderWriterProviderFactory)") | ||
private ServiceFactory<CacheLoaderWriterProvider> cacheLoaderWriterProviderFactory; | ||
|
||
@Reference(target = "("+ComponentConstants.COMPONENT_NAME+"=org.ehcache.impl.internal.loaderwriter.writebehind.WriteBehindProviderFactory)") | ||
private ServiceFactory<WriteBehindProvider> writeBehindProviderFactory; | ||
|
||
@Reference(target = "("+ComponentConstants.COMPONENT_NAME+"=org.ehcache.impl.internal.events.CacheEventNotificationListenerServiceProviderFactory)") | ||
private ServiceFactory<CacheEventDispatcherFactory> cacheEventNotificationListenerServiceProviderFactory; | ||
|
||
@Reference(target = "("+ComponentConstants.COMPONENT_NAME+"=org.ehcache.impl.internal.spi.event.DefaultCacheEventListenerProviderFactory)") | ||
private ServiceFactory<CacheEventListenerProvider> cacheEventListenerProviderFactory; | ||
|
||
@Reference(target = "("+ComponentConstants.COMPONENT_NAME+"=org.ehcache.impl.internal.spi.resilience.DefaultResilienceStrategyProviderFactory)") | ||
private ServiceFactory<ResilienceStrategyProvider> resilienceStrategyProviderFactory; | ||
} |