ReplicatedDHT
Date: 2016-02-29

de.zib.scalaris

## Class ReplicatedDHT

- java.lang.Object
- - de.zib.scalaris.ReplicatedDHT

-     public class ReplicatedDHT
      extends Object

  Provides methods to delete all replicas of the given key (from `api_rdht.erl`).

  Instances of this class can be generated using a given connection to a scalaris node using `ReplicatedDHT(Connection)` or without a connection (`ReplicatedDHT()`) in which case a new connection is created using `ConnectionFactory.createConnection()`.

  ### Deleting values

         String key;
         int timeout;
         DeleteResult result;

         TransactionSingleOp sc = new ReplicatedDHT();
         sc.delete(key);                    // delete(String)
         sc.delete(key, timeout);           // delete(String, int)
         result = sc.getLastDeleteResult(); // getLastDeleteResult()

  ### Connection errors

  Errors when setting up connections or trying to send/receive RPCs will be handed to the `ConnectionPolicy` that has been set when the connection was created. By default, `ConnectionFactory` uses `DefaultConnectionPolicy` which implements automatic connection-retries by classifying nodes as good or bad depending on their previous state. The number of automatic retries is adjustable (default: 3).
  Since:
    2.6
  Version:
    3.19
  Author:
    Nico Kruber, kruber@zib.de

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ReplicatedDHT()` Constructor, uses the default connection returned by `ConnectionFactory.createConnection()`.
    `ReplicatedDHT(Connection conn)` Constructor, uses the given connection to an erlang node.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `closeConnection()` Closes the transaction's connection to a scalaris node.
    `DeleteResult` | `delete(OtpErlangString key)` Tries to delete all replicas of the given `key` in 2000ms.
    `DeleteResult` | `delete(OtpErlangString key, int timeout)` Tries to delete all replicas of the given `key`.
    `DeleteResult` | `delete(String key)` Tries to delete all replicas of the given `key` in 2000ms.
    `DeleteResult` | `delete(String key, int timeout)` Tries to delete all replicas of the given `key`.
    `DeleteResult` | `getLastDeleteResult()` Returns the result of the last call to `delete(String)`.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ReplicatedDHT

          public ReplicatedDHT()
                        throws ConnectionException

      Constructor, uses the default connection returned by `ConnectionFactory.createConnection()`.
      Throws:
        `ConnectionException` - if the connection fails

    - #### ReplicatedDHT

          public ReplicatedDHT(Connection conn)

      Constructor, uses the given connection to an erlang node.
      Parameters:
        `conn` - connection to use for the transaction

  - ### Method Detail

    - #### delete

          public DeleteResult delete(OtpErlangString key)
                              throws ConnectionException,
                                     TimeoutException,
                                     UnknownException

      Tries to delete all replicas of the given `key` in 2000ms. WARNING: This function can lead to inconsistent data (e.g. deleted items can re-appear). Also when re-creating an item the version before the delete can re-appear.
      Parameters:
        `key` - the key to delete
      Returns:
        a delete result object
      Throws:
        `ConnectionException` - if the connection is not active or a communication error occurs or an exit signal was received or the remote node sends a message containing an invalid cookie
        `TimeoutException` - if a timeout occurred while trying to delete the value
        `UnknownException` - if any other error occurs
      Since:
        3.19
      See Also:
        `delete(OtpErlangString, int)`

    - #### delete

          public DeleteResult delete(OtpErlangString key,
                            int timeout)
                              throws ConnectionException,
                                     TimeoutException,
                                     UnknownException

      Tries to delete all replicas of the given `key`. WARNING: This function can lead to inconsistent data (e.g. deleted items can re-appear). Also when re-creating an item the version before the delete can re-appear.
      Parameters:
        `key` - the key to delete
        `timeout` - the time (in milliseconds) to wait for results
      Returns:
        a delete result object
      Throws:
        `ConnectionException` - if the connection is not active or a communication error occurs or an exit signal was received or the remote node sends a message containing an invalid cookie
        `TimeoutException` - if a timeout occurred while trying to delete the value
        `UnknownException` - if any other error occurs
      Since:
        3.19

    - #### delete

          public DeleteResult delete(String key)
                              throws ConnectionException,
                                     TimeoutException,
                                     UnknownException

      Tries to delete all replicas of the given `key` in 2000ms.
      Parameters:
        `key` - the key to delete
      Returns:
        a delete result object
      Throws:
        `ConnectionException` - if the connection is not active or a communication error occurs or an exit signal was received or the remote node sends a message containing an invalid cookie
        `TimeoutException` - if a timeout occurred while trying to delete the value
        `UnknownException` - if any other error occurs
      Since:
        3.19
      See Also:
        `delete(String, int)`

    - #### delete

          public DeleteResult delete(String key,
                            int timeout)
                              throws ConnectionException,
                                     TimeoutException,
                                     UnknownException

      Tries to delete all replicas of the given `key`. WARNING: This function can lead to inconsistent data (e.g. deleted items can re-appear). Also when re-creating an item the version before the delete can re-appear.
      Parameters:
        `key` - the key to delete
        `timeout` - the time (in milliseconds) to wait for results
      Returns:
        a delete result object
      Throws:
        `ConnectionException` - if the connection is not active or a communication error occurs or an exit signal was received or the remote node sends a message containing an invalid cookie
        `TimeoutException` - if a timeout occurred while trying to delete the value
        `UnknownException` - if any other error occurs
      Since:
        3.19
      See Also:
        `delete(OtpErlangString, int)`

    - #### getLastDeleteResult

          public DeleteResult getLastDeleteResult()

      Returns the result of the last call to `delete(String)`.
      Returns:
        the delete result
      Throws:
        `UnknownException` - is thrown if an unknown reason was encountered
      See Also:
        `delete(String)`

    - #### closeConnection

          public void closeConnection()

      Closes the transaction's connection to a scalaris node. Note: Subsequent calls to the other methods will throw `ConnectionException`s!