Skip to content

Commit

Permalink
Ericsson#674 Specify Interval for Next Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Chandler committed Sep 3, 2024
1 parent 957b09f commit 0bf9489
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public final class AgentConnectionConfig
{
private ConnectionType myType = ConnectionType.datacenterAware;
private String myLocalDatacenter;
private Integer myConnectionDelay;
private Map<String, Host> myContactPoints = new HashMap<>();
private DatacenterAware myDatacenterAware = new DatacenterAware();
private RackAware myRackAware = new RackAware();
Expand Down Expand Up @@ -105,6 +106,28 @@ public String getLocalDatacenter()
return myLocalDatacenter;
}

/**
* Sets the connectionDelay used to specify the time until the next connection
*
* @param connectionDelay
* the local datacenter to set.
*/
@JsonProperty("connectionDelay")
public void setConnectionDelay(final Integer connectionDelay)
{
myConnectionDelay = connectionDelay;
}
/**
* Gets the connectionDelay used to specify the time until the next connection
*
* @return the connectionDelay.
*/
@JsonProperty("connectionDelay")
public Integer getConnectionDelay()
{
return myConnectionDelay;
}

/**
* Gets the DataCenterAwarePolicy used for load-balancing policy.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,13 @@ public DistributedNativeConnectionProvider distributedNativeConnectionProvider(
* if the local host name cannot be determined.
* @throws EcChronosException
* if there is an error during node synchronization.
* @throws ConfigurationException
* if there is an error during node synchronization.
*/
@Bean
public EccNodesSync eccNodesSync(
final DistributedNativeConnectionProvider distributedNativeConnectionProvider
) throws UnknownHostException, EcChronosException
{
) throws UnknownHostException, EcChronosException, ConfigurationException {
return getEccNodesSync(distributedNativeConnectionProvider);
}

Expand Down Expand Up @@ -264,12 +265,13 @@ private static CertificateHandler createCertificateHandler(

private EccNodesSync getEccNodesSync(
final DistributedNativeConnectionProvider distributedNativeConnectionProvider
) throws UnknownHostException, EcChronosException
{
) throws UnknownHostException, EcChronosException, ConfigurationException {
Integer connectionDelay = config().getConnectionConfig().getCqlConnection().getAgentConnectionConfig().getConnectionDelay();
EccNodesSync myEccNodesSync = EccNodesSync.newBuilder()
.withInitialNodesList(distributedNativeConnectionProvider.getNodes())
.withSession(distributedNativeConnectionProvider.getCqlSession())
.withEcchronosID(ecChronosID)
.withConnectionDelayInMinutes( connectionDelay )
.build();
myEccNodesSync.acquireNodes();
LOG.info("Nodes acquired with success");
Expand Down
1 change: 1 addition & 0 deletions application/src/main/resources/ecc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ connection:
## to connect to. The application will use the configurations
## specified below, connecting to the listed hosts;
agent:
connectionDelay: 60
## Define the Agent strategy, it can be
## - datacenterAware;
## - rackAware; and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public final class EccNodesSync

private final PreparedStatement myCreateStatement;
private final PreparedStatement myUpdateStatusStatement;
private final Integer connectionDelayInMinutes;




private EccNodesSync(final Builder builder) throws UnknownHostException
{
Expand All @@ -92,6 +96,8 @@ private EccNodesSync(final Builder builder) throws UnknownHostException
.build()
.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM));
ecChronosID = builder.myEcchronosID;

connectionDelayInMinutes = builder.connectionDelayInMinutes;
}

public void acquireNodes() throws EcChronosException
Expand Down Expand Up @@ -126,7 +132,7 @@ private ResultSet acquireNode(final Node node)
node.getEndPoint().toString(),
node.getState().toString(),
Instant.now(),
Instant.now().plus(DEFAULT_CONNECTION_DELAY_IN_MINUTES, ChronoUnit.MINUTES),
Instant.now().plus(connectionDelayInMinutes, ChronoUnit.MINUTES),
node.getHostId());
}

Expand Down Expand Up @@ -220,6 +226,7 @@ public static class Builder
private CqlSession mySession;
private List<Node> initialNodesList;
private String myEcchronosID;
private Integer connectionDelayInMinutes;

/**
* Builds EccNodesSync with session.
Expand All @@ -246,6 +253,13 @@ public Builder withInitialNodesList(final List<Node> nodes)
this.initialNodesList = nodes;
return this;
}
public Builder withConnectionDelayInMinutes(final Integer connectionDelayInMinutes)
{
this.connectionDelayInMinutes = connectionDelayInMinutes;
return this;

}


/**
* Builds EccNodesSync with ecchronosID.
Expand Down

0 comments on commit 0bf9489

Please sign in to comment.