public abstract class SpaceRepository extends Object implements SpaceListener
This repository is thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
SpaceRepository.SpaceDescription
Description of a space.
|
static class |
SpaceRepository.SpaceSpecificationKey
Key for a space specification.
|
Constructor and Description |
---|
SpaceRepository(injector : com.google.inject.Injector,
executor : ExecutorService,
logger : LoggingService,
config : SreConfig,
specificationFactory : SreSpaceSpecificationFactory,
factories : javax.inject.Provider<Factories>)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addSpaceRepositoryListener(listener : SpaceRepositoryListener)
Add listener on the space repository changes.
|
OpenEventSpace |
createDefaultSpace(spaceID : SpaceID)
Create an instance of the default space if it was not created before.
|
protected Logger |
createLogger(loggingService : LoggingService)
Create the logger for this repository.
|
<S extends Space> |
createSpace(spaceID : SpaceID,
spec : Class<? extends SpaceSpecification<S>>,
creationParams : Object*)
Create a space.
|
protected SpaceRepository.SpaceDescription |
createSpaceDescription(id : SpaceID,
space : Space)
Create a space description.
|
protected <S extends Space> |
createSpaceFirstInstance(spec : Class<? extends SpaceSpecification<S>>,
spaceID : SpaceID,
creationParams : Object[])
Create the first instance of a given space.
|
void |
destroy()
Destroy this repository and release all the resources.
|
void |
destroyableSpace(space : Space)
Invoked when the space could be destroyed.
|
protected void |
destroyThreadUnsafe()
Destroy this repository and release all the resources inside a synchronized section.
|
protected void |
fireSpaceAdded(space : Space,
isLocalCreation : boolean)
Notifies the listeners on the space creation.
|
protected void |
fireSpaceRemoved(space : Space,
isLocalDestruction : boolean)
Notifies the listeners on the space destruction.
|
protected ReadWriteLock |
getLock() |
<S extends Space> |
getOrCreateSpaceWithID(spaceID : SpaceID,
spec : Class<? extends SpaceSpecification<S>>,
creationParams : Object*)
Retrieve the first space of the given identifier, or create a space if none.
|
<S extends Space> |
getOrCreateSpaceWithSpec(spaceID : SpaceID,
spec : Class<? extends SpaceSpecification<S>>,
creationParams : Object*)
Retrieve the first space of the given specification, or create a space if none.
|
protected abstract Map<UUID,SpaceRepository.SpaceDescription> |
getSharedStructure()
Replies the internal map that contains the spaces.
|
Space |
getSpace(spaceID : SpaceID)
Returns the first instance of a space with the specified SpaceID.
|
ConcurrentCollection<? extends Space> |
getSpaces()
Returns the collection of all spaces stored in this repository.
|
<S extends Space> |
getSpaces(spec : Class<? extends SpaceSpecification<S>>)
Returns the collection of all spaces with the specified
SpaceSpecification stored in this repository. |
boolean |
hasSpace(id : UUID)
Replies if the given space was defined into the repository.
|
protected SpaceRepository.SpaceDescription |
life(spaceId : SpaceID,
newDescription : SpaceRepository.SpaceDescription)
Replies the space information associated to the space identifier if already associated.
|
protected SpaceRepository.SpaceDescription |
life(space : Space,
newDescription : SpaceRepository.SpaceDescription)
Replies the space information associated to the space if already associated.
|
void |
refreshInternalStructures()
Synchronize the internal structures of SpaceRepository with the content of
SpaceRepository.getSharedStructure() . |
protected void |
removeEmptySpaces()
Remove all the spaces that are empty.
|
void |
removeSpace(space : Space)
Remove the given space.
|
void |
removeSpaceIfEmpty(space : Space)
Remove the given space if the it is empty, i.e. it has no more strong participant.
|
void |
removeSpaceIfEmpty(id : UUID)
Remove the space with the given id if the space is empty, i.e. it has no more strong participant.
|
void |
removeSpaceRepositoryListener(listener : SpaceRepositoryListener)
Remove listener on the space repository changes.
|
protected val
logger : Logger
@Inject
public new
(injector : com.google.inject.Injector,
executor : ExecutorService,
logger : LoggingService,
config : SreConfig,
specificationFactory : SreSpaceSpecificationFactory,
factories : javax.inject.Provider<Factories>)
injector
- the injector.executor
- the asynchronous execution service.logger
- the logging service.config
- the configuration.specificiationFactory
- the factory of space spacification.factories
- the provider of factories tool.@Pure
protected def
createLogger(loggingService : LoggingService) : Logger
SpaceRepository
This function should not have a border effect; and it is therefore thread-safe.
loggingService
- the service for logging.@Pure
protected abstract def
getSharedStructure() : Map<UUID,SpaceRepository.SpaceDescription>
SpaceRepository
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".
@Pure
protected def
createSpaceDescription(id : SpaceID,
space : Space) : SpaceRepository.SpaceDescription
SpaceRepository
This function should be overridden by the sub-types.
This function should not have a border effect; and it is therefore thread-safe.
id
- the space identifier.space
- the space instance.protected def
life(space : Space,
newDescription : SpaceRepository.SpaceDescription) : SpaceRepository.SpaceDescription
SpaceRepository
This function is not thread-safe; but enough efficient to be assumed to not cause issues related to threads.
newDescription
- the description to associated to the space.null
protected def
life(spaceId : SpaceID,
newDescription : SpaceRepository.SpaceDescription) : SpaceRepository.SpaceDescription
SpaceRepository
This function is not thread-safe; but enough efficient to be assumed to not cause issues related to threads.
newDescription
- the description to associated to the space.null
public def
createDefaultSpace(spaceID : SpaceID) : OpenEventSpace
SpaceRepository
This function is thread-safe.
spaceID
- ID of the default space.protecteddef
createSpaceFirstInstance(spec : Class<? extends SpaceSpecification<S>>, spaceID : SpaceID, creationParams : Object[]) : Swith
<S extends Space>
SpaceRepository
This function is thread-safe. It notifies the listeners about the space creation.
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.public def
refreshInternalStructures() : void
SpaceRepository
SpaceRepository.getSharedStructure()
.
This function is thread-safe.
Caution: Do not call this function if you are not certain it does the expected things.
public final def
destroy() : void
SpaceRepository
protected def
destroyThreadUnsafe() : void
SpaceRepository
This function is not thread-safe.
publicdef
createSpace(spaceID : SpaceID, spec : Class<? extends SpaceSpecification<S>>, creationParams : Object*) : Swith
<S extends Space>
SpaceRepository
This function notifies the listeners about the space creation.
S
- - the type of the space to reply.spaceID
- ID of the space.spec
- specification of the space.creationParams
- creation parameters.null
if the space already exists.protected def
removeEmptySpaces() : void
SpaceRepository
This function is thread-safe.
public def
removeSpaceIfEmpty(id : UUID) : void
SpaceRepository
This function is thread-safe.
id
- is the identifier of the space.public def
removeSpaceIfEmpty(space : Space) : void
SpaceRepository
This function is thread-safe.
id
- is the identifier of the space.public def
removeSpace(space : Space) : void
SpaceRepository
This function notifies the listeners about the space removal.
space
- the space.@Pure publicdef
getOrCreateSpaceWithSpec(spaceID : SpaceID, spec : Class<? extends SpaceSpecification<S>>, creationParams : Object*) : Swith
<S extends Space>
SpaceRepository
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).@Pure publicdef
getOrCreateSpaceWithID(spaceID : SpaceID, spec : Class<? extends SpaceSpecification<S>>, creationParams : Object*) : Swith
<S extends Space>
SpaceRepository
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).@Pure
public def
getSpaces() : ConcurrentCollection<? extends Space>
SpaceRepository
@Pure publicdef
getSpaces(spec : Class<? extends SpaceSpecification<S>>) : ConcurrentCollection<S>with
<S extends Space>
SpaceRepository
SpaceSpecification
stored in this repository.S
- - type of the spaces to reply.spec
- the specification used to filter the set of stored spaces.SpaceSpecification
stored in this repository@Pure
public def
getSpace(spaceID : SpaceID) : Space
SpaceRepository
spaceID
- the identifier to retrieve.null
if none.public def
addSpaceRepositoryListener(listener : SpaceRepositoryListener) : void
SpaceRepository
This function is thread-safe.
listener
- public def
removeSpaceRepositoryListener(listener : SpaceRepositoryListener) : void
SpaceRepository
This function is thread-safe.
listener
- protected def
fireSpaceAdded(space : Space,
isLocalCreation : boolean) : void
SpaceRepository
This function is thread-safe.
space
- the created space.isLocalCreation
- indicates if the creation of the space was initiated on the current kernel.protected def
fireSpaceRemoved(space : Space,
isLocalDestruction : boolean) : void
SpaceRepository
This function is thread-safe.
space
- the removed space.isLocalDestruction
- indicates if the destruction of the space was initiated on the current kernel.public def
destroyableSpace(space : Space) : void
SpaceListener
destroyableSpace
in interface SpaceListener
space
- reference to the created space.@Pure
public def
hasSpace(id : UUID) : boolean
SpaceRepository
id
- is the identifier of the space.true
if the space exists into the repository, or false
otherwise.@Pure
protected def
getLock() : ReadWriteLock
Copyright © 2021 the original authors or authors.