org.apache.brooklyn.api.objs.Configurable Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package org.apache.brooklyn.api.objs;
import java.util.Set;
import org.apache.brooklyn.api.mgmt.Task;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
import com.google.common.annotations.Beta;
import com.google.common.base.Predicate;
/**
* Something that has mutable config, such as an entity or policy.
*
* @author aled
*/
public interface Configurable {
/**
* @return the old value, or null if there was not one
* @deprecated since 0.7.0; use {@link ConfigurationSupport#set(ConfigKey, Object)}, such as {@code config().set(key, val)}
*/
@Deprecated
public T setConfig(ConfigKey key, T val);
/**
* Convenience for calling {@link ConfigurationSupport#get(ConfigKey)},
* via code like {@code config().get(key)}.
*
* @since 0.9.0
*/
T getConfig(ConfigKey key);
ConfigurationSupport config();
@Beta
public interface ConfigurationSupport {
/**
* Gets the given configuration value for this entity, in the following order of precedence:
*
* - value (including null) explicitly set on the entity
*
- value (including null) explicitly set on an ancestor (inherited)
*
- a default value (including null) on the best equivalent static key of the same name declared on the entity
* (where best equivalence is defined as preferring a config key which extends another,
* as computed in EntityDynamicType.getConfigKeys)
*
- a default value (including null) on the key itself
*
- null
*
*/
T get(ConfigKey key);
/**
* @see {@link #getConfig(ConfigKey)}
*/
T get(HasConfigKey key);
/**
* Sets the config to the given value.
*/
T set(ConfigKey key, T val);
/**
* @see {@link #setConfig(HasConfigKey, Object)}
*/
T set(HasConfigKey key, T val);
/**
* Sets the config to the value returned by the task.
*
* Returns immediately without blocking; subsequent calls to {@link #getConfig(ConfigKey)}
* will execute the task, and block until the task completes.
*
* @see {@link #setConfig(ConfigKey, Object)}
*/
T set(ConfigKey key, Task val);
/**
* @see {@link #setConfig(ConfigKey, Task)}
*/
T set(HasConfigKey key, Task val);
Set> findKeys(Predicate super ConfigKey>> predicate);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy