Package 

Class MqttDefaultFilePersistence

  • All Implemented Interfaces:
    org.eclipse.paho.client.mqttv3.MqttClientPersistence

    
    public class MqttDefaultFilePersistence
     implements MqttClientPersistence
                        

    An implementation of the MqttClientPersistence interface that provides file based persistence. A directory is specified when the Persistence object is created. When the persistence is then opened (see open), a sub-directory is made beneath the base for this client ID and connection key. This allows one persistence base directory to be shared by multiple clients. The sub-directory's name is created from a concatenation of the client ID and connection key with any instance of '/', '\\', ':' or ' ' removed.

    • Method Summary

      Modifier and Type Method Description
      void open(String clientId, String theConnection) Initialise the persistent store.
      void close() Close the persistent store that was previously opened.
      void put(String key, MqttPersistable message) Writes the specified persistent data to the previously specified persistence directory.
      MqttPersistable get(String key) Gets the specified data out of the persistent store.
      void remove(String key) Deletes the data with the specified key from the previously specified persistence directory.
      Enumeration keys() Returns all of the persistent data from the previously specified persistence directory.
      boolean containsKey(String key) Returns whether or not data is persisted using the specified key.
      void clear() Clears persistence, so that it no longer contains any persisted data.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MqttDefaultFilePersistence

        MqttDefaultFilePersistence()
      • MqttDefaultFilePersistence

        MqttDefaultFilePersistence(String directory)
        Create an file-based persistent data store within the specified directory.
        Parameters:
        directory - the directory to use.
    • Method Detail

      • open

         void open(String clientId, String theConnection)

        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.
      • close

         void close()

        Close the persistent store that was previously opened. This will be called when a client application disconnects from the broker.

      • put

         void put(String key, MqttPersistable message)

        Writes the specified persistent data to the previously specified persistence directory. This method uses a safe overwrite policy to ensure IO errors do not lose messages.

      • get

         MqttPersistable get(String key)

        Gets the specified data out of the persistent store.

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

         void remove(String key)

        Deletes the data with the specified key from the previously specified persistence directory.

      • keys

         Enumeration keys()

        Returns all of the persistent data from the previously specified persistence directory.

      • containsKey

         boolean containsKey(String key)

        Returns whether or not data is persisted using the specified key.

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

         void clear()

        Clears persistence, so that it no longer contains any persisted data.