Class ReplicatorConfig

java.lang.Object
org.cojen.tupl.repl.ReplicatorConfig
All Implemented Interfaces:
Cloneable

public class ReplicatorConfig extends Object implements Cloneable
Configuration options used when opening a replicator.
See Also:
  • Constructor Details

    • ReplicatorConfig

      public ReplicatorConfig()
  • Method Details

    • baseFile

      public ReplicatorConfig baseFile(File file)
      Set the base file name for the replicator, which must reside in an ordinary file directory.
      Throws:
      IllegalArgumentException - if file is null
    • baseFilePath

      public ReplicatorConfig baseFilePath(String path)
      Set the base file name for the replicator, which must reside in an ordinary file directory.
      Throws:
      IllegalArgumentException - if path is null
    • createFilePath

      public ReplicatorConfig createFilePath(boolean mkdirs)
      Set true to create the directory for the replication files, if it doesn't already exist. Default is true.
    • groupToken

      public ReplicatorConfig groupToken(long token)
      Set a unique group token, which acts as a simple security measure to prevent different replication groups from communicating with each other. Connections are accepted when the tokens match.
      Throws:
      IllegalArgumentException - if the token is zero
    • groupTokens

      public ReplicatorConfig groupTokens(long token, long altToken)
      Set a unique group token (and an alternate), which acts as a simple security measure to prevent different replication groups from communicating with each other. Connections are accepted when a token matches to any other.
      Throws:
      IllegalArgumentException - if either token is zero
    • localPort

      public ReplicatorConfig localPort(int port) throws UnknownHostException
      Set the local member socket port, for accepting connections on any address. Calling this overrides any explicitly set local address or listen address.
      Throws:
      UnknownHostException
    • localAddress

      public ReplicatorConfig localAddress(SocketAddress addr)
      Set the local member socket address and port.
      Throws:
      IllegalArgumentException - if address is null or a wildcard address
    • listenAddress

      public ReplicatorConfig listenAddress(SocketAddress addr)
      Optionally restrict the socket address for accepting connections, which can be a wildcard address.
      Throws:
      IllegalArgumentException - if address is null
    • localSocket

      public ReplicatorConfig localSocket(ServerSocket ss) throws UnknownHostException
      Explicitly specify a connected local socket, intended only for testing.
      Throws:
      UnknownHostException
    • localRole

      public ReplicatorConfig localRole(Role role)
      Set the desired local member role, which is normal by default, and for the primordial group member. Members can join an existing group only by consensus, which implies that the group has a leader. All joining members start out as restoring, and then the role is updated after the replicator has started. Role changes also require consensus.
      Throws:
      IllegalArgumentException - if role is null
    • addSeed

      public ReplicatorConfig addSeed(String addressString) throws UnknownHostException
      Add a remote member address for allowing the local member to join the group. Opening a replicator for the first time without any seeds indicates that a new replication group is to be formed. If the local member is already in a group, the seeds are ignored.
      Throws:
      IllegalArgumentException - if addressString is null or malformed
      UnknownHostException
    • addSeed

      public ReplicatorConfig addSeed(String hostname, int port)
      Add a remote member address for allowing the local member to join the group. Opening a replicator for the first time without any seeds indicates that a new replication group is to be formed. If the local member is already in a group, the seeds are ignored.
      Throws:
      IllegalArgumentException - if hostname is null
    • addSeed

      public ReplicatorConfig addSeed(SocketAddress addr)
      Add a remote member address for allowing the local member to join the group. Opening a replicator for the first time without any seeds indicates that a new replication group is to be formed. If the local member is already in a group, the seeds are ignored.
      Throws:
      IllegalArgumentException - if address is null
    • proxyWrites

      public ReplicatorConfig proxyWrites(boolean proxy)
      Pass true to proxy writes from the leader, reducing load on the leader, but increasing commit latency a bit. Default is false.
    • checksumSockets

      public ReplicatorConfig checksumSockets(boolean checksums)
      Pass true to enable CRC checksums for all socket commands written. Default is true.
    • eventListener

      public ReplicatorConfig eventListener(EventListener listener)
      Set a listener which receives notifications of actions being performed by the replicator.
    • socketFactory

      public ReplicatorConfig socketFactory(SocketFactory factory)
      Set a factory for creating new client-side sockets.
    • serverSocketFactory

      public ReplicatorConfig serverSocketFactory(ServerSocketFactory factory)
      Set a factory for creating new server-side sockets.
    • failoverLagTimeoutMillis

      public ReplicatorConfig failoverLagTimeoutMillis(long timeout)
      Set a timeout for a newly elected leader to be caught up, or else a new election is run. Default is 1000 milliseconds, and a negative timeout disables the check.
    • clone

      public ReplicatorConfig clone()
      Overrides:
      clone in class Object