/
DefaultClientActorPropsFactory.java
96 lines (84 loc) · 4.31 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
/*
* 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.services.connectivity.messaging;
import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull;
import javax.annotation.concurrent.Immutable;
import org.eclipse.ditto.model.connectivity.Connection;
import org.eclipse.ditto.model.connectivity.ConnectionType;
import org.eclipse.ditto.services.connectivity.mapping.MappingConfig;
import org.eclipse.ditto.services.connectivity.messaging.amqp.AmqpClientActor;
import org.eclipse.ditto.services.connectivity.messaging.config.ClientConfig;
import org.eclipse.ditto.services.connectivity.messaging.config.ConnectionConfig;
import org.eclipse.ditto.services.connectivity.messaging.kafka.DefaultKafkaPublisherActorFactory;
import org.eclipse.ditto.services.connectivity.messaging.kafka.KafkaClientActor;
import org.eclipse.ditto.services.connectivity.messaging.mqtt.MqttClientActor;
import org.eclipse.ditto.services.connectivity.messaging.rabbitmq.RabbitMQClientActor;
import org.eclipse.ditto.services.utils.protocol.config.ProtocolConfig;
import akka.actor.ActorRef;
import akka.actor.Props;
/**
* The default implementation of {@link ClientActorPropsFactory}.
*/
@Immutable
public final class DefaultClientActorPropsFactory implements ClientActorPropsFactory {
private final ClientConfig clientConfig;
private final MappingConfig mappingConfig;
private final ProtocolConfig protocolConfig;
private final ConnectionConfig connectionConfig;
private DefaultClientActorPropsFactory(final ClientConfig clientConfig,
final MappingConfig mappingConfig,
final ProtocolConfig protocolConfig,
final ConnectionConfig connectionConfig) {
this.clientConfig = checkNotNull(clientConfig, "ClientConfig");
this.mappingConfig = checkNotNull(mappingConfig, "MappingConfig");
this.protocolConfig = checkNotNull(protocolConfig, "ProtocolConfig");
this.connectionConfig = checkNotNull(connectionConfig, "ConnectionConfig");
}
/**
* Returns an instance of {@code DefaultClientActorPropsFactory}.
*
* @param clientConfig the client config.
* @param mappingConfig the mapping config.
* @param protocolConfig the configuration settings for protocol mapping.
* @param connectionConfig the connection config.
* @return the factory instance.
* @throws NullPointerException if any argument is {@code null}.
*/
public static DefaultClientActorPropsFactory getInstance(final ClientConfig clientConfig,
final MappingConfig mappingConfig,
final ProtocolConfig protocolConfig,
final ConnectionConfig connectionConfig) {
return new DefaultClientActorPropsFactory(clientConfig, mappingConfig, protocolConfig, connectionConfig);
}
@Override
public Props getActorPropsForType(final Connection connection, final ActorRef conciergeForwarder) {
final ConnectionType connectionType = connection.getConnectionType();
switch (connectionType) {
case AMQP_091:
return RabbitMQClientActor.props(connection, clientConfig, mappingConfig, protocolConfig,
conciergeForwarder);
case AMQP_10:
return AmqpClientActor.props(connection, clientConfig, mappingConfig, protocolConfig,
conciergeForwarder);
case MQTT:
return MqttClientActor.props(connection, clientConfig, mappingConfig, protocolConfig,
connectionConfig.getMqttConfig(), conciergeForwarder);
case KAFKA:
return KafkaClientActor.props(connection, clientConfig, mappingConfig, protocolConfig,
connectionConfig.getKafkaConfig(), conciergeForwarder,
DefaultKafkaPublisherActorFactory.getInstance());
default:
throw new IllegalArgumentException("ConnectionType <" + connectionType + "> is not supported.");
}
}
}