• 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 package software.amazon.awssdk.crt.mqtt5;
6 
7 /**
8  * MQTT behavior settings that are dynamically negotiated as part of the CONNECT/CONNACK exchange.
9  *
10  * While you can infer all of these values from a combination of
11  *   (1) defaults as specified in the MQTT5 spec
12  *   (2) your CONNECT settings
13  *   (3) the CONNACK from the broker
14  *
15  * the client instead does the combining for you and emits a NegotiatedSettings object with final, authoritative values.
16  *
17  * Negotiated settings are communicated with every successful connection establishment.
18  */
19 public class NegotiatedSettings {
20 
21     private QOS maximumQOS;
22     private long sessionExpiryInterval;
23     private int receiveMaximumFromServer;
24     private long maximumPacketSizeToServer;
25     private int topicAliasMaximumToServer;
26     private int topicAliasMaximumToClient;
27     private int serverKeepAlive;
28     private boolean retainAvailable;
29     private boolean wildcardSubscriptionsAvailable;
30     private boolean subscriptionIdentifiersAvailable;
31     private boolean sharedSubscriptionsAvailable;
32     private String assignedClientID;
33     private boolean rejoinedSession;
34 
35     /**
36      * @return Returns the maximum QoS allowed for publishes on this connection instance
37      */
getMaximumQOS()38     public QOS getMaximumQOS() {
39         return this.maximumQOS;
40     }
41 
42     /**
43      * @return Returns the amount of time in seconds the server will retain the MQTT session after a disconnect.
44      */
getSessionExpiryIntervalSeconds()45     public long getSessionExpiryIntervalSeconds() {
46         return this.sessionExpiryInterval;
47     }
48 
49     /**
50      * @return Returns the amount of time in seconds the server will retain the MQTT session after a disconnect.
51      * @deprecated prefer getSessionExpiryIntervalSeconds instead
52      */
getSessionExpiryInterval()53     public long getSessionExpiryInterval() {
54         return this.getSessionExpiryIntervalSeconds();
55     }
56 
57     /**
58      * @return Returns the number of in-flight QoS 1 and QoS 2 publications the server is willing to process concurrently.
59      */
getReceiveMaximumFromServer()60     public int getReceiveMaximumFromServer() {
61         return this.receiveMaximumFromServer;
62     }
63 
64     /**
65      * @return Returns the maximum packet size the server is willing to accept.
66      */
getMaximumPacketSizeToServer()67     public long getMaximumPacketSizeToServer() {
68         return this.maximumPacketSizeToServer;
69     }
70 
71     /**
72      * @return returns the maximum allowed topic alias value on publishes sent from client to server
73      */
getTopicAliasMaximumToServer()74     public int getTopicAliasMaximumToServer() {
75         return this.topicAliasMaximumToServer;
76     }
77 
78     /**
79      * @return returns the maximum allowed topic alias value on publishes sent from server to client
80      */
getTopicAliasMaximumToClient()81     public int getTopicAliasMaximumToClient() {
82         return this.topicAliasMaximumToClient;
83     }
84 
85     /**
86      * Returns the maximum amount of time in seconds between client packets. The client should use PINGREQs to ensure this
87      * limit is not breached.  The server will disconnect the client for inactivity if no MQTT packet is received
88      * in a time interval equal to 1.5 x this value.
89      *
90      * @return The maximum amount of time in seconds between client packets.
91      */
getServerKeepAliveSeconds()92     public int getServerKeepAliveSeconds() {
93         return this.serverKeepAlive;
94     }
95 
96     /**
97      * Returns the maximum amount of time in seconds between client packets. The client should use PINGREQs to ensure this
98      * limit is not breached.  The server will disconnect the client for inactivity if no MQTT packet is received
99      * in a time interval equal to 1.5 x this value.
100      *
101      * @deprecated prefer getServerKeepAliveSeconds
102      *
103      * @return The maximum amount of time in seconds between client packets.
104      */
getServerKeepAlive()105     public int getServerKeepAlive() {
106         return this.getServerKeepAliveSeconds();
107     }
108 
109     /**
110      * @return Returns whether the server supports retained messages.
111      */
getRetainAvailable()112     public boolean getRetainAvailable() {
113         return this.retainAvailable;
114     }
115 
116     /**
117      * @return Returns whether the server supports wildcard subscriptions.
118      */
getWildcardSubscriptionsAvailable()119     public boolean getWildcardSubscriptionsAvailable() {
120         return this.wildcardSubscriptionsAvailable;
121     }
122 
123     /**
124      * @return Returns whether the server supports subscription identifiers
125      */
getSubscriptionIdentifiersAvailable()126     public boolean getSubscriptionIdentifiersAvailable() {
127         return this.subscriptionIdentifiersAvailable;
128     }
129 
130     /**
131      * @return Returns whether the server supports shared subscriptions
132      */
getSharedSubscriptionsAvailable()133     public boolean getSharedSubscriptionsAvailable() {
134         return this.sharedSubscriptionsAvailable;
135     }
136 
137     /**
138      * @return Returns whether the client has rejoined an existing session.
139      */
getRejoinedSession()140     public boolean getRejoinedSession() {
141         return this.rejoinedSession;
142     }
143 
144     /**
145      * Returns the final client id in use by the newly-established connection.  This will be the configured client id if one
146      * was given in the configuration, otherwise, if no client id was specified, this will be the client id assigned
147      * by the server.  Reconnection attempts will always use the auto-assigned client id, allowing for auto-assigned
148      * session resumption.
149      *
150      * @return The final client id in use by the newly-established connection
151      */
getAssignedClientID()152     public String getAssignedClientID() {
153         return this.assignedClientID;
154     }
155 
NegotiatedSettings()156     public NegotiatedSettings() {}
157 
158     /**
159      * A native, JNI-only helper function for more easily setting the QOS
160      * @param QOSValue A int representing the QoS
161      */
nativeSetQOS(int QOSValue)162     private void nativeSetQOS(int QOSValue) {
163         this.maximumQOS = QOS.getEnumValueFromInteger(QOSValue);
164     }
165 }
166