-
Notifications
You must be signed in to change notification settings - Fork 215
/
DefaultThingCommandAdapterProvider.java
184 lines (161 loc) · 7.84 KB
/
DefaultThingCommandAdapterProvider.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
/*
* Copyright (c) 2019 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.protocol.adapter.things;
import java.util.Arrays;
import java.util.List;
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
import org.eclipse.ditto.base.model.headers.translator.HeaderTranslator;
import org.eclipse.ditto.base.model.signals.ErrorRegistry;
import org.eclipse.ditto.messages.model.signals.commands.MessageCommand;
import org.eclipse.ditto.messages.model.signals.commands.MessageCommandResponse;
import org.eclipse.ditto.protocol.adapter.Adapter;
import org.eclipse.ditto.protocol.adapter.provider.ThingCommandAdapterProvider;
import org.eclipse.ditto.things.model.signals.commands.ThingErrorResponse;
import org.eclipse.ditto.things.model.signals.commands.modify.MergeThing;
import org.eclipse.ditto.things.model.signals.commands.modify.MergeThingResponse;
import org.eclipse.ditto.things.model.signals.commands.modify.ThingModifyCommand;
import org.eclipse.ditto.things.model.signals.commands.modify.ThingModifyCommandResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThings;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThingsResponse;
import org.eclipse.ditto.things.model.signals.commands.query.ThingQueryCommand;
import org.eclipse.ditto.things.model.signals.commands.query.ThingQueryCommandResponse;
import org.eclipse.ditto.things.model.signals.events.ThingEvent;
import org.eclipse.ditto.things.model.signals.events.ThingMerged;
import org.eclipse.ditto.thingsearch.model.signals.commands.SearchErrorResponse;
import org.eclipse.ditto.thingsearch.model.signals.commands.ThingSearchCommand;
import org.eclipse.ditto.thingsearch.model.signals.events.SubscriptionEvent;
/**
* Instantiates and provides {@link Adapter}s used to process Thing commands, responses, messages, events and errors.
*/
public class DefaultThingCommandAdapterProvider implements ThingCommandAdapterProvider {
private final ThingQueryCommandAdapter queryCommandAdapter;
private final ThingModifyCommandAdapter modifyCommandAdapter;
private final ThingMergeCommandAdapter mergeCommandAdapter;
private final ThingQueryCommandResponseAdapter queryCommandResponseAdapter;
private final ThingModifyCommandResponseAdapter modifyCommandResponseAdapter;
private final ThingMergeCommandResponseAdapter mergeCommandResponseAdapter;
private final ThingSearchCommandAdapter searchCommandAdapter;
private final MessageCommandAdapter messageCommandAdapter;
private final MessageCommandResponseAdapter messageCommandResponseAdapter;
private final ThingEventAdapter thingEventAdapter;
private final ThingMergedEventAdapter thingMergedEventAdapter;
private final SubscriptionEventAdapter subscriptionEventAdapter;
private final ThingErrorResponseAdapter errorResponseAdapter;
private final RetrieveThingsCommandAdapter retrieveThingsCommandAdapter;
private final RetrieveThingsCommandResponseAdapter retrieveThingsCommandResponseAdapter;
private final SearchErrorResponseAdapter searchErrorResponseAdapter;
public DefaultThingCommandAdapterProvider(final ErrorRegistry<DittoRuntimeException> errorRegistry,
final HeaderTranslator headerTranslator) {
this.queryCommandAdapter = ThingQueryCommandAdapter.of(headerTranslator);
this.retrieveThingsCommandAdapter = RetrieveThingsCommandAdapter.of(headerTranslator);
this.retrieveThingsCommandResponseAdapter = RetrieveThingsCommandResponseAdapter.of(headerTranslator);
this.modifyCommandAdapter = ThingModifyCommandAdapter.of(headerTranslator);
this.mergeCommandAdapter = ThingMergeCommandAdapter.of(headerTranslator);
this.queryCommandResponseAdapter = ThingQueryCommandResponseAdapter.of(headerTranslator);
this.modifyCommandResponseAdapter = ThingModifyCommandResponseAdapter.of(headerTranslator);
this.mergeCommandResponseAdapter = ThingMergeCommandResponseAdapter.of(headerTranslator);
this.searchCommandAdapter = ThingSearchCommandAdapter.of(headerTranslator);
this.messageCommandAdapter = MessageCommandAdapter.of(headerTranslator);
this.messageCommandResponseAdapter = MessageCommandResponseAdapter.of(headerTranslator);
this.thingEventAdapter = ThingEventAdapter.of(headerTranslator);
this.thingMergedEventAdapter = ThingMergedEventAdapter.of(headerTranslator);
this.subscriptionEventAdapter = SubscriptionEventAdapter.of(headerTranslator, errorRegistry);
this.errorResponseAdapter = ThingErrorResponseAdapter.of(headerTranslator, errorRegistry);
this.searchErrorResponseAdapter = SearchErrorResponseAdapter.of(headerTranslator, errorRegistry);
}
@Override
public List<Adapter<?>> getAdapters() {
return Arrays.asList(
queryCommandAdapter,
retrieveThingsCommandAdapter,
retrieveThingsCommandResponseAdapter,
modifyCommandAdapter,
mergeCommandAdapter,
queryCommandResponseAdapter,
modifyCommandResponseAdapter,
mergeCommandResponseAdapter,
messageCommandAdapter,
messageCommandResponseAdapter,
thingEventAdapter,
thingMergedEventAdapter,
searchCommandAdapter,
subscriptionEventAdapter,
errorResponseAdapter,
searchErrorResponseAdapter
);
}
@Override
public Adapter<ThingErrorResponse> getErrorResponseAdapter() {
return errorResponseAdapter;
}
@Override
public Adapter<ThingEvent<?>> getEventAdapter() {
return thingEventAdapter;
}
@Override
public Adapter<ThingMerged> getMergedEventAdapter() {
return thingMergedEventAdapter;
}
@Override
public Adapter<SubscriptionEvent<?>> getSubscriptionEventAdapter() {
return subscriptionEventAdapter;
}
@Override
public Adapter<ThingModifyCommand<?>> getModifyCommandAdapter() {
return modifyCommandAdapter;
}
@Override
public Adapter<MergeThing> getMergeCommandAdapter() {
return mergeCommandAdapter;
}
@Override
public Adapter<ThingModifyCommandResponse<?>> getModifyCommandResponseAdapter() {
return modifyCommandResponseAdapter;
}
@Override
public Adapter<MergeThingResponse> getMergeCommandResponseAdapter() {
return mergeCommandResponseAdapter;
}
@Override
public Adapter<ThingQueryCommand<?>> getQueryCommandAdapter() {
return queryCommandAdapter;
}
@Override
public Adapter<ThingQueryCommandResponse<?>> getQueryCommandResponseAdapter() {
return queryCommandResponseAdapter;
}
@Override
public Adapter<MessageCommand<?, ?>> getMessageCommandAdapter() {
return messageCommandAdapter;
}
@Override
public Adapter<MessageCommandResponse<?, ?>> getMessageCommandResponseAdapter() {
return messageCommandResponseAdapter;
}
@Override
public Adapter<ThingSearchCommand<?>> getSearchCommandAdapter() {
return searchCommandAdapter;
}
@Override
public Adapter<RetrieveThings> getRetrieveThingsCommandAdapter() {
return retrieveThingsCommandAdapter;
}
@Override
public Adapter<RetrieveThingsResponse> getRetrieveThingsCommandResponseAdapter() {
return retrieveThingsCommandResponseAdapter;
}
@Override
public Adapter<SearchErrorResponse> getSearchErrorResponseAdapter() {
return searchErrorResponseAdapter;
}
}