brooklyn.entity.basic.ConfigKeys Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brooklyn-core Show documentation
Show all versions of brooklyn-core Show documentation
Entity implementation classes, events, and other core elements
package brooklyn.entity.basic;
import javax.annotation.Nonnull;
import brooklyn.config.ConfigKey;
import brooklyn.event.basic.BasicConfigKey;
import brooklyn.event.basic.BasicConfigKey.BasicConfigKeyOverwriting;
import brooklyn.util.internal.ssh.SshTool;
import com.google.common.base.CaseFormat;
import com.google.common.base.Preconditions;
import com.google.common.reflect.TypeToken;
/**
* Dictionary of {@link ConfigKey} entries.
*/
public class ConfigKeys {
public static ConfigKey newConfigKey(Class type, String name) {
return new BasicConfigKey(type, name);
}
public static ConfigKey newConfigKey(Class type, String name, String description) {
return new BasicConfigKey(type, name, description);
}
public static ConfigKey newConfigKey(TypeToken type, String name, String description) {
return new BasicConfigKey(type, name, description);
}
public static ConfigKey newConfigKey(Class type, String name, String description, T defaultValue) {
return new BasicConfigKey(type, name, description, defaultValue);
}
public static ConfigKey newConfigKey(TypeToken type, String name, String description, T defaultValue) {
return new BasicConfigKey(type, name, description, defaultValue);
}
/** Infers the type from the default value */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static ConfigKey newConfigKey(String name, String description, @Nonnull T defaultValue) {
return new BasicConfigKey((Class)Preconditions.checkNotNull(defaultValue,
"Type must be exlicit for ConfigKey if defaultValue is null").getClass(),
name, description, defaultValue);
}
public static BasicConfigKey.Builder builder(Class type) {
return BasicConfigKey.builder(type);
}
public static BasicConfigKey.Builder builder(TypeToken type) {
return BasicConfigKey.builder(type);
}
// ---- extensions to keys
public static ConfigKey newConfigKeyWithDefault(ConfigKey parent, T defaultValue) {
return new BasicConfigKeyOverwriting(parent, defaultValue);
}
public static ConfigKey newConfigKeyRenamed(String newName, ConfigKey key) {
return new BasicConfigKey(key.getTypeToken(), newName, key.getDescription(), key.getDefaultValue());
}
public static ConfigKey newConfigKeyWithPrefix(String prefix, ConfigKey key) {
return newConfigKeyRenamed(prefix+key.getName(), key);
}
/** converts the name of the key from one case-strategy (e.g. lowerCamel) to andother (e.g. lower-hyphen) */
public static ConfigKey convert(ConfigKey key, CaseFormat inputCaseStrategy, CaseFormat outputCaseStrategy) {
return newConfigKeyRenamed(inputCaseStrategy.to(outputCaseStrategy, key.getName()), key);
}
// ---- typed keys
public static ConfigKey newStringConfigKey(String name) {
return newConfigKey(String.class, name);
}
public static ConfigKey newStringConfigKey(String name, String description) {
return newConfigKey(String.class, name, description);
}
public static ConfigKey newStringConfigKey(String name, String description, String defaultValue) {
return newConfigKey(String.class, name, description, defaultValue);
}
public static ConfigKey newIntegerConfigKey(String name) {
return newConfigKey(Integer.class, name);
}
public static ConfigKey newIntegerConfigKey(String name, String description) {
return newConfigKey(Integer.class, name, description);
}
public static ConfigKey newIntegerConfigKey(String name, String description, Integer defaultValue) {
return newConfigKey(Integer.class, name, description, defaultValue);
}
public static ConfigKey newLongConfigKey(String name) {
return newConfigKey(Long.class, name);
}
public static ConfigKey newLongConfigKey(String name, String description) {
return newConfigKey(Long.class, name, description);
}
public static ConfigKey newLongConfigKey(String name, String description, Long defaultValue) {
return newConfigKey(Long.class, name, description, defaultValue);
}
public static ConfigKey newDoubleConfigKey(String name) {
return newConfigKey(Double.class, name);
}
public static ConfigKey newDoubleConfigKey(String name, String description) {
return newConfigKey(Double.class, name, description);
}
public static ConfigKey newDoubleConfigKey(String name, String description, Double defaultValue) {
return newConfigKey(Double.class, name, description, defaultValue);
}
public static ConfigKey newBooleanConfigKey(String name) {
return newConfigKey(Boolean.class, name);
}
public static ConfigKey newBooleanConfigKey(String name, String description) {
return newConfigKey(Boolean.class, name, description);
}
public static ConfigKey newBooleanConfigKey(String name, String description, Boolean defaultValue) {
return newConfigKey(Boolean.class, name, description, defaultValue);
}
// ------- keys
public static final ConfigKey BROOKLYN_DATA_DIR = newStringConfigKey(
"brooklyn.datadir", "Directory for writing all brooklyn data", "/tmp/brooklyn-"+System.getProperty("user.name"));
// FIXME Rename to VERSION, instead of SUGGESTED_VERSION? And declare as BasicAttributeSensorAndConfigKey?
public static final ConfigKey SUGGESTED_VERSION = newStringConfigKey("install.version", "Suggested version");
public static final ConfigKey SUGGESTED_INSTALL_DIR = newStringConfigKey("install.dir", "Suggested installation directory");
public static final ConfigKey SUGGESTED_RUN_DIR = newStringConfigKey("run.dir", "Suggested working directory for the running app");
/**
* Intention is to use this with DependentConfiguration.attributeWhenReady, to allow an entity's start
* to block until dependents are ready. This is particularly useful when we want to block until a dependent
* component is up, but this entity does not care about the dependent component's actual config values.
*/
public static final ConfigKey START_LATCH = newBooleanConfigKey("start.latch", "Latch for blocking start until ready");
public static final ConfigKey INSTALL_LATCH = newBooleanConfigKey("install.latch", "Latch for blocking install until ready");
public static final ConfigKey CUSTOMIZE_LATCH = newBooleanConfigKey("customize.latch", "Latch for blocking customize until ready");
public static final ConfigKey LAUNCH_LATCH = newBooleanConfigKey("launch.latch", "Latch for blocking launch until ready");
public static final ConfigKey START_TIMEOUT = newConfigKey(
"start.timeout", "Time to wait for SERVICE_UP to be set before failing (in seconds, default 60)", 60);
/* selected properties from SshTool for external public access (e.g. putting on entities) */
public static final ConfigKey SSH_TOOL_CLASS = newConfigKeyWithPrefix(SshTool.BROOKLYN_CONFIG_KEY_PREFIX, SshTool.PROP_TOOL_CLASS);
public static final ConfigKey SSH_CONFIG_HOST = newConfigKeyWithPrefix(SshTool.BROOKLYN_CONFIG_KEY_PREFIX, SshTool.PROP_HOST);
public static final ConfigKey SSH_CONFIG_PORT = newConfigKeyWithPrefix(SshTool.BROOKLYN_CONFIG_KEY_PREFIX, SshTool.PROP_PORT);
public static final ConfigKey SSH_CONFIG_USER = newConfigKeyWithPrefix(SshTool.BROOKLYN_CONFIG_KEY_PREFIX, SshTool.PROP_USER);
public static final ConfigKey SSH_CONFIG_PASSWORD = newConfigKeyWithPrefix(SshTool.BROOKLYN_CONFIG_KEY_PREFIX, SshTool.PROP_PASSWORD);
public static final ConfigKey SSH_CONFIG_SCRIPT_DIR = newConfigKeyWithPrefix(SshTool.BROOKLYN_CONFIG_KEY_PREFIX, SshTool.PROP_SCRIPT_DIR);
public static final ConfigKey SSH_CONFIG_SCRIPT_HEADER = newConfigKeyWithPrefix(SshTool.BROOKLYN_CONFIG_KEY_PREFIX, SshTool.PROP_SCRIPT_HEADER);
public static final ConfigKey SSH_CONFIG_DIRECT_HEADER = newConfigKeyWithPrefix(SshTool.BROOKLYN_CONFIG_KEY_PREFIX, SshTool.PROP_DIRECT_HEADER);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy