public class Context extends AgentTrait implements AgentContext
This class is thread-safe.
Constructor and Description |
---|
Context(id : UUID,
defaultSpaceID : UUID,
owner : Agent,
spaceRepositoryProvider : javax.inject.Provider<SpaceRepository>,
factories : javax.inject.Provider<Factories>,
loggingService : LoggingService,
listenerFactory : SpaceRepositoryListenerFactory)
Constructs a
Context . |
Modifier and Type | Method and Description |
---|---|
void |
addSpaceRepositoryListener(listener : SpaceRepositoryListener)
Add listener on the space repository changes.
|
<S extends Space> |
createSpace(spec : Class<? extends SpaceSpecification<S>>,
spaceUUID : UUID,
creationParams : Object*)
Create an instance of space following the given specification.
|
void |
destroy()
Destroy any associated resources.
|
protected SpaceRepository |
ensureRepository([defaultSpaceCallback : (OpenEventSpace)=>void])
Replies the space repository and creates it if it does not exist.
|
OpenEventSpace |
getDefaultSpace()
Replies the default space of the context.
|
UUID |
getID()
Replies the identifier of the agent that has this trait.
|
protected ReadWriteLock |
getLock()
Replies the lock to be used.
|
<S extends Space> |
getOrCreateSpaceWithID(spec : Class<? extends SpaceSpecification<S>>,
spaceUUID : UUID,
creationParams : Object*)
Retrieve or create an instance of space with the given identifier.
|
<S extends Space> |
getOrCreateSpaceWithSpec(spec : Class<? extends SpaceSpecification<S>>,
spaceUUID : UUID,
creationParams : Object*)
Retrieve or create an instance of space which was created with the given
specification.
|
<S extends Space> |
getSpace(spaceUUID : UUID)
Retrieve, but do not create, an instance of space following the given ID.
|
ConcurrentCollection<? extends Space> |
getSpaces()
Replies all the spaces defined in this context.
|
<S extends Space> |
getSpaces(spec : Class<? extends SpaceSpecification<S>>)
Replies all the spaces that are implementing the given specification.
|
void |
initialize()
Initialize the context when it is published to the agents.
|
boolean |
isRootContext()
Replies if the context is a root context.
|
void |
removeSpaceRepositoryListener(listener : SpaceRepositoryListener)
Remove listener on the space repository changes.
|
void |
toString(builder : org.eclipse.xtext.xbase.lib.util.ToStringBuilder)
fill the given builder with the string representation of this object.
|
clearSkill, getOwner, getSkill, hasSkill, isFromMe, isMe, isMe, operator_mappedTo, setSkill, setSkillIfAbsent
toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getOrCreateSpace, getOrCreateSpaceWithID
public new
(id : UUID,
defaultSpaceID : UUID,
owner : Agent,
spaceRepositoryProvider : javax.inject.Provider<SpaceRepository>,
factories : javax.inject.Provider<Factories>,
loggingService : LoggingService,
listenerFactory : SpaceRepositoryListenerFactory)
Context
.id
- identifier of the context.defaultSpaceID
- identifier of the default space in the context.owner
- is the owner of the context. If null
, it is the root context.factories
- the provider of factories.spaceRepositoryProvider
- the provider of space repositorylogger
- the logging service.listenerFactory
- the factory of space listeners.@Pure
protected def
getLock() : ReadWriteLock
Context
@Pure
public def
isRootContext() : boolean
AgentContext
A root context is associated to the platform kernel agent, which is not created into memory. For example, it means that there is no parent registered into the default space.
isRootContext
in interface AgentContext
true
if the context is a root context.@Pure
public def
getID() : UUID
AgentTrait
getID
in interface AgentContext
getID
in class AgentTrait
@Pure
public def
toString(builder : org.eclipse.xtext.xbase.lib.util.ToStringBuilder) : void
AgentProtectedAPIObject
toString
in class AgentTrait
builder
- the string builder.protected def
ensureRepository([defaultSpaceCallback : (OpenEventSpace)=>void]) : SpaceRepository
Context
This function is thread-safe.
defaultSpaceCallback
- the call back for default space.public def
initialize() : void
Context
public def
destroy() : void
Context
@Pure
public def
getDefaultSpace() : OpenEventSpace
AgentContext
event-based space
.getDefaultSpace
in interface AgentContext
@Pure publicdef
getSpace(spaceUUID : UUID) : Swith
<S extends Space>
AgentContext
null
.getSpace
in interface AgentContext
S
- - type of the replied space.spaceUUID
- identifier of the space.null
if there is no space found.AgentContext.createSpace(Class, UUID, Object...)
,
AgentContext.getOrCreateSpace(Class, UUID, Object...)
@Pure publicdef
getSpaces(spec : Class<? extends SpaceSpecification<S>>) : ConcurrentCollection<S>with
<S extends Space>
AgentContext
getSpaces
in interface AgentContext
S
- - type of the replied space.spec
- specification of the space to retreive.@Pure
public def
getSpaces() : ConcurrentCollection<? extends Space>
AgentContext
getSpaces
in interface AgentContext
publicdef
createSpace(spec : Class<? extends SpaceSpecification<S>>, spaceUUID : UUID, creationParams : Object*) : Swith
<S extends Space>
AgentContext
null
. If you want to find an existing space prior to the creation of
a new one, you should use AgentContext.getOrCreateSpace(Class, UUID, Object...)
.createSpace
in interface AgentContext
S
- - type of the created space.spec
- specification of the space to create.spaceUUID
- identifier of the new space.creationParams
- parameters to pass to the space constructor.null
if the space already exists.AgentContext.getOrCreateSpace(Class, UUID, Object...)
,
AgentContext.getSpace(UUID)
publicdef
getOrCreateSpaceWithSpec(spec : Class<? extends SpaceSpecification<S>>, spaceUUID : UUID, creationParams : Object*) : Swith
<S extends Space>
AgentContext
This function tries to find a space that was created with the given specification. If none was found, this function creates a new space with the given space identifier and creation parameters.
Caution: This function ignores the default space when
searching for a space created with an EventSpaceSpecification
or
OpenEventSpaceSpecification
. Consequently, in the case of the
spec
argument is one of the previous types, and there is no other
space in the context that was created with this specification, then the
function creates a totally new space.
Caution: The spaceUUID
parameter is used only if no
existing space created with the given specification was found.
getOrCreateSpaceWithSpec
in interface AgentContext
S
- - type of the replied space.spec
- specification of the space to retrieve/create.spaceUUID
- identifier used only when creating the space.creationParams
- parameters to pass to the space constructor.null
and never the default space.AgentContext.getOrCreateSpaceWithID(UUID, Class, Object...)
,
AgentContext.createSpace(Class, UUID, Object...)
,
AgentContext.getSpace(UUID)
publicdef
getOrCreateSpaceWithID(spec : Class<? extends SpaceSpecification<S>>, spaceUUID : UUID, creationParams : Object*) : Swith
<S extends Space>
AgentContext
This function tries to find a space with the given identifier. If none was found, this function creates a new space with the given specification and creation parameters.
Caution #1: The spaceUUID
parameter is given to the
specification when creating the space.
Caution #2: The spaceUUID
parameter is equal to the
identifier of the default space in this context, then the default space is
returned by this function.
getOrCreateSpaceWithID
in interface AgentContext
S
- - type of the replied space.spec
- specification of the space for creating the space.spaceUUID
- identifier of the space.creationParams
- parameters to pass to the space constructor.null
.AgentContext.getOrCreateSpaceWithID(UUID, Class, Object...)
,
AgentContext.createSpace(Class, UUID, Object...)
,
AgentContext.getSpace(UUID)
public def
addSpaceRepositoryListener(listener : SpaceRepositoryListener) : void
Context
listener
- public def
removeSpaceRepositoryListener(listener : SpaceRepositoryListener) : void
Context
listener
- Copyright © 2021 the original authors or authors.