org.eclipse.paho.client.mqttv3
Interface MqttClientPersistence

All Known Implementing Classes:
MqttDefaultFilePersistence

public interface MqttClientPersistence

Represents a persistent data store, used to store outbound and inbound messages while they are in flight, enabling delivery to the QOS specified. You can specify an implementation of this interface using MqttClient.MqttClient(String, String, MqttClientPersistence), which the MqttClient will use to persist QoS 1 and 2 messages.

If the methods defined throw the MqttPersistenceException then the state of the data persisted should remain as prior to the method being called. For example, if put(String, MqttPersistable) throws an exception at any point then the data will be assumed to not be in the persistent store. Similarly if remove(String) throws an exception then the data will be assumed to still be held in the persistent store.

It is up to the persistence interface to log any exceptions or error information which may be required when diagnosing a persistence failure.


Method Summary
 void clear()
          Clears persistence, so that it no longer contains any persisted data.
 void close()
          Close the persistent store that was previously opened.
 boolean containsKey(java.lang.String key)
          Returns whether or not data is persisted using the specified key.
 MqttPersistable get(java.lang.String key)
          Gets the specified data out of the persistent store.
 java.util.Enumeration keys()
          Returns an Enumeration over the keys in this persistent data store.
 void open(java.lang.String clientId, java.lang.String serverURI)
          Initialise the persistent store.
 void put(java.lang.String key, MqttPersistable persistable)
          Puts the specified data into the persistent store.
 void remove(java.lang.String key)
          Remove the data for the specified key.
 

Method Detail

open

public void open(java.lang.String clientId,
                 java.lang.String serverURI)
          throws MqttPersistenceException
Initialise the persistent store. If a persistent store exists for this client ID then open it, otherwise create a new one. If the persistent store is already open then just return. An application may use the same client ID to connect to many different servers, so the client ID in conjunction with the connection will uniquely identify the persistence store required.

Parameters:
clientId - The client for which the persistent store should be opened.
serverURI - The connection string as specified when the MQTT client instance was created.
Throws:
MqttPersistenceException - if there was a problem opening the persistent store.

close

public void close()
           throws MqttPersistenceException
Close the persistent store that was previously opened. This will be called when a client application disconnects from the broker.

Throws:
MqttPersistenceException

put

public void put(java.lang.String key,
                MqttPersistable persistable)
         throws MqttPersistenceException
Puts the specified data into the persistent store.

Parameters:
key - the key for the data, which will be used later to retrieve it.
persistable - the data to persist
Throws:
MqttPersistenceException - if there was a problem putting the data into the persistent store.

get

public MqttPersistable get(java.lang.String key)
                    throws MqttPersistenceException
Gets the specified data out of the persistent store.

Parameters:
key - the key for the data, which was used when originally saving it.
Returns:
the un-persisted data
Throws:
MqttPersistenceException - if there was a problem getting the data from the persistent store.

remove

public void remove(java.lang.String key)
            throws MqttPersistenceException
Remove the data for the specified key.

Throws:
MqttPersistenceException

keys

public java.util.Enumeration keys()
                           throws MqttPersistenceException
Returns an Enumeration over the keys in this persistent data store.

Returns:
an enumeration of String objects.
Throws:
MqttPersistenceException

clear

public void clear()
           throws MqttPersistenceException
Clears persistence, so that it no longer contains any persisted data.

Throws:
MqttPersistenceException

containsKey

public boolean containsKey(java.lang.String key)
                    throws MqttPersistenceException
Returns whether or not data is persisted using the specified key.

Parameters:
key - the key for data, which was used when originally saving it.
Throws:
MqttPersistenceException