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

192 lines
5.8 KiB
Java
Raw Normal View History

2016-03-03 16:08:52 -08:00
/*
2017-01-04 14:37:29 +01:00
* Copyright (c) 2012-2017 The original author or authorsgetRockQuestions()
2016-03-03 16:08:52 -08: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.
*/
package io.moquette.spi;
import java.util.Collection;
2016-03-03 16:08:52 -08:00
import java.util.List;
import java.util.concurrent.BlockingQueue;
2016-03-03 16:08:52 -08:00
import io.moquette.spi.IMessagesStore.StoredMessage;
import io.moquette.spi.impl.subscriptions.Subscription;
/**
* Store used to handle the persistence of the subscriptions tree.
*
* @author andrea
*/
public interface ISessionsStore {
class ClientTopicCouple {
public final String topicFilter;
public final String clientID;
public ClientTopicCouple(String clientID, String topicFilter) {
this.clientID = clientID;
this.topicFilter = topicFilter;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClientTopicCouple that = (ClientTopicCouple) o;
if (topicFilter != null ? !topicFilter.equals(that.topicFilter) : that.topicFilter != null) return false;
return !(clientID != null ? !clientID.equals(that.clientID) : that.clientID != null);
}
@Override
public int hashCode() {
int result = topicFilter != null ? topicFilter.hashCode() : 0;
result = 31 * result + (clientID != null ? clientID.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "ClientTopicCouple{" +
"topicFilter='" + topicFilter + '\'' +
", clientID='" + clientID + '\'' +
'}';
}
}
void initStore();
void updateCleanStatus(String clientID, boolean cleanSession);
2016-03-03 16:08:52 -08:00
/**
* Add a new subscription to the session
2017-01-04 12:52:42 +01:00
* @param newSubscription the subscription to add.
2016-03-03 16:08:52 -08:00
*/
void addNewSubscription(Subscription newSubscription);
/**
* Removed a specific subscription
2017-01-04 12:52:42 +01:00
* @param topic the topic of the subscription.
* @param clientID the session client.
2016-03-03 16:08:52 -08:00
* */
void removeSubscription(String topic, String clientID);
/**
* Remove all the subscriptions of the session
2017-01-04 12:52:42 +01:00
* @param sessionID the client ID
2016-03-03 16:08:52 -08:00
*/
void wipeSubscriptions(String sessionID);
/**
* Return all topic filters to recreate the subscription tree.
* */
List<ClientTopicCouple> listAllSubscriptions();
/**
2017-01-04 12:52:42 +01:00
* @param couple the subscription descriptor.
2016-03-03 16:08:52 -08:00
* @return the subscription stored by clientID and topicFilter, if any else null;
* */
Subscription getSubscription(ClientTopicCouple couple);
2016-09-16 10:08:02 +09:00
/*
* @return all subscriptions stored.
*/
List<Subscription> getSubscriptions();
2016-03-03 16:08:52 -08:00
/**
2017-01-04 12:52:42 +01:00
* @param clientID the session client ID.
2016-03-03 16:08:52 -08:00
* @return true iff there are subscriptions persisted with clientID
*/
boolean contains(String clientID);
ClientSession createNewSession(String clientID, boolean cleanSession);
/**
* @param clientID the client owning the session.
* @return the session for the given clientID, null if not found.
* */
ClientSession sessionForClient(String clientID);
/**
* Returns all the sessions
* @return
*/
Collection<ClientSession> getAllSessions();
2016-03-03 16:08:52 -08:00
void inFlightAck(String clientID, int messageID);
/**
2017-01-04 12:52:42 +01:00
* Save the binding messageID, clientID - guid
* @param clientID the client ID
* @param messageID the message ID
* @param guid the uuid of the message to mark as inflight.
2016-03-03 16:08:52 -08:00
* */
void inFlight(String clientID, int messageID, MessageGUID guid);
2016-03-03 16:08:52 -08:00
/**
* Return the next valid packetIdentifier for the given client session.
2017-01-04 12:52:42 +01:00
* @param clientID the clientID requesting next packet id.
* @return the next valid id.
2016-03-03 16:08:52 -08:00
* */
int nextPacketID(String clientID);
/**
* List the guids for retained messages for the session
2017-01-04 12:52:42 +01:00
* @param clientID the client ID owning the queue.
* @return the list of queue message UUIDs.
2016-03-03 16:08:52 -08:00
* */
BlockingQueue<StoredMessage> queue(String clientID);
2016-03-03 16:08:52 -08:00
void dropQueue(String clientID);
2016-03-03 16:08:52 -08:00
void moveInFlightToSecondPhaseAckWaiting(String clientID, int messageID);
2016-03-03 16:08:52 -08:00
/**
2017-01-04 12:52:42 +01:00
* @param clientID the client ID accessing the second phase.
* @param messageID the message ID that reached the second phase.
* @return the guid of message just acked.
* */
MessageGUID secondPhaseAcknowledged(String clientID, int messageID);
2016-03-03 16:08:52 -08:00
MessageGUID mapToGuid(String clientID, int messageID);
2016-03-03 16:08:52 -08:00
StoredMessage getInflightMessage(String clientID, int messageID);
/**
* Returns the number of inflight messages for the given client ID
*
* @param clientID
* @return
*/
int getInflightMessagesNo(String clientID);
/**
* Returns the size of the session queue for the given client ID
*
* @param clientID
* @return
*/
int getPendingPublishMessagesNo(String clientID);
/**
* Returns the number of second-phase ACK pending messages for the given
* client ID
*
* @param clientID
* @return
*/
int getSecondPhaseAckPendingMessages(String clientID);
2016-03-03 16:08:52 -08:00
}