2014-06-11 23:40:19 +02:00
|
|
|
/*
|
2015-08-08 19:36:14 +02:00
|
|
|
* Copyright (c) 2012-2015 The original author or authors
|
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;
|
2015-11-20 20:54:27 +01:00
|
|
|
import io.moquette.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;
|
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;
|
|
|
|
|
private String 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
|
|
|
|
|
|
|
|
public void setGuid(String guid) {
|
|
|
|
|
this.m_guid = guid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getGuid() {
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2015-11-18 22:19:43 +01:00
|
|
|
void storeRetained(String topic, String 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.
|
|
|
|
|
*/
|
2012-09-01 16:02:48 +02:00
|
|
|
Collection<StoredMessage> searchMatching(IMatchingCondition condition);
|
|
|
|
|
|
2015-11-15 11:16:18 +01:00
|
|
|
/**
|
|
|
|
|
* Persist the message.
|
|
|
|
|
* @return the unique id in the storage (guid).
|
|
|
|
|
* */
|
2015-11-18 22:19:43 +01:00
|
|
|
String storePublishForFuture(StoredMessage evt);
|
2012-09-01 16:18:09 +02:00
|
|
|
|
2014-05-20 23:02:52 +02:00
|
|
|
/**
|
|
|
|
|
* Return the list of persisted publishes for the given clientID.
|
|
|
|
|
* For QoS1 and QoS2 with clean session flag, this method return the list of
|
|
|
|
|
* missed publish events while the client was disconnected.
|
|
|
|
|
*/
|
2015-11-18 22:19:43 +01:00
|
|
|
List<StoredMessage> listMessagesInSession(Collection<String> guids);
|
2013-11-27 18:47:34 +01:00
|
|
|
|
2015-01-30 00:28:01 +01:00
|
|
|
void dropMessagesInSession(String clientID);
|
2012-09-01 16:18:09 +02:00
|
|
|
|
2015-11-18 22:19:43 +01:00
|
|
|
StoredMessage getMessageByGuid(String 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
|
|
|
}
|