Class CassandraBuilder
- java.lang.Object
-
- com.github.nosan.embedded.cassandra.CassandraBuilder
-
public class CassandraBuilder extends Object
A builder that can be used to configure and createCassandra.This class is not thread safe and should not be shared across different threads!
- Since:
- 4.0.0
- Author:
- Dmytro Nosan
- See Also:
build(),CassandraBuilderConfigurator
-
-
Field Summary
Fields Modifier and Type Field Description static VersionDEFAULT_VERSIONDefault Cassandra version.
-
Constructor Summary
Constructors Constructor Description CassandraBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CassandraBuilderaddConfigProperties(Map<String,?> configProperties)Puts Cassandra config properties, that should be merged with properties from cassandra.yaml.CassandraBuilderaddConfigProperty(String name, Object value)Puts Cassandra config property, that should be merged with a property from cassandra.yaml.CassandraBuilderaddEnvironmentVariable(String name, Object value)Puts Cassandra environment variable.CassandraBuilderaddEnvironmentVariables(Map<String,?> environmentVariables)Puts Cassandra environment variables.CassandraBuilderaddJvmOptions(String... jvmOptions)Adds Cassandra native Java Virtual Machine (JVM) Options.CassandraBuilderaddJvmOptions(Collection<String> jvmOptions)Adds Cassandra native Java Virtual Machine (JVM) Options.CassandraBuilderaddSystemProperties(Map<String,?> systemProperties)Puts Cassandra native Java Virtual Machine (JVM) system parameters.CassandraBuilderaddSystemProperty(String name, Object value)Puts Cassandra native Java Virtual Machine (JVM) system parameter, For example:CassandraBuilderaddWorkingDirectoryCustomizers(WorkingDirectoryCustomizer... workingDirectoryCustomizers)Adds theWorkingDirectoryCustomizer.CassandraBuilderaddWorkingDirectoryCustomizers(Collection<? extends WorkingDirectoryCustomizer> workingDirectoryCustomizers)Adds theWorkingDirectoryCustomizer.CassandraBuilderaddWorkingDirectoryResource(Resource resource, String path)Copy a resource to a target path within the working directory.Cassandrabuild()Build a newCassandrainstance.CassandraBuilderconfigFile(Resource configFile)Sets the Cassandra configuration file.CassandraBuilderconfigProperties(Map<String,?> configProperties)Sets Cassandra config properties, that should be merged with properties from cassandra.yaml.CassandraBuilderconfigure(CassandraBuilderConfigurator configurator)Applies the provided configurator to this builder.CassandraBuilderenvironmentVariables(Map<String,?> environmentVariables)Sets Cassandra environment variables.StringgetName()Gets current configured Cassandra instance name.VersiongetVersion()Gets current configured Cassandra version orDEFAULT_VERSION.CassandraBuilderjvmOptions(String... jvmOptions)Sets Cassandra native Java Virtual Machine (JVM) Options.CassandraBuilderjvmOptions(Collection<String> jvmOptions)Sets Cassandra native Java Virtual Machine (JVM) Options.CassandraBuilderlogger(Logger logger)Sets the Cassandra logger.CassandraBuildername(String name)Sets the Cassandra instance name.CassandraBuilderregisterShutdownHook(boolean registerShutdownHook)Sets if the createdCassandrashould have a shutdown hook registered.CassandraBuilderstartupTimeout(Duration startupTimeout)Sets the startup timeout.CassandraBuildersystemProperties(Map<String,?> systemProperties)Sets Cassandra native Java Virtual Machine (JVM) system parameters.CassandraBuilderversion(Version version)Sets the Cassandra version.CassandraBuilderversion(String version)Sets the Cassandra version.CassandraBuilderworkingDirectory(IOSupplier<? extends Path> workingDirectorySupplier)Set theSupplierof the working directory that should be called each time whenbuild()is called.CassandraBuilderworkingDirectoryCustomizers(WorkingDirectoryCustomizer... workingDirectoryCustomizers)Sets theWorkingDirectoryCustomizer.CassandraBuilderworkingDirectoryCustomizers(Collection<? extends WorkingDirectoryCustomizer> workingDirectoryCustomizers)Sets theWorkingDirectoryCustomizer.CassandraBuilderworkingDirectoryDestroyer(WorkingDirectoryDestroyer workingDirectoryDestroyer)Sets theWorkingDirectoryDestroyer.CassandraBuilderworkingDirectoryInitializer(WorkingDirectoryInitializer workingDirectoryInitializer)Sets theWorkingDirectoryInitializer.
-
-
-
Field Detail
-
DEFAULT_VERSION
public static final Version DEFAULT_VERSION
Default Cassandra version.
-
-
Method Detail
-
name
public CassandraBuilder name(String name)
Sets the Cassandra instance name.Defaults to cassandra-0, cassandra-1, and so on.
- Parameters:
name- the Cassandra name- Returns:
- this builder
-
getName
public String getName()
Gets current configured Cassandra instance name.- Returns:
- Cassandra instance name, or
null
-
version
public CassandraBuilder version(String version)
Sets the Cassandra version.Defaults to
DEFAULT_VERSION- Parameters:
version- the Cassandra version- Returns:
- this builder
-
version
public CassandraBuilder version(Version version)
Sets the Cassandra version.Defaults to
DEFAULT_VERSION- Parameters:
version- the Cassandra version- Returns:
- this builder
-
getVersion
public Version getVersion()
Gets current configured Cassandra version orDEFAULT_VERSION.- Returns:
- Cassandra version, never
null
-
logger
public CassandraBuilder logger(Logger logger)
Sets the Cassandra logger. This logger will consume Cassandra stdout and stderr outputs.Defaults to
Logger.get(Cassandra.class)- Parameters:
logger- the Cassandra logger- Returns:
- this builder
-
registerShutdownHook
public CassandraBuilder registerShutdownHook(boolean registerShutdownHook)
Sets if the createdCassandrashould have a shutdown hook registered.Defaults to
true.- Parameters:
registerShutdownHook-trueif shutdown hook should be registered, otherwisefalse- Returns:
- this builder
-
startupTimeout
public CassandraBuilder startupTimeout(Duration startupTimeout)
Sets the startup timeout.Defaults to 2 minutes.
- Parameters:
startupTimeout- the startup timeout- Returns:
- this builder
-
configFile
public CassandraBuilder configFile(Resource configFile)
Sets the Cassandra configuration file.Equal to:
addSystemProperty("cassandra.config", configFile);- Parameters:
configFile- the config file- Returns:
- this builder
-
workingDirectory
public CassandraBuilder workingDirectory(IOSupplier<? extends Path> workingDirectorySupplier)
Set theSupplierof the working directory that should be called each time whenbuild()is called.The supplied directory will be initialized by
WorkingDirectoryInitializerand used as Cassandra home directory.In the end, provided working directory may be deleted or partly deleted by
WorkingDirectoryDestroyer.Defaults to
Files.createTempDirectory("")- Parameters:
workingDirectorySupplier- the working directory supplier- Returns:
- this builder
- See Also:
IOSupplier.wrap(Supplier)
-
workingDirectoryInitializer
public CassandraBuilder workingDirectoryInitializer(WorkingDirectoryInitializer workingDirectoryInitializer)
Sets theWorkingDirectoryInitializer.Defaults to
DefaultWorkingDirectoryInitializerwith the underlyingWebCassandraDirectoryProvider.- Parameters:
workingDirectoryInitializer- the working directory initializer- Returns:
- this builder
- See Also:
DefaultWorkingDirectoryInitializer
-
workingDirectoryDestroyer
public CassandraBuilder workingDirectoryDestroyer(WorkingDirectoryDestroyer workingDirectoryDestroyer)
Sets theWorkingDirectoryDestroyer.Defaults to
WorkingDirectoryDestroyer.deleteOnly("bin", "pylib", "lib", "tools", "doc", "javadoc", "interface")- Parameters:
workingDirectoryDestroyer- the working directory destroyer- Returns:
- this builder
- See Also:
WorkingDirectoryDestroyer.doNothing(),WorkingDirectoryDestroyer.deleteOnly(String...),WorkingDirectoryDestroyer.deleteAll()
-
workingDirectoryCustomizers
public CassandraBuilder workingDirectoryCustomizers(WorkingDirectoryCustomizer... workingDirectoryCustomizers)
Sets theWorkingDirectoryCustomizer. Setting this value will replace any previously configured customizers.- Parameters:
workingDirectoryCustomizers- the working directory customizers to set- Returns:
- this builder
- See Also:
WorkingDirectoryCustomizer.addResource(Resource, String),workingDirectoryCustomizers(Collection),addWorkingDirectoryCustomizers(WorkingDirectoryCustomizer...),addWorkingDirectoryCustomizers(Collection)
-
workingDirectoryCustomizers
public CassandraBuilder workingDirectoryCustomizers(Collection<? extends WorkingDirectoryCustomizer> workingDirectoryCustomizers)
Sets theWorkingDirectoryCustomizer. Setting this value will replace any previously configured customizers.- Parameters:
workingDirectoryCustomizers- the working directory customizers to set- Returns:
- this builder
- See Also:
WorkingDirectoryCustomizer.addResource(Resource, String),workingDirectoryCustomizers(WorkingDirectoryCustomizer...),addWorkingDirectoryCustomizers(WorkingDirectoryCustomizer...),addWorkingDirectoryCustomizers(Collection)
-
addWorkingDirectoryCustomizers
public CassandraBuilder addWorkingDirectoryCustomizers(WorkingDirectoryCustomizer... workingDirectoryCustomizers)
Adds theWorkingDirectoryCustomizer.- Parameters:
workingDirectoryCustomizers- the working directory customizers to add- Returns:
- this builder
- See Also:
WorkingDirectoryCustomizer.addResource(Resource, String),addWorkingDirectoryCustomizers(Collection),workingDirectoryCustomizers(WorkingDirectoryCustomizer...),workingDirectoryCustomizers(Collection)
-
addWorkingDirectoryCustomizers
public CassandraBuilder addWorkingDirectoryCustomizers(Collection<? extends WorkingDirectoryCustomizer> workingDirectoryCustomizers)
Adds theWorkingDirectoryCustomizer.- Parameters:
workingDirectoryCustomizers- the working directory customizers to add- Returns:
- this builder
- See Also:
WorkingDirectoryCustomizer.addResource(Resource, String),addWorkingDirectoryCustomizers(WorkingDirectoryCustomizer...),workingDirectoryCustomizers(WorkingDirectoryCustomizer...),workingDirectoryCustomizers(Collection)
-
environmentVariables
public CassandraBuilder environmentVariables(Map<String,?> environmentVariables)
Sets Cassandra environment variables. Setting this value will replace any previously configured environment variables. For example:JAVA_HOME=System.getEnv("JAVA_HOME") | System.getProperty("java.home")- Parameters:
environmentVariables- Cassandra environment variables- Returns:
- this builder
- See Also:
addEnvironmentVariable(String, Object),addEnvironmentVariables(Map)
-
addEnvironmentVariable
public CassandraBuilder addEnvironmentVariable(String name, Object value)
Puts Cassandra environment variable. For example:JAVA_HOME=System.getEnv("JAVA_HOME") | System.getProperty("java.home")- Parameters:
name- Cassandra environment variable namevalue- Cassandra environment variable value- Returns:
- this builder
- See Also:
addEnvironmentVariables(Map),environmentVariables(Map)
-
addEnvironmentVariables
public CassandraBuilder addEnvironmentVariables(Map<String,?> environmentVariables)
Puts Cassandra environment variables. For example:JAVA_HOME=System.getEnv("JAVA_HOME") | System.getProperty("java.home")- Parameters:
environmentVariables- Cassandra environment variables- Returns:
- this builder
- See Also:
addEnvironmentVariable(String, Object),environmentVariables(Map)
-
systemProperties
public CassandraBuilder systemProperties(Map<String,?> systemProperties)
Sets Cassandra native Java Virtual Machine (JVM) system parameters. Setting this value will replace any previously configured system parameters. For example:cassandra.config=new ClassPathResource("cassandra.yaml") cassandra.native_transport_port=9042 cassandra.jmx.local.port=7199- Parameters:
systemProperties- Cassandra system parameters- Returns:
- this builder
- See Also:
addSystemProperty(String, Object)
-
addSystemProperty
public CassandraBuilder addSystemProperty(String name, Object value)
Puts Cassandra native Java Virtual Machine (JVM) system parameter, For example:cassandra.config=new ClassPathResource("cassandra.yaml").- Parameters:
name- Cassandra system parameter namevalue- Cassandra system parameter value- Returns:
- this builder
- See Also:
addSystemProperties(Map)
-
addSystemProperties
public CassandraBuilder addSystemProperties(Map<String,?> systemProperties)
Puts Cassandra native Java Virtual Machine (JVM) system parameters. For example:cassandra.config=new ClassPathResource("cassandra.yaml") cassandra.native_transport_port=9042 cassandra.jmx.local.port=7199- Parameters:
systemProperties- Cassandra system parameters- Returns:
- this builder
- See Also:
addSystemProperty(String, Object)
-
jvmOptions
public CassandraBuilder jvmOptions(String... jvmOptions)
Sets Cassandra native Java Virtual Machine (JVM) Options. Setting this value will replace any previously configured options.- Parameters:
jvmOptions- the JVM options to set- Returns:
- this builder
- See Also:
jvmOptions(Collection),addJvmOptions(Collection),addJvmOptions(String...)
-
jvmOptions
public CassandraBuilder jvmOptions(Collection<String> jvmOptions)
Sets Cassandra native Java Virtual Machine (JVM) Options. Setting this value will replace any previously configured options.- Parameters:
jvmOptions- the JVM options to set- Returns:
- this builder
- See Also:
jvmOptions(Collection),addJvmOptions(Collection),addJvmOptions(String...)
-
addJvmOptions
public CassandraBuilder addJvmOptions(String... jvmOptions)
Adds Cassandra native Java Virtual Machine (JVM) Options.- Parameters:
jvmOptions- the JVM options to add- Returns:
- this builder
- See Also:
addJvmOptions(Collection),jvmOptions(Collection),jvmOptions(String...)
-
addJvmOptions
public CassandraBuilder addJvmOptions(Collection<String> jvmOptions)
Adds Cassandra native Java Virtual Machine (JVM) Options.- Parameters:
jvmOptions- the JVM options to add- Returns:
- this builder
- See Also:
addJvmOptions(String...),jvmOptions(Collection),jvmOptions(String...)
-
configProperties
public CassandraBuilder configProperties(Map<String,?> configProperties)
Sets Cassandra config properties, that should be merged with properties from cassandra.yaml. Setting this value will replace any previously configured config properties. For example:
Output Yaml:Map<String,Object> properties = new LinkedHashMap<>(); properties.put("client_encryption_options.enabled", true); properties.put("cluster_name", "MyCluster"); builder.configProperties(properties);... cluster_name: "MyCluster" client_encryption_options: enabled: true ... ...- Parameters:
configProperties- Cassandra config properties- Returns:
- this builder
- See Also:
addConfigProperty(String, Object),addConfigProperties(Map)
-
addConfigProperty
public CassandraBuilder addConfigProperty(String name, Object value)
Puts Cassandra config property, that should be merged with a property from cassandra.yaml. For example:builder.configProperty("client_encryption_options.enabled",true) .configProperty("cluster_name","MyCluster")Output Yaml:
... cluster_name: "MyCluster" client_encryption_options: enabled: true ... ...- Parameters:
name- config property name (e.g. native_transport_port, client_encryption_options.enabled)value- config property value- Returns:
- this builder
- See Also:
addConfigProperties(Map),configProperties(Map)
-
addConfigProperties
public CassandraBuilder addConfigProperties(Map<String,?> configProperties)
Puts Cassandra config properties, that should be merged with properties from cassandra.yaml. For example:
Output Yaml:Map<String,Object> properties = new LinkedHashMap<>(); properties.put("client_encryption_options.enabled", true); properties.put("cluster_name", "MyCluster"); builder.configProperties(properties);... cluster_name: "MyCluster" client_encryption_options: enabled: true ... ...- Parameters:
configProperties- Cassandra config properties- Returns:
- this builder
- See Also:
addConfigProperty(String, Object),configProperties(Map)
-
addWorkingDirectoryResource
public CassandraBuilder addWorkingDirectoryResource(Resource resource, String path)
Copy a resource to a target path within the working directory.Equal to:
addWorkingDirectoryCustomizers(WorkingDirectoryCustomizer.addResource(resource, path));- Parameters:
path- path (file only) within the working directory (e.g conf/cassandra.yaml)resource- the resource- Returns:
- this builder
- See Also:
WorkingDirectoryCustomizer.addResource(Resource, String)
-
configure
public CassandraBuilder configure(CassandraBuilderConfigurator configurator)
Applies the provided configurator to this builder.- Parameters:
configurator- configurator to use- Returns:
- this builder
- See Also:
SimpleSeedProviderConfigurator
-
-