• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 package software.amazon.awssdk.crt.mqtt5;
7 
8 import java.util.Map;
9 import java.util.function.Function;
10 import java.util.stream.Collectors;
11 import java.util.stream.Stream;
12 
13 /**
14   * MQTT message delivery quality of service.
15   *
16   * Enum values match <a href="https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901234">MQTT5 spec</a> encoding values.
17   */
18 public enum QOS {
19     /**
20      * The message is delivered according to the capabilities of the underlying network. No response is sent by the
21      * receiver and no retry is performed by the sender. The message arrives at the receiver either once or not at all.
22      */
23     AT_MOST_ONCE(0),
24 
25     /**
26      * A level of service that ensures that the message arrives at the receiver at least once.
27      */
28     AT_LEAST_ONCE(1),
29 
30     /**
31      * A level of service that ensures that the message arrives at the receiver exactly once.
32      */
33     EXACTLY_ONCE(2);
34 
35     private int qos;
36 
QOS(int value)37     private QOS(int value) {
38         qos = value;
39     }
40 
41     /**
42      * @return The native enum integer value associated with this Java enum value
43      */
getValue()44     public int getValue() {
45         return qos;
46     }
47 
48     /**
49      * Creates a Java QualityOfService enum value from a native integer value.
50      *
51      * @param value native integer value for quality of service
52      * @return a new QualityOfService value
53      */
getEnumValueFromInteger(int value)54     public static QOS getEnumValueFromInteger(int value) {
55         QOS enumValue = enumMapping.get(value);
56         if (enumValue != null) {
57             return enumValue;
58         }
59         throw new RuntimeException("Illegal QOS");
60     }
61 
buildEnumMapping()62     private static Map<Integer, QOS> buildEnumMapping() {
63         return Stream.of(QOS.values())
64             .collect(Collectors.toMap(QOS::getValue, Function.identity()));
65     }
66 
67     private static Map<Integer, QOS> enumMapping = buildEnumMapping();
68 }
69