-
Notifications
You must be signed in to change notification settings - Fork 214
/
ConnectivityConfigModifiedBehavior.java
72 lines (61 loc) · 2.8 KB
/
ConnectivityConfigModifiedBehavior.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
64
65
66
67
68
69
70
71
72
/*
* Copyright (c) 2020 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.connectivity.service.config;
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import org.eclipse.ditto.base.model.signals.events.Event;
import com.typesafe.config.Config;
import org.apache.pekko.actor.AbstractActor;
import org.apache.pekko.actor.Actor;
import org.apache.pekko.actor.ActorRef;
import org.apache.pekko.japi.pf.ReceiveBuilder;
/**
* Behavior to modify this actor's {@link ConnectivityConfig} and register for changes to {@link ConnectivityConfig}.
*/
public interface ConnectivityConfigModifiedBehavior extends Actor {
/**
* Injectable behavior to handle an {@code Event} that transports config changes.
* This involves modified credentials for Hono-connections as well.
*
* @param supervisorActor the actor that potentially will receive a command message after handling the event.
* @param persistenceActorSupplier a supplier of the actor that potentially will receive a command message after
* handling the event.
* @return behavior to handle an {@code Event} that transports config changes.
*/
default AbstractActor.Receive connectivityConfigModifiedBehavior(final ActorRef supervisorActor,
final Supplier<ActorRef> persistenceActorSupplier) {
checkNotNull(persistenceActorSupplier);
return ReceiveBuilder.create()
.match(Event.class, getConnectivityConfigProvider()::canHandle,
event -> handleEvent(event, supervisorActor, persistenceActorSupplier.get()))
.build();
}
/**
* Handles the received event by converting it to a {@link Config}.
*
* @param supervisorActor the connection supervisor actor reference
* @param persistenceActor the connection persistence actor reference
* @param event the received event
*/
default void handleEvent(final Event<?> event, final ActorRef supervisorActor,
@Nullable final ActorRef persistenceActor) {
getConnectivityConfigProvider().handleEvent(event, supervisorActor, persistenceActor);
}
/**
* @return a {@link ConnectionConfigProvider} required to register this actor for config changes
*/
default ConnectionConfigProvider getConnectivityConfigProvider() {
return ConnectionConfigProviderFactory.getInstance(context().system());
}
}