-
Notifications
You must be signed in to change notification settings - Fork 215
/
Source.java
228 lines (194 loc) · 8.48 KB
/
Source.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* 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.model;
import java.util.Optional;
import java.util.Set;
import javax.annotation.concurrent.Immutable;
import org.eclipse.ditto.base.model.acks.AcknowledgementLabel;
import org.eclipse.ditto.base.model.acks.FilteredAcknowledgementRequest;
import org.eclipse.ditto.base.model.auth.AuthorizationContext;
import org.eclipse.ditto.base.model.json.FieldType;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.base.model.json.Jsonifiable;
import org.eclipse.ditto.json.JsonArray;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonFieldSelector;
import org.eclipse.ditto.json.JsonObject;
/**
* A {@link Connection} source contains several addresses to consume external messages from.
*/
public interface Source extends Jsonifiable.WithFieldSelectorAndPredicate<JsonField> {
/**
* @return the addresses of this source
*/
Set<String> getAddresses();
/**
* @return number of consumers (connections) that will be opened to the remote server, default is {@code 1}
*/
int getConsumerCount();
/**
* Returns the Authorization Context of this {@code Source}. If an authorization context is set on a {@link Source}
* it overrides the authorization context set on the enclosing {@link Connection}.
*
* @return the Authorization Context of this {@link Source}.
*/
AuthorizationContext getAuthorizationContext();
/**
* @return an index to distinguish between sources that would otherwise be different
*/
int getIndex();
/**
* @return the optional qos value of this source - only applicable for certain {@link ConnectionType}s.
*/
Optional<Integer> getQos();
/**
* @return the enforcement options that should be applied to this source
*/
Optional<Enforcement> getEnforcement();
/**
* Returns the acknowledgement requests which should be added to each by the source consumed message
* with an optional filter.
*
* @return the acknowledgements that are requested from messages consumed in this source
* @since 1.2.0
*/
Optional<FilteredAcknowledgementRequest> getAcknowledgementRequests();
/**
* Defines an optional header mapping e.g. rename, combine etc. headers for inbound message. Mapping is
* applied after payload mapping is applied. The mapping may contain {@code thing:*} and {@code header:*}
* placeholders.
*
* @return the header mappings
*/
HeaderMapping getHeaderMapping();
/**
* The payload mappings that should be applied for messages received on this source. Each
* mapping can produce multiple signals on its own that are then forwarded independently.
*
* @return the payload mappings to execute
*/
PayloadMapping getPayloadMapping();
/**
* The target to handle Ditto command responses to commands sent by this source.
* If undefined, responses are published for commands with {@code response-required=true}
* at the address defined by the header {@code reply-to} without header or payload mapping.
*
* @return an optional reply-target.
*/
Optional<ReplyTarget> getReplyTarget();
/**
* Whether reply-target is enabled for this source.
*
* @return whether reply-target is enabled.
*/
boolean isReplyTargetEnabled();
/**
* The declared acknowledgement labels are those of acknowledgements this source is allowed to send.
*
* @return the declared acknowledgement labels.
* @since 1.4.0
*/
Set<AcknowledgementLabel> getDeclaredAcknowledgementLabels();
/**
* Returns all non-hidden marked fields of this {@code Source}.
*
* @return a JSON object representation of this Source including only non-hidden marked fields.
*/
@Override
default JsonObject toJson() {
return toJson(FieldType.notHidden());
}
@Override
default JsonObject toJson(final JsonSchemaVersion schemaVersion, final JsonFieldSelector fieldSelector) {
return toJson(schemaVersion, FieldType.notHidden()).get(fieldSelector);
}
/**
* An enumeration of the known {@code JsonField}s of a {@code Source} configuration.
*/
@Immutable
final class JsonFields {
/**
* JSON field containing the {@code Source} addresses.
*/
public static final JsonFieldDefinition<JsonArray> ADDRESSES =
JsonFactory.newJsonArrayFieldDefinition("addresses", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Source} consumer count.
*/
public static final JsonFieldDefinition<Integer> CONSUMER_COUNT =
JsonFactory.newIntFieldDefinition("consumerCount", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Source} qos.
*/
public static final JsonFieldDefinition<Integer> QOS =
JsonFactory.newIntFieldDefinition("qos", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Source} authorization context (list of authorization subjects).
*/
public static final JsonFieldDefinition<JsonArray> AUTHORIZATION_CONTEXT =
JsonFactory.newJsonArrayFieldDefinition("authorizationContext",
FieldType.REGULAR,
JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Source} enforcement options.
*/
public static final JsonFieldDefinition<JsonObject> ENFORCEMENT =
JsonFactory.newJsonObjectFieldDefinition("enforcement", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Source} acknowledgements that are requested from messages consumed in this
* source.
*
* @since 1.2.0
*/
public static final JsonFieldDefinition<JsonObject> ACKNOWLEDGEMENT_REQUESTS =
JsonFactory.newJsonObjectFieldDefinition("acknowledgementRequests",
FieldType.REGULAR,
JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Source} header mapping.
*/
public static final JsonFieldDefinition<JsonObject> HEADER_MAPPING =
JsonFactory.newJsonObjectFieldDefinition("headerMapping", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Source} payload mapping.
*/
public static final JsonFieldDefinition<JsonArray> PAYLOAD_MAPPING =
JsonFactory.newJsonArrayFieldDefinition("payloadMapping", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field containing the reply-target.
*/
public static final JsonFieldDefinition<JsonObject> REPLY_TARGET =
JsonFactory.newJsonObjectFieldDefinition("replyTarget", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field for whether reply-target is enabled. Set to false explicitly to disable reply sending.
* Otherwise it is assumed that the connection was created before reply-target was introduced and
* live migration will occur. The field is within the "replyTarget" block but is treated as a part of
* Source instead.
*/
public static final JsonFieldDefinition<Boolean> REPLY_TARGET_ENABLED =
JsonFactory.newBooleanFieldDefinition("replyTarget/enabled", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field for declared acknowledgement labels, namely the labels of acknowledgements the connection
* source is allowed to send.
*
* @since 1.4.0
*/
public static final JsonFieldDefinition<JsonArray> DECLARED_ACKS =
JsonFactory.newJsonArrayFieldDefinition("declaredAcks", FieldType.REGULAR, JsonSchemaVersion.V_2);
private JsonFields() {
throw new AssertionError();
}
}
}