Brooklyn

brooklyn.entity.basic
[Java] Class AbstractEntity

java.lang.Object
  brooklyn.entity.basic.AbstractEntity
All Implemented Interfaces:
EntityInternal, EntityLocal

public abstract class AbstractEntity

Default Entity implementation, which should be extended whenever implementing an entity.

Provides several common fields (displayName, id), and supports the core features of an entity such as configuration keys, attributes, subscriptions and effector invocation.

If a sub-class is creating other entities, this should be done in an overridden init() method.

Note that config is typically inherited by children, whereas the fields and attributes are not.

Though currently Groovy code, this is very likely to change to pure Java in a future release of Brooklyn so Groovy'isms should not be relied on.

Sub-classes should have a no-argument constructor. When brooklyn creates an entity, it will:

  1. Construct the entity via the no-argument constructor
  2. Call setDisplayName(String)
  3. Call setManagementContext(ManagementContextInternal)
  4. Call setProxy(Entity); the proxy should be used by everything else when referring to this entity (except for drivers/policies that are attached to the entity, which can be given a reference to this entity itself).
  5. Call configure(Map) and then setConfig(ConfigKey, Object)
  6. Call init()
  7. Call addPolicy(Policy) (for any policies defined in the EntitySpec)
  8. Call setParent(Entity), if a parent is specified in the EntitySpec

The legacy (pre 0.5) mechanism for creating entities is for others to call the constructor directly. This is now deprecated.


Field Summary
static BasicNotificationSensor CHILD_ADDED

static BasicNotificationSensor CHILD_REMOVED

static BasicNotificationSensor EFFECTOR_ADDED

static BasicNotificationSensor EFFECTOR_CHANGED

static BasicNotificationSensor EFFECTOR_REMOVED

static BasicNotificationSensor POLICY_ADDED

static BasicNotificationSensor POLICY_REMOVED

static BasicNotificationSensor SENSOR_ADDED

static BasicNotificationSensor SENSOR_REMOVED

protected SubscriptionTracker _subscriptionTracker

protected EntityManagementSupport managementSupport

protected java.util.Map tempWorkings

 
Constructor Summary
AbstractEntity()

AbstractEntity(java.util.Map flags)

@deprecated since 0.5; instead use no-arg constructor with EntityManager().createEntity(spec)

AbstractEntity(Entity parent)

@deprecated since 0.5; instead use no-arg constructor with EntityManager().createEntity(spec)

AbstractEntity(java.util.Map flags, Entity parent)

 
Method Summary
java.lang.Object addChild(java.lang.Object child)

Creates an entity using the given spec, and adds it as a child of this entity.

java.lang.Object addChild(EntitySpec spec)

Adds this as a member of the given group, registers with application if necessary

java.lang.Object addEnricher(EnricherSpec spec)

void addEnricher(Enricher enricher)

Invoke an Effector directly.

void addGroup(Group e)

Returns the application, looking it up if not yet known (registering if necessary)

void addLocations(java.util.Collection newLocations)

void addPolicy(Policy policy)

java.lang.Object addPolicy(PolicySpec spec)

void clearLocations()

void clearParent()

Adds the given entity as a child of this parent and sets this entity as the parent of the child; returns argument passed in, for convenience.

AbstractEntity configure()

AbstractEntity configure(java.util.Map flags)

AbstractEntity configure(ConfigKey key, java.lang.Object value)

Sets a config key value, and returns this Entity instance for use in fluent-API style coding.

AbstractEntity configure(ConfigKey key, java.lang.String value)

AbstractEntity configure(HasConfigKey key, java.lang.Object value)

AbstractEntity configure(HasConfigKey key, java.lang.String value)

void destroy()

void emit(Sensor sensor, java.lang.Object val)

Invoked by EntityManagementSupport when this entity is becoming managed (i.e. it has a working management context, but before the entity is visible to other entities).

void emitInternal(Sensor sensor, java.lang.Object val)

Invoked by EntityManagementSupport when this entity is fully managed and visible to other entities through the management context.

boolean equals(java.lang.Object o)

protected void finalize()

Location firstLocation()

java.util.Map getAllAttributes()

java.util.Map getAllConfig()

ConfigBag getAllConfigBag()

Unsubscribes the given producer.

Application getApplication()

java.lang.String getApplicationId()

java.lang.Object getAttribute(AttributeSensor attribute)

java.lang.Object getAttributeByNameParts(java.util.List nameParts)

java.util.Collection getChildren()

java.lang.Object getConfig(ConfigKey key)

java.lang.Object getConfig(HasConfigKey key)

java.lang.Object getConfig(HasConfigKey key, java.lang.Object defaultValue)

java.lang.Object getConfig(ConfigKey key, java.lang.Object defaultValue)

EntityConfigMap getConfigMap()

@see EntityLocal#subscribeToMembers

Maybe getConfigRaw(ConfigKey key, boolean includeInherited)

Maybe getConfigRaw(HasConfigKey key, boolean includeInherited)

long getCreationTime()

allows subclasses to set the default display name to use if none is provided

java.lang.String getDisplayName()

Effector getEffector(java.lang.String effectorName)

Invoked by ManagementContext when this entity becomes mastered at a particular management node, including the final management end and subsequent management node master-change for this entity.

java.util.Collection getEnrichers()

Convenience for finding named effector in EntityType#getEffectors()#getEffectors() java.util.Map.

protected EntityManager getEntityManager()

EntityType getEntityType()

protected java.lang.String getEntityTypeName()

ExecutionContext getExecutionContext()

java.util.Collection getGroups()

java.lang.String getIconUrl()

Gets the entity type name, to be returned by getEntityType().getName().

java.lang.String getId()

ConfigBag getLocalConfigBag()

java.util.Collection getLocations()

ManagementContext getManagementContext()

EntityManagementSupport getManagementSupport()

EntityDynamicType getMutableEntityType()

Entity getParent()

@deprecated since 0.4.0 should not be needed / leaked outwith brooklyn internals / mgmt support?

java.util.Collection getPolicies()

Entity getProxy()

Entity getProxyIfAvailable()

RebindSupport getRebindSupport()

SubscriptionContext getSubscriptionContext()

protected SubscriptionTracker getSubscriptionTracker()

int hashCode()

void init()

Adds this as a child of the given entity; registers with application if necessary.

void invalidateReferences()

Task invoke(Effector eff)

Invoked by EntityManagementSupport when this entity is fully unmanaged.

Task invoke(java.util.Map parameters, Effector eff)

Task invoke(Effector eff, java.util.Map parameters)

For use by management plane, to invalidate all fields (e.g. when an entity is changing to being proxied)

protected boolean isLegacyConstruction()

void onManagementBecomingMaster()

void onManagementNoLongerMaster()

void onManagementStarted()

void onManagementStarting()

void onManagementStopped()

void refreshInheritedConfig()

boolean removeAllEnrichers()

boolean removeAllPolicies()

void removeAttribute(AttributeSensor attribute)

boolean removeChild(Entity child)

boolean removeEnricher(Enricher enricher)

void removeLocations(java.util.Collection removedLocations)

Should be invoked at end-of-life to clean up the item.

boolean removePolicy(Policy policy)

protected void setApplication(Application app)

java.lang.Object setAttribute(AttributeSensor attribute, java.lang.Object val)

java.lang.Object setAttribute(AttributeSensorAndConfigKey configuredSensor)

java.lang.Object setAttributeWithoutPublishing(AttributeSensor attribute, java.lang.Object val)

java.lang.Object setConfig(ConfigKey key, java.lang.Object val)

java.lang.Object setConfig(ConfigKey key, Task val)

java.lang.Object setConfig(ConfigKey key, DeferredSupplier val)

java.lang.Object setConfig(HasConfigKey key, java.lang.Object val)

java.lang.Object setConfig(HasConfigKey key, Task val)

java.lang.Object setConfig(HasConfigKey key, DeferredSupplier val)

java.lang.Object setConfigEvenIfOwned(ConfigKey key, java.lang.Object val)

java.lang.Object setConfigEvenIfOwned(HasConfigKey key, java.lang.Object val)

protected void setConfigIfValNonNull(ConfigKey key, java.lang.Object val)

protected void setConfigIfValNonNull(HasConfigKey key, java.lang.Object val)

protected void setDefaultDisplayName(java.lang.String displayNameIfDefault)

void setDisplayName(java.lang.String newDisplayName)

void setManagementContext(ManagementContextInternal managementContext)

AbstractEntity setParent(Entity entity)

void setProxy(Entity proxy)

SubscriptionHandle subscribe(Entity producer, Sensor sensor, SensorEventListener listener)

SubscriptionHandle subscribeToChildren(Entity parent, Sensor sensor, SensorEventListener listener)

Default String representation is simplified name of class, together with selected fields.

SubscriptionHandle subscribeToMembers(Group group, Sensor sensor, SensorEventListener listener)

java.util.Map toMetadataRecord()

java.lang.String toString()

protected ToStringHelper toStringHelper()

boolean unsubscribe(Entity producer)

boolean unsubscribe(Entity producer, SubscriptionHandle handle)

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

CHILD_ADDED

public static final BasicNotificationSensor CHILD_ADDED


CHILD_REMOVED

public static final BasicNotificationSensor CHILD_REMOVED


EFFECTOR_ADDED

public static final BasicNotificationSensor EFFECTOR_ADDED


EFFECTOR_CHANGED

public static final BasicNotificationSensor EFFECTOR_CHANGED


EFFECTOR_REMOVED

public static final BasicNotificationSensor EFFECTOR_REMOVED


POLICY_ADDED

public static final BasicNotificationSensor POLICY_ADDED


POLICY_REMOVED

public static final BasicNotificationSensor POLICY_REMOVED


SENSOR_ADDED

public static final BasicNotificationSensor SENSOR_ADDED


SENSOR_REMOVED

public static final BasicNotificationSensor SENSOR_REMOVED


_subscriptionTracker

protected SubscriptionTracker _subscriptionTracker


managementSupport

protected final EntityManagementSupport managementSupport


tempWorkings

@java.lang.Deprecated}
protected final java.util.Map tempWorkings


 
Constructor Detail

AbstractEntity

public AbstractEntity()


AbstractEntity

@java.lang.Deprecatedpublic AbstractEntity(Entity parent) {
public AbstractEntity(java.util.Map flags)
deprecated:
since 0.5; instead use no-arg constructor with EntityManager().createEntity(spec)


AbstractEntity

@java.lang.Deprecated
public AbstractEntity(Entity parent)
deprecated:
since 0.5; instead use no-arg constructor with EntityManager().createEntity(spec)


AbstractEntity

@java.lang.Deprecated}
public AbstractEntity(java.util.Map flags, Entity parent)


 
Method Detail

addChild

@java.lang.Override}
public java.lang.Object addChild(java.lang.Object child)
Creates an entity using the given spec, and adds it as a child of this entity.
throws:
IllegalArgumentException If spec.getParent() is set and is different from this entity
See Also:
addChild(Entity)
EntityManager#createEntity(EntitySpec)#createEntity(EntitySpec)


addChild

@java.lang.Override
public java.lang.Object addChild(EntitySpec spec)
Adds this as a member of the given group, registers with application if necessary


addEnricher

@java.lang.Overrideboolean changed = false;
public java.lang.Object addEnricher(EnricherSpec spec)


addEnricher

@java.lang.Override
public void addEnricher(Enricher enricher)
Invoke an Effector directly.


addGroup

@java.lang.Override}
public void addGroup(Group e)
Returns the application, looking it up if not yet known (registering if necessary)


addLocations

@java.lang.Overridepublic void clearLocations() {
public void addLocations(java.util.Collection newLocations)


addPolicy

@java.lang.Override}
public void addPolicy(Policy policy)


addPolicy

@java.lang.Overridepublic boolean removeEnricher(Enricher enricher) {
public java.lang.Object addPolicy(PolicySpec spec)


clearLocations

@java.lang.Overridepublic  T setAttributeWithoutPublishing(AttributeSensor attribute, T val) {
public void clearLocations()


clearParent

@java.lang.Override}
public void clearParent()
Adds the given entity as a child of this parent and sets this entity as the parent of the child; returns argument passed in, for convenience.

The child is NOT managed, even if the parent is already managed at this point (e.g. the child is added *after* the parent's AbstractEntity#init()#init() is invoked) and so will need an explicit getEntityManager().manage(childReturnedFromThis) call. These semantics are currently under review.


configure

public AbstractEntity configure()


configure

@java.lang.Overrideif (suppliedParent != null) {
public AbstractEntity configure(java.util.Map flags)


configure

public AbstractEntity configure(ConfigKey key, java.lang.Object value)
Sets a config key value, and returns this Entity instance for use in fluent-API style coding.


configure

public AbstractEntity configure(ConfigKey key, java.lang.String value)


configure

public AbstractEntity configure(HasConfigKey key, java.lang.Object value)


configure

public AbstractEntity configure(HasConfigKey key, java.lang.String value)


destroy

@java.lang.Override/** sets the value of the given attribute sensor from the config key value herein
public void destroy()


emit

@java.lang.Override}
public void emit(Sensor sensor, java.lang.Object val)
Invoked by EntityManagementSupport when this entity is becoming managed (i.e. it has a working management context, but before the entity is visible to other entities).


emitInternal

public void emitInternal(Sensor sensor, java.lang.Object val)
Invoked by EntityManagementSupport when this entity is fully managed and visible to other entities through the management context.


equals

@java.lang.Overridepublic String getId() {
public boolean equals(java.lang.Object o)


finalize

@java.lang.Override
protected void finalize()


firstLocation

public Location firstLocation()


getAllAttributes

@java.lang.Overridereturn getSubscriptionTracker().unsubscribe(producer, handle);
public java.util.Map getAllAttributes()


getAllConfig

@java.lang.Override/**
public java.util.Map getAllConfig()


getAllConfigBag

@Beta@Override
@java.lang.Overridepublic boolean unsubscribe(Entity producer) {
public ConfigBag getAllConfigBag()
Unsubscribes the given producer.
See Also:
SubscriptionContext#unsubscribe(SubscriptionHandle)#unsubscribe(SubscriptionHandle)


getApplication

@java.lang.Overrideprotected EntityManager getEntityManager() {
public Application getApplication()


getApplicationId

@java.lang.OverrideSet truelyNewLocations = Sets.newLinkedHashSet(newLocations);
public java.lang.String getApplicationId()


getAttribute

@java.lang.Override* @deprecated on interface since 0.5.0; use {@link ConfigToAttributes#apply(EntityLocal, AttributeSensorAndConfigKey)} */
public java.lang.Object getAttribute(AttributeSensor attribute)


getAttributeByNameParts

public java.lang.Object getAttributeByNameParts(java.util.List nameParts)


getChildren

@java.lang.Override}
public java.util.Collection getChildren()


getConfig

@java.lang.Override
public java.lang.Object getConfig(ConfigKey key)


getConfig

@java.lang.Overridereturn setConfigInternal(key, val);
public java.lang.Object getConfig(HasConfigKey key)


getConfig

@java.lang.Overridereturn setConfigInternal(key, val);
public java.lang.Object getConfig(HasConfigKey key, java.lang.Object defaultValue)


getConfig

@java.lang.Override
public java.lang.Object getConfig(ConfigKey key, java.lang.Object defaultValue)


getConfigMap

@java.lang.Override
public EntityConfigMap getConfigMap()
See Also:
EntityLocal#subscribeToMembers#subscribeToMembers


getConfigRaw

@java.lang.Override
public Maybe getConfigRaw(ConfigKey key, boolean includeInherited)


getConfigRaw

@java.lang.Overridepublic  T setConfig(HasConfigKey key, DeferredSupplier val) {
public Maybe getConfigRaw(HasConfigKey key, boolean includeInherited)


getCreationTime

@java.lang.Overrideif (displayNameAutoGenerated) {
public long getCreationTime()
allows subclasses to set the default display name to use if none is provided


getDisplayName

@java.lang.Override/**
public java.lang.String getDisplayName()


getEffector

public Effector getEffector(java.lang.String effectorName)
Invoked by ManagementContext when this entity becomes mastered at a particular management node, including the final management end and subsequent management node master-change for this entity.
deprecated:
since 0.4.0 override EntityManagementSupport.onManagementStopping if customization needed


getEnrichers

@java.lang.Override
public java.util.Collection getEnrichers()
Convenience for finding named effector in EntityType#getEffectors()#getEffectors() java.util.Map.


getEntityManager

protected EntityManager getEntityManager()


getEntityType

@java.lang.Override}
public EntityType getEntityType()


getEntityTypeName

protected java.lang.String getEntityTypeName()


getExecutionContext

@java.lang.Overridereturn enricher;
public ExecutionContext getExecutionContext()


getGroups

@java.lang.Overridereturn (app == null) ? null : app.getId();
public java.util.Collection getGroups()


getIconUrl

@java.lang.Overrideprotected String getEntityTypeName() {
public java.lang.String getIconUrl()
Gets the entity type name, to be returned by getEntityType().getName(). To be called by brooklyn internals only. Can be overridden to customize the name.


getId

@java.lang.Overridereturn selfProxy;
public java.lang.String getId()


getLocalConfigBag

@Beta* Unsubscribes the given handle.
@java.lang.Override*
public ConfigBag getLocalConfigBag()


getLocations

@java.lang.Override// around forever, even if not referenced.
public java.util.Collection getLocations()


getManagementContext

@java.lang.Override
public ManagementContext getManagementContext()


getManagementSupport

@java.lang.Override
public EntityManagementSupport getManagementSupport()


getMutableEntityType

@java.lang.Overridelocations.set(MutableList.builder().addAll(oldLocations).removeAll(removedLocations).buildImmutable());
public EntityDynamicType getMutableEntityType()


getParent

@java.lang.Overrideif (application.getId() != app.getId()) {
public Entity getParent()
deprecated:
since 0.4.0 should not be needed / leaked outwith brooklyn internals / mgmt support?


getPolicies

@java.lang.Override}
public java.util.Collection getPolicies()


getProxy

public Entity getProxy()


getProxyIfAvailable

@Beta*
public Entity getProxyIfAvailable()


getRebindSupport

@java.lang.Override
public RebindSupport getRebindSupport()


getSubscriptionContext

@java.lang.Override
public SubscriptionContext getSubscriptionContext()


getSubscriptionTracker

protected SubscriptionTracker getSubscriptionTracker()


hashCode

@java.lang.Overrideprotected boolean isLegacyConstruction() {
public int hashCode()


init

public void init()
Adds this as a child of the given entity; registers with application if necessary.


invalidateReferences

public void invalidateReferences()


invoke

public Task invoke(Effector eff)
Invoked by EntityManagementSupport when this entity is fully unmanaged.


invoke

public Task invoke(java.util.Map parameters, Effector eff)


invoke

@java.lang.Overridepublic void invalidateReferences() {
public Task invoke(Effector eff, java.util.Map parameters)
For use by management plane, to invalidate all fields (e.g. when an entity is changing to being proxied)


isLegacyConstruction

protected boolean isLegacyConstruction()


onManagementBecomingMaster

public void onManagementBecomingMaster()


onManagementNoLongerMaster

public void onManagementNoLongerMaster()


onManagementStarted

public void onManagementStarted()


onManagementStarting

public void onManagementStarting()


onManagementStopped

public void onManagementStopped()


refreshInheritedConfig

@java.lang.Override}
public void refreshInheritedConfig()


removeAllEnrichers

@java.lang.Overridereturn EffectorUtils.invokeEffectorAsync(this, eff, parameters);
public boolean removeAllEnrichers()


removeAllPolicies

@java.lang.Overrideif (LOG.isDebugEnabled()) LOG.debug("Emitting sensor notification {} value {} on {}", new Object[] {sensor.getName(), val, this});
public boolean removeAllPolicies()


removeAttribute

@java.lang.Override
public void removeAttribute(AttributeSensor attribute)


removeChild

@java.lang.Override}
public boolean removeChild(Entity child)


removeEnricher

@java.lang.Override* Additional form supplied for when the parameter map needs to be made explicit.
public boolean removeEnricher(Enricher enricher)


removeLocations

@java.lang.Override}
public void removeLocations(java.util.Collection removedLocations)
Should be invoked at end-of-life to clean up the item.


removePolicy

@java.lang.Override// -------- SENSORS --------------------
public boolean removePolicy(Policy policy)


setApplication

protected void setApplication(Application app)


setAttribute

@java.lang.Override
public java.lang.Object setAttribute(AttributeSensor attribute, java.lang.Object val)


setAttribute

public java.lang.Object setAttribute(AttributeSensorAndConfigKey configuredSensor)


setAttributeWithoutPublishing

@java.lang.Override}
public java.lang.Object setAttributeWithoutPublishing(AttributeSensor attribute, java.lang.Object val)


setConfig

@java.lang.Override}
public java.lang.Object setConfig(ConfigKey key, java.lang.Object val)


setConfig

@java.lang.Overridevoid refreshInheritedConfigOfChildren() {
public java.lang.Object setConfig(ConfigKey key, Task val)


setConfig

public java.lang.Object setConfig(ConfigKey key, DeferredSupplier val)


setConfig

@java.lang.Override}
public java.lang.Object setConfig(HasConfigKey key, java.lang.Object val)


setConfig

@java.lang.Override}
public java.lang.Object setConfig(HasConfigKey key, Task val)


setConfig

public java.lang.Object setConfig(HasConfigKey key, DeferredSupplier val)


setConfigEvenIfOwned

public java.lang.Object setConfigEvenIfOwned(ConfigKey key, java.lang.Object val)


setConfigEvenIfOwned

public java.lang.Object setConfigEvenIfOwned(HasConfigKey key, java.lang.Object val)


setConfigIfValNonNull

protected void setConfigIfValNonNull(ConfigKey key, java.lang.Object val)


setConfigIfValNonNull

protected void setConfigIfValNonNull(HasConfigKey key, java.lang.Object val)


setDefaultDisplayName

protected void setDefaultDisplayName(java.lang.String displayNameIfDefault)


setDisplayName

@java.lang.Overridereturn typeName;
public void setDisplayName(java.lang.String newDisplayName)


setManagementContext

public void setManagementContext(ManagementContextInternal managementContext)


setParent

@java.lang.OverriderefreshInheritedConfig();
public AbstractEntity setParent(Entity entity)


setProxy

public void setProxy(Entity proxy)


subscribe

@java.lang.Overridepublic synchronized ExecutionContext getExecutionContext() {
public SubscriptionHandle subscribe(Entity producer, Sensor sensor, SensorEventListener listener)


subscribeToChildren

@java.lang.Overridepublic String toString() {
public SubscriptionHandle subscribeToChildren(Entity parent, Sensor sensor, SensorEventListener listener)
Default String representation is simplified name of class, together with selected fields.


subscribeToMembers

@java.lang.Override*
public SubscriptionHandle subscribeToMembers(Group group, Sensor sensor, SensorEventListener listener)


toMetadataRecord

@java.lang.OverridegetManagementSupport().getEntityChangeListener().onChanged();
public java.util.Map toMetadataRecord()


toString

@java.lang.Overrideboolean changed = policies.remove(policy);
public java.lang.String toString()


toStringHelper

protected ToStringHelper toStringHelper()


unsubscribe

@java.lang.Override// -------- POLICIES --------------------
public boolean unsubscribe(Entity producer)


unsubscribe

@java.lang.Override((AbstractPolicy)policy).setEntity(this);
public boolean unsubscribe(Entity producer, SubscriptionHandle handle)


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.