Skip to content

Commit

Permalink
Read implementation that should be instatiated directly from akka config
Browse files Browse the repository at this point in the history
* Since this config key is only required at this single place
  we don't add this to the java typed configuration

Signed-off-by: Yannic Klem <Yannic.Klem@bosch.io>
  • Loading branch information
Yannic92 committed May 18, 2022
1 parent 65b37a7 commit 9749916
Show file tree
Hide file tree
Showing 44 changed files with 106 additions and 729 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import java.util.List;

import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader;
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig;

import akka.actor.ActorSystem;

/**
Expand Down Expand Up @@ -46,10 +41,6 @@ public interface RootActorStarter extends DittoExtensionPoint {
static RootActorStarter get(final ActorSystem actorSystem) {
checkNotNull(actorSystem, "actorSystem");
final var implementation = actorSystem.settings().config().getString(CONFIG_PATH);

return AkkaClassLoader.instantiate(actorSystem, RootActorStarter.class,
implementation,
List.of(ActorSystem.class),
List.of(actorSystem));
return new ExtensionId<>(implementation, RootActorStarter.class).get(actorSystem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import java.util.List;

import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader;
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig;

import akka.actor.ActorContext;
import akka.actor.ActorSystem;

Expand Down Expand Up @@ -49,10 +44,6 @@ public interface RootChildActorStarter extends DittoExtensionPoint {
static RootChildActorStarter get(final ActorSystem actorSystem) {
checkNotNull(actorSystem, "actorSystem");
final var implementation = actorSystem.settings().config().getString(CONFIG_PATH);

return AkkaClassLoader.instantiate(actorSystem, RootChildActorStarter.class,
implementation,
List.of(ActorSystem.class),
List.of(actorSystem));
return new ExtensionId<>(implementation, RootChildActorStarter.class).get(actorSystem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,6 @@ public interface ConnectionConfig extends WithSupervisorConfig, WithActivityChec
*/
boolean doubleDecodingEnabled();

/**
* Returns the full qualified classname of the {@code org.eclipse.ditto.connectivity.service.messaging.validation.CustomConnectivityCommandInterceptorProvider}
* implementation to use for custom executions in {@code CustomConnectivityCommandInterceptorProvider}.
*
* @return the full qualified classname of the {@code CustomConnectivityCommandInterceptorProvider} implementation to use.
* @since 3.0.0
*/
String getCustomCommandInterceptorProvider();


/**
* Returns the full qualified classname of the
* {@code org.eclipse.ditto.connectivity.service.messaging.persistence.ConnectionPriorityProviderFactory}
* implementation to use for custom priority providers.
*
* @return the full qualified classname of the {@code ConnectionPriorityProviderFactory} implementation to use.
* @since 3.0.0
*/
String getConnectionPriorityProviderFactory();


/**
* An enumeration of the known config path expressions and their associated default values for
* {@code ConnectionConfig}.
Expand Down Expand Up @@ -246,23 +225,7 @@ enum ConnectionConfigValue implements KnownConfigValue {
/**
* Whether double decoding of usernames and passwords in connection URIs is enabled.
*/
DOUBLE_DECODING_ENABLED("double-decoding-enabled", true),

/**
* The full qualified classname of the {@code CustomConnectivityCommandInterceptorProvider} to instantiate.
*
* @since 3.0.0
*/
CUSTOM_COMMAND_INTERCEPTOR_PROVIDER("custom-command-interceptor-provider",
"org.eclipse.ditto.connectivity.service.messaging.validation.NoOpConnectivityCommandInterceptorProvider"),

/**
* The full qualified classname of the {@code ConnectionPriorityProviderFactory} to instantiate.
*
* @since 3.0.0
*/
CONNECTION_PRIORITY_PROVIDER_FACTORY("connection-priority-provider-factory",
"org.eclipse.ditto.connectivity.service.messaging.persistence.UsageBasedPriorityProviderFactory");
DOUBLE_DECODING_ENABLED("double-decoding-enabled", true);

private final String path;
private final Object defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public final class DefaultConnectionConfig implements ConnectionConfig {
private final Duration priorityUpdateInterval;
private final boolean allClientActorsOnOneNode;
private final boolean doubleDecodingEnabled;
private final String customCommandInterceptorProvider;
private final String connectionPriorityProviderFactory;

private DefaultConnectionConfig(final ConfigWithFallback config) {
clientActorAskTimeout =
Expand Down Expand Up @@ -92,10 +90,6 @@ private DefaultConnectionConfig(final ConfigWithFallback config) {
priorityUpdateInterval =
config.getNonNegativeAndNonZeroDurationOrThrow(ConnectionConfigValue.PRIORITY_UPDATE_INTERVAL);
doubleDecodingEnabled = config.getBoolean(ConnectionConfigValue.DOUBLE_DECODING_ENABLED.getConfigPath());
customCommandInterceptorProvider =
config.getString(ConnectionConfigValue.CUSTOM_COMMAND_INTERCEPTOR_PROVIDER.getConfigPath());
connectionPriorityProviderFactory =
config.getString(ConnectionConfigValue.CONNECTION_PRIORITY_PROVIDER_FACTORY.getConfigPath());
}

/**
Expand Down Expand Up @@ -227,16 +221,6 @@ public boolean doubleDecodingEnabled() {
return doubleDecodingEnabled;
}

@Override
public String getCustomCommandInterceptorProvider() {
return customCommandInterceptorProvider;
}

@Override
public String getConnectionPriorityProviderFactory() {
return connectionPriorityProviderFactory;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand Down Expand Up @@ -267,9 +251,7 @@ public boolean equals(final Object o) {
Objects.equals(ackLabelDeclareInterval, that.ackLabelDeclareInterval) &&
Objects.equals(priorityUpdateInterval, that.priorityUpdateInterval) &&
allClientActorsOnOneNode == that.allClientActorsOnOneNode &&
doubleDecodingEnabled == that.doubleDecodingEnabled &&
Objects.equals(customCommandInterceptorProvider, that.customCommandInterceptorProvider) &&
Objects.equals(connectionPriorityProviderFactory, that.connectionPriorityProviderFactory);
doubleDecodingEnabled == that.doubleDecodingEnabled;
}

@Override
Expand All @@ -278,8 +260,7 @@ public int hashCode() {
blockedHostnames, blockedSubnets, blockedHostRegex, supervisorConfig, snapshotConfig,
acknowledgementConfig, cleanupConfig, maxNumberOfTargets, maxNumberOfSources, activityCheckConfig,
amqp10Config, amqp091Config, mqttConfig, kafkaConfig, httpPushConfig, ackLabelDeclareInterval,
priorityUpdateInterval, allClientActorsOnOneNode, doubleDecodingEnabled,
customCommandInterceptorProvider, connectionPriorityProviderFactory);
priorityUpdateInterval, allClientActorsOnOneNode, doubleDecodingEnabled);
}

@Override
Expand Down Expand Up @@ -307,8 +288,6 @@ public String toString() {
", priorityUpdateInterval=" + priorityUpdateInterval +
", allClientActorsOnOneNode=" + allClientActorsOnOneNode +
", doubleDecodingEnabled=" + doubleDecodingEnabled +
", customCommandInterceptorProvider=" + customCommandInterceptorProvider +
", connectionPriorityProviderFactory=" + connectionPriorityProviderFactory +
"]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.Arrays;

import org.eclipse.ditto.base.service.DittoExtensionPoint;
import org.eclipse.ditto.connectivity.model.ConnectionId;
import org.eclipse.ditto.internal.models.signalenrichment.DefaultSignalEnrichmentConfig;
import org.eclipse.ditto.internal.models.signalenrichment.SignalEnrichmentConfig;
Expand All @@ -23,7 +24,6 @@
import akka.actor.AbstractExtensionId;
import akka.actor.ActorSystem;
import akka.actor.ExtendedActorSystem;
import akka.actor.Extension;

/**
* Provider of {@link SignalEnrichmentFacade} to be loaded by reflection.
Expand All @@ -34,7 +34,7 @@
* <li>Config config: configuration for the facade provider.</li>
* </ul>
*/
public abstract class ConnectivitySignalEnrichmentProvider implements Extension {
public abstract class ConnectivitySignalEnrichmentProvider implements DittoExtensionPoint {

/**
* Create a signal-enriching facade from the ID of a connection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import java.util.List;

import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.service.DittoExtensionPoint;
import org.eclipse.ditto.connectivity.model.Connection;
import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader;

import com.typesafe.config.Config;

Expand Down Expand Up @@ -62,11 +59,7 @@ Props getActorPropsForType(Connection connection,
static ClientActorPropsFactory get(final ActorSystem actorSystem) {
checkNotNull(actorSystem, "actorSystem");
final var implementation = actorSystem.settings().config().getString(CONFIG_PATH);

return AkkaClassLoader.instantiate(actorSystem, ClientActorPropsFactory.class,
implementation,
List.of(ActorSystem.class),
List.of(actorSystem));
return new ExtensionId<>(implementation, ClientActorPropsFactory.class).get(actorSystem);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import java.util.List;

import org.eclipse.ditto.base.service.DittoExtensionPoint;
import org.eclipse.ditto.connectivity.service.config.DittoConnectivityConfig;
import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader;
import org.eclipse.ditto.internal.utils.akka.logging.DittoDiagnosticLoggingAdapter;
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
Expand All @@ -30,6 +25,8 @@
*/
public interface ConnectionPriorityProviderFactory extends DittoExtensionPoint {

String CONFIG_PATH = "ditto.connectivity.connection.connection-priority-provider-factory";

/**
* Creates a connection priority provider based on the connection persistence actor and its logger.
*
Expand All @@ -51,14 +48,8 @@ ConnectionPriorityProvider newProvider(ActorRef connectionPersistenceActor,
*/
static ConnectionPriorityProviderFactory get(final ActorSystem actorSystem) {
checkNotNull(actorSystem, "actorSystem");
final var implementation =
DittoConnectivityConfig.of(DefaultScopedConfig.dittoScoped(
actorSystem.settings().config())).getConnectionConfig().getConnectionPriorityProviderFactory();

return AkkaClassLoader.instantiate(actorSystem, ConnectionPriorityProviderFactory.class,
implementation,
List.of(ActorSystem.class),
List.of(actorSystem));
final var implementation = actorSystem.settings().config().getString(CONFIG_PATH);
return new ExtensionId<>(implementation, ConnectionPriorityProviderFactory.class).get(actorSystem);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import java.util.List;

import org.eclipse.ditto.base.service.DittoExtensionPoint;
import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommandInterceptor;
import org.eclipse.ditto.connectivity.service.config.DittoConnectivityConfig;
import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader;
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig;

import akka.actor.ActorSystem;

public interface CustomConnectivityCommandInterceptorProvider extends DittoExtensionPoint {

String CONFIG_PATH = "ditto.connectivity.connection.custom-command-interceptor-provider";

ConnectivityCommandInterceptor getCommandInterceptor();

/**
Expand All @@ -38,13 +35,8 @@ public interface CustomConnectivityCommandInterceptorProvider extends DittoExten
*/
static CustomConnectivityCommandInterceptorProvider get(final ActorSystem actorSystem) {
checkNotNull(actorSystem, "actorSystem");
final var implementation = DittoConnectivityConfig.of(DefaultScopedConfig.dittoScoped(
actorSystem.settings().config())).getConnectionConfig().getCustomCommandInterceptorProvider();

return AkkaClassLoader.instantiate(actorSystem, CustomConnectivityCommandInterceptorProvider.class,
implementation,
List.of(ActorSystem.class),
List.of(actorSystem));
final var implementation = actorSystem.settings().config().getString(CONFIG_PATH);
return new ExtensionId<>(implementation, CustomConnectivityCommandInterceptorProvider.class).get(actorSystem);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import java.util.List;
import java.util.function.UnaryOperator;

import org.eclipse.ditto.base.model.signals.Signal;
import org.eclipse.ditto.base.service.DittoExtensionPoint;
import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader;
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig;

import akka.actor.ActorSystem;

public interface SignalTransformer extends DittoExtensionPoint, UnaryOperator<Signal<?>> {

static final String CONFIG_PATH = "signal-transformer";
static final String CONFIG_PATH = "ditto.signal-transformer";

/**
* Loads the implementation of {@code SignalTransformer} which is configured for the
Expand All @@ -38,12 +35,7 @@ public interface SignalTransformer extends DittoExtensionPoint, UnaryOperator<Si
*/
static SignalTransformer get(final ActorSystem actorSystem) {
checkNotNull(actorSystem, "actorSystem");
final DefaultScopedConfig dittoScoped = DefaultScopedConfig.dittoScoped(actorSystem.settings().config());
final var implementation = dittoScoped.getString(CONFIG_PATH);

return AkkaClassLoader.instantiate(actorSystem, SignalTransformer.class,
implementation,
List.of(ActorSystem.class),
List.of(actorSystem));
final var implementation = actorSystem.settings().config().getString(CONFIG_PATH);
return new ExtensionId<>(implementation, SignalTransformer.class).get(actorSystem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.concurrent.CompletableFuture;

import org.eclipse.ditto.base.model.headers.translator.HeaderTranslator;
import org.eclipse.ditto.base.service.DittoExtensionPoint;
import org.eclipse.ditto.gateway.service.util.config.endpoints.CommandConfig;
import org.eclipse.ditto.gateway.service.util.config.endpoints.HttpConfig;

Expand All @@ -27,7 +28,8 @@
* Factory of props of actors that handle HTTP requests.
*/
@FunctionalInterface
public interface HttpRequestActorPropsFactory {
//TODO: Yannic fix this extension
public interface HttpRequestActorPropsFactory extends DittoExtensionPoint {

/**
* Create Props object of an actor to handle 1 HTTP request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*/
public interface GatewayAuthenticationDirectiveFactory extends DittoExtensionPoint {

String CONFIG_PATH = "ditto.gateway.authentication.gateway-authentication-directive-factory";

/**
* Builds the {@link GatewayAuthenticationDirective authentication directive} that should be used for HTTP API.
*
Expand All @@ -52,10 +54,7 @@ public interface GatewayAuthenticationDirectiveFactory extends DittoExtensionPoi
*/
static GatewayAuthenticationDirectiveFactory get(final ActorSystem actorSystem) {
checkNotNull(actorSystem, "actorSystem");
final AuthenticationConfig authenticationConfig =
DittoGatewayConfig.of(DefaultScopedConfig.dittoScoped(actorSystem.settings().config()))
.getAuthenticationConfig();
final var implementation = authenticationConfig.getGatewayAuthenticationDirectiveFactory();
final var implementation = actorSystem.settings().config().getString(CONFIG_PATH);
return new ExtensionId<>(implementation, GatewayAuthenticationDirectiveFactory.class).get(actorSystem);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.base.service.DittoExtensionPoint;
import org.eclipse.ditto.gateway.service.util.config.DittoGatewayConfig;
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig;

import akka.actor.ActorSystem;
import akka.http.javadsl.server.Route;
Expand All @@ -29,6 +27,8 @@
*/
public interface CustomApiRoutesProvider extends DittoExtensionPoint {

String CONFIG_PATH = "ditto.gateway.http.custom-api-routes-provider";

/**
* Provides a custom route for unauthorized access.
*
Expand Down Expand Up @@ -58,8 +58,7 @@ public interface CustomApiRoutesProvider extends DittoExtensionPoint {
*/
static CustomApiRoutesProvider get(final ActorSystem actorSystem) {
checkNotNull(actorSystem, "actorSystem");
final var implementation = DittoGatewayConfig.of(DefaultScopedConfig.dittoScoped(
actorSystem.settings().config())).getHttpConfig().getCustomApiRoutesProvider();
final var implementation = actorSystem.settings().config().getString(CONFIG_PATH);

return new ExtensionId<>(implementation, CustomApiRoutesProvider.class).get(actorSystem);
}
Expand Down
Loading

0 comments on commit 9749916

Please sign in to comment.