Skip to content

Commit

Permalink
Merge pull request #118 from yma96/master
Browse files Browse the repository at this point in the history
Update Cassandra reconnect policy and default delay value
  • Loading branch information
yma96 authored Oct 15, 2024
2 parents daa95d5 + 5ce976e commit 6a63cec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.policies.ConstantReconnectionPolicy;
import com.datastax.driver.mapping.Mapper;
import com.datastax.driver.mapping.MappingManager;
import com.datastax.driver.mapping.Result;
Expand Down Expand Up @@ -87,6 +88,8 @@ public class CassandraPathDB

private int replicationFactor = 1; // keyspace replica, default 1

private long reconnectDelay = 60000;

private PreparedStatement preparedExistQuery, preparedListQuery, preparedListCheckEmpty, preparedContainingQuery, preparedExistFileQuery,
preparedUpdateExpiration, preparedReverseMapIncrement, preparedReverseMapReduction,
preparedFilesystemIncrement, preparedFilesystemReduction, preparedFilesystemList;
Expand Down Expand Up @@ -114,8 +117,15 @@ public CassandraPathDB( PathMappedStorageConfig config )
int port = (Integer) config.getProperty( CassandraPathDBUtils.PROP_CASSANDRA_PORT );
String username = (String) config.getProperty( CassandraPathDBUtils.PROP_CASSANDRA_USER );
String password = (String) config.getProperty( CassandraPathDBUtils.PROP_CASSANDRA_PASS );
Long delay = (Long) config.getProperty( CassandraPathDBUtils.PROP_CASSANDRA_RECONNECT_DELAY );

Cluster.Builder builder = Cluster.builder().withoutJMXReporting().addContactPoint( host ).withPort( port );
if ( delay != null )
{
reconnectDelay = delay;
}
builder.withReconnectionPolicy( new ConstantReconnectionPolicy( reconnectDelay ) );

if ( isNotBlank( username ) && isNotBlank( password ) )
{
logger.debug( "Build with credentials, user: {}, pass: ****", username );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class CassandraPathDBUtils

public static final String PROP_CASSANDRA_PASS = "cassandra_pass";

public static final String PROP_CASSANDRA_RECONNECT_DELAY = "cassandra_reconnect_delay";

public static final String PROP_CASSANDRA_KEYSPACE = "cassandra_keyspace";

public static final String PROP_CASSANDRA_REPLICATION_FACTOR = "cassandra_replication_factor";
Expand Down

0 comments on commit 6a63cec

Please sign in to comment.