org.cinchapi.concourse.config.ConcoursePreferences Maven / Gradle / Ivy
Show all versions of concourse-config Show documentation
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Jeff Nelson, Cinchapi Software Collective
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.cinchapi.concourse.config;
import java.io.File;
import ch.qos.logback.classic.Level;
/**
* A wrapper around the {@code concourse.prefs} file that is used to
* configure the server.
*
* Instantiate using {@link ConcoursePreferences#load(String)}
*
*
* @author jnelson
*/
public class ConcoursePreferences extends AbstractPreferences {
/**
* Return a {@link ConcoursePreferences} wrapper that is backed by the
* configuration information in {@code file}.
*
* @param file
* @return the preferences
*/
public static ConcoursePreferences load(String file) {
return new ConcoursePreferences(file);
}
// Defaults
private static String DEFAULT_DATA_HOME = System.getProperty("user.home")
+ File.separator + "concourse" + File.separator;
private static String DEFAULT_BUFFER_DIRECTORY = DEFAULT_DATA_HOME
+ "buffer";
private static String DEFAULT_DATABASE_DIRECTORY = DEFAULT_DATA_HOME + "db";
private static int DEFAULT_BUFFER_PAGE_SIZE = 8192;
private static Level DEFAULT_LOG_LEVEL = Level.INFO;
private static boolean DEFAULT_ENABLE_CONSOLE_LOGGING = false;
private static int DEFAULT_CLIENT_PORT = 1717;
private static int DEFAULT_SHUTDOWN_PORT = 3434;
private static int DEFAULT_JMX_PORT = 9010;
private static String DEFAULT_DEFAULT_ENVIRONMENT = "default";
/**
* Construct a new instance.
*
* @param file
*/
protected ConcoursePreferences(String file) {
super(file);
}
/**
* The absolute path to the directory where the Buffer data is stored.
* For optimal write performance, the Buffer should be placed on a
* separate disk partition (ideally a separate physical device) from
* the database_directory.
*
* @return the buffer directory
*/
public String getBufferDirectory() {
return getHandler().getString("buffer_directory",
DEFAULT_BUFFER_DIRECTORY);
}
/**
* The size for each page in the Buffer. During reads, Buffer pages
* are individually locked, so it is desirable to have several smaller
* pages as opposed to few larger ones. Nevertheless, be sure to balance
* the desire to maximize lock granularity with the risks of having too
* many open buffer files simultaneously.
*
* @return the buffer page size in bytes
*/
public long getBufferPageSize() {
return getHandler().getSize("buffer_page_size",
DEFAULT_BUFFER_PAGE_SIZE);
}
/**
* The listener port (1-65535) for client connections. Choose a port between
* 49152 and 65535 to minimize the possibility of conflicts with other
* services on this host.
*
* @return the client port
*/
public int getClientPort() {
return getHandler().getInt("client_port", DEFAULT_CLIENT_PORT);
}
/**
* The absolute path to the directory where the Database record and index
* files are stored. For optimal performance, the Database should be
* placed on a separate disk partition (ideally a separate physical device)
* from the buffer_directory.
*
* @return the database directory
*/
public String getDatabaseDirectory() {
return getHandler().getString("database_directory",
DEFAULT_DATABASE_DIRECTORY);
}
/**
* The default environment that is automatically loaded when the server
* starts and is used whenever a client does not specify an environment for
* its connection.
*
* @return the default environment
*/
public String getDefaultEnvironment() {
return getHandler().getString("default_environment",
DEFAULT_DEFAULT_ENVIRONMENT);
}
/**
* Determine whether log messages should also be printed to the console
* (STDOUT).
*
* @return the determination whether to enable console logging
*/
public boolean getEnableConsoleLogging() {
return getHandler().getBoolean("enable_console_logging",
DEFAULT_ENABLE_CONSOLE_LOGGING);
}
/**
* The listener port (1-65535) for management commands via JMX. Choose a
* port between 49152 and 65535 to minimize the possibility of conflicts
* with other services on this host.
*
* @return the jmx port
*/
public int getJmxPort() {
return getHandler().getInt("jmx_port", DEFAULT_JMX_PORT);
}
/**
* # The amount of runtime information logged by the system. The options
* below
* are listed from least to most verbose. In addition to the indicated types
* of information, each level also logs the information for each less
* verbose
* level (i.e. ERROR only prints error messages, but INFO prints info, warn
* and error messages).
*
*
* ERROR: critical information when the system reaches a
* potentially fatal state and may not operate normally.
*
*
* WARN: useful information when the system reaches a less
* than ideal state but can continue to operate normally.
*
*
* INFO: status information about the system that can be
* used for sanity checking.
*
*
* DEBUG: detailed information about the system that can be
* used to diagnose bugs.
*
*
*
* Logging is important, but may cause performance degradation. Only use the
* DEBUG level for staging environments or instances when detailed
* information is needed to diagnose a bug. Otherwise use the WARN or INFO
* levels.
*
*
* @return the log level
*/
public Level getLogLevel() {
return Level.valueOf(getHandler().getString("log_level",
DEFAULT_LOG_LEVEL.toString()));
}
/**
* The listener port (1-65535) for shutdown commands. Choose a port between
* 49152 and 65535 to minimize the possibility of conflicts with other
* services on this host.
*
* @return the shutdown port
*/
public int getShutdownPort() {
return getHandler().getInt("shutdown_port", DEFAULT_SHUTDOWN_PORT);
}
/**
* Set the value associated with the {@code buffer_directory} key.
*
* @param bufferDirectory
*/
public void setBufferDirectory(String bufferDirectory) {
set("buffer_directory", bufferDirectory);
}
/**
* Set the value associated with the {@code buffer_page_size} key.
*/
public void setBufferPageSize(long sizeInBytes) {
set("buffer_page_size", sizeInBytes);
}
/**
* Set the value associated with the {@code client_port} key.
*
* @param clientPort
*/
public void setClientPort(int clientPort) {
set("client_port", clientPort);
}
/**
* Set the value associated with the {@code database_directory} key.
*
* @param databaseDirectory
*/
public void setDatabaseDirectory(String databaseDirectory) {
set("database_directory", databaseDirectory);
}
/**
* Set the value associated with the {@code default_environment} key.
*
* @param defaultEnvironment
*/
public void setDefaultEnvironment(String defaultEnvironment) {
set("default_environment", defaultEnvironment);
}
/**
* Set the value associated with the {@code enable_console_logging} key.
*
* @param enableConsoleLogging
*/
public void setEnableConsoleLogging(boolean enableConsoleLogging) {
set("enable_console_logging", enableConsoleLogging);
}
/**
* Set the value associated with the {@code jmx_port} key.
*
* @param port
*/
public void setJmxPort(int port) {
set("jmx_port", port);
}
/**
* Set the value associated with the {@code log_level} key.
*
* @param level
*/
public void setLogLevel(Level level) {
set("log_level", level.toString());
}
/**
* Set the value associated with the {@code shutdown_port} key.
*
* @param shutdownPort
*/
public void setShutdownPort(int shutdownPort) {
set("shutdown_port", shutdownPort);
}
}