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

146 lines
4.0 KiB
Java
Raw Normal View History

/*
2017-03-19 22:01:23 +01:00
* Copyright (c) 2012-2017 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:46:15 +01:00
package io.moquette.spi;
2017-02-14 17:23:04 +01:00
import io.moquette.spi.impl.subscriptions.Topic;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.mqtt.MqttQoS;
2014-08-30 15:59:59 +02:00
import java.io.Serializable;
2013-11-25 09:34:36 +01:00
import java.nio.ByteBuffer;
import java.util.Collection;
/**
* Defines the SPI to be implemented by a StorageService that handle persistence of messages
*/
public interface IMessagesStore {
class StoredMessage implements Serializable {
2017-02-01 15:46:15 +01:00
private static final long serialVersionUID = 1755296138639817304L;
final MqttQoS m_qos;
2014-08-30 15:59:59 +02:00
final byte[] m_payload;
final String m_topic;
private boolean m_retained;
private String m_clientID;
2017-02-01 15:46:15 +01:00
// Optional attribute, available only fo QoS 1 and 2
private Integer m_msgID;
private MessageGUID m_guid;
2014-08-30 15:59:59 +02:00
public StoredMessage(byte[] message, MqttQoS qos, String topic) {
2014-08-30 15:59:59 +02:00
m_qos = qos;
m_payload = message;
m_topic = topic;
}
public MqttQoS getQos() {
2014-08-30 15:59:59 +02:00
return m_qos;
}
public ByteBuffer getPayload() {
return (ByteBuffer) ByteBuffer.allocate(m_payload.length).put(m_payload).flip();
}
public String getTopic() {
return m_topic;
}
public void setGuid(MessageGUID guid) {
this.m_guid = guid;
}
public MessageGUID 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 ByteBuf getMessage() {
return Unpooled.copiedBuffer(m_payload);
}
public void setRetained(boolean retained) {
this.m_retained = retained;
}
public boolean isRetained() {
return m_retained;
}
@Override
public String toString() {
2017-02-01 15:46:15 +01:00
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
}
/**
* Used to initialize all persistent store structures
2017-02-01 15:46:15 +01:00
*/
void initStore();
/**
2017-02-01 15:46:15 +01:00
* Persist the message. If the message is empty then the topic is cleaned, else it's stored.
*
* @param topic
* for the retained.
* @param guid
* of the message to mark as retained.
*/
2017-02-14 17:23:04 +01:00
void storeRetained(Topic topic, MessageGUID guid);
/**
* Return a list of retained messages that satisfy the condition.
2017-02-01 15:46:15 +01:00
*
* @param condition
* the condition to match during the search.
2017-01-04 12:52:42 +01:00
* @return the collection of matching messages.
*/
Collection<StoredMessage> searchMatching(IMatchingCondition condition);
/**
* Persist the message.
2017-02-01 15:46:15 +01:00
*
* @param storedMessage
* the message to store for future usage.
* @return the unique id in the storage (guid).
2017-02-01 15:46:15 +01:00
*/
2017-01-04 12:52:42 +01:00
MessageGUID storePublishForFuture(StoredMessage storedMessage);
2015-01-30 00:28:01 +01:00
void dropMessagesInSession(String clientID);
StoredMessage getMessageByGuid(MessageGUID guid);
2015-11-16 23:45:47 +01:00
2017-02-14 17:23:04 +01:00
void cleanRetained(Topic topic);
int getPendingPublishMessages(String clientID);
}