2014-06-11 23:40:19 +02:00
|
|
|
/*
|
2017-01-04 14:37:29 +01:00
|
|
|
* Copyright (c) 2012-2017 The original author or authorsgetRockQuestions()
|
2014-06-11 23:40:19 +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.
|
|
|
|
|
*/
|
2015-11-20 20:54:27 +01:00
|
|
|
package io.moquette.spi;
|
2012-09-01 16:02:48 +02:00
|
|
|
|
2014-08-30 15:59:59 +02:00
|
|
|
import java.io.Serializable;
|
2013-11-25 09:34:36 +01:00
|
|
|
import java.nio.ByteBuffer;
|
2016-02-03 23:20:15 +01:00
|
|
|
import io.moquette.parser.proto.messages.AbstractMessage;
|
2012-09-01 16:02:48 +02:00
|
|
|
|
|
|
|
|
import java.util.Collection;
|
2012-09-01 16:18:09 +02:00
|
|
|
import java.util.List;
|
2016-11-10 14:13:42 -08:00
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
2012-09-01 16:02:48 +02:00
|
|
|
|
|
|
|
|
/**
|
2014-06-30 23:36:00 +02:00
|
|
|
* Defines the SPI to be implemented by a StorageService that handle persistence of messages
|
2012-09-01 16:02:48 +02:00
|
|
|
*/
|
2014-06-30 23:36:00 +02:00
|
|
|
public interface IMessagesStore {
|
2012-09-01 16:02:48 +02:00
|
|
|
|
2015-10-24 16:26:43 +02:00
|
|
|
class StoredMessage implements Serializable {
|
2014-08-30 15:59:59 +02:00
|
|
|
final AbstractMessage.QOSType m_qos;
|
|
|
|
|
final byte[] m_payload;
|
|
|
|
|
final String m_topic;
|
2015-11-18 22:19:43 +01:00
|
|
|
private boolean m_retained;
|
|
|
|
|
private String m_clientID;
|
|
|
|
|
//Optional attribute, available only fo QoS 1 and 2
|
|
|
|
|
private Integer m_msgID;
|
2016-09-23 11:51:25 +02:00
|
|
|
private MessageGUID m_guid;
|
2014-08-30 15:59:59 +02:00
|
|
|
|
|
|
|
|
public StoredMessage(byte[] message, AbstractMessage.QOSType qos, String topic) {
|
|
|
|
|
m_qos = qos;
|
|
|
|
|
m_payload = message;
|
|
|
|
|
m_topic = topic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AbstractMessage.QOSType getQos() {
|
|
|
|
|
return m_qos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ByteBuffer getPayload() {
|
|
|
|
|
return (ByteBuffer) ByteBuffer.allocate(m_payload.length).put(m_payload).flip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getTopic() {
|
|
|
|
|
return m_topic;
|
|
|
|
|
}
|
2015-11-18 22:19:43 +01:00
|
|
|
|
2016-09-23 11:51:25 +02:00
|
|
|
public void setGuid(MessageGUID guid) {
|
2015-11-18 22:19:43 +01:00
|
|
|
this.m_guid = guid;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-23 11:51:25 +02:00
|
|
|
public MessageGUID getGuid() {
|
2015-11-18 22:19:43 +01:00
|
|
|
return m_guid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getClientID() {
|
|
|
|
|
return m_clientID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setClientID(String m_clientID) {
|
|
|
|
|
this.m_clientID = m_clientID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setMessageID(Integer messageID) {
|
|
|
|
|
this.m_msgID = messageID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer getMessageID() {
|
|
|
|
|
return m_msgID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ByteBuffer getMessage() {
|
|
|
|
|
return ByteBuffer.wrap(m_payload);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setRetained(boolean retained) {
|
|
|
|
|
this.m_retained = retained;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isRetained() {
|
|
|
|
|
return m_retained;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
return "PublishEvent{" +
|
|
|
|
|
"m_msgID=" + m_msgID +
|
|
|
|
|
", clientID='" + m_clientID + '\'' +
|
|
|
|
|
", m_retain=" + m_retained +
|
|
|
|
|
", m_qos=" + m_qos +
|
|
|
|
|
", m_topic='" + m_topic + '\'' +
|
|
|
|
|
'}';
|
|
|
|
|
}
|
2014-08-30 15:59:59 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-01 16:02:48 +02:00
|
|
|
/**
|
|
|
|
|
* Used to initialize all persistent store structures
|
|
|
|
|
* */
|
|
|
|
|
void initStore();
|
|
|
|
|
|
2014-05-20 23:02:52 +02:00
|
|
|
/**
|
|
|
|
|
* Persist the message.
|
|
|
|
|
* If the message is empty then the topic is cleaned, else it's stored.
|
2017-01-04 12:52:42 +01:00
|
|
|
* @param topic for the retained.
|
|
|
|
|
* @param guid of the message to mark as retained.
|
2014-05-20 23:02:52 +02:00
|
|
|
*/
|
2016-09-23 11:51:25 +02:00
|
|
|
void storeRetained(String topic, MessageGUID guid);
|
2012-09-01 16:02:48 +02:00
|
|
|
|
2014-05-20 23:02:52 +02:00
|
|
|
/**
|
|
|
|
|
* Return a list of retained messages that satisfy the condition.
|
2017-01-04 12:52:42 +01:00
|
|
|
* @param condition the condition to match during the search.
|
|
|
|
|
* @return the collection of matching messages.
|
2014-05-20 23:02:52 +02:00
|
|
|
*/
|
2012-09-01 16:02:48 +02:00
|
|
|
Collection<StoredMessage> searchMatching(IMatchingCondition condition);
|
|
|
|
|
|
2015-11-15 11:16:18 +01:00
|
|
|
/**
|
|
|
|
|
* Persist the message.
|
2017-01-04 12:52:42 +01:00
|
|
|
* @param storedMessage the message to store for future usage.
|
2015-11-15 11:16:18 +01:00
|
|
|
* @return the unique id in the storage (guid).
|
|
|
|
|
* */
|
2017-01-04 12:52:42 +01:00
|
|
|
MessageGUID storePublishForFuture(StoredMessage storedMessage);
|
2012-09-01 16:18:09 +02:00
|
|
|
|
2015-01-30 00:28:01 +01:00
|
|
|
void dropMessagesInSession(String clientID);
|
2012-09-01 16:18:09 +02:00
|
|
|
|
2016-09-23 11:51:25 +02:00
|
|
|
StoredMessage getMessageByGuid(MessageGUID guid);
|
2015-11-16 23:45:47 +01:00
|
|
|
|
2014-07-31 00:08:41 +02:00
|
|
|
void cleanRetained(String topic);
|
2012-09-01 16:02:48 +02:00
|
|
|
}
|