Package io.github.mfvanek.pg.connection
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 Summary
Modifier and TypeMethodDescriptionRetrieves connections to all hosts in the cluster (including a connection to a primary host).Retrieves connection to a primary host in the cluster.static HighAvailabilityPgConnectionof(PgConnection connectionToPrimary) Constructs aHighAvailabilityPgConnectionobject with the givenPgConnection.static HighAvailabilityPgConnectionof(PgConnection connectionToPrimary, Collection<PgConnection> connectionsToAllHostsInCluster) Constructs aHighAvailabilityPgConnectionobject with the given connections to primary and replicas.static HighAvailabilityPgConnectionof(PgConnection connectionToPrimary, Collection<PgConnection> connectionsToAllHostsInCluster, long primaryRefreshIntervalMilliseconds) Constructs aHighAvailabilityPgConnectionobject with the given connections to primary and replicas and a refresh interval.
-
Method Details
-
getConnectionToPrimary
Retrieves connection to a primary host in the cluster.- Specified by:
getConnectionToPrimaryin interfaceHighAvailabilityPgConnection- Returns:
PgConnectionto a primary host in the cluster
-
getConnectionsToAllHostsInCluster
Retrieves connections to all hosts in the cluster (including a connection to a primary host).- Specified by:
getConnectionsToAllHostsInClusterin interfaceHighAvailabilityPgConnection- Returns:
Setof connections to all hosts in target cluster
-
of
Constructs aHighAvailabilityPgConnectionobject with the givenPgConnection.- 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 aHighAvailabilityPgConnectionobject 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 aHighAvailabilityPgConnectionobject 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
-