Skip to content

Commit

Permalink
Separating the properties files for each Configuration object.
Browse files Browse the repository at this point in the history
  • Loading branch information
datumbox committed Jan 1, 2017
1 parent 97e9b0d commit c816666
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 100 deletions.
Expand Up @@ -22,6 +22,7 @@
import java.io.UncheckedIOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.Properties;

/**
Expand All @@ -30,6 +31,8 @@
* @author Vasilis Vryniotis <bbriniotis@datumbox.com>
*/
public class ConfigurableFactory {

private static final String DEFAULT_POSTFIX = ".default";

/**
* Initializes the Configuration Object based on the configuration file.
Expand All @@ -39,6 +42,8 @@ public class ConfigurableFactory {
* @return
*/
public static <C extends Configurable> C getConfiguration(Class<C> klass) {
String defaultPropertyFile = "datumbox." + klass.getSimpleName().toLowerCase(Locale.ENGLISH) + DEFAULT_POSTFIX + ".properties";

//Initialize configuration object
C configuration;
try {
Expand All @@ -55,17 +60,18 @@ public static <C extends Configurable> C getConfiguration(Class<C> klass) {
ClassLoader cl = ConfigurableFactory.class.getClassLoader();

//Load default properties from jar
try (InputStream in = cl.getResourceAsStream("datumbox.configuration.default.properties")) {
try (InputStream in = cl.getResourceAsStream(defaultPropertyFile)) {
properties.load(in);
}
catch(IOException ex) {
throw new UncheckedIOException(ex);
}

//Look for user defined properties
if(cl.getResource("datumbox.configuration.properties")!=null) {
String propertyFile = defaultPropertyFile.replaceFirst(DEFAULT_POSTFIX, "");
if(cl.getResource(propertyFile)!=null) {
//Override the default if they exist
try (InputStream in = cl.getResourceAsStream("datumbox.configuration.properties")) {
try (InputStream in = cl.getResourceAsStream(propertyFile)) {
properties.load(in);
}
catch(IOException ex) {
Expand Down
Expand Up @@ -77,7 +77,7 @@ public void setConcurrencyConfiguration(ConcurrencyConfiguration concurrencyConf
/** {@inheritDoc} */
@Override
public void load(Properties properties) {
String storageConfigurationClassName = properties.getProperty("storageConfiguration.className");
String storageConfigurationClassName = properties.getProperty("configuration.storageConfiguration");
try {
storageConfiguration = ConfigurableFactory.getConfiguration((Class<StorageConfiguration>) Class.forName(storageConfigurationClassName));
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ public StorageEngine createStorageEngine(String storageName) {
/** {@inheritDoc} */
@Override
public void load(Properties properties) {
outputDirectory = properties.getProperty("storageConfiguration.InMemoryConfiguration.outputDirectory");
outputDirectory = properties.getProperty("inMemoryConfiguration.outputDirectory");
}

}
Expand Up @@ -47,11 +47,11 @@ public StorageEngine createStorageEngine(String storageName) {
/** {@inheritDoc} */
@Override
public void load(Properties properties) {
outputDirectory = properties.getProperty("storageConfiguration.MapDBConfiguration.outputDirectory");
cacheSize = Integer.parseInt(properties.getProperty("storageConfiguration.MapDBConfiguration.cacheSize"));
compressed = "true".equalsIgnoreCase(properties.getProperty("storageConfiguration.MapDBConfiguration.compressed"));
hybridized = "true".equalsIgnoreCase(properties.getProperty("storageConfiguration.MapDBConfiguration.hybridized"));
asynchronous = "true".equalsIgnoreCase(properties.getProperty("storageConfiguration.MapDBConfiguration.asynchronous"));
outputDirectory = properties.getProperty("mapDBConfiguration.outputDirectory");
cacheSize = Integer.parseInt(properties.getProperty("mapDBConfiguration.cacheSize"));
compressed = "true".equalsIgnoreCase(properties.getProperty("mapDBConfiguration.compressed"));
hybridized = "true".equalsIgnoreCase(properties.getProperty("mapDBConfiguration.hybridized"));
asynchronous = "true".equalsIgnoreCase(properties.getProperty("mapDBConfiguration.asynchronous"));
}

/**
Expand Down
@@ -0,0 +1,24 @@
#
# Copyright (C) 2013-2017 Vasilis Vryniotis <bbriniotis@datumbox.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Whether the concurrent execution of tasks is allowed (options: true/false):
concurrencyConfiguration.parallelized=true

# The maximum number of Threads that can be executed concurrently for each task:
# - Use 0 for setting it equal to the number of CPUs on the system.
# - Use 1 to turn off concurrency (same as concurrencyConfiguration.parallelized=false).
# - Any other positive value acts as a limit on the concurrency level, provided that the concurrencyConfiguration.parallelized=true.
concurrencyConfiguration.maxNumberOfThreadsPerTask=0
Expand Up @@ -14,48 +14,5 @@
# limitations under the License.
#


# Configuration
# -------------

# The full class name of the Storage Configuration class. This determines the default storage engine which is used for storing the models:
storageConfiguration.className=com.datumbox.framework.common.storageengines.inmemory.InMemoryConfiguration


# InMemoryConfiguration
# ---------------------

# The relative or absolute path for the output directory where the models are stored (if not specified the temporary directory is used):
storageConfiguration.InMemoryConfiguration.outputDirectory=


# MapDBConfiguration
# ------------------

# The relative or absolute path for the output directory where the models are stored (if not specified the temporary directory is used):
storageConfiguration.MapDBConfiguration.outputDirectory=

# The number of records kept in each LRU cache. Setting it to 0 will disable caching (not recommended):
storageConfiguration.MapDBConfiguration.cacheSize=10000

# Whether compression will be used in storage (options: true/false):
storageConfiguration.MapDBConfiguration.compressed=true

# The hybridized mode enables small and important data to be stored directly In-Memory (options: true/false):
storageConfiguration.MapDBConfiguration.hybridized=true

# Whether the writes will be performed asynchronously (options: true/false):
storageConfiguration.MapDBConfiguration.asynchronous=true


# ConcurrencyConfiguration
# ------------------------

# Whether the concurrent execution of tasks is allowed (options: true/false):
concurrencyConfiguration.parallelized=true

# The maximum number of Threads that can be executed concurrently for each task:
# - Use 0 for setting it equal to the number of CPUs on the system.
# - Use 1 to turn off concurrency (same as concurrencyConfiguration.parallelized=false).
# - Any other positive value acts as a limit on the concurrency level, provided that the concurrencyConfiguration.parallelized=true.
concurrencyConfiguration.maxNumberOfThreadsPerTask=0
# The full class name of the Configuration of the Storage Engine. This determines the default storage engine which is used for storing the models:
configuration.storageConfiguration=com.datumbox.framework.common.storageengines.inmemory.InMemoryConfiguration
@@ -0,0 +1,18 @@
#
# Copyright (C) 2013-2017 Vasilis Vryniotis <bbriniotis@datumbox.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# The relative or absolute path for the output directory where the models are stored (if not specified the temporary directory is used):
inMemoryConfiguration.outputDirectory=
@@ -0,0 +1,30 @@
#
# Copyright (C) 2013-2017 Vasilis Vryniotis <bbriniotis@datumbox.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# The relative or absolute path for the output directory where the models are stored (if not specified the temporary directory is used):
mapDBConfiguration.outputDirectory=

# The number of records kept in each LRU cache. Setting it to 0 will disable caching (not recommended):
mapDBConfiguration.cacheSize=10000

# Whether compression will be used in storage (options: true/false):
mapDBConfiguration.compressed=true

# The hybridized mode enables small and important data to be stored directly In-Memory (options: true/false):
mapDBConfiguration.hybridized=true

# Whether the writes will be performed asynchronously (options: true/false):
mapDBConfiguration.asynchronous=true
@@ -0,0 +1,24 @@
#
# Copyright (C) 2013-2017 Vasilis Vryniotis <bbriniotis@datumbox.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Whether the concurrent execution of tasks is allowed (options: true/false):
concurrencyConfiguration.parallelized=true

# The maximum number of Threads that can be executed concurrently for each task:
# - Use 0 for setting it equal to the number of CPUs on the system.
# - Use 1 to turn off concurrency (same as concurrencyConfiguration.parallelized=false).
# - Any other positive value acts as a limit on the concurrency level, provided that the concurrencyConfiguration.parallelized=true.
concurrencyConfiguration.maxNumberOfThreadsPerTask=0
Expand Up @@ -14,48 +14,5 @@
# limitations under the License.
#


# Configuration
# -------------

# The full class name of the Storage Configuration class. This determines the default storage engine which is used for storing the models:
storageConfiguration.className=com.datumbox.framework.common.storageengines.inmemory.InMemoryConfiguration


# InMemoryConfiguration
# ---------------------

# The relative or absolute path for the output directory where the models are stored (if not specified the temporary directory is used):
storageConfiguration.InMemoryConfiguration.outputDirectory=


# MapDBConfiguration
# ------------------

# The relative or absolute path for the output directory where the models are stored (if not specified the temporary directory is used):
storageConfiguration.MapDBConfiguration.outputDirectory=

# The number of records kept in each LRU cache. Setting it to 0 will disable caching (not recommended):
storageConfiguration.MapDBConfiguration.cacheSize=10000

# Whether compression will be used in storage (options: true/false):
storageConfiguration.MapDBConfiguration.compressed=true

# The hybridized mode enables small and important data to be stored directly In-Memory (options: true/false):
storageConfiguration.MapDBConfiguration.hybridized=true

# Whether the writes will be performed asynchronously (options: true/false):
storageConfiguration.MapDBConfiguration.asynchronous=true


# ConcurrencyConfiguration
# ------------------------

# Whether the concurrent execution of tasks is allowed (options: true/false):
concurrencyConfiguration.parallelized=true

# The maximum number of Threads that can be executed concurrently for each task:
# - Use 0 for setting it equal to the number of CPUs on the system.
# - Use 1 to turn off concurrency (same as concurrencyConfiguration.parallelized=false).
# - Any other positive value acts as a limit on the concurrency level, provided that the concurrencyConfiguration.parallelized=true.
concurrencyConfiguration.maxNumberOfThreadsPerTask=0
# The full package name of the Storage Engine. This determines the default storage engine which is used for storing the models:
configuration.storageConfiguration=com.datumbox.framework.common.storageengines.inmemory.InMemoryConfiguration
@@ -0,0 +1,18 @@
#
# Copyright (C) 2013-2017 Vasilis Vryniotis <bbriniotis@datumbox.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# The relative or absolute path for the output directory where the models are stored (if not specified the temporary directory is used):
inMemoryConfiguration.outputDirectory=
@@ -0,0 +1,30 @@
#
# Copyright (C) 2013-2017 Vasilis Vryniotis <bbriniotis@datumbox.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# The relative or absolute path for the output directory where the models are stored (if not specified the temporary directory is used):
mapDBConfiguration.outputDirectory=

# The number of records kept in each LRU cache. Setting it to 0 will disable caching (not recommended):
mapDBConfiguration.cacheSize=10000

# Whether compression will be used in storage (options: true/false):
mapDBConfiguration.compressed=true

# The hybridized mode enables small and important data to be stored directly In-Memory (options: true/false):
mapDBConfiguration.hybridized=true

# Whether the writes will be performed asynchronously (options: true/false):
mapDBConfiguration.asynchronous=true

0 comments on commit c816666

Please sign in to comment.