Files
IM-server-new/broker/src/main/java/io/moquette/spi/ClientSession.java
T

121 lines
3.7 KiB
Java
Raw Normal View History

/*
2018-04-27 20:17:47 +02:00
* Copyright (c) 2012-2018 The original author or authors
* ------------------------------------------------------
* 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
package io.moquette.spi;
import io.moquette.spi.impl.subscriptions.Subscription;
2017-02-14 17:23:04 +01:00
import io.moquette.spi.impl.subscriptions.Topic;
import java.util.HashSet;
import java.util.Set;
/**
* 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>
*/
2017-09-12 19:48:42 +02:00
public abstract class ClientSession {
public final String clientID;
2017-09-12 19:48:42 +02:00
protected Set<Subscription> subscriptions = new HashSet<>();
2017-09-12 19:48:42 +02:00
public ClientSession(String clientID) {
this.clientID = clientID;
}
2017-09-12 19:48:42 +02:00
public Subscription findSubscriptionByTopicFilter(Subscription matchingSub) {
for (Subscription sub : this.subscriptions) {
2017-09-12 19:48:42 +02:00
if (matchingSub.equals(sub)) {
return sub;
}
}
2017-09-12 19:48:42 +02:00
return null;
}
2017-09-12 19:48:42 +02:00
public Set<Subscription> getSubscriptions() {
return subscriptions;
}
2017-09-12 19:48:42 +02:00
public abstract boolean isCleanSession();
2017-09-12 19:48:42 +02:00
public abstract boolean subscribe(Subscription newSubscription);
2017-09-12 19:48:42 +02:00
public abstract void unsubscribeFrom(Topic topicFilter);
2017-09-12 19:48:42 +02:00
public abstract void disconnect();
2017-09-12 19:48:42 +02:00
public abstract void cleanSession();
protected abstract int nextPacketId();
public abstract IMessagesStore.StoredMessage inFlightAcknowledged(int messageID);
/**
2017-09-12 19:48:42 +02:00
* Mark the message as publish in flight.
*
* @return the packetID for the message in flight.
* */
2017-09-12 19:48:42 +02:00
public abstract int inFlightAckWaiting(IMessagesStore.StoredMessage msg);
2017-09-12 19:48:42 +02:00
public abstract IMessagesStore.StoredMessage completeReleasedPublish(int messageID);
/**
* 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-09-12 19:48:42 +02:00
public abstract boolean isEmptyQueue();
2017-09-12 19:48:42 +02:00
public abstract void dropQueue();
2017-09-12 19:48:42 +02:00
public abstract IMessagesStore.StoredMessage inboundInflight(int messageID);
2017-09-12 19:48:42 +02:00
public abstract void markAsInboundInflight(int messageID, IMessagesStore.StoredMessage msg);
2017-09-12 19:48:42 +02:00
public abstract void moveInFlightToSecondPhaseAckWaiting(int messageID, IMessagesStore.StoredMessage msg);
2017-09-12 19:48:42 +02:00
public abstract int getPendingPublishMessagesNo();
2017-09-12 19:48:42 +02:00
public abstract int countPubReleaseWaitingPubComplete();
public abstract int getInflightMessagesNo();
@Override
public String toString() {
return getClass().getSimpleName() + "{clientID='" + clientID + "'}";
}
public abstract void wipeSubscriptions();
2017-02-01 15:45:06 +01:00
}