2015-10-24 16:26:43 +02:00
|
|
|
|
/*
|
2018-04-27 20:17:47 +02:00
|
|
|
|
* Copyright (c) 2012-2018 The original author or authors
|
2015-10-24 16:26:43 +02:00
|
|
|
|
* ------------------------------------------------------
|
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
|
|
* and Apache License v2.0 which accompanies this distribution.
|
|
|
|
|
|
*
|
|
|
|
|
|
* The Eclipse Public License is available at
|
|
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
*
|
|
|
|
|
|
* The Apache License v2.0 is available at
|
|
|
|
|
|
* http://www.opensource.org/licenses/apache2.0.php
|
|
|
|
|
|
*
|
|
|
|
|
|
* You may elect to redistribute this code under either of these licenses.
|
|
|
|
|
|
*/
|
2017-02-01 15:45:06 +01:00
|
|
|
|
|
2015-11-20 20:54:27 +01:00
|
|
|
|
package io.moquette.spi;
|
2015-10-24 16:26:43 +02:00
|
|
|
|
|
2018-07-19 17:57:52 +02:00
|
|
|
|
import io.moquette.spi.impl.WillMessage;
|
2015-11-20 20:54:27 +01:00
|
|
|
|
import io.moquette.spi.impl.subscriptions.Subscription;
|
2017-02-14 17:23:04 +01:00
|
|
|
|
import io.moquette.spi.impl.subscriptions.Topic;
|
2018-07-19 17:57:52 +02:00
|
|
|
|
import io.netty.handler.codec.mqtt.MqttConnectMessage;
|
2017-04-20 23:14:23 +02:00
|
|
|
|
|
2015-10-31 11:14:40 +01:00
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
import java.util.Set;
|
2015-10-24 16:26:43 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
2015-11-15 11:16:18 +01:00
|
|
|
|
* Model a Session like describe on page 25 of MQTT 3.1.1 specification:
|
|
|
|
|
|
* The Session state in the Server consists of:
|
|
|
|
|
|
* <ul>
|
|
|
|
|
|
* <li>The existence of a Session, even if the rest of the Session state is empty.</li>
|
|
|
|
|
|
* <li>The Client’s subscriptions.</li>
|
|
|
|
|
|
* <li>QoS 1 and QoS 2 messages which have been sent to the Client, but have not been
|
|
|
|
|
|
* completely acknowledged.</li>
|
|
|
|
|
|
* <li>QoS 1 and QoS 2 messages pending transmission to the Client.</li>
|
|
|
|
|
|
* <li>QoS 2 messages which have been received from the Client, but have not been
|
|
|
|
|
|
* completely acknowledged.</li>
|
|
|
|
|
|
* <li>Optionally, QoS 0 messages pending transmission to the Client.</li>
|
|
|
|
|
|
* </ul>
|
2015-10-24 16:26:43 +02:00
|
|
|
|
*/
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract class ClientSession {
|
2015-10-31 11:14:40 +01:00
|
|
|
|
|
2015-10-24 16:26:43 +02:00
|
|
|
|
public final String clientID;
|
|
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
protected Set<Subscription> subscriptions = new HashSet<>();
|
2015-10-31 11:14:40 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public ClientSession(String clientID) {
|
2015-10-24 16:26:43 +02:00
|
|
|
|
this.clientID = clientID;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public Subscription findSubscriptionByTopicFilter(Subscription matchingSub) {
|
2015-10-31 11:34:15 +01:00
|
|
|
|
for (Subscription sub : this.subscriptions) {
|
2017-09-12 19:48:42 +02:00
|
|
|
|
if (matchingSub.equals(sub)) {
|
|
|
|
|
|
return sub;
|
2015-10-31 11:34:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-09-12 19:48:42 +02:00
|
|
|
|
return null;
|
2015-10-31 11:34:15 +01:00
|
|
|
|
}
|
2015-11-08 18:25:55 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public Set<Subscription> getSubscriptions() {
|
|
|
|
|
|
return subscriptions;
|
2015-11-08 18:25:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract boolean isCleanSession();
|
2015-11-08 18:25:55 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract boolean subscribe(Subscription newSubscription);
|
2015-12-06 19:55:04 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract void unsubscribeFrom(Topic topicFilter);
|
2016-02-02 22:39:11 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract void disconnect();
|
2015-11-15 11:16:18 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract void cleanSession();
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract int nextPacketId();
|
|
|
|
|
|
|
|
|
|
|
|
public abstract IMessagesStore.StoredMessage inFlightAcknowledged(int messageID);
|
2015-11-15 11:16:18 +01:00
|
|
|
|
|
2017-04-04 21:29:38 +02:00
|
|
|
|
/**
|
2017-09-12 19:48:42 +02:00
|
|
|
|
* Mark the message as publish in flight.
|
2017-04-04 21:29:38 +02:00
|
|
|
|
*
|
|
|
|
|
|
* @return the packetID for the message in flight.
|
|
|
|
|
|
* */
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract int inFlightAckWaiting(IMessagesStore.StoredMessage msg);
|
2015-11-15 11:16:18 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract IMessagesStore.StoredMessage completeReleasedPublish(int messageID);
|
2015-11-15 11:16:18 +01:00
|
|
|
|
|
2017-01-09 21:53:26 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* Enqueue a message to be sent to the client.
|
2017-02-01 15:45:06 +01:00
|
|
|
|
*
|
|
|
|
|
|
* @param message
|
|
|
|
|
|
* the message to enqueue.
|
|
|
|
|
|
*/
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract void enqueue(IMessagesStore.StoredMessage message);
|
2015-11-16 23:45:47 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* @return the next message queued to this client or null if empty.
|
|
|
|
|
|
* */
|
|
|
|
|
|
public abstract EnqueuedMessage poll();
|
2017-04-04 21:29:38 +02:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract boolean isEmptyQueue();
|
2016-03-06 19:50:26 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract void dropQueue();
|
2017-01-12 17:00:18 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract IMessagesStore.StoredMessage inboundInflight(int messageID);
|
2017-01-12 17:00:18 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract void markAsInboundInflight(int messageID, IMessagesStore.StoredMessage msg);
|
2017-01-12 17:00:18 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract void moveInFlightToSecondPhaseAckWaiting(int messageID, IMessagesStore.StoredMessage msg);
|
2017-01-12 17:00:18 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract int getPendingPublishMessagesNo();
|
2017-01-12 17:00:18 +01:00
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
public abstract int countPubReleaseWaitingPubComplete();
|
|
|
|
|
|
|
|
|
|
|
|
public abstract int getInflightMessagesNo();
|
|
|
|
|
|
|
2018-07-19 17:57:52 +02:00
|
|
|
|
public abstract void wipeSubscriptions();
|
|
|
|
|
|
|
|
|
|
|
|
public abstract void storeWillMessage(MqttConnectMessage msg, String clientId);
|
|
|
|
|
|
|
|
|
|
|
|
public abstract void removeWill();
|
|
|
|
|
|
|
|
|
|
|
|
public abstract WillMessage willMessage();
|
|
|
|
|
|
|
2017-09-12 19:48:42 +02:00
|
|
|
|
@Override
|
|
|
|
|
|
public String toString() {
|
|
|
|
|
|
return getClass().getSimpleName() + "{clientID='" + clientID + "'}";
|
|
|
|
|
|
}
|
2017-02-01 15:45:06 +01:00
|
|
|
|
}
|