public abstract class AbstractEntity extends AbstractBrooklynObject implements EntityInternal
Entity
implementation, which should be extended whenever implementing an entity.
Provides several common fields (displayName
, AbstractBrooklynObject.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.
Sub-classes should have a no-argument constructor. When brooklyn creates an entity, it will:
setDisplayName(String)
setManagementContext(ManagementContextInternal)
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).
configure(Map)
and then #setConfig(ConfigKey, Object)
init()
#addPolicy(Policy)
(for any policies defined in the EntitySpec
)
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.
Modifier and Type | Class and Description |
---|---|
class |
AbstractEntity.BasicConfigurationSupport
Direct use of this class is strongly discouraged.
|
class |
AbstractEntity.BasicEnricherSupport
Direct use of this class is strongly discouraged.
|
class |
AbstractEntity.BasicGroupSupport
Direct use of this class is strongly discouraged.
|
class |
AbstractEntity.BasicPolicySupport
Direct use of this class is strongly discouraged.
|
class |
AbstractEntity.BasicSensorSupport
Direct use of this class is strongly discouraged.
|
class |
AbstractEntity.BasicSubscriptionSupport
Direct use of this class is strongly discouraged.
|
EntityInternal.EnricherSupportInternal, EntityInternal.EntitySubscriptionSupportInternal, EntityInternal.FeedSupport, EntityInternal.GroupSupportInternal, EntityInternal.PolicySupportInternal, EntityInternal.SensorSupportInternal
BrooklynObjectInternal.ConfigurationSupportInternal, BrooklynObjectInternal.RelationSupportInternal<T extends BrooklynObject>, BrooklynObjectInternal.SubscriptionSupportInternal
Entity.AdjunctSupport<T extends EntityAdjunct>, Entity.EnricherSupport, Entity.GroupSupport, Entity.PolicySupport, Entity.SensorSupport
BrooklynObject.RelationSupport<T extends BrooklynObject>, BrooklynObject.SubscriptionSupport, BrooklynObject.TagSupport
Configurable.ConfigurationSupport
Constructor and Description |
---|
AbstractEntity() |
AbstractEntity(Entity parent)
Deprecated.
since 0.5; instead use no-arg constructor with EntityManager().createEntity(spec)
|
AbstractEntity(java.util.Map flags)
Deprecated.
since 0.5; instead use no-arg constructor with EntityManager().createEntity(spec)
|
AbstractEntity(java.util.Map flags,
Entity parent)
Deprecated.
since 0.5; instead use no-arg constructor with EntityManager().createEntity(spec)
|
Modifier and Type | Method and Description |
---|---|
<T extends Entity> |
addChild(EntitySpec<T> spec)
Creates an entity using the given spec, and adds it as a child of this entity.
|
<T extends Entity> |
addChild(T child)
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.
|
<T extends Feed> |
addFeed(T feed)
Convenience, which calls
EntityInternal.feeds() and FeedSupport#addFeed(Feed) . |
void |
addLocations(java.util.Collection<? extends Location> newLocations) |
void |
addLocationsWithoutPublishing(java.util.Collection<? extends Location> newLocations)
Adds the given locations to this entity, but without emitting
LOCATION_ADDED
events, and without auto-managing the locations. |
void |
clearLocations() |
void |
clearParent()
Clears the parent (i.e.
|
AbstractEntity.BasicConfigurationSupport |
config() |
void |
configure(java.lang.Iterable<ConfigKey<?>> configKeys)
Adds the config keys to the entity dynamic type
|
AbstractEntity |
configure(java.util.Map flags)
Deprecated.
since 0.7.0; only used for legacy brooklyn types where constructor is called directly
|
void |
destroy()
Should be invoked at end-of-life to clean up the item.
|
AbstractEntity.BasicEnricherSupport |
enrichers() |
boolean |
equals(java.lang.Object o) |
EntityInternal.FeedSupport |
feeds() |
Location |
firstLocation() |
Application |
getApplication()
Returns the application, looking it up if not yet known (registering if necessary)
|
java.lang.String |
getApplicationId() |
<T> T |
getAttribute(AttributeSensor<T> attribute)
Convenience for calling
Entity.SensorSupport.get(AttributeSensor) ,
via code like sensors().get(key) . |
java.util.Collection<Entity> |
getChildren()
Return the entities that are children of (i.e.
|
<T> T |
getConfig(ConfigKey.HasConfigKey<T> key) |
<T> T |
getConfig(ConfigKey<T> key)
Convenience for calling
Configurable.ConfigurationSupport.get(ConfigKey) ,
via code like config().get(key) . |
long |
getCreationTime()
Returns the creation time for this entity, in UTC.
|
java.lang.String |
getDisplayName()
A display name; recommended to be a concise single-line description.
|
Effector<?> |
getEffector(java.lang.String effectorName)
Convenience for finding named effector in
EntityType.getEffectors() Map . |
EntityType |
getEntityType()
Information about the type of this entity; analogous to Java's object.getClass.
|
ExecutionContext |
getExecutionContext()
Returns the task execution context for the entity.
|
java.lang.String |
getIconUrl()
Deprecated.
|
java.util.Collection<Location> |
getLocations()
Return all the
Location s this entity is deployed to. |
ManagementContext |
getManagementContext()
Returns the management context for the entity.
|
EntityManagementSupport |
getManagementSupport() |
EntityDynamicType |
getMutableEntityType()
returns the dynamic type corresponding to the type of this entity instance
|
Entity |
getParent()
The parent of this entity, null if no parent.
|
Entity |
getProxy() |
Entity |
getProxyIfAvailable()
Returns the proxy, or if not available (because using legacy code) then returns the real entity.
|
RebindSupport<EntityMemento> |
getRebindSupport()
As described in
EntityInternal.getRebindSupport() ... |
AbstractEntity.BasicGroupSupport |
groups() |
int |
hashCode() |
void |
init()
Default entity initialization sets ID sensors and calls
initEnrichers() . |
void |
invalidateReferences()
For use by management plane, to invalidate all fields (e.g.
|
<T> Task<T> |
invoke(Effector<T> eff)
Invoke an
Effector directly. |
<T> Task<T> |
invoke(Effector<T> eff,
java.util.Map<java.lang.String,?> parameters)
Additional form supplied for when the parameter map needs to be made explicit.
|
<T> Task<T> |
invoke(java.util.Map parameters,
Effector<T> eff) |
void |
onManagementBecomingMaster()
Deprecated.
since 0.4.0 override EntityManagementSupport.onManagementStarted if customization needed
|
void |
onManagementNoLongerMaster()
Deprecated.
since 0.4.0 override EntityManagementSupport.onManagementStopped if customization needed
|
void |
onManagementStarted()
Invoked by
EntityManagementSupport when this entity is fully managed and visible to other entities
through the management context. |
void |
onManagementStarting()
Invoked by
EntityManagementSupport when this entity is becoming managed (i.e. |
void |
onManagementStopped()
Invoked by
EntityManagementSupport when this entity is fully unmanaged. |
AbstractEntity.BasicPolicySupport |
policies() |
BrooklynObjectInternal.RelationSupportInternal<Entity> |
relations()
Relations specify a typed, directed connection between two entities.
|
boolean |
removeChild(Entity child)
Removes the specified child
Entity ; its parent will be set to null. |
void |
removeLocations(java.util.Collection<? extends Location> removedLocations) |
void |
requestPersist()
Can be called to request that the entity be persisted.
|
void |
resetProxy(Entity proxy)
internal use only
|
AbstractEntity.BasicSensorSupport |
sensors() |
<T> T |
setConfigEvenIfOwned(ConfigKey.HasConfigKey<T> key,
T val) |
<T> T |
setConfigEvenIfOwned(ConfigKey<T> key,
T val) |
void |
setDisplayName(java.lang.String newDisplayName)
Sets the entity's display name.
|
void |
setManagementContext(ManagementContextInternal managementContext) |
AbstractEntity |
setParent(Entity entity)
Adds this as a child of the given entity; registers with application if necessary.
|
void |
setProxy(Entity proxy)
internal use only
|
AbstractEntity.BasicSubscriptionSupport |
subscriptions()
Subscriptions are the mechanism for receiving notifications of sensor-events (e.g.
|
java.util.Map<java.lang.String,java.lang.String> |
toMetadataRecord() |
java.lang.String |
toString()
Default String representation is simplified name of class, together with selected fields.
|
addSearchPath, getCatalogItemId, getCatalogItemIdSearchPath, getId, rebind, setCatalogItemId, setCatalogItemIdAndSearchPath, stackCatalogItemId, tags
addSearchPath, setCatalogItemId, setCatalogItemIdAndSearchPath, stackCatalogItemId
getCatalogItemId, getCatalogItemIdSearchPath, tags
public static final ConfigKey<java.lang.String> DEFAULT_DISPLAY_NAME
public static final BasicNotificationSensor<Location> LOCATION_ADDED
public static final BasicNotificationSensor<Location> LOCATION_REMOVED
public static final BasicNotificationSensor<Sensor> SENSOR_ADDED
public static final BasicNotificationSensor<Sensor> SENSOR_REMOVED
public static final BasicNotificationSensor<java.lang.String> EFFECTOR_ADDED
public static final BasicNotificationSensor<java.lang.String> EFFECTOR_REMOVED
public static final BasicNotificationSensor<java.lang.String> EFFECTOR_CHANGED
public static final BasicNotificationSensor<ConfigKey> CONFIG_KEY_ADDED
public static final BasicNotificationSensor<ConfigKey> CONFIG_KEY_REMOVED
public static final BasicNotificationSensor<PolicyDescriptor> POLICY_ADDED
public static final BasicNotificationSensor<PolicyDescriptor> POLICY_REMOVED
public static final BasicNotificationSensor<Entity> CHILD_ADDED
public static final BasicNotificationSensor<Entity> CHILD_REMOVED
public static final BasicNotificationSensor<Group> GROUP_ADDED
public static final BasicNotificationSensor<Group> GROUP_REMOVED
public static final AttributeSensor<java.lang.String> ENTITY_ID
public static final AttributeSensor<java.lang.String> APPLICATION_ID
public static final AttributeSensor<java.lang.String> CATALOG_ID
public AbstractEntity()
@Deprecated public AbstractEntity(java.util.Map flags)
@Deprecated public AbstractEntity(Entity parent)
@Deprecated public AbstractEntity(java.util.Map flags, Entity parent)
@Deprecated public AbstractEntity configure(java.util.Map flags)
AbstractBrooklynObject
ConfigBag.getUnusedConfig()
.
To be overridden by AbstractEntity, AbstractLoation, AbstractPolicy, AbstractEnricher, etc.
But should not be overridden by specific entity types. If you do, the entity may break in subsequent releases. Also note that if you require fields to be initialized you must do that in this method. You must *not* rely on field initializers because they may not run until *after* this method (this method is invoked by the constructor in this class, so initializers in subclasses will not have run when this overridden method is invoked.)
configure
in interface EntityInternal
public void configure(java.lang.Iterable<ConfigKey<?>> configKeys)
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public void setProxy(Entity proxy)
public void resetProxy(Entity proxy)
public Entity getProxy()
public Entity getProxyIfAvailable()
public void setManagementContext(ManagementContextInternal managementContext)
setManagementContext
in class AbstractBrooklynObject
public java.util.Map<java.lang.String,java.lang.String> toMetadataRecord()
toMetadataRecord
in interface EntityInternal
public long getCreationTime()
Entity
getCreationTime
in interface Entity
public java.lang.String getDisplayName()
BrooklynObject
getDisplayName
in interface Entity
getDisplayName
in interface BrooklynObject
@Deprecated public java.lang.String getIconUrl()
Entity
getIconUrl
in interface Entity
public void setDisplayName(java.lang.String newDisplayName)
Entity
setDisplayName
in interface Entity
setDisplayName
in class AbstractBrooklynObject
public AbstractEntity setParent(Entity entity)
setParent
in interface Entity
Entity.getParent()
,
Entity.clearParent()
public void clearParent()
Entity
clearParent
in interface Entity
Entity.getParent()
,
Entity.setParent(org.apache.brooklyn.api.entity.Entity)
public <T extends Entity> T addChild(T child)
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 init()
is invoked)
and so will need an explicit getEntityManager().manage(childReturnedFromThis)
call.
These semantics are currently under review.
public <T extends Entity> T addChild(EntitySpec<T> spec)
addChild
in interface Entity
java.lang.IllegalArgumentException
- If spec.getParent()
is set and is different from this entityaddChild(Entity)
,
EntityManager.createEntity(EntitySpec)
public boolean removeChild(Entity child)
Entity
Entity
; its parent will be set to null.removeChild
in interface Entity
public AbstractEntity.BasicGroupSupport groups()
groups
in interface Entity
groups
in interface EntityInternal
public Entity getParent()
Entity
getParent
in interface Entity
Entity.setParent(Entity)
,
Entity.clearParent()
public java.util.Collection<Entity> getChildren()
Entity
getChildren
in interface Entity
public Application getApplication()
getApplication
in interface Entity
Application
this entity is registered with, or null if not registered.public java.lang.String getApplicationId()
getApplicationId
in interface Entity
Application
this entity is registered with, or null if not registered.public ManagementContext getManagementContext()
EntityInternal
getManagementContext
in interface EntityInternal
getManagementContext
in interface BrooklynObjectInternal
getManagementContext
in class AbstractBrooklynObject
public EntityType getEntityType()
Entity
getEntityType
in interface Entity
public EntityDynamicType getMutableEntityType()
EntityInternal
getMutableEntityType
in interface EntityInternal
public java.util.Collection<Location> getLocations()
Entity
Location
s this entity is deployed to.getLocations
in interface Entity
public void addLocations(java.util.Collection<? extends Location> newLocations)
addLocations
in interface EntityInternal
public void addLocationsWithoutPublishing(java.util.Collection<? extends Location> newLocations)
EntityInternal
LOCATION_ADDED
events, and without auto-managing the locations. This is for internal purposes only; it is primarily
intended for use during rebind.addLocationsWithoutPublishing
in interface EntityInternal
public void removeLocations(java.util.Collection<? extends Location> removedLocations)
removeLocations
in interface EntityInternal
public void clearLocations()
clearLocations
in interface EntityInternal
public Location firstLocation()
public void destroy()
destroy
in interface EntityInternal
public <T> T getAttribute(AttributeSensor<T> attribute)
Entity
Entity.SensorSupport.get(AttributeSensor)
,
via code like sensors().get(key)
.getAttribute
in interface Entity
public AbstractEntity.BasicConfigurationSupport config()
config
in interface Configurable
config
in interface BrooklynObjectInternal
public AbstractEntity.BasicSensorSupport sensors()
sensors
in interface Entity
sensors
in interface EntityInternal
public <T> T getConfig(ConfigKey<T> key)
Configurable
Configurable.ConfigurationSupport.get(ConfigKey)
,
via code like config().get(key)
.getConfig
in interface Configurable
public <T> T getConfig(ConfigKey.HasConfigKey<T> key)
public <T> T setConfigEvenIfOwned(ConfigKey<T> key, T val)
public <T> T setConfigEvenIfOwned(ConfigKey.HasConfigKey<T> key, T val)
public AbstractEntity.BasicSubscriptionSupport subscriptions()
BrooklynObject
subscriptions
in interface BrooklynObject
subscriptions
in interface EntityInternal
subscriptions
in interface BrooklynObjectInternal
public ExecutionContext getExecutionContext()
EntityInternal
getExecutionContext
in interface EntityInternal
public java.lang.String toString()
toString
in class java.lang.Object
public void init()
initEnrichers()
.init
in class AbstractBrooklynObject
public AbstractEntity.BasicPolicySupport policies()
policies
in interface Entity
policies
in interface EntityInternal
public AbstractEntity.BasicEnricherSupport enrichers()
enrichers
in interface Entity
enrichers
in interface EntityInternal
public <T extends Feed> T addFeed(T feed)
EntityInternal.feeds()
and FeedSupport#addFeed(Feed)
.public EntityInternal.FeedSupport feeds()
feeds
in interface EntityInternal
public Effector<?> getEffector(java.lang.String effectorName)
EntityType.getEffectors()
Map
.getEffector
in interface EntityInternal
public <T> Task<T> invoke(Effector<T> eff, java.util.Map<java.lang.String,?> parameters)
invoke
in interface Entity
invoke(Effector)
public void onManagementStarting()
EntityManagementSupport
when this entity is becoming managed (i.e. it has a working
management context, but before the entity is visible to other entities), including during a rebind.public void onManagementStarted()
EntityManagementSupport
when this entity is fully managed and visible to other entities
through the management context.@Deprecated public void onManagementBecomingMaster()
ManagementContext
when this entity becomes managed at a particular management node,
including the initial management started and subsequent management node master-change for this entity.@Deprecated public void onManagementNoLongerMaster()
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.public void onManagementStopped()
EntityManagementSupport
when this entity is fully unmanaged.
Note that the activies possible here (when unmanaged) are limited, and that this event may be caused by either a brooklyn node itself being demoted (so the entity is managed elsewhere) or by a controlled shutdown.
public void invalidateReferences()
public EntityManagementSupport getManagementSupport()
getManagementSupport
in interface EntityInternal
public void requestPersist()
EntityInternal
requestPersist
in interface EntityInternal
public RebindSupport<EntityMemento> getRebindSupport()
EntityInternal.getRebindSupport()
...
Users are strongly discouraged to call or override this method.
It is for internal calls only, relating to persisting/rebinding entities.
This method may change (or be removed) in a future release without notice.getRebindSupport
in interface Rebindable
getRebindSupport
in interface EntityInternal
getRebindSupport
in interface BrooklynObjectInternal
public BrooklynObjectInternal.RelationSupportInternal<Entity> relations()
BrooklynObject
relations
in interface Entity
relations
in interface BrooklynObject
relations
in interface EntityInternal
relations
in interface BrooklynObjectInternal
relations
in class AbstractBrooklynObject