<commit_before>package brooklyn.entity.basic;

import java.util.Collection;

import brooklyn.entity.Entity;
import brooklyn.entity.Group;
import brooklyn.event.AttributeSensor;
import brooklyn.event.EventListener;
import brooklyn.event.Sensor;
import brooklyn.event.SensorEvent;
import brooklyn.event.basic.ConfigKey;
import brooklyn.management.ManagementContext;
import brooklyn.policy.Policy;
import brooklyn.management.SubscriptionHandle;

public interface EntityLocal extends Entity {
    /**
     * Gets the value of the given attribute on this entity, or null if has not been set.
     * 
     * Attributes can be things like workrate and status information, as well as 
     * configuration (e.g. url/jmxHost/jmxPort), etc.
     */
    <T> T getAttribute(AttributeSensor<T> sensor);

    /**
     * Sets the {@link Sensor} data for the given attribute to the specified value.
     * 
     * This can be used to "enrich" the entity, such as adding aggregated information, 
     * rolling averages, etc.
     * 
     * @return the old value for the attribute (possibly <code>null</code>)
     */
    <T> T setAttribute(AttributeSensor<T> sensor, T val);
    
    // ??? = policy which detects a group is too hot and want the entity to fire a TOO_HOT event
    
    /**
     * Gets the given configuration value for this entity, which may be inherited from 
     * its owner.
     */
    <T> T getConfig(ConfigKey<T> key);
    
    /**
     * Must be called before the entity is started. Also must be called before the entity's 
     * "owned children" are added, to guarantee that those children inherit the config.
     */
    <T> T setConfig(ConfigKey<T> key, T val);
    
    /**
     * Emits a {@link SensorEvent} event on behalf of this entity (as though produced by this entity).
     */
    <T> void emit(Sensor<T> sensor, T value);
    
    /**
     * Allow us to subscribe to data from a {@link Sensor} on another entity.
     * 
     * @return a subscription id which can be used to unsubscribe
     *
     * @see SubscriptionManger#subscribe(Map, Entity, Sensor, EventListener)
     */
    <T> SubscriptionHandle subscribe(Entity producer, Sensor<T> sensor, EventListener<T> listener);
 
    /** @see SubscriptionManger#subscribeToChildren(Map, Entity, Sensor, EventListener) */
    <T> SubscriptionHandle subscribeToChildren(Entity parent, Sensor<T> sensor, EventListener<T> listener);
 

    /**
     * @return an immutable thread-safe view of the policies.
     */
    Collection<Policy> getPolicies();
    
    /**
     * Adds the given policy to this entity. Also calls policy.setEntity if available.
     */
    void addPolicy(Policy policy);
    
    /**
     * Removes the given policy from this entity. 
     * @return True if the policy existed at this entity; false otherwise
     */
    boolean removePolicy(Policy policy);
    
    ManagementContext getManagementContext();
}<commit_msg>EntityLocal: some todo/fixme about moving methods around<commit_after>package brooklyn.entity.basic;

import java.util.Collection;
import java.util.Map;

import brooklyn.entity.Entity;
import brooklyn.event.AttributeSensor;
import brooklyn.event.EventListener;
import brooklyn.event.Sensor;
import brooklyn.event.SensorEvent;
import brooklyn.event.basic.ConfigKey;
import brooklyn.management.ManagementContext;
import brooklyn.management.SubscriptionHandle;
import brooklyn.policy.Policy;

public interface EntityLocal extends Entity {
    
    // FIXME Rename to something other than EntityLocal.
    // Separate out what is specific to "local jvm", and what is here for an SPI rather than API.
    
    /**
     * Gets the value of the given attribute on this entity, or null if has not been set.
     * 
     * Attributes can be things like workrate and status information, as well as 
     * configuration (e.g. url/jmxHost/jmxPort), etc.
     */
    // TODO Move to Entity, and document semantics of when vals are available in remote JVM?
    //      Or have getLatestEvent instead?
    <T> T getAttribute(AttributeSensor<T> sensor);

    /**
     * Sets the {@link Sensor} data for the given attribute to the specified value.
     * 
     * This can be used to "enrich" the entity, such as adding aggregated information, 
     * rolling averages, etc.
     * 
     * @return the old value for the attribute (possibly <code>null</code>)
     */
    <T> T setAttribute(AttributeSensor<T> sensor, T val);
    
    // ??? = policy which detects a group is too hot and want the entity to fire a TOO_HOT event
    
    /**
     * Gets the given configuration value for this entity, which may be inherited from 
     * its owner.
     */
    <T> T getConfig(ConfigKey<T> key);
    
    /**
     * Must be called before the entity is started.
     */
    <T> T setConfig(ConfigKey<T> key, T val);
    
    /**
     * Emits a {@link SensorEvent} event on behalf of this entity (as though produced by this entity).
     */
    <T> void emit(Sensor<T> sensor, T value);
    
    /**
     * Allow us to subscribe to data from a {@link Sensor} on another entity.
     * 
     * @return a subscription id which can be used to unsubscribe
     *
     * @see SubscriptionManger#subscribe(Map, Entity, Sensor, EventListener)
     */
    // FIXME remove from interface?
    <T> SubscriptionHandle subscribe(Entity producer, Sensor<T> sensor, EventListener<T> listener);
 
    /** @see SubscriptionManger#subscribeToChildren(Map, Entity, Sensor, EventListener) */
    // FIXME remove from interface?
    <T> SubscriptionHandle subscribeToChildren(Entity parent, Sensor<T> sensor, EventListener<T> listener);
 

    /**
     * @return an immutable thread-safe view of the policies.
     */
    // FIXME move to Entity
    Collection<Policy> getPolicies();
    
    /**
     * Adds the given policy to this entity. Also calls policy.setEntity if available.
     */
    void addPolicy(Policy policy);
    
    /**
     * Removes the given policy from this entity. 
     * @return True if the policy existed at this entity; false otherwise
     */
    boolean removePolicy(Policy policy);
    
    ManagementContext getManagementContext();
}
{'fraction_non_alphanumeric': 0.09022801302931596, 'fraction_numerical': 0.0, 'mean_word_length': 2.9593810444874276, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6813173', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1705, 'n_words': 639}