-
Notifications
You must be signed in to change notification settings - Fork 214
/
DefaultClientActorPropsFactory.java
97 lines (86 loc) · 3.95 KB
/
DefaultClientActorPropsFactory.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2017 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.messaging;
import javax.annotation.concurrent.Immutable;
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.connectivity.model.Connection;
import org.eclipse.ditto.connectivity.service.messaging.amqp.AmqpClientActor;
import org.eclipse.ditto.connectivity.service.messaging.hono.HonoConnectionFactory;
import org.eclipse.ditto.connectivity.service.messaging.httppush.HttpPushClientActor;
import org.eclipse.ditto.connectivity.service.messaging.kafka.KafkaClientActor;
import org.eclipse.ditto.connectivity.service.messaging.mqtt.hivemq.MqttClientActor;
import org.eclipse.ditto.connectivity.service.messaging.rabbitmq.RabbitMQClientActor;
import com.typesafe.config.Config;
import org.apache.pekko.actor.ActorRef;
import org.apache.pekko.actor.ActorSystem;
import org.apache.pekko.actor.Props;
/**
* The default implementation of {@link ClientActorPropsFactory}. Singleton which is created just once
* and otherwise returns the already created instance.
*/
@Immutable
public final class DefaultClientActorPropsFactory implements ClientActorPropsFactory {
private final HonoConnectionFactory honoConnectionFactory;
public DefaultClientActorPropsFactory(final ActorSystem actorSystem, final Config config) {
honoConnectionFactory = HonoConnectionFactory.get(actorSystem, config);
}
@Override
public Props getActorPropsForType(final Connection connection,
final ActorRef commandForwarderActor,
final ActorRef connectionActor,
final ActorSystem actorSystem,
final DittoHeaders dittoHeaders,
final Config connectivityConfigOverwrites) {
return switch (connection.getConnectionType()) {
case AMQP_091 -> RabbitMQClientActor.props(connection,
commandForwarderActor,
connectionActor,
dittoHeaders,
connectivityConfigOverwrites);
case AMQP_10 -> AmqpClientActor.props(connection,
commandForwarderActor,
connectionActor,
connectivityConfigOverwrites,
actorSystem,
dittoHeaders);
case MQTT, MQTT_5 -> MqttClientActor.props(connection,
commandForwarderActor,
connectionActor,
dittoHeaders,
connectivityConfigOverwrites);
case KAFKA -> KafkaClientActor.props(connection,
commandForwarderActor,
connectionActor,
dittoHeaders,
connectivityConfigOverwrites);
case HTTP_PUSH -> HttpPushClientActor.props(connection,
commandForwarderActor,
connectionActor,
dittoHeaders,
connectivityConfigOverwrites);
case HONO -> KafkaClientActor.props(getResolvedHonoConnectionOrThrow(connection, dittoHeaders),
commandForwarderActor,
connectionActor,
dittoHeaders,
connectivityConfigOverwrites);
};
}
private Connection getResolvedHonoConnectionOrThrow(final Connection connection, final DittoHeaders dittoHeaders) {
try {
return honoConnectionFactory.getHonoConnection(connection);
} catch (final DittoRuntimeException e) {
throw e.setDittoHeaders(dittoHeaders);
}
}
}