/
AgentContext.java
160 lines (147 loc) · 6.42 KB
/
AgentContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014 Sebastian RODRIGUEZ, Nicolas GAUD, Stéphane GALLAND.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.sarl.lang.core;
import io.sarl.lang.util.SynchronizedCollection;
import java.util.UUID;
/**
* An AgentContext defines the boundary of a sub-system, and gathers a collection of Spaces.
* Each context has a default context that provides a basic interaction context.
*
* @author $Author: srodriguez$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
public interface AgentContext {
/** Replies the identifier of the context.
*
* @return the identifier of the context.
*/
UUID getID();
/** Replies the default space of the context.
* The default space is assumed to be always an {@link EventSpace event-based space}.
*
* @return the default space.
*/
EventSpace getDefaultSpace();
/** Replies all the spaces defined in this context.
*
* @return the spaces.
*/
SynchronizedCollection<? extends Space> getSpaces();
/** Create an instance of space following the given specification.
* This function always creates a new instance of space.
* It means that is a space with the given identifier already
* exists, this function does nothing and replies <code>null</code>.
* If you want to find an existing space prior to the creation of
* a new one, you should use {@link #getOrCreateSpace(Class, UUID, Object...)}.
*
* @param <S> - type of the created space.
* @param spec - specification of the space to create.
* @param spaceUUID - identifier of the new space.
* @param creationParams - parameters to pass to the space constructor.
* @return the new space, or <code>null</code> if the space already exists.
* @see #getOrCreateSpace(Class, UUID, Object...)
* @see #getSpace(UUID)
*/
<S extends Space> S createSpace(Class<? extends SpaceSpecification<S>> spec,
UUID spaceUUID, Object... creationParams);
/** Replies all the spaces that are implementing the given specification.
*
* @param <S> - type of the replied space.
* @param spec - specification of the space to retreive.
* @return the spaces associated to the given space specification.
*/
<S extends Space> SynchronizedCollection<S> getSpaces(Class<? extends SpaceSpecification<S>> spec);
/** 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)
* @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>.
*
* @param <S> - type of the replied space.
* @param spaceUUID - identifier of the space.
* @return the space, or <code>null</code> if there is no space found.
* @see #createSpace(Class, UUID, Object...)
* @see #getOrCreateSpace(Class, UUID, Object...)
*/
<S extends Space> S getSpace(UUID spaceUUID);
}