@@ -148,19 +148,19 @@ public class ClientState implements MqttState {
148148 // Topic Alias Maps
149149 private Hashtable <String , Integer > outgoingTopicAliases ;
150150 private Hashtable <Integer , String > incomingTopicAliases ;
151- private int outgoingTopicAliasCount = 1 ;
152151
153- private MqttSession mqttSession ;
152+ private MqttConnectionState mqttConnection ;
154153
155154 protected ClientState (MqttClientPersistence persistence , CommsTokenStore tokenStore , CommsCallback callback ,
156- ClientComms clientComms , MqttPingSender pingSender , MqttSession mqttSession ) throws MqttException {
155+ ClientComms clientComms , MqttPingSender pingSender , MqttConnectionState mqttConnection )
156+ throws MqttException {
157157
158158 log .setResourceName (clientComms .getClient ().getClientId ());
159159 log .finer (CLASS_NAME , "<Init>" , "" );
160160
161161 inUseMsgIds = new ConcurrentHashMap <>();
162162 pendingFlows = new Vector <MqttWireMessage >();
163- pendingMessages = new Vector <MqttWireMessage >(mqttSession .getReceiveMaximum ());
163+ pendingMessages = new Vector <MqttWireMessage >(mqttConnection .getReceiveMaximum ());
164164 outboundQoS2 = new ConcurrentHashMap <>();
165165 outboundQoS1 = new ConcurrentHashMap <>();
166166 outboundQoS0 = new ConcurrentHashMap <>();
@@ -176,7 +176,7 @@ protected ClientState(MqttClientPersistence persistence, CommsTokenStore tokenSt
176176 this .tokenStore = tokenStore ;
177177 this .clientComms = clientComms ;
178178 this .pingSender = pingSender ;
179- this .mqttSession = mqttSession ;
179+ this .mqttConnection = mqttConnection ;
180180
181181 restoreState ();
182182 }
@@ -460,7 +460,7 @@ protected void restoreState() throws MqttException {
460460
461461 private void restoreInflightMessages () {
462462 final String methodName = "restoreInflightMessages" ;
463- pendingMessages = new Vector <MqttWireMessage >(this .mqttSession .getReceiveMaximum ());
463+ pendingMessages = new Vector <MqttWireMessage >(this .mqttConnection .getReceiveMaximum ());
464464 pendingFlows = new Vector <MqttWireMessage >();
465465
466466 Enumeration <Integer > keys = outboundQoS2 .keys ();
@@ -519,18 +519,18 @@ public void send(MqttWireMessage message, MqttToken token) throws MqttException
519519 message .setMessageId (getNextMessageId ());
520520 }
521521 // Set Topic Alias if required
522- if (message instanceof MqttPublish && this .mqttSession .getOutgoingTopicAliasMaximum () > 0 ) {
522+ if (message instanceof MqttPublish && this .mqttConnection .getOutgoingTopicAliasMaximum () > 0 ) {
523523 String topic = ((MqttPublish ) message ).getTopicName ();
524524 if (outgoingTopicAliases .containsKey (topic )) {
525525 // Existing Topic Alias, Assign it and remove the topic string
526526 ((MqttPublish ) message ).getProperties ().setTopicAlias (outgoingTopicAliases .get (topic ));
527527 ((MqttPublish ) message ).setTopicName (null );
528528 } else {
529- if (outgoingTopicAliasCount <= this .mqttSession .getOutgoingTopicAliasMaximum ()) {
529+ int nextOutgoingTopicAlias = this .mqttConnection .getNextOutgoingTopicAlias ();
530+ if (nextOutgoingTopicAlias <= this .mqttConnection .getOutgoingTopicAliasMaximum ()) {
530531 // Create a new Topic Alias and increment the counter
531- ((MqttPublish ) message ).getProperties ().setTopicAlias (outgoingTopicAliasCount );
532- outgoingTopicAliases .put (((MqttPublish ) message ).getTopicName (), outgoingTopicAliasCount );
533- outgoingTopicAliasCount ++;
532+ ((MqttPublish ) message ).getProperties ().setTopicAlias (nextOutgoingTopicAlias );
533+ outgoingTopicAliases .put (((MqttPublish ) message ).getTopicName (), nextOutgoingTopicAlias );
534534 }
535535 }
536536 }
@@ -544,7 +544,7 @@ public void send(MqttWireMessage message, MqttToken token) throws MqttException
544544
545545 if (message instanceof MqttPublish ) {
546546 synchronized (queueLock ) {
547- if (actualInFlight >= this .mqttSession .getReceiveMaximum ()) {
547+ if (actualInFlight >= this .mqttConnection .getReceiveMaximum ()) {
548548 // @TRACE 613= sending {0} msgs at max inflight window
549549 log .fine (CLASS_NAME , methodName , "613" , new Object [] { Integer .valueOf (actualInFlight ) });
550550
@@ -830,7 +830,7 @@ protected MqttWireMessage get() throws MqttException {
830830 // freed.
831831 // In both cases queueLock will be notified.
832832 if ((pendingMessages .isEmpty () && pendingFlows .isEmpty ())
833- || (pendingFlows .isEmpty () && actualInFlight >= this .mqttSession .getReceiveMaximum ())) {
833+ || (pendingFlows .isEmpty () && actualInFlight >= this .mqttConnection .getReceiveMaximum ())) {
834834 try {
835835 // @TRACE 644=wait for new work or for space in the inflight window
836836 log .fine (CLASS_NAME , methodName , "644" );
@@ -876,7 +876,7 @@ protected MqttWireMessage get() throws MqttException {
876876
877877 // If the inflight window is full then messages are not
878878 // processed until the inflight window has space.
879- if (actualInFlight < this .mqttSession .getReceiveMaximum ()) {
879+ if (actualInFlight < this .mqttConnection .getReceiveMaximum ()) {
880880 // The in flight window is not full so process the
881881 // first message in the queue
882882 result = (MqttWireMessage ) pendingMessages .elementAt (0 );
@@ -1127,7 +1127,7 @@ protected void handleOrphanedAcks(MqttAck ack) throws MqttException {
11271127 } else if (ack instanceof MqttPubRec ) {
11281128 // MqttPubRec - Send an MqttPubRel with the appropriate Reason Code
11291129 MqttProperties pubRelProperties = new MqttProperties ();
1130- if (this .mqttSession .isSendReasonMessages ()) {
1130+ if (this .mqttConnection .isSendReasonMessages ()) {
11311131 String reasonString = String .format ("Message identifier [%d] was not found. Discontinuing QoS 2 flow." ,
11321132 ack .getMessageId ());
11331133 pubRelProperties .setReasonString (reasonString );
@@ -1192,10 +1192,11 @@ protected void notifyReceivedMsg(MqttWireMessage message) throws MqttException {
11921192 int incomingTopicAlias = send .getProperties ().getTopicAlias ();
11931193
11941194 // Are incoming Topic Aliases enabled / is it a valid Alias?
1195- if (incomingTopicAlias > this .mqttSession .getIncomingTopicAliasMax () || incomingTopicAlias == 0 ) {
1195+ if (incomingTopicAlias > this .mqttConnection .getIncomingTopicAliasMax ()
1196+ || incomingTopicAlias == 0 ) {
11961197 // @TRACE 653=Invalid Topic Alias: topicAliasMax={0}, publishTopicAlias={1}
11971198 log .severe (CLASS_NAME , methodName , "653" ,
1198- new Object [] { Integer .valueOf (this .mqttSession .getIncomingTopicAliasMax ()),
1199+ new Object [] { Integer .valueOf (this .mqttConnection .getIncomingTopicAliasMax ()),
11991200 Integer .valueOf (incomingTopicAlias ) });
12001201 if (callback != null ) {
12011202 callback .mqttErrorOccurred (new MqttException (MqttException .REASON_CODE_INVALID_TOPIC_ALAS ));
@@ -1613,7 +1614,7 @@ public Properties getDebug() {
16131614 props .put ("In use msgids" , inUseMsgIds );
16141615 props .put ("pendingMessages" , pendingMessages );
16151616 props .put ("pendingFlows" , pendingFlows );
1616- props .put ("serverReceiveMaximum" , Integer .valueOf (this .mqttSession .getReceiveMaximum ()));
1617+ props .put ("serverReceiveMaximum" , Integer .valueOf (this .mqttConnection .getReceiveMaximum ()));
16171618 props .put ("nextMsgID" , Integer .valueOf (nextMsgId ));
16181619 props .put ("actualInFlight" , Integer .valueOf (actualInFlight ));
16191620 props .put ("inFlightPubRels" , Integer .valueOf (inFlightPubRels ));
0 commit comments