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 TypeMethodDescriptionGets connections to all hosts in the cluster (including a connection to a primary host).Gets connection to a primary host in the cluster.static HighAvailabilityPgConnection
of
(PgConnection connectionToPrimary) Constructs aHighAvailabilityPgConnection
object with the givenPgConnection
.static HighAvailabilityPgConnection
of
(PgConnection connectionToPrimary, Collection<PgConnection> connectionsToAllHostsInCluster) Constructs aHighAvailabilityPgConnection
object with the given connections to primary and replicas.static HighAvailabilityPgConnection
of
(PgConnection connectionToPrimary, Collection<PgConnection> connectionsToAllHostsInCluster, long primaryRefreshIntervalMilliseconds) Constructs aHighAvailabilityPgConnection
object with the given connections to primary and replicas and a refresh interval.
-
Method Details
-
getConnectionToPrimary
Gets connection to a primary host in the cluster.- Specified by:
getConnectionToPrimary
in interfaceHighAvailabilityPgConnection
- Returns:
PgConnection
to a primary host in the cluster
-
getConnectionsToAllHostsInCluster
Gets connections to all hosts in the cluster (including a connection to a primary host).- Specified by:
getConnectionsToAllHostsInCluster
in interfaceHighAvailabilityPgConnection
- Returns:
Set
of connections to all hosts in target cluster
-
of
Constructs aHighAvailabilityPgConnection
object 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 aHighAvailabilityPgConnection
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 aHighAvailabilityPgConnection
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
-