DistributedSQLCounter (Apache Hadoop HDFS-RBF 3.5.0 API)
Description: declaration: package: org.apache.hadoop.hdfs.server.federation.router.security.token, class: DistributedSQLCounter

Package org.apache.hadoop.hdfs.server.federation.router.security.token

# Class DistributedSQLCounter

java.lang.Object
org.apache.hadoop.hdfs.server.federation.router.security.token.DistributedSQLCounter

public class DistributedSQLCounter extends Object
Distributed counter that relies on a SQL database to synchronize between multiple clients. This expects a table with a single int field to exist in the database. One record must exist on the table at all times, representing the last used value reserved by a client.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DistributedSQLCounter(String field, String table, SQLConnectionFactory connectionFactory)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `incrementCounterValue(int amount)`
  Increments the counter by the given amount and returns the previous counter value.
  `int`
  `selectCounterValue()`
  Obtains the value of the counter.
  `void`
  `updateCounterValue(int value)`
  Sets the counter to the given value.
  `void`
  `updateCounterValue(int value, Connection connection)`
  Sets the counter to the given value.

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

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

- ## Constructor Details

  - ### DistributedSQLCounter

    public DistributedSQLCounter(String field, String table, SQLConnectionFactory connectionFactory)

- ## Method Details

  - ### selectCounterValue

    public int selectCounterValue() throws SQLException
    Obtains the value of the counter.
    Returns:
      counter value.
    Throws:
      `SQLException` - if querying the database fails.

  - ### updateCounterValue

    public void updateCounterValue(int value) throws SQLException
    Sets the counter to the given value.
    Parameters:
      `value` - Value to assign to counter.
    Throws:
      `SQLException` - if querying the database fails.

  - ### updateCounterValue

    public void updateCounterValue(int value, Connection connection) throws SQLException
    Sets the counter to the given value.
    Parameters:
      `value` - Value to assign to counter.
      `connection` - Connection to database hosting the counter table.
    Throws:
      `SQLException` - if querying the database fails.

  - ### incrementCounterValue

    public int incrementCounterValue(int amount) throws SQLException
    Increments the counter by the given amount and returns the previous counter value.
    Parameters:
      `amount` - Amount to increase the counter.
    Returns:
      Previous counter value.
    Throws:
      `SQLException` - if querying the database fails.