-
Notifications
You must be signed in to change notification settings - Fork 215
/
Target.java
181 lines (153 loc) · 6.47 KB
/
Target.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
/*
* 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.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} target contains one address to publish to and several topics of Ditto signals for which to
* subscribe in the Ditto cluster.
*/
public interface Target extends Jsonifiable.WithFieldSelectorAndPredicate<JsonField>, GenericTarget {
/**
* @return the address for the configured type of signals of this target
*/
@Override
String getAddress();
/**
* @return the original address (before placeholders were resolved)
*/
String getOriginalAddress();
@Override
Target withAddress(String newAddress);
/**
* @return set of topics that should be published via this target
*/
Set<FilteredTopic> getTopics();
@Override
Optional<Integer> getQos();
/**
* Returns the Authorization Context of this {@code Target}. If an authorization context is set on a {@link Target}
* it overrides the authorization context set on the enclosing {@link Connection}.
*
* @return the Authorization Context of this {@link Target}.
*/
AuthorizationContext getAuthorizationContext();
/**
* Defines the optional label of an acknowledgement which should automatically be issued by this target
* based on the technical settlement/ACK the connection channel provides.
*
* @return the optional label of an automatically issued acknowledgement
* @since 1.2.0
*/
Optional<AcknowledgementLabel> getIssuedAcknowledgementLabel();
/**
* Defines an optional header mapping e.g. to rename, combine etc. headers for outbound message. Mapping is
* applied after payload mapping is applied. The mapping may contain {@code thing:*} and {@code header:*}
* placeholders.
*
* @return the optional header mapping
*/
@Override
HeaderMapping getHeaderMapping();
/**
* The payload mappings that should be applied in this order for messages sent on this target. Each
* mapping can produce multiple signals on its own that are then forwarded to the external system.
*
* @return the payload mappings to execute
*/
PayloadMapping getPayloadMapping();
/**
* Returns all non-hidden marked fields of this {@code Connection}.
*
* @return a JSON object representation of this Target 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 Target} configuration.
*/
@Immutable
final class JsonFields {
/**
* JSON field containing the {@code JsonSchemaVersion}.
*
* @deprecated as of 2.3.0 this field definition is not used anymore.
*/
@Deprecated
public static final JsonFieldDefinition<Integer> SCHEMA_VERSION =
JsonFactory.newIntFieldDefinition(JsonSchemaVersion.getJsonKey(),
FieldType.SPECIAL,
FieldType.HIDDEN,
JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Target} address.
*/
public static final JsonFieldDefinition<String> ADDRESS =
JsonFactory.newStringFieldDefinition("address", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Target} topics.
*/
public static final JsonFieldDefinition<JsonArray> TOPICS =
JsonFactory.newJsonArrayFieldDefinition("topics", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Target} qos.
*/
public static final JsonFieldDefinition<Integer> QOS =
JsonFactory.newIntFieldDefinition("qos", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Target} 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 Target} acknowledgement label of an automatically issued acknowledgement.
*/
public static final JsonFieldDefinition<String> ISSUED_ACKNOWLEDGEMENT_LABEL =
JsonFactory.newStringFieldDefinition("issuedAcknowledgementLabel",
FieldType.REGULAR,
JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Target} header mapping.
*/
public static final JsonFieldDefinition<JsonObject> HEADER_MAPPING =
JsonFactory.newJsonObjectFieldDefinition("headerMapping", FieldType.REGULAR, JsonSchemaVersion.V_2);
/**
* JSON field containing the {@code Target} payload mapping.
*/
public static final JsonFieldDefinition<JsonArray> PAYLOAD_MAPPING =
JsonFactory.newJsonArrayFieldDefinition("payloadMapping", FieldType.REGULAR, JsonSchemaVersion.V_2);
private JsonFields() {
throw new AssertionError();
}
}
}