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 EFFECTOR_ADDED

static BasicNotificationSensor EFFECTOR_CHANGED

static BasicNotificationSensor EFFECTOR_REMOVED

protected static Logger LOG

@deprecated since 0.6; will be made private in subsequent release; instead declare more appropriate logger

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)

java.lang.Object addChild(EntitySpec spec)

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

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)

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()

Application getApplication()

java.lang.String getApplicationId()

java.lang.Object getAttribute(AttributeSensor attribute)

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

java.util.Collection getChildren()

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

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()

long getCreationTime()

java.lang.String getDisplayName()

Effector getEffector(java.lang.String effectorName)

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()

java.lang.String getId()

java.util.Collection getLocations()

ManagementContext getManagementContext()

EntityManagementSupport getManagementSupport()

EntityDynamicType getMutableEntityType()

Entity getParent()

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)

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

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

protected boolean isLegacyConstruction()

void onManagementBecomingMaster()

void onManagementNoLongerMaster()

void onManagementStarted()

void onManagementStarting()

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

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)

@see EntityLocal#subscribe

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)

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

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

java.util.Map toMetadataRecord()

java.lang.String toString()

protected ToStringHelper toStringHelper()

boolean unsubscribe(Entity producer)

Override this to add to the toString(), e.g.

boolean unsubscribe(Entity producer, SubscriptionHandle handle)

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), 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

EFFECTOR_ADDED

public static final BasicNotificationSensor EFFECTOR_ADDED


EFFECTOR_CHANGED

public static final BasicNotificationSensor EFFECTOR_CHANGED


EFFECTOR_REMOVED

public static final BasicNotificationSensor EFFECTOR_REMOVED


LOG

@Deprecated
protected static final Logger LOG
deprecated:
since 0.6; will be made private in subsequent release; instead declare more appropriate logger


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

}
protected final java.util.Map tempWorkings


 
Constructor Detail

AbstractEntity

public AbstractEntity()


AbstractEntity

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


AbstractEntity

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


AbstractEntity

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


 
Method Detail

addChild

synchronized (children) {
public java.lang.Object addChild(java.lang.Object child)


addChild

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


addEnricher

public  Task invoke(Effector eff) {
public void addEnricher(Enricher enricher)
Invoke an Effector directly.


addGroup

setApplication(app);
public void addGroup(Group e)
Returns the application, looking it up if not yet known (registering if necessary)


addLocations

}
public void addLocations(java.util.Collection newLocations)


addPolicy

return enrichers.remove(enricher);
public void addPolicy(Policy policy)


clearLocations

}
public void clearLocations()


clearParent

*/
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.


configure

public AbstractEntity configure()


configure

if (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

entityType.removeSensor(attribute);
public void destroy()


emit

entityType.setName(getEntityTypeName());
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

return id;
public boolean equals(java.lang.Object o)


finalize

protected void finalize()


firstLocation

public Location firstLocation()


getAllAttributes

*/
public java.util.Map getAllAttributes()


getAllConfig

public java.util.Map getAllConfig()


getApplication

return getManagementSupport().getManagementContext();
public Application getApplication()


getApplicationId

public void addLocations(Collection newLocations) {
public java.lang.String getApplicationId()


getAttribute

* if the attribtue sensor is not-set or null
public java.lang.Object getAttribute(AttributeSensor attribute)


getAttributeByNameParts

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


getChildren

}
public java.util.Collection getChildren()
deprecated:
since 0.4.0 should not be needed / leaked outwith brooklyn internals / mgmt support?


getConfig

}
public java.lang.Object getConfig(ConfigKey key)


getConfig

public java.lang.Object getConfig(HasConfigKey key)


getConfig

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


getConfig

return setConfig(key.getConfigKey(), val);
public java.lang.Object getConfig(ConfigKey key, java.lang.Object defaultValue)


getConfigMap

*/
public EntityConfigMap getConfigMap()


getCreationTime

* To be called by brooklyn internals only.
public long getCreationTime()


getDisplayName

Class typeClazz = getManagementContext().getEntityManager().getEntityTypeRegistry().getEntityTypeOf(getClass());
public java.lang.String getDisplayName()


getEffector

public Effector getEffector(java.lang.String effectorName)


getEnrichers

public Effector getEffector(String effectorName) {
public java.util.Collection getEnrichers()
Convenience for finding named effector in EntityType#getEffectors()#getEffectors() java.util.Map.


getEntityManager

protected EntityManager getEntityManager()


getEntityType

}
public EntityType getEntityType()


getEntityTypeName

protected java.lang.String getEntityTypeName()


getExecutionContext

}
public ExecutionContext getExecutionContext()


getGroups

@Override
public java.util.Collection getGroups()


getIconUrl

String typeName = getClass().getCanonicalName();
public java.lang.String getIconUrl()


getId

return selfProxy;
public java.lang.String getId()


getLocations

public java.util.Collection getLocations()


getManagementContext

locations.set(ImmutableList.builder().addAll(oldLocations).addAll(truelyNewLocations).build());
public ManagementContext getManagementContext()


getManagementSupport

public EntityManagementSupport getManagementSupport()


getMutableEntityType

public void removeLocations(Collection removedLocations) {
public EntityDynamicType getMutableEntityType()


getParent

/** @deprecated since 0.4.0 should not be needed / leaked outwith brooklyn internals / mgmt support? */
public Entity getParent()


getPolicies

}
public java.util.Collection getPolicies()


getProxy

public Entity getProxy()


getProxyIfAvailable

*
public Entity getProxyIfAvailable()


getRebindSupport

public RebindSupport getRebindSupport()


getSubscriptionContext

getManagementSupport().getEntityChangeListener().onPoliciesChanged();
public SubscriptionContext getSubscriptionContext()


getSubscriptionTracker

protected SubscriptionTracker getSubscriptionTracker()


hashCode

return _legacyConstruction;
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)


invoke

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


invoke

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


isLegacyConstruction

protected boolean isLegacyConstruction()


onManagementBecomingMaster

public void onManagementBecomingMaster()


onManagementNoLongerMaster

public void onManagementNoLongerMaster()


onManagementStarted

public void onManagementStarted()


onManagementStarting

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


onManagementStopped

public void onManagementStopped()


refreshInheritedConfig

public void refreshInheritedConfig()


removeAllEnrichers

*/
public boolean removeAllEnrichers()


removeAllPolicies

LOG.warn("Strongly discouraged use of emit with sensor event as value "+sensor+" "+val+"; value should be unpacked!",
public boolean removeAllPolicies()


removeAttribute

if (!inConstruction && getManagementSupport().isDeployed()) {
public void removeAttribute(AttributeSensor attribute)


removeChild

@Override
public boolean removeChild(Entity child)


removeEnricher

}
public boolean removeEnricher(Enricher enricher)


removeLocations

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


removePolicy

return changed;
public boolean removePolicy(Policy policy)


setApplication

protected void setApplication(Application app)


setAttribute

return null;
public java.lang.Object setAttribute(AttributeSensor attribute, java.lang.Object val)


setAttribute

public java.lang.Object setAttribute(AttributeSensorAndConfigKey configuredSensor)


setAttributeWithoutPublishing

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


setConfig

configsInternal.setInheritedConfig(((EntityInternal)getParent()).getAllConfig());
public java.lang.Object setConfig(ConfigKey key, java.lang.Object val)


setConfig

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


setConfig

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


setConfig

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


setConfig

@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)
See Also:
EntityLocal#subscribe#subscribe


setDisplayName

}
public void setDisplayName(java.lang.String newDisplayName)


setManagementContext

public void setManagementContext(ManagementContextInternal managementContext)


setParent

entity.addChild(getProxyIfAvailable());
public AbstractEntity setParent(Entity entity)


setProxy

public void setProxy(Entity proxy)


subscribe

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


subscribeToChildren

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


subscribeToMembers

public SubscriptionHandle subscribeToMembers(Group group, Sensor sensor, SensorEventListener listener)
Default String representation is simplified name of class, together with selected fields.


toMetadataRecord

displayNameAutoGenerated = false;
public java.util.Map toMetadataRecord()


toString

boolean changed = false;
public java.lang.String toString()


toStringHelper

protected ToStringHelper toStringHelper()


unsubscribe

}
public boolean unsubscribe(Entity producer)
Override this to add to the toString(), e.g. return super.toStringHelper().add("port", port); Cannot be used in combination with overriding the deprecated toStringFieldsToInclude.


unsubscribe

@Override
public boolean unsubscribe(Entity producer, SubscriptionHandle handle)


 

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