public class DefaultJALSE extends AbstractIdentifiable implements JALSE
JALSE
implementation that using default implementations.DefaultEntityFactory
(with no Entity
limit) and
ForkJoinActionEngine.commonPoolEngine()
by default if no EntityFactory
or
ActionEngine
are provided.Modifier and Type | Class and Description |
---|---|
static class |
DefaultJALSE.Builder
A
DefaultJALSE instance builder that uses the defined ActionEngine
implementation with DefaultEntityFactory .By default this builder uses the common pool ( ForkJoinActionEngine.commonPoolEngine()
), has a random ID and has no entity limit. |
Modifier and Type | Field and Description |
---|---|
protected ActionEngine |
engine
Action engine to be supplied to entities.
|
protected DefaultEntityContainer |
entities
Backing entity container for top level entities.
|
protected EntityFactory |
factory
Entity factory for creating/killing entities.
|
protected DefaultActionScheduler<JALSE> |
scheduler
Self action scheduler.
|
protected TagTypeSet |
tags
Current state information.
|
id
Constructor and Description |
---|
DefaultJALSE(java.util.UUID id,
ActionEngine engine,
EntityFactory factory)
Creates a new instance of DefaultJALSE with the supplied engine and factory.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addEntityListener(EntityListener listener)
Adds a listener for entities.
|
void |
cancelAllScheduledForActor()
Cancels all tasks currently running/scheduled (scheduled by this).
|
ActionBindings |
getBindings()
Bindings for this engine.
|
Entity |
getEntity(java.util.UUID id)
Gets the entity with the specified ID.
|
int |
getEntityCount()
Gets the direct entity count.
|
java.util.Set<java.util.UUID> |
getEntityIDs()
Gets the IDs of all the entities within the container.
|
java.util.Set<? extends EntityListener> |
getEntityListeners()
Gets all the entity listeners.
|
java.util.Set<java.util.UUID> |
getIDsInTree()
Gets the current set of IDs for the entire tree.
|
int |
getTreeCount()
Gets the current total number of entities.
|
boolean |
isPaused()
Whether the engine is paused.
|
boolean |
isStopped()
Whether the engine is stopped.
|
void |
killEntities()
Kills all entities.
|
boolean |
killEntity(java.util.UUID id)
Kills the specified entity.
|
<T> SchedulableActionContext<T> |
newContext(Action<T> action)
Creates an action context to define how the action will be scheduled for execution.
|
SchedulableActionContext<JALSE> |
newContextForActor(Action<JALSE> action)
Creates a new mutable context for the supplied action and this actor.
|
Entity |
newEntity(java.util.UUID id,
AttributeContainer sourceContainer)
Creates new entity with the specified ID.
|
<T extends Entity> |
newEntity(java.util.UUID id,
java.lang.Class<T> type,
AttributeContainer sourceContainer)
Creates new entity with the specified ID.
|
void |
pause()
Pauses action processing.
|
boolean |
receiveEntity(Entity e)
Receives an entity (from a transfer).
|
boolean |
removeEntityListener(EntityListener listener)
Removes a entity listener.
|
void |
removeEntityListeners()
Removes all listeners for entities.
|
void |
resume()
Resumes performing actions.
|
ActionContext<JALSE> |
scheduleForActor(Action<JALSE> action,
long initialDelay,
long period,
java.util.concurrent.TimeUnit unit)
Schedules an action for execution with a supplied initial delay and repeat period.
|
void |
stop()
Permanently stops the engine.
|
java.util.stream.Stream<Entity> |
streamEntities()
Provides a stream of entities from the container.
|
java.util.stream.Stream<Entity> |
streamEntityTree()
Streams the entire entity tree.
|
java.util.stream.Stream<Tag> |
streamTags()
Streams all tag state information.
|
boolean |
transferEntity(java.util.UUID id,
EntityContainer destination)
Transfers the entity to the supplied destination container.
|
equals, getID, hashCode, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getEntityTree
equals, getID, getID, hashCode, is, not, toString
putInBindings, removeFromBindings, schedule, schedule
scheduleForActor, scheduleForActor
getEntities, getEntitiesAsType, getEntitiesOfType, getEntityAsType, getOptEntity, getOptEntityAsType, hasEntities, hasEntity, hasEntityListener, newEntity, newEntity, newEntity, newEntity, newEntity, newEntity, streamEntitiesAsType, streamEntitiesOfType, streamEntityIDs, transferAllEntities, transferEntities, transferEntities
protected final ActionEngine engine
protected final DefaultEntityContainer entities
protected final EntityFactory factory
protected final DefaultActionScheduler<JALSE> scheduler
protected final TagTypeSet tags
public DefaultJALSE(java.util.UUID id, ActionEngine engine, EntityFactory factory)
id
- The ID used to identify between JALSE instances.engine
- Action engine to associate to factory and schedule actions.factory
- Entity factory to create/kill child entities.public boolean addEntityListener(EntityListener listener)
EntityContainer
addEntityListener
in interface EntityContainer
listener
- Listener to add.true
if container did not already contain this listener.ListenerSet.add(Object)
public void cancelAllScheduledForActor()
ActionScheduler
cancelAllScheduledForActor
in interface ActionScheduler<JALSE>
public ActionBindings getBindings()
ActionEngine
getBindings
in interface ActionEngine
public Entity getEntity(java.util.UUID id)
EntityContainer
getEntity
in interface EntityContainer
id
- Unique ID of the entity.public int getEntityCount()
EntityContainer
getEntityCount
in interface EntityContainer
public java.util.Set<java.util.UUID> getEntityIDs()
EntityContainer
getEntityIDs
in interface EntityContainer
public java.util.Set<? extends EntityListener> getEntityListeners()
EntityContainer
getEntityListeners
in interface EntityContainer
public java.util.Set<java.util.UUID> getIDsInTree()
JALSE
getIDsInTree
in interface JALSE
Entities.getEntityIDsRecursively(EntityContainer)
public int getTreeCount()
JALSE
getTreeCount
in interface JALSE
Entities.getEntityCountRecursively(EntityContainer)
public boolean isPaused()
ActionEngine
isPaused
in interface ActionEngine
public boolean isStopped()
ActionEngine
isStopped
in interface ActionEngine
public void killEntities()
EntityContainer
killEntities
in interface EntityContainer
public boolean killEntity(java.util.UUID id)
EntityContainer
killEntity
in interface EntityContainer
id
- Entity ID.public <T> SchedulableActionContext<T> newContext(Action<T> action)
ActionEngine
newContext
in interface ActionEngine
action
- Action to create context for.public SchedulableActionContext<JALSE> newContextForActor(Action<JALSE> action)
ActionScheduler
newContextForActor
in interface ActionScheduler<JALSE>
action
- Action to create context for.public Entity newEntity(java.util.UUID id, AttributeContainer sourceContainer)
EntityContainer
newEntity
in interface EntityContainer
id
- Entity ID.sourceContainer
- Source attribute container.public <T extends Entity> T newEntity(java.util.UUID id, java.lang.Class<T> type, AttributeContainer sourceContainer)
EntityContainer
newEntity
in interface EntityContainer
id
- Entity ID.type
- Entity type.sourceContainer
- Source attribute container.Entity.markAsType(Class)
,
Entities.asType(Entity, Class)
public void pause()
ActionEngine
pause
in interface ActionEngine
public boolean receiveEntity(Entity e)
EntityContainer
receiveEntity
in interface EntityContainer
e
- Entity to receive.EntityContainer.transferEntity(UUID, EntityContainer)
public boolean removeEntityListener(EntityListener listener)
EntityContainer
removeEntityListener
in interface EntityContainer
listener
- Listener to remove.true
if the listener was removed.ListenerSet.remove(Object)
public void removeEntityListeners()
EntityContainer
removeEntityListeners
in interface EntityContainer
public void resume()
ActionEngine
resume
in interface ActionEngine
public ActionContext<JALSE> scheduleForActor(Action<JALSE> action, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
ActionScheduler
scheduleForActor
in interface ActionScheduler<JALSE>
action
- Action to schedule.initialDelay
- Initial delay before schedule (can be 0
).period
- Period for repeating (can be 0
).unit
- Time unit of initial delay and period.public void stop()
ActionEngine
stop
in interface ActionEngine
public java.util.stream.Stream<Entity> streamEntities()
EntityContainer
streamEntities
in interface EntityContainer
public java.util.stream.Stream<Entity> streamEntityTree()
JALSE
streamEntityTree
in interface JALSE
Entities.walkEntities(EntityContainer)
public java.util.stream.Stream<Tag> streamTags()
Taggable
streamTags
in interface Taggable
public boolean transferEntity(java.util.UUID id, EntityContainer destination)
EntityContainer
transferEntity
in interface EntityContainer
id
- Entity ID.destination
- Target container.EntityContainer.receiveEntity(Entity)