Skip to content

Commit

Permalink
Review: Optimize configurability of extension
Browse files Browse the repository at this point in the history
Signed-off-by: David Schwilk <david.schwilk@bosch.io>
  • Loading branch information
DerSchwilk committed Jul 20, 2022
1 parent 137cfba commit 4334505
Show file tree
Hide file tree
Showing 39 changed files with 66 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private ConnectivityRootActor(final ConnectivityConfig connectivityConfig,

final ClusterConfig clusterConfig = connectivityConfig.getClusterConfig();
final ActorSystem actorSystem = getContext().system();
final Config config = actorSystem.settings().config();

final ActorRef commandForwarder = getCommandForwarder(clusterConfig, pubSubMediator);

Expand All @@ -101,7 +102,6 @@ private ConnectivityRootActor(final ConnectivityConfig connectivityConfig,
startConnectionShardRegion(actorSystem, connectionSupervisorProps, clusterConfig),
connectivityConfig.getPingConfig(), mongoReadJournal),
PersistencePingActor.ACTOR_NAME);
final Config config = actorSystem.settings().config();
final ConnectionIdsRetrievalConfig connectionIdsRetrievalConfig =
connectivityConfig.getConnectionIdsRetrievalConfig();
final ActorRef connectionIdsRetrievalActor = startChildActor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public interface ConnectivitySignalEnrichmentProvider extends DittoExtensionPoin
* Load a {@code ConnectivitySignalEnrichmentProvider} dynamically according to the streaming configuration.
*
* @param actorSystem The actor system in which to load the facade provider class.
* @param config the config the extension is configured.
* @return The configured facade provider.
*/
static ConnectivitySignalEnrichmentProvider get(final ActorSystem actorSystem, final Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class UsageBasedPriorityProviderFactory implements ConnectionPriorityProv

/**
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
protected UsageBasedPriorityProviderFactory(final ActorSystem actorSystem, final Config config) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class NoOpConnectivityCommandInterceptorProvider implements CustomConnect

/**
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
protected NoOpConnectivityCommandInterceptorProvider(final ActorSystem actorSystem, final Config config) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import akka.actor.ActorSystem;
import akka.actor.Props;

public class ExceptionClientActorPropsFactory implements ClientActorPropsFactory{
@SuppressWarnings("unused")
public class ExceptionClientActorPropsFactory implements ClientActorPropsFactory {

/**
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
@SuppressWarnings("unused")
protected ExceptionClientActorPropsFactory(final ActorSystem actorSystem, final Config config) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ExceptionalCommandValidator implements CustomConnectivityCommandInt

/**
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
protected ExceptionalCommandValidator(final ActorSystem actorSystem, final Config config) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
import akka.actor.ActorSystem;
import akka.actor.Props;

@SuppressWarnings("unused")
public final class FaultyClientActorPropsFactory implements ClientActorPropsFactory {

private final boolean allowFirstCreateCommand;
private final boolean allowCloseCommands;

/**
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
protected FaultyClientActorPropsFactory(final ActorSystem actorSystem, final Config config) {
@SuppressWarnings("unused")
private FaultyClientActorPropsFactory(final ActorSystem actorSystem, final Config config) {
allowFirstCreateCommand = actorSystem.settings().config().getBoolean("allowFirstCreateCommand");
allowCloseCommands = actorSystem.settings().config().getBoolean("allowCloseCommands");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
import akka.cluster.pubsub.DistributedPubSubMediator;
import akka.event.DiagnosticLoggingAdapter;

@SuppressWarnings("unused")
public final class MockClientActorPropsFactory implements ClientActorPropsFactory {

/**
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
public MockClientActorPropsFactory(final ActorSystem actorSystem, final Config config) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@
import akka.event.DiagnosticLoggingAdapter;
import akka.japi.pf.ReceiveBuilder;

@SuppressWarnings("unused")
public final class SearchForwardingClientActorPropsFactory implements ClientActorPropsFactory {

/**
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
@SuppressWarnings("unused")
public SearchForwardingClientActorPropsFactory(final ActorSystem actorSystem, final Config config) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
public interface EdgeCommandForwarderExtension extends DittoExtensionPoint {

/**
* Loads the implementation of {@code RootChildActorStarter} which is configured for the
* Loads the implementation of {@code EdgeCommandForwarderExtension} which is configured for the
* {@code ActorSystem}.
*
* @param actorSystem the actorSystem in which the {@code RootChildActorStarter} should be loaded.
* @param actorSystem the actorSystem in which the {@code EdgeCommandForwarderExtension} should be loaded.
* @param config the configuration for this extension.
* @return the {@code RootChildActorStarter} implementation.
* @return the {@code EdgeCommandForwarderExtension} implementation.
* @throws NullPointerException if {@code actorSystem} is {@code null}.
*/
static EdgeCommandForwarderExtension get(final ActorSystem actorSystem, final Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public final class NoOpEdgeCommandForwarderExtension implements EdgeCommandForwa
* Constructs a new instance of NoOpEdgeCommandForwarderExtension.
*
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
@SuppressWarnings("unused")
public NoOpEdgeCommandForwarderExtension(final ActorSystem actorSystem, final Config config) {
// no-op
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public final class DefaultNamespaceAppender implements SignalTransformer {
* Constructs a new instance of DefaultNamespaceAppender extension.
*
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
@SuppressWarnings("unused")
public DefaultNamespaceAppender(final ActorSystem actorSystem, final Config config) {
defaultNamespace = config.hasPath(DEFAULT_NAMESPACE_CONFIG_KEY) ?
config.getString(DEFAULT_NAMESPACE_CONFIG_KEY) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public final class OriginatorSetterSignalTransformer implements SignalTransforme
* Constructs a new instance of HeaderSetterPreEnforcer extension.
*
* @param actorSystem the actor system in which to load the extension.
* @param config the configuration for this extension.
*/
@SuppressWarnings("unused")
public OriginatorSetterSignalTransformer(final ActorSystem actorSystem, final Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public final class LoggingHttpBindFlowProvider implements HttpBindFlowProvider {

/**
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
@SuppressWarnings("unused")
public LoggingHttpBindFlowProvider(final ActorSystem actorSystem, final Config config) {
this.actorSystem = actorSystem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public final class NoOpSseConnectionSupervisor implements SseConnectionSuperviso

/**
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
@SuppressWarnings("unused")
public NoOpSseConnectionSupervisor(final ActorSystem actorSystem, final Config config) {
//No-Op because extensions need a constructor accepting an actorSystem
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
public final class NoOpSseEventSniffer implements SseEventSniffer {

@SuppressWarnings("unused")
public NoOpSseEventSniffer(final ActorSystem actorSystem, final Config config) {
//No-Op because extensions need a constructor accepting an actorSystem
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public interface SseConnectionSupervisor extends DittoExtensionPoint, StreamSupe
* {@code ActorSystem}.
*
* @param actorSystem the actorSystem in which the {@code SseConnectionSupervisor} should be loaded.
* @param config the config the extension is configured.
* @return the {@code SseConnectionSupervisor} implementation.
* @throws NullPointerException if {@code actorSystem} is {@code null}.
* @since 3.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public interface SseEventSniffer extends DittoExtensionPoint {
* {@code ActorSystem}.
*
* @param actorSystem the actorSystem in which the {@code SseEventSniffer} should be loaded.
* @param config the config the extension is configured.
* @return the {@code SseEventSniffer} implementation.
* @throws NullPointerException if {@code actorSystem} is {@code null}.
* @since 3.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final class NoOpWebSocketConfigProvider implements WebSocketConfigProvide

/**
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
@SuppressWarnings("unused")
public NoOpWebSocketConfigProvider(final ActorSystem actorSystem, final Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public final class NoOpWebSocketSupervisor implements WebSocketSupervisor {

/**
* @param actorSystem the actor system in which to load the extension.
* @param config the config the extension is configured.
*/
@SuppressWarnings("unused")
public NoOpWebSocketSupervisor(final ActorSystem actorSystem, final Config config) {
//No-Op because extensions need a constructor accepting an actorSystem
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public interface WebSocketSupervisor extends DittoExtensionPoint, StreamSupervis
* {@code ActorSystem}.
*
* @param actorSystem the actorSystem in which the {@code WebSocketSupervisor} should be loaded.
* @param config the config the extension is configured.
* @return the {@code WebSocketSupervisor} implementation.
* @throws NullPointerException if {@code actorSystem} is {@code null}.
* @since 3.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public final class DefaultGatewaySignalEnrichmentProvider implements GatewaySignalEnrichmentProvider {

private static final String CONCIERGE_FORWARDER = "/user/gatewayRoot/" + EdgeCommandForwarderActor.ACTOR_NAME;
private static final String COMMAND_FORWARDER = "/user/gatewayRoot/" + EdgeCommandForwarderActor.ACTOR_NAME;
private static final String CACHE_LOADER_DISPATCHER = "signal-enrichment-cache-dispatcher";

private final SignalEnrichmentFacade facade;
Expand All @@ -42,9 +42,10 @@ public final class DefaultGatewaySignalEnrichmentProvider implements GatewaySign
* Instantiate this provider. Called by reflection.
*
* @param actorSystem The actor system for which this provider is instantiated.
* @param config the config the extension is configured.
*/
public DefaultGatewaySignalEnrichmentProvider(final ActorSystem actorSystem, final Config config) {
final var commandHandler = actorSystem.actorSelection(CONCIERGE_FORWARDER);
final var commandHandler = actorSystem.actorSelection(COMMAND_FORWARDER);
final var providerConfig = DefaultSignalEnrichmentProviderConfig.of(config);
final var delegate = ByRoundTripSignalEnrichmentFacade.of(commandHandler, providerConfig.getAskTimeout());
if (providerConfig.isCachingEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public DittoJwtAuthorizationSubjectsProvider(final ActorSystem actorSystem, fina
}

private DittoJwtAuthorizationSubjectsProvider(final JwtSubjectIssuersConfig jwtSubjectIssuersConfig) {

this.jwtSubjectIssuersConfig = checkNotNull(jwtSubjectIssuersConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ private ExtensionId(final ExtensionIdConfig<JwtAuthorizationSubjectsProvider> ex
}

static ExtensionIdConfig<JwtAuthorizationSubjectsProvider> computeConfig(final Config config) {

return ExtensionIdConfig.of(JwtAuthorizationSubjectsProvider.class, config, CONFIG_KEY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ private GatewayRootActor(final GatewayConfig gatewayConfig, final ActorRef pubSu
healthCheckActor, pubSubMediator, healthCheckConfig, jwtAuthenticationFactory,
devopsAuthenticationDirectiveFactory, protocolAdapterProvider, headerTranslator);


httpBinding = Http.get(actorSystem)
.newServerAt(hostname, httpConfig.getPort())
.bindFlow(HttpBindFlowProvider.get(actorSystem, dittoExtensionConfig).getFlow(rootRoute))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public final class NoOpAuthorizationEnforcer implements StreamingAuthorizationEn

/**
* @param actorSystem the actor system in which to load the extension.
*@param config the configuration for this extension.
*/
@SuppressWarnings("unused")
public NoOpAuthorizationEnforcer(final ActorSystem actorSystem, final Config config) {
//No-Op because extensions need a constructor accepting an actorSystem
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ public interface StreamingAuthorizationEnforcer extends DittoExtensionPoint {
CompletionStage<DittoHeaders> checkAuthorization(RequestContext requestContext, DittoHeaders dittoHeaders);

/**
* Loads the implementation of {@code WebSocketAuthorizationEnforcer} which is configured for the
* Loads the implementation of {@code StreamingAuthorizationEnforcer} which is configured for the
* {@code ActorSystem}.
*
* @param actorSystem the actorSystem in which the {@code WebSocketAuthorizationEnforcer} should be loaded.
* @return the {@code WebSocketAuthorizationEnforcer} implementation.
* @param actorSystem the actorSystem in which the {@code StreamingAuthorizationEnforcer} should be loaded.
* @param config the configuration for this extension.
* @return the {@code StreamingAuthorizationEnforcer} implementation.
* @throws NullPointerException if {@code actorSystem} is {@code null}.
* @since 3.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public record ExtensionIdConfig<T extends Extension>(Class<T> parentClass,
* @param configKey the configuration key on root level of the given config.
* @param <T> The type of the extension that should be initialized.
* @return the extension id config.
* @throws com.typesafe.config.ConfigException.WrongType in case neither an object nor a string is configured at the config key of config.
* @throws com.typesafe.config.ConfigException.WrongType in case neither an object nor a string is
* configured at the config key of config.
*/
public static <T extends akka.actor.Extension> ExtensionIdConfig<T> of(
final Class<T> parentClass,
Expand All @@ -127,6 +128,7 @@ public static <T extends akka.actor.Extension> ExtensionIdConfig<T> of(
@SuppressWarnings("unchecked")
public static <T extends Extension> ExtensionIdConfig<T> of(final Class<T> parentClass,
final ConfigValue configValue) {

final var valueType = configValue.valueType();
final Object unwrappedValue = configValue.unwrapped();
if (valueType == ConfigValueType.OBJECT) {
Expand All @@ -148,6 +150,7 @@ private static <T extends Extension> ExtensionIdConfig<T> ofStringConfig(
private static <T extends Extension> ExtensionIdConfig<T> ofObjectConfig(
final Class<T> parentClass,
final Config config) {

@Nullable final String extensionClass;
final Config extensionConfig;
if (config.hasPath(EXTENSION_CLASS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class BlockedNamespacePreEnforcer implements PreEnforcer {
* Constructs a new instance of BlockedNamespacePreEnforcer extension.
*
* @param actorSystem the actor system in which to load the extension.
* @param config the configuration for this extension.
*/
@SuppressWarnings("unused")
public BlockedNamespacePreEnforcer(final ActorSystem actorSystem, final Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public final class CommandWithOptionalEntityPreEnforcer implements PreEnforcer {
* Constructs a new instance of CommandWithOptionalEntityPreEnforcer extension.
*
* @param actorSystem the actor system in which to load the extension.
* @param config the configuration for this extension.
*/
@SuppressWarnings("unused")
public CommandWithOptionalEntityPreEnforcer(final ActorSystem actorSystem, final Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public final class CreationRestrictionPreEnforcer implements PreEnforcer {
* Constructs a new instance of CreationRestrictionPreEnforcer extension.
*
* @param actorSystem the actor system in which to load the extension.
* @param config the configuration for this extension.
*/
@SuppressWarnings("unused")
public CreationRestrictionPreEnforcer(final ActorSystem actorSystem, final Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ private PreEnforcerProvider(final ActorSystem actorSystem, final Config config)
.toList();
}


/**
* Applies the pre-enforcement to the signal.
*
Expand All @@ -86,6 +85,7 @@ public CompletionStage<Signal<?>> apply(final Signal<?> signal) {
* {@code ActorSystem}.
*
* @param actorSystem the actorSystem in which the {@code PreEnforcerProvider} should be loaded.
* @param config the configuration for this extension.
* @return the {@code PreEnforcerProvider} implementation.
* @throws NullPointerException if {@code actorSystem} is {@code null}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class PoliciesPlaceholderSubstitution extends AbstractPlaceholderSubstitu
* Constructs a new instance of PoliciesPlaceholderSubstitutionPreEnforcer extension.
*
* @param actorSystem the actor system in which to load the extension.
* @param config the configuration for this extension.
*/
@SuppressWarnings("unused")
public PoliciesPlaceholderSubstitution(final ActorSystem actorSystem, final Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ThingsPlaceholderSubstitution extends AbstractPlaceholderSubstituti
* Constructs a new instance of ThingsPlaceholderSubstitutionPreEnforcer extension.
*
* @param actorSystem the actor system in which to load the extension.
* @param config the configuration for this extension.
*/
@SuppressWarnings("unused")
public ThingsPlaceholderSubstitution(final ActorSystem actorSystem, final Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public final class DefaultQueryCriteriaValidator implements QueryCriteriaValidat

/**
* Instantiate this provider. Called by reflection.
* @param actorSystem the actor system in which to load the extension.
* @param config the configuration for this extension.
*/
@SuppressWarnings("unused")
public DefaultQueryCriteriaValidator(final ActorSystem actorSystem, final Config config) {
// Nothing to initialize.
}
Expand Down

0 comments on commit 4334505

Please sign in to comment.