-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made DefaultPolicyEnforcerProvider no longer aware of sister "cache b…
…ased" implementation * let the PolicyEnforcerProvider interface decide based on config which implementation to instantiate * use the existing PolicyEnforcerCacheLoader in CachingPolicyEnforcerProvider cache to async load entries * adjusted config keys and defaults of caching to old values Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
- Loading branch information
Showing
7 changed files
with
212 additions
and
176 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
.../src/main/java/org/eclipse/ditto/policies/enforcement/AbstractPolicyEnforcerProvider.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,62 @@ | ||
/* | ||
* Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.policies.enforcement; | ||
|
||
import org.eclipse.ditto.internal.utils.cache.entry.Entry; | ||
import org.eclipse.ditto.internal.utils.cacheloaders.EnforcementCacheKey; | ||
import org.eclipse.ditto.internal.utils.cacheloaders.config.AskWithRetryConfig; | ||
import org.eclipse.ditto.internal.utils.cluster.ShardRegionProxyActorFactory; | ||
import org.eclipse.ditto.internal.utils.cluster.config.ClusterConfig; | ||
import org.eclipse.ditto.internal.utils.cluster.config.DefaultClusterConfig; | ||
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig; | ||
import org.eclipse.ditto.policies.api.PoliciesMessagingConstants; | ||
import org.eclipse.ditto.policies.enforcement.config.DefaultEnforcementConfig; | ||
|
||
import com.github.benmanes.caffeine.cache.AsyncCacheLoader; | ||
|
||
import akka.actor.ActorRef; | ||
import akka.actor.ActorSystem; | ||
import akka.dispatch.MessageDispatcher; | ||
|
||
/** | ||
* Abstract base of {@link PolicyEnforcer} implementations. | ||
*/ | ||
abstract class AbstractPolicyEnforcerProvider implements PolicyEnforcerProvider { | ||
|
||
protected AbstractPolicyEnforcerProvider() { | ||
// no-op | ||
} | ||
|
||
protected static AsyncCacheLoader<EnforcementCacheKey, Entry<PolicyEnforcer>> policyEnforcerCacheLoader( | ||
final ActorSystem actorSystem) { | ||
|
||
final DefaultScopedConfig dittoScoped = DefaultScopedConfig.dittoScoped(actorSystem.settings().config()); | ||
final AskWithRetryConfig askWithRetryConfig = DefaultEnforcementConfig.of(dittoScoped) | ||
.getAskWithRetryConfig(); | ||
|
||
final ClusterConfig clusterConfig = DefaultClusterConfig.of(dittoScoped); | ||
final ShardRegionProxyActorFactory shardRegionProxyActorFactory = | ||
ShardRegionProxyActorFactory.newInstance(actorSystem, clusterConfig); | ||
|
||
final ActorRef policiesShardRegion = shardRegionProxyActorFactory.getShardRegionProxyActor( | ||
PoliciesMessagingConstants.CLUSTER_ROLE, | ||
PoliciesMessagingConstants.SHARD_REGION | ||
); | ||
return new PolicyEnforcerCacheLoader(askWithRetryConfig, actorSystem.getScheduler(), policiesShardRegion); | ||
} | ||
|
||
protected static MessageDispatcher enforcementCacheDispatcher(final ActorSystem actorSystem) { | ||
return actorSystem.dispatchers().lookup(PolicyEnforcerCacheLoader.ENFORCEMENT_CACHE_DISPATCHER); | ||
} | ||
|
||
} |
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
Oops, something went wrong.