Skip to content

Commit

Permalink
Allow custom configuration for the WebSocketConnectionSupervisor exte…
Browse files Browse the repository at this point in the history
…nsion

Signed-off-by: Yannic Klem <yannic.klem@bosch.io>
  • Loading branch information
Yannic92 committed Jul 12, 2022
1 parent 3894dc6 commit 53a90e9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private WebSocketRoute(final ActorSystem actorSystem,
outgoingMessageSniffer = OutgoingWebSocketEventSniffer.get(actorSystem, dittoExtensionsConfig);
final var websocketConfig = ScopedConfig.getOrEmpty(config, "ditto.gateway.streaming.websocket");
authorizationEnforcer = StreamingAuthorizationEnforcer.get(actorSystem, websocketConfig);
webSocketSupervisor = WebSocketSupervisor.get(actorSystem);
webSocketSupervisor = WebSocketSupervisor.get(actorSystem, dittoExtensionsConfig);
webSocketConfigProvider = WebSocketConfigProvider.get(actorSystem, dittoExtensionsConfig);
signalEnrichmentProvider = null;
headerTranslator = HeaderTranslator.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

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

import org.eclipse.ditto.base.service.DittoExtensionIds;
import org.eclipse.ditto.base.service.DittoExtensionPoint;
import org.eclipse.ditto.gateway.service.streaming.actors.StreamSupervisor;

import com.typesafe.config.Config;

import akka.actor.ActorSystem;

/**
Expand All @@ -33,18 +36,26 @@ public interface WebSocketSupervisor extends DittoExtensionPoint, StreamSupervis
* @throws NullPointerException if {@code actorSystem} is {@code null}.
* @since 3.0.0
*/
static WebSocketSupervisor get(final ActorSystem actorSystem) {
static WebSocketSupervisor get(final ActorSystem actorSystem, final Config config) {
checkNotNull(actorSystem, "actorSystem");
return ExtensionId.INSTANCE.get(actorSystem);
checkNotNull(config, "config");
final var extensionIdConfig = ExtensionId.computeConfig(config);
return DittoExtensionIds.get(actorSystem)
.computeIfAbsent(extensionIdConfig, ExtensionId::new)
.get(actorSystem);
}

final class ExtensionId extends DittoExtensionPoint.ExtensionId<WebSocketSupervisor> {

private static final String CONFIG_PATH = "ditto.gateway.streaming.websocket.connection-supervisor";
private static final ExtensionId INSTANCE = new ExtensionId(WebSocketSupervisor.class);
private static final String CONFIG_KEY = "websocket-connection-supervisor";
private static final String CONFIG_PATH = "ditto.extensions." + CONFIG_KEY;

private ExtensionId(final ExtensionIdConfig<WebSocketSupervisor> extensionIdConfig) {
super(extensionIdConfig);
}

private ExtensionId(final Class<WebSocketSupervisor> parentClass) {
super(parentClass);
static ExtensionIdConfig<WebSocketSupervisor> computeConfig(final Config config) {
return ExtensionIdConfig.of(WebSocketSupervisor.class, config, CONFIG_KEY);
}

@Override
Expand Down
6 changes: 2 additions & 4 deletions gateway/service/src/main/resources/gateway.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ ditto {
custom-api-routes-provider = org.eclipse.ditto.gateway.service.endpoints.routes.NoopCustomApiRoutesProvider
# The supervisor for SSE connections
sse-connection-supervisor = org.eclipse.ditto.gateway.service.endpoints.routes.sse.NoOpSseConnectionSupervisor
# The supervisor for WebSocket connections
websocket-connection-supervisor = "org.eclipse.ditto.gateway.service.endpoints.routes.websocket.NoOpWebSocketSupervisor"
}

service-name = "gateway"
Expand Down Expand Up @@ -164,10 +166,6 @@ ditto {
# The provider enforcer for WebSocket connections
streaming-authorization-enforcer = "org.eclipse.ditto.gateway.service.streaming.NoOpAuthorizationEnforcer"

# The supervisor for WebSocket connections
connection-supervisor = "org.eclipse.ditto.gateway.service.endpoints.routes.websocket.NoOpWebSocketSupervisor"
connection-supervisor = ${?GATEWAY_WEBSOCKET_CONNECTION_SUPERVISOR}

}

sse {
Expand Down
2 changes: 1 addition & 1 deletion gateway/service/src/test/resources/test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ ditto {
outgoing-websocket-event-sniffer = org.eclipse.ditto.gateway.service.endpoints.routes.websocket.NoOpOutgoingWebSocketEventSniffer
custom-api-routes-provider = org.eclipse.ditto.gateway.service.endpoints.routes.NoopCustomApiRoutesProvider
sse-connection-supervisor = org.eclipse.ditto.gateway.service.endpoints.routes.sse.NoOpSseConnectionSupervisor
websocket-connection-supervisor = org.eclipse.ditto.gateway.service.endpoints.routes.websocket.NoOpWebSocketSupervisor
}

mapping-strategy.implementation = "org.eclipse.ditto.gateway.service.util.GatewayMappingStrategies"
Expand All @@ -173,7 +174,6 @@ ditto {
publisher.backpressure-buffer-size = 200
# The provider enforcer for WebSocket connections
streaming-authorization-enforcer = org.eclipse.ditto.gateway.service.streaming.NoOpAuthorizationEnforcer
connection-supervisor = org.eclipse.ditto.gateway.service.endpoints.routes.websocket.NoOpWebSocketSupervisor
}
}

Expand Down

0 comments on commit 53a90e9

Please sign in to comment.