Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #ditto/757: always throw IllegalStateException on missing expec…
…ted acknowledgement label; throw IllegalArgumentException when told to send signals with missing acknowledgement requests. Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
- Loading branch information
Showing
5 changed files
with
238 additions
and
15 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...src/main/java/org/eclipse/ditto/client/ack/internal/AcknowledgementRequestsValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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.client.ack.internal; | ||
|
||
import java.util.Set; | ||
|
||
import org.eclipse.ditto.model.base.acks.AcknowledgementLabel; | ||
import org.eclipse.ditto.model.base.acks.AcknowledgementRequest; | ||
|
||
/** | ||
* Validate an acknowledgement request from the client. | ||
*/ | ||
public final class AcknowledgementRequestsValidator { | ||
|
||
private AcknowledgementRequestsValidator() {} | ||
|
||
/** | ||
* Validate acknowledgement requests from the client. | ||
* | ||
* @param acknowledgementRequests the acknowledgement requests of a signal sent by the client. | ||
* @param mandatoryLabel the mandatory acknowledgement label for the channel. | ||
*/ | ||
public static void validate(final Set<AcknowledgementRequest> acknowledgementRequests, | ||
final AcknowledgementLabel mandatoryLabel) { | ||
|
||
if (!acknowledgementRequests.isEmpty() && | ||
!acknowledgementRequests.contains(AcknowledgementRequest.of(mandatoryLabel))) { | ||
throw new IllegalArgumentException("Expected acknowledgement request for label '" + | ||
mandatoryLabel + | ||
"' not found. Please make sure to always request the '" + | ||
mandatoryLabel + | ||
"' Acknowledgement if you need to process the response in the client."); | ||
} | ||
} | ||
|
||
/** | ||
* Create an {@code IllegalStateException} when receiving acknowledgements from the back-end not containing | ||
* an expected acknowledgement label. | ||
* | ||
* @param mandatoryLabel the mandatory acknowledgement label. | ||
* @return the {@code IllegalStateException}. | ||
*/ | ||
public static IllegalStateException didNotReceiveAcknowledgement(final AcknowledgementLabel mandatoryLabel) { | ||
return new IllegalStateException("Didn't receive an Acknowledgement for label '" + | ||
mandatoryLabel + "'. Please make sure to always request the '" + | ||
mandatoryLabel + "' Acknowledgement if you need to process the " + | ||
"response in the client."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters