-
Notifications
You must be signed in to change notification settings - Fork 215
/
GatewayByRoundTripSignalEnrichmentProvider.java
63 lines (53 loc) · 2.55 KB
/
GatewayByRoundTripSignalEnrichmentProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.gateway.service.endpoints.utils;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import org.eclipse.ditto.edge.api.dispatching.ConciergeForwarderActor;
import org.eclipse.ditto.gateway.service.util.config.streaming.GatewaySignalEnrichmentConfig;
import org.eclipse.ditto.internal.models.signalenrichment.ByRoundTripSignalEnrichmentFacade;
import org.eclipse.ditto.internal.models.signalenrichment.SignalEnrichmentFacade;
import akka.actor.ActorSelection;
import akka.actor.ActorSystem;
import akka.http.javadsl.model.HttpRequest;
/**
* Provider for gateway-service of signal-enriching facades that make a round-trip for each query.
*/
public final class GatewayByRoundTripSignalEnrichmentProvider implements GatewaySignalEnrichmentProvider {
private static final String CONCIERGE_FORWARDER = "/user/gatewayRoot/" + ConciergeForwarderActor.ACTOR_NAME;
private final ByRoundTripSignalEnrichmentFacade byRoundTripSignalEnrichmentFacade;
/**
* Instantiate this provider. Called by reflection.
*
* @param actorSystem The actor system for which this provider is instantiated.
* @param signalEnrichmentConfig Configuration for this provider.
*/
public GatewayByRoundTripSignalEnrichmentProvider(final ActorSystem actorSystem,
final GatewaySignalEnrichmentConfig signalEnrichmentConfig) {
final ActorSelection commandHandler = actorSystem.actorSelection(CONCIERGE_FORWARDER);
byRoundTripSignalEnrichmentFacade =
ByRoundTripSignalEnrichmentFacade.of(commandHandler, signalEnrichmentConfig.getAskTimeout());
}
@Override
public CompletionStage<SignalEnrichmentFacade> getFacade(final HttpRequest request) {
return CompletableFuture.completedStage(getByRoundTripSignalEnrichmentFacade());
}
/**
* Package-private getter for the unique by-round-trip signal enrichment facade per provider instance.
*
* @return the unique by-round-trip signal enrichment facade.
*/
ByRoundTripSignalEnrichmentFacade getByRoundTripSignalEnrichmentFacade() {
return byRoundTripSignalEnrichmentFacade;
}
}