Skip to content

Commit

Permalink
Make all DittoExtensionPoint implementations accept two parameters in…
Browse files Browse the repository at this point in the history
… their constructor

Signed-off-by: Yannic Klem <yannic.klem@bosch.io>
  • Loading branch information
Yannic92 committed Jul 8, 2022
1 parent a13d5ab commit cc2f261
Show file tree
Hide file tree
Showing 35 changed files with 110 additions and 34 deletions.
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.ditto.base.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -51,6 +52,10 @@ protected ExtensionId(final ExtensionIdConfig<T> extensionIdConfig) {
this.extensionIdConfig = extensionIdConfig;
}

protected ExtensionId(final Class<T> parentClass) {
this(new ExtensionIdConfig<>(parentClass, null, ConfigFactory.empty()));
}

@Override
public T createExtension(final ExtendedActorSystem system) {
return AkkaClassLoader.instantiate(system, extensionIdConfig.parentClass,
Expand All @@ -61,7 +66,12 @@ public T createExtension(final ExtendedActorSystem system) {

protected String getImplementation(final ExtendedActorSystem actorSystem) {
if (extensionIdConfig.extensionClass == null) {
return actorSystem.settings().config().getString(getConfigPath());
final Object anyRef = actorSystem.settings().config().getAnyRef(getConfigPath());
if (anyRef instanceof Map<?, ?> map) {
return map.get("extension-class").toString();
} else {
return anyRef.toString();
}
} else {
return extensionIdConfig.extensionClass;
}
Expand Down
Expand Up @@ -12,6 +12,8 @@
*/
package org.eclipse.ditto.base.service;

import com.typesafe.config.Config;

import akka.actor.ActorSystem;

/**
Expand All @@ -22,7 +24,7 @@ public final class NoOpRootActorStarter implements RootActorStarter {
/**
* @param actorSystem the actor system in which to load the extension.
*/
public NoOpRootActorStarter(final ActorSystem actorSystem) {
public NoOpRootActorStarter(final ActorSystem actorSystem, final Config config) {
//No-Op because extensions need a constructor accepting an actorSystem
}

Expand Down
Expand Up @@ -15,14 +15,16 @@
import org.eclipse.ditto.connectivity.model.ConnectionId;
import org.eclipse.ditto.connectivity.service.enforcement.ConnectionEnforcerActorPropsFactory;

import com.typesafe.config.Config;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;

public final class NoOpEnforcerActorPropsFactory implements ConnectionEnforcerActorPropsFactory {

NoOpEnforcerActorPropsFactory(final ActorSystem actorSystem) {
NoOpEnforcerActorPropsFactory(final ActorSystem actorSystem, final Config config) {
//NoOp Constructor to match extension initialization
}

Expand Down
Expand Up @@ -37,7 +37,7 @@
@Immutable
public final class DefaultClientActorPropsFactory implements ClientActorPropsFactory {

public DefaultClientActorPropsFactory(final ActorSystem actorSystem) {
public DefaultClientActorPropsFactory(final ActorSystem actorSystem, final Config config) {
}

@Override
Expand Down
Expand Up @@ -14,6 +14,8 @@

import org.eclipse.ditto.internal.utils.akka.logging.DittoDiagnosticLoggingAdapter;

import com.typesafe.config.Config;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;

Expand All @@ -22,7 +24,7 @@ public class UsageBasedPriorityProviderFactory implements ConnectionPriorityProv
/**
* @param actorSystem the actor system in which to load the extension.
*/
protected UsageBasedPriorityProviderFactory(final ActorSystem actorSystem) {
protected UsageBasedPriorityProviderFactory(final ActorSystem actorSystem, final Config config) {
}

@Override
Expand Down
Expand Up @@ -18,14 +18,16 @@
import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand;
import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommandInterceptor;

import com.typesafe.config.Config;

import akka.actor.ActorSystem;

public class NoOpConnectivityCommandInterceptorProvider implements CustomConnectivityCommandInterceptorProvider{

/**
* @param actorSystem the actor system in which to load the extension.
*/
protected NoOpConnectivityCommandInterceptorProvider(final ActorSystem actorSystem) {
protected NoOpConnectivityCommandInterceptorProvider(final ActorSystem actorSystem, final Config config) {
}

@Override
Expand Down
Expand Up @@ -27,7 +27,7 @@ public class ExceptionClientActorPropsFactory implements ClientActorPropsFactory
/**
* @param actorSystem the actor system in which to load the extension.
*/
protected ExceptionClientActorPropsFactory(final ActorSystem actorSystem) {
protected ExceptionClientActorPropsFactory(final ActorSystem actorSystem, final Config config) {

}

Expand Down
Expand Up @@ -20,14 +20,16 @@
import org.eclipse.ditto.connectivity.model.signals.commands.exceptions.ConnectionUnavailableException;
import org.eclipse.ditto.connectivity.service.messaging.validation.CustomConnectivityCommandInterceptorProvider;

import com.typesafe.config.Config;

import akka.actor.ActorSystem;

public class ExceptionalCommandValidator implements CustomConnectivityCommandInterceptorProvider {

/**
* @param actorSystem the actor system in which to load the extension.
*/
protected ExceptionalCommandValidator(final ActorSystem actorSystem) {
protected ExceptionalCommandValidator(final ActorSystem actorSystem, final Config config) {
}

@Override
Expand Down
Expand Up @@ -34,7 +34,7 @@ public final class FailingActorProvider implements ClientActorPropsFactory {
private final int retriesUntilSuccess;
private int current = 0;

public FailingActorProvider(final ActorSystem actorSystem) {
public FailingActorProvider(final ActorSystem actorSystem, final Config config) {
retriesUntilSuccess = actorSystem.settings().config().getInt("failingRetries");
}

Expand Down
Expand Up @@ -29,7 +29,7 @@ public final class FaultyClientActorPropsFactory implements ClientActorPropsFact
/**
* @param actorSystem the actor system in which to load the extension.
*/
protected FaultyClientActorPropsFactory(final ActorSystem actorSystem) {
protected FaultyClientActorPropsFactory(final ActorSystem actorSystem, final Config config) {
allowFirstCreateCommand = actorSystem.settings().config().getBoolean("allowFirstCreateCommand");
allowCloseCommands = actorSystem.settings().config().getBoolean("allowCloseCommands");
}
Expand Down
Expand Up @@ -53,7 +53,7 @@ public final class MockClientActorPropsFactory implements ClientActorPropsFactor
/**
* @param actorSystem the actor system in which to load the extension.
*/
public MockClientActorPropsFactory(final ActorSystem actorSystem) {
public MockClientActorPropsFactory(final ActorSystem actorSystem, final Config config) {
}

@Override
Expand Down
Expand Up @@ -37,7 +37,7 @@ public final class SearchForwardingClientActorPropsFactory implements ClientActo
/**
* @param actorSystem the actor system in which to load the extension.
*/
public SearchForwardingClientActorPropsFactory(final ActorSystem actorSystem) {
public SearchForwardingClientActorPropsFactory(final ActorSystem actorSystem, final Config config) {
}

@Override
Expand Down
Expand Up @@ -31,6 +31,8 @@
import org.eclipse.ditto.things.model.ThingId;
import org.eclipse.ditto.things.model.signals.commands.modify.CreateThing;

import com.typesafe.config.Config;

import akka.actor.ActorSystem;
import akka.japi.pf.PFBuilder;
import scala.PartialFunction;
Expand All @@ -49,7 +51,7 @@ public final class DefaultNamespaceAppender implements SignalTransformer {
*
* @param actorSystem the actor system in which to load the extension.
*/
public DefaultNamespaceAppender(final ActorSystem actorSystem) {
public DefaultNamespaceAppender(final ActorSystem actorSystem, final Config config) {
final EntityCreationConfig entityCreationConfig = DefaultEntityCreationConfig.of(
DefaultScopedConfig.dittoScoped(actorSystem.settings().config())
);
Expand Down
Expand Up @@ -14,6 +14,8 @@

import javax.annotation.concurrent.Immutable;

import com.typesafe.config.Config;

import akka.actor.AbstractActor.Receive;
import akka.actor.ActorContext;
import akka.actor.ActorSystem;
Expand All @@ -30,7 +32,7 @@ public final class NoOpEdgeCommandForwarderExtension implements EdgeCommandForwa
*
* @param actorSystem the actor system in which to load the extension.
*/
public NoOpEdgeCommandForwarderExtension(final ActorSystem actorSystem) {
public NoOpEdgeCommandForwarderExtension(final ActorSystem actorSystem, final Config config) {
// no-op
}

Expand Down
Expand Up @@ -18,6 +18,8 @@
import org.eclipse.ditto.gateway.service.util.config.endpoints.CommandConfig;
import org.eclipse.ditto.gateway.service.util.config.endpoints.HttpConfig;

import com.typesafe.config.Config;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
Expand All @@ -29,7 +31,7 @@
*/
public final class DefaultHttpRequestActorPropsFactory implements HttpRequestActorPropsFactory {

private DefaultHttpRequestActorPropsFactory(final ActorSystem actorSystem) {
private DefaultHttpRequestActorPropsFactory(final ActorSystem actorSystem, final Config config) {
//NoOp Constructor to match extension instantiation
}

Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.slf4j.LoggerFactory;

import com.mongodb.lang.Nullable;
import com.typesafe.config.Config;

import akka.actor.ActorSystem;

Expand All @@ -47,7 +48,7 @@ public final class DittoGatewayAuthenticationDirectiveFactory implements Gateway
@Nullable private GatewayAuthenticationDirective gatewayHttpAuthenticationDirective;
@Nullable private GatewayAuthenticationDirective gatewayWsAuthenticationDirective;

public DittoGatewayAuthenticationDirectiveFactory(final ActorSystem actorSystem) {
public DittoGatewayAuthenticationDirectiveFactory(final ActorSystem actorSystem, final Config config) {
authConfig = DittoGatewayConfig.of(DefaultScopedConfig.dittoScoped(actorSystem.settings().config()))
.getAuthenticationConfig();
authenticationDispatcher = actorSystem.dispatchers().lookup(AUTHENTICATION_DISPATCHER_NAME);
Expand Down
Expand Up @@ -12,6 +12,8 @@
*/
package org.eclipse.ditto.gateway.service.endpoints.routes;

import com.typesafe.config.Config;

import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.event.Logging;
Expand All @@ -33,7 +35,7 @@ public final class LoggingHttpBindFlowProvider implements HttpBindFlowProvider {
/**
* @param actorSystem the actor system in which to load the extension.
*/
public LoggingHttpBindFlowProvider(final ActorSystem actorSystem) {
public LoggingHttpBindFlowProvider(final ActorSystem actorSystem, final Config config) {
this.actorSystem = actorSystem;
}

Expand Down
Expand Up @@ -17,6 +17,8 @@
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;

import com.typesafe.config.Config;

import akka.actor.ActorSystem;
import akka.http.javadsl.server.Directives;
import akka.http.javadsl.server.Route;
Expand All @@ -26,7 +28,7 @@ public final class NoopCustomApiRoutesProvider implements CustomApiRoutesProvide

private static final Route EMPTY_ROUTE = Directives.reject();

public NoopCustomApiRoutesProvider(final ActorSystem actorSystem) {
public NoopCustomApiRoutesProvider(final ActorSystem actorSystem, final Config config) {
// No-Op because Extensions need to have constructor accepting the actorSystem.
}

Expand Down
Expand Up @@ -15,6 +15,8 @@
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.gateway.service.streaming.actors.SupervisedStream;

import com.typesafe.config.Config;

import akka.actor.ActorSystem;

/**
Expand All @@ -25,7 +27,7 @@ public final class NoOpSseConnectionSupervisor implements SseConnectionSuperviso
/**
* @param actorSystem the actor system in which to load the extension.
*/
public NoOpSseConnectionSupervisor(final ActorSystem actorSystem) {
public NoOpSseConnectionSupervisor(final ActorSystem actorSystem, final Config config) {
//No-Op because extensions need a constructor accepting an actorSystem
}

Expand Down
Expand Up @@ -12,6 +12,8 @@
*/
package org.eclipse.ditto.gateway.service.endpoints.routes.sse;

import com.typesafe.config.Config;

import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.http.javadsl.model.HttpRequest;
Expand All @@ -23,7 +25,7 @@
*/
public final class NoOpSseEventSniffer implements SseEventSniffer {

public NoOpSseEventSniffer(final ActorSystem actorSystem) {
public NoOpSseEventSniffer(final ActorSystem actorSystem, final Config config) {
//No-Op because extensions need a constructor accepting an actorSystem
}

Expand Down
Expand Up @@ -12,6 +12,8 @@
*/
package org.eclipse.ditto.gateway.service.endpoints.routes.websocket;

import com.typesafe.config.Config;

import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.http.javadsl.model.HttpRequest;
Expand All @@ -23,7 +25,7 @@
*/
public final class NoOpIncomingWebSocketEventSniffer implements IncomingWebSocketEventSniffer {

public NoOpIncomingWebSocketEventSniffer(final ActorSystem actorSystem) {
public NoOpIncomingWebSocketEventSniffer(final ActorSystem actorSystem, final Config config) {
//No-Op because extensions need a constructor accepting an actorSystem
}

Expand Down
Expand Up @@ -12,6 +12,8 @@
*/
package org.eclipse.ditto.gateway.service.endpoints.routes.websocket;

import com.typesafe.config.Config;

import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.http.javadsl.model.HttpRequest;
Expand All @@ -23,7 +25,7 @@
*/
public final class NoOpOutgoingWebSocketEventSniffer implements OutgoingWebSocketEventSniffer {

public NoOpOutgoingWebSocketEventSniffer(final ActorSystem actorSystem) {
public NoOpOutgoingWebSocketEventSniffer(final ActorSystem actorSystem, final Config config) {
//No-Op because extensions need a constructor accepting an actorSystem
}

Expand Down
Expand Up @@ -15,6 +15,8 @@
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.gateway.service.util.config.streaming.WebsocketConfig;

import com.typesafe.config.Config;

import akka.actor.ActorSystem;

/**
Expand All @@ -26,7 +28,7 @@ public final class NoOpWebSocketConfigProvider implements WebSocketConfigProvide
* @param actorSystem the actor system in which to load the extension.
*/
@SuppressWarnings("unused")
public NoOpWebSocketConfigProvider(final ActorSystem actorSystem) {
public NoOpWebSocketConfigProvider(final ActorSystem actorSystem, final Config config) {
//No-Op because extensions need a constructor accepting an actorSystem
}

Expand Down
Expand Up @@ -15,6 +15,8 @@
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.gateway.service.streaming.actors.SupervisedStream;

import com.typesafe.config.Config;

import akka.actor.ActorSystem;

/**
Expand All @@ -25,7 +27,7 @@ public final class NoOpWebSocketSupervisor implements WebSocketSupervisor {
/**
* @param actorSystem the actor system in which to load the extension.
*/
public NoOpWebSocketSupervisor(final ActorSystem actorSystem) {
public NoOpWebSocketSupervisor(final ActorSystem actorSystem, final Config config) {
//No-Op because extensions need a constructor accepting an actorSystem
}

Expand Down

0 comments on commit cc2f261

Please sign in to comment.