Skip to content

Commit

Permalink
Load PreEnforcerProvider via ExtensionId to guarantee system singleton.
Browse files Browse the repository at this point in the history
  • Loading branch information
DerSchwilk committed May 20, 2022
1 parent f51b321 commit 24c3448
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
*/
public interface PreEnforcerProvider extends DittoExtensionPoint {

static final String CONFIG_PATH = "pre-enforcer-provider";

/**
* Gets the pre-enforcer.
*/
Expand All @@ -47,12 +45,22 @@ public interface PreEnforcerProvider extends DittoExtensionPoint {
*/
static PreEnforcerProvider get(final ActorSystem actorSystem) {
checkNotNull(actorSystem, "actorSystem");
final DefaultScopedConfig dittoScoped = DefaultScopedConfig.dittoScoped(actorSystem.settings().config());
final var implementation = dittoScoped.getString(CONFIG_PATH);
return ExtensionId.INSTANCE.get(actorSystem);
}

final class ExtensionId extends DittoExtensionPoint.ExtensionId<PreEnforcerProvider> {

private static final String CONFIG_PATH = "pre-enforcer-provider";
private static final ExtensionId INSTANCE = new ExtensionId(PreEnforcerProvider.class);

private ExtensionId(final Class<PreEnforcerProvider> parentClass) {
super(parentClass);
}

@Override
protected String getConfigPath() {
return CONFIG_PATH;
}

return AkkaClassLoader.instantiate(actorSystem, PreEnforcerProvider.class,
implementation,
List.of(ActorSystem.class),
List.of(actorSystem));
}
}

0 comments on commit 24c3448

Please sign in to comment.