Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[lang] Refine getOrCreateSpace function.
The getOrCreateSpace function is deprecated. The
getOrCreateSpaceWithSpec function is replacing the deprecated function.
The getOrCreateSpaceWithID function is introduced.

see #242

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Nov 25, 2014
1 parent 8344deb commit b93867a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 24 deletions.
Expand Up @@ -167,14 +167,11 @@ describe "Agent Communication in Sub-Space with the Ping Pong Agents"{
*
* The sub-space is located in the default context.
* For creating or joining it, we must use the
* `getOrCreateSpace` function. This function
* takes the type of the space specification that
* permits to create an instance of the desired space.
* The second argument is the identifier of the
* new space.
* The `getOrCreateSpace` function creates a new
* space if there is no existing space with the given
* identifier, or it replies the existing space.
* `getOrCreateSpaceWithSpec` function.
* This function searches for a space, which was
* created with the given specification. If there
* is no space, the space identifier is used
* for creating a new space.
*
* After retrieving the instance of the space,
* it is mandatory to register the agent for
Expand All @@ -195,7 +192,7 @@ describe "Agent Communication in Sub-Space with the Ping Pong Agents"{
var space : OpenEventSpace

on Initialize {
space = defaultContext.getOrCreateSpace(
space = defaultContext.getOrCreateSpaceWithSpec(
typeof(OpenEventSpaceSpecification),
occurrence.parameters.get(0) as UUID)
space.register(asEventListener())
Expand Down Expand Up @@ -234,7 +231,7 @@ describe "Agent Communication in Sub-Space with the Ping Pong Agents"{
var space : OpenEventSpace

on Initialize {
space = defaultContext.getOrCreateSpace(
space = defaultContext.getOrCreateSpaceWithSpec(
typeof(OpenEventSpaceSpecification),
occurrence.parameters.get(0) as UUID)
space.register(asEventListener())
Expand Down Expand Up @@ -312,7 +309,7 @@ describe "Agent Communication in Sub-Space with the Ping Pong Agents"{
var space : OpenEventSpace

on Initialize {
space = defaultContext.getOrCreateSpace(
space = defaultContext.getOrCreateSpaceWithSpec(
typeof(OpenEventSpaceSpecification),
occurrence.parameters.get(0) as UUID)
space.register(asEventListener())
Expand Down Expand Up @@ -383,7 +380,7 @@ describe "Agent Communication in Sub-Space with the Ping Pong Agents"{
var space : OpenEventSpace

on Initialize {
space = defaultContext.getOrCreateSpace(
space = defaultContext.getOrCreateSpaceWithSpec(
typeof(OpenEventSpaceSpecification),
occurrence.parameters.get(0) as UUID)
space.register(asEventListener())
Expand Down Expand Up @@ -444,7 +441,7 @@ describe "Agent Communication in Sub-Space with the Ping Pong Agents"{
var space : OpenEventSpace

on Initialize {
space = defaultContext.getOrCreateSpace(
space = defaultContext.getOrCreateSpaceWithSpec(
typeof(OpenEventSpaceSpecification),
occurrence.parameters.get(0) as UUID)
space.register(asEventListener())
Expand Down Expand Up @@ -478,7 +475,7 @@ describe "Agent Communication in Sub-Space with the Ping Pong Agents"{
var space : OpenEventSpace

on Initialize {
space = defaultContext.getOrCreateSpace(
space = defaultContext.getOrCreateSpaceWithSpec(
typeof(OpenEventSpaceSpecification),
occurrence.parameters.get(0) as UUID)
space.register(asEventListener())
Expand Down Expand Up @@ -527,7 +524,7 @@ describe "Agent Communication in Sub-Space with the Ping Pong Agents"{
var space : OpenEventSpace

on Initialize {
space = defaultContext.getOrCreateSpace(
space = defaultContext.getOrCreateSpaceWithSpec(
typeof(OpenEventSpaceSpecification),
occurrence.parameters.get(0) as UUID)
space.register(asEventListener())
Expand Down Expand Up @@ -587,7 +584,7 @@ describe "Agent Communication in Sub-Space with the Ping Pong Agents"{
var space : OpenEventSpace

on Initialize {
space = defaultContext.getOrCreateSpace(
space = defaultContext.getOrCreateSpaceWithSpec(
typeof(OpenEventSpaceSpecification),
occurrence.parameters.get(0) as UUID)
space.register(asEventListener())
Expand Down Expand Up @@ -673,7 +670,7 @@ describe "Agent Communication in Sub-Space with the Ping Pong Agents"{
var space : OpenEventSpace

on Initialize {
space = defaultContext.getOrCreateSpace(
space = defaultContext.getOrCreateSpaceWithSpec(
typeof(OpenEventSpaceSpecification),
occurrence.parameters.get(0) as UUID)
space.register(asEventListener())
Expand Down
63 changes: 56 additions & 7 deletions plugins/io.sarl.lang.core/src/io/sarl/lang/core/AgentContext.java
Expand Up @@ -80,22 +80,71 @@ <S extends Space> S createSpace(Class<? extends SpaceSpecification<S>> spec,
*/
<S extends Space> SynchronizedCollection<S> getSpaces(Class<? extends SpaceSpecification<S>> spec);

/** Retreive or create an instance of space following the given specification.
* This function tries to find a space that fits the given specification.
* If none was found, this function create a new space in the same way as
* {@link #createSpace(Class, UUID, Object...)}.
/** Retreive or create an instance of space which was created with the given specification.
* <p>
* 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.
* <p>
* <strong>Caution:</strong> The <code>spaceUUID</code> parameter is used only
* if no existing space created with the given specification was found.
*
* @param <S> - type of the replied space.
* @param spec - specification of the space to create.
* @param spaceUUID - identifier of the new space.
* @param spec - specification of the space to retreive/create.
* @param spaceUUID - identifier used only when creating the space.
* @param creationParams - parameters to pass to the space constructor.
* @return the new space, never <code>null</code>.
* @return the space, never <code>null</code>.
* @see #getOrCreateSpaceWithID(UUID, Class, Object...)
* @see #createSpace(Class, UUID, Object...)
* @see #getSpace(UUID)
* @deprecated see {@link #getOrCreateSpaceWithSpec(Class, UUID, Object...)}
*/
@Deprecated
<S extends Space> S getOrCreateSpace(Class<? extends SpaceSpecification<S>> spec,
UUID spaceUUID, Object... creationParams);

/** Retreive or create an instance of space which was created with the given specification.
* <p>
* 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.
* <p>
* <strong>Caution:</strong> The <code>spaceUUID</code> parameter is used only
* if no existing space created with the given specification was found.
*
* @param <S> - type of the replied space.
* @param spec - specification of the space to retreive/create.
* @param spaceUUID - identifier used only when creating the space.
* @param creationParams - parameters to pass to the space constructor.
* @return the space, never <code>null</code>.
* @see #getOrCreateSpaceWithID(UUID, Class, Object...)
* @see #createSpace(Class, UUID, Object...)
* @see #getSpace(UUID)
*/
<S extends Space> S getOrCreateSpaceWithSpec(Class<? extends SpaceSpecification<S>> spec,
UUID spaceUUID, Object... creationParams);

/** Retreive or create an instance of space with the given identifier.
* <p>
* 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.
* <p>
* <strong>Caution:</strong> The <code>spaceUUID</code> parameter is given to
* the specification when creating the space.
*
* @param <S> - type of the replied space.
* @param spaceUUID - identifier of the space.
* @param spec - specification of the space for creating the space.
* @param creationParams - parameters to pass to the space constructor.
* @return the space, never <code>null</code>.
* @see #getOrCreateSpaceWithID(UUID, Class, Object...)
* @see #createSpace(Class, UUID, Object...)
* @see #getSpace(UUID)
*/
<S extends Space> S getOrCreateSpaceWithID(UUID spaceUUID,
Class<? extends SpaceSpecification<S>> spec, Object... creationParams);

/** Retreive, but do not create, an instance of space following the given ID.
* This function tries to find a space that fits the given specification.
* If none was found, this function replies <code>null</code>.
Expand Down

0 comments on commit b93867a

Please sign in to comment.