io.sarl.sre.janus.services.context
Class SpaceRepository
All Superinterfaces:
SpaceListener, java.util.EventListener
All Known Subclasses:
LocalSpaceRepository
abstract class SpaceRepository
extends java.lang.Object
implements SpaceListener
A repository of spaces specific to a given context.

This repository is thread-safe.
Maven Group Identifier:
io.sarl.sre.janus
Maven Artifact Identifier:
janus.kernel
Property Summary
Modifier and type Property and description
protected java.util.concurrent.locks.ReadWriteLock lock
protected java.util.Map<K,V> sharedStructure
Replies the internal map that contains the spaces.
ConcurrentCollection<T> spaces
Returns the collection of all spaces stored in this repository.
Nested Type Summary
Modifier and type Type and description
class SpaceRepository.SpaceDescription
Description of a space.
class SpaceRepository.SpaceSpecificationKey
Key for a space specification.
Field Summary
Modifier and type Field and description
protected val java.util.logging.Logger logger
Constructor Summary
Action Summary
Modifier and type Action and description
void addSpaceRepositoryListener(SpaceRepositoryListener)
Add listener on the space repository changes.
OpenEventSpace createDefaultSpace(SpaceID)
Create an instance of the default space if it was not created before.
protected java.util.logging.Logger createLogger(LoggingService)
Create the logger for this repository.
S createSpace(SpaceID,Class<T>,Object*)
Create a space.
protected SpaceDescription createSpaceDescription(SpaceID,Space)
Create a space description.
protected S createSpaceFirstInstance(Class<T>,SpaceID,Object)
Create the first instance of a given space.
final void destroy
Destroy this repository and release all the resources.
void destroyableSpace(Space)
protected void destroyThreadUnsafe
Destroy this repository and release all the resources inside a synchronized section.
protected void fireSpaceAdded(Space,boolean)
Notifies the listeners on the space creation.
protected void fireSpaceRemoved(Space,boolean)
Notifies the listeners on the space destruction.
protected java.util.concurrent.locks.ReadWriteLock getLock
S getOrCreateSpaceWithID(SpaceID,Class<T>,Object*)
Retrieve the first space of the given identifier, or create a space if none.
S getOrCreateSpaceWithSpec(SpaceID,Class<T>,Object*)
Retrieve the first space of the given specification, or create a space if none.
protected abstract java.util.Map<K,V> getSharedStructure
Replies the internal map that contains the spaces.
Space getSpace(SpaceID)
Returns the first instance of a space with the specified SpaceID.
ConcurrentCollection<T> getSpaces
Returns the collection of all spaces stored in this repository.
ConcurrentCollection<T> getSpaces(Class<T>)
Returns the collection of all spaces with the specified SpaceSpecification stored in this repository.
boolean hasSpace(UUID)
Replies if the given space was defined into the repository.
protected SpaceDescription life(Space,SpaceDescription)
Replies the space information associated to the space if already associated.
protected SpaceDescription life(SpaceID,SpaceDescription)
Replies the space information associated to the space identifier if already associated.
void refreshInternalStructures
Synchronize the internal structures of SpaceRepository with the content of getSharedStructure().
protected void removeEmptySpaces
Remove all the spaces that are empty.
void removeSpace(Space)
Remove the given space.
void removeSpaceIfEmpty(Space)
Remove the given space if the it is empty, i.e. it has no more strong participant.
void removeSpaceIfEmpty(UUID)
Remove the space with the given id if the space is empty, i.e. it has no more strong participant.
void removeSpaceRepositoryListener(SpaceRepositoryListener)
Remove listener on the space repository changes.
Property Details
lock
protected val lock : java.util.concurrent.locks.ReadWriteLock

This property is an alias for the action: getLock

sharedStructure
protected val sharedStructure : java.util.Map<K,V>
Replies the internal map that contains the spaces.

This function should not have a border effect; and it is therefore thread-safe.

This function shoud be invoked into a locked/synchronized block of code. That's why it does not need to reply a "concurrent" collection. Moreover, all the functions that are providing a collection of spaces to the outside of this class are creating a copy of the collection that is "concurrent".

This property is an alias for the action: getSharedStructure

Returns:
the internal data structure for storing the spaces.
spaces
val spaces : ConcurrentCollection<T>
Returns the collection of all spaces stored in this repository.

This property is an alias for the action: getSpaces

Returns:
the collection of all spaces stored in this repository.
Field Details
logger
protected val logger : java.util.logging.Logger
Constructor Details
new(Injector,ExecutorService,LoggingService,SreConfig,SreSpaceSpecificationFactory,Provider<T>)
new(Injector,ExecutorService,LoggingService,SreConfig,SreSpaceSpecificationFactory,Provider<T>)
Constructor.
Parameters:
injector - the injector.
executor - the asynchronous execution service.
logger - the logging service.
config - the configuration.
specificationFactory - the factory of space specification.
factories - the provider of factories tool.
Action Details
addSpaceRepositoryListener(SpaceRepositoryListener)
def addSpaceRepositoryListener(SpaceRepositoryListener)
Add listener on the space repository changes.

This function is thread-safe.
Parameters:
listener - the listener to be added.
createDefaultSpace(SpaceID)
def createDefaultSpace(SpaceID) : OpenEventSpace
Create an instance of the default space if it was not created before.

This function is thread-safe.
Parameters:
spaceID - ID of the default space.
Returns:
the new space.
createLogger(LoggingService)
protected def createLogger(LoggingService) : java.util.logging.Logger
Create the logger for this repository.

This function should not have a border effect; and it is therefore thread-safe.
Parameters:
loggingService - the service for logging.
Returns:
the logger.
createSpace(SpaceID,Class<T>,Object*)
def createSpace(SpaceID,Class<T>,Object*) : S

with S extends Space

Create a space. This function does not test if the space already exist into the repository. It means that any previously created instance of a space with the given space identifier will be lost after the return of this function.

This function notifies the listeners about the space creation.
Parameters:
<S> - - the type of the space to reply.
spaceID - ID of the space.
spec - specification of the space.
creationParams - creation parameters.
Returns:
the new space, or null if the space already exists.
createSpaceDescription(SpaceID,Space)
protected def createSpaceDescription(SpaceID,Space) : SpaceDescription
Create a space description.

This function should be overridden by the sub-types.

This function should not have a border effect; and it is therefore thread-safe.
Parameters:
id - the space identifier.
space - the space instance.
Returns:
the description.
createSpaceFirstInstance(Class<T>,SpaceID,Object)
protected def createSpaceFirstInstance(Class<T>,SpaceID,Object) : S

with S extends Space

Create the first instance of a given space.

This function is thread-safe. It notifies the listeners about the space creation.
Parameters:
spec - is the type of space specification to be used for creating the space.
spaceID - is the identifier to give to the new space instance.
creationParams - is the list of parameters that must be used for creating the space instance, through the space specification.
destroy
def destroy
Destroy this repository and release all the resources.
destroyableSpace(Space)
def destroyableSpace(Space)
destroyThreadUnsafe
protected def destroyThreadUnsafe
Destroy this repository and release all the resources inside a synchronized section.

This function is not thread-safe.
fireSpaceAdded(Space,boolean)
protected def fireSpaceAdded(Space,boolean)
Notifies the listeners on the space creation.

This function is thread-safe.
Parameters:
space - the created space.
isLocalCreation - indicates if the creation of the space was initiated on the current kernel.
fireSpaceRemoved(Space,boolean)
protected def fireSpaceRemoved(Space,boolean)
Notifies the listeners on the space destruction.

This function is thread-safe.
Parameters:
space - the removed space.
isLocalDestruction - indicates if the destruction of the space was initiated on the current kernel.
getLock
protected def getLock : java.util.concurrent.locks.ReadWriteLock
getOrCreateSpaceWithID(SpaceID,Class<T>,Object*)
def getOrCreateSpaceWithID(SpaceID,Class<T>,Object*) : S

with S extends Space

Retrieve the first space of the given identifier, or create a space if none.
Parameters:
<S> - - the type of the space to reply.
spaceID - ID of the space.
spec - specification of the space.
creationParams - creation parameters (used only when creating a space).
Returns:
the new space.
getOrCreateSpaceWithSpec(SpaceID,Class<T>,Object*)
def getOrCreateSpaceWithSpec(SpaceID,Class<T>,Object*) : S

with S extends Space

Retrieve the first space of the given specification, or create a space if none.
Parameters:
<S> - - the type of the space to reply.
spaceID - ID of the space (used only when creating a space).
spec - specification of the space.
creationParams - creation parameters (used only when creating a space).
Returns:
the new space.
getSharedStructure
protected def getSharedStructure : java.util.Map<K,V>
Replies the internal map that contains the spaces.

This function should not have a border effect; and it is therefore thread-safe.

This function shoud be invoked into a locked/synchronized block of code. That's why it does not need to reply a "concurrent" collection. Moreover, all the functions that are providing a collection of spaces to the outside of this class are creating a copy of the collection that is "concurrent".
Returns:
the internal data structure for storing the spaces.
getSpace(SpaceID)
def getSpace(SpaceID) : Space
Returns the first instance of a space with the specified SpaceID.
Parameters:
spaceID - the identifier to retrieve.
Returns:
the space instance of null if none.
getSpaces
def getSpaces : ConcurrentCollection<T>
Returns the collection of all spaces stored in this repository.
Returns:
the collection of all spaces stored in this repository.
getSpaces(Class<T>)
def getSpaces(Class<T>) : ConcurrentCollection<T>

with S extends Space

Returns the collection of all spaces with the specified SpaceSpecification stored in this repository.
Parameters:
<S> - - type of the spaces to reply.
spec - the specification used to filter the set of stored spaces.
Returns:
the collection of all spaces with the specified SpaceSpecification stored in this repository
hasSpace(UUID)
def hasSpace(UUID) : boolean
Replies if the given space was defined into the repository.
Parameters:
id - is the identifier of the space.
Returns:
true if the space exists into the repository, or false otherwise.
life(Space,SpaceDescription)
protected def life(Space,SpaceDescription) : SpaceDescription
Replies the space information associated to the space if already associated.

This function is not thread-safe; but enough efficient to be assumed to not cause issues related to threads.
Parameters:
newDescription - the description to associated to the space.
Returns:
the space description, or null
life(SpaceID,SpaceDescription)
protected def life(SpaceID,SpaceDescription) : SpaceDescription
Replies the space information associated to the space identifier if already associated.

This function is not thread-safe; but enough efficient to be assumed to not cause issues related to threads.
Parameters:
newDescription - the description to associated to the space.
Returns:
the space description, or null
refreshInternalStructures
def refreshInternalStructures
Synchronize the internal structures of SpaceRepository with the content of getSharedStructure().

This function is thread-safe.

Caution: Do not call this function if you are not certain it does the expected things.
removeEmptySpaces
protected def removeEmptySpaces
Remove all the spaces that are empty.

This function is thread-safe.
Since:
0.12
removeSpace(Space)
def removeSpace(Space)
Remove the given space.

This function notifies the listeners about the space removal.
Parameters:
space - the space.
removeSpaceIfEmpty(Space)
def removeSpaceIfEmpty(Space)
Remove the given space if the it is empty, i.e. it has no more strong participant.

This function is thread-safe.
Parameters:
space - is the identifier of the space.
Since:
0.12
removeSpaceIfEmpty(UUID)
def removeSpaceIfEmpty(UUID)
Remove the space with the given id if the space is empty, i.e. it has no more strong participant.

This function is thread-safe.
Parameters:
id - is the identifier of the space.
Since:
0.12
removeSpaceRepositoryListener(SpaceRepositoryListener)
def removeSpaceRepositoryListener(SpaceRepositoryListener)
Remove listener on the space repository changes.

This function is thread-safe.
Parameters:
listener - the listener to be removed.