Class HighAvailabilityPgConnectionImpl

java.lang.Object
io.github.mfvanek.pg.connection.HighAvailabilityPgConnectionImpl
All Implemented Interfaces:
HighAvailabilityPgConnection

public class HighAvailabilityPgConnectionImpl extends Object implements HighAvailabilityPgConnection
Implementation of a connection to a high availability cluster (with set of primary host and replicas).
See Also:
  • Method Details

    • getConnectionToPrimary

      @Nonnull public PgConnection getConnectionToPrimary()
      Gets connection to a primary host in the cluster.
      Specified by:
      getConnectionToPrimary in interface HighAvailabilityPgConnection
      Returns:
      PgConnection to a primary host in the cluster
    • getConnectionsToAllHostsInCluster

      @Nonnull public Set<PgConnection> getConnectionsToAllHostsInCluster()
      Gets connections to all hosts in the cluster (including a connection to a primary host).
      Specified by:
      getConnectionsToAllHostsInCluster in interface HighAvailabilityPgConnection
      Returns:
      Set of connections to all hosts in target cluster
    • of

      @Nonnull public static HighAvailabilityPgConnection of(@Nonnull PgConnection connectionToPrimary)
      Constructs a HighAvailabilityPgConnection object with the given PgConnection.
      Parameters:
      connectionToPrimary - connection to the primary host in the single-node cluster.
      Returns:
      HighAvailabilityPgConnection
    • of

      @Nonnull public static HighAvailabilityPgConnection of(@Nonnull PgConnection connectionToPrimary, @Nonnull Collection<PgConnection> connectionsToAllHostsInCluster)
      Constructs a HighAvailabilityPgConnection object with the given connections to primary and replicas.
      Parameters:
      connectionToPrimary - connection to the primary host in the cluster.
      connectionsToAllHostsInCluster - connections to all replicas in the cluster.
      Returns:
      HighAvailabilityPgConnection
    • of

      @Nonnull public static HighAvailabilityPgConnection of(@Nonnull PgConnection connectionToPrimary, @Nonnull Collection<PgConnection> connectionsToAllHostsInCluster, long primaryRefreshIntervalMilliseconds)
      Constructs a HighAvailabilityPgConnection object with the given connections to primary and replicas and a refresh interval.
      Parameters:
      connectionToPrimary - connection to the primary host in the cluster.
      connectionsToAllHostsInCluster - connections to all replicas in the cluster.
      primaryRefreshIntervalMilliseconds - time interval in milliseconds to refresh connection to the primary host.
      Returns:
      HighAvailabilityPgConnection