-
Notifications
You must be signed in to change notification settings - Fork 215
/
InboundMappingOutcomes.java
145 lines (128 loc) · 4.35 KB
/
InboundMappingOutcomes.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
/*
* Copyright (c) 2020 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 java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
import org.eclipse.ditto.connectivity.api.ExternalMessage;
import org.eclipse.ditto.connectivity.api.MappedInboundExternalMessage;
import org.eclipse.ditto.connectivity.service.messaging.mappingoutcome.MappingOutcome;
import akka.actor.ActorRef;
/**
* Outcome of mapping one inbound external message.
*/
public final class InboundMappingOutcomes {
private final List<MappingOutcome<MappedInboundExternalMessage>> outcomes;
private final ExternalMessage externalMessage;
@Nullable private final Exception error;
private final ActorRef sender;
private InboundMappingOutcomes(final List<MappingOutcome<MappedInboundExternalMessage>> outcomes,
final ExternalMessage externalMessage,
@Nullable final Exception error,
final ActorRef sender) {
this.outcomes = outcomes;
this.externalMessage = externalMessage;
this.error = error;
this.sender = sender;
}
/**
* Create an {@code InboundMappingOutcomes} object from an error.
*
* @param message the inbound message.
* @param error the error.
* @param sender the actor who cares about the result of the error response.
* @return the {@code InboundMappingOutcomes} object.
*/
public static InboundMappingOutcomes of(final ExternalMessage message, final Exception error,
final ActorRef sender) {
return new InboundMappingOutcomes(List.of(), message, error, sender);
}
/**
* Create an {@code InboundMappingOutcomes} object.
*
* @param outcomes the mapping outcomes.
* @param externalMessage the external message.
* @param sender actor who cares about the outcome of this message.
* @return the {@code InboundMappingOutcomes} object.
*/
public static InboundMappingOutcomes of(final List<MappingOutcome<MappedInboundExternalMessage>> outcomes,
final ExternalMessage externalMessage,
final ActorRef sender) {
return new InboundMappingOutcomes(outcomes, externalMessage, null, sender);
}
/**
* Retrieve the mapping outcomes of an inbound message.
*
* @return the outcomes.
*/
public List<MappingOutcome<MappedInboundExternalMessage>> getOutcomes() {
return outcomes;
}
/**
* Retrieve the external message.
*
* @return the external message.
*/
public ExternalMessage getExternalMessage() {
return externalMessage;
}
/**
* Retrieve the error, if any.
*
* @return the error.
*/
@Nullable
public Exception getError() {
return error;
}
/**
* Test if the mapping outcomes result in an error response.
*
* @return whether an error response exists.
*/
public boolean hasError() {
return error != null;
}
/**
* Retrieve the actor who cares about the outcome of the incoming message.
*
* @return the sender actor reference.
*/
public ActorRef getSender() {
return sender;
}
@Override
public String toString() {
return getClass().getSimpleName() + " [" +
"outcomes=" + outcomes +
", externalMessage=" + externalMessage +
", error=" + error +
", sender=" + sender +
"]";
}
@Override
public int hashCode() {
return Objects.hash(outcomes, externalMessage, error, sender);
}
@Override
public boolean equals(final Object o) {
if (o instanceof InboundMappingOutcomes that) {
return Objects.equals(outcomes, that.outcomes) &&
Objects.equals(externalMessage, that.externalMessage) &&
Objects.equals(error, that.error) &&
Objects.equals(sender, that.sender);
} else {
return false;
}
}
}