Skip to main content
summaryrefslogtreecommitdiffstats
blob: b77c5f092227a6188f3d470232d65d442361dae9 (plain) (blame)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**********************************************************************
 * This file is part of the "Object Teams Runtime Environment"
 * 
 * Copyright 2010 Stephan Herrmann.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * $Id: ITeam.java 23408 2010-02-03 18:07:35Z stephan $
 * 
 * Please visit http://www.objectteams.org for updates and contact.
 * 
 * Contributors:
 * 		Stephan Herrmann - Initial API and implementation
 **********************************************************************/
package org.objectteams;

/**
 * Public interface of all team classes.
 */
public interface ITeam {
	
    /**
     *  Interface for all role classes that should allow explicit lowering.
     *  The interface provides a phantom method <pre>&lt;B&gt; B lower()</pre>
     *  where B is the bound base class of the implementing role class.
     *  There is no need to implement the method lower, since this is done by the compiler.
     */
    public interface ILowerable {
		// internal method needed for cast and instanceof
    	ITeam _OT$getTeam();
    }

	/**
	 *  This role interface has no properties not even those of java.lang.Object.
	 */
	public interface IConfined extends org.objectteams.IConfined {
		// internal method needed for cast and instanceof
		ITeam _OT$getTeam(); 
	}


	/**
	 * Activates the team and therefore all of its callin bindings. 
	 * This activation applies to the current thread only.
	 */
	public abstract void activate();

	/**
	 * Deactivates the team and therefore all of its callin bindings. 
	 * This deactivation applies to the current thread only.
	 */
	public abstract void deactivate();

	/**
	 * Activates the team and therefore all of its callin bindings for passed thread. 
	 * If the constant 'Team.ALL_THREADS' is passed, this activation globally applies to all threads.
	 */
	public abstract void activate(Thread thread);

	/**
	 * Deactivates the team and therefore all of its callin bindings for passed thread. 
	 * If the constant 'Team.ALL_THREADS' is passed, this deactivation globally applies to all threads.
	 */
	public abstract void deactivate(Thread thread);

	/**
	 * Checks, if the team instance is active for the current thread.
	 * @return true, if the team is active, false else.
	 */
	public abstract boolean isActive();

	/**
	 * Checks, if the team instance is active for the 'thread'.
	 * @param thread	The thread for which to check activity.
	 * @return	true, if the team is active for 'thread', false else.
	 */
	public abstract boolean isActive(Thread thread);

	/**
	 * Does given base object have a role in this team?
	 * This method will consider roles of any type.
	 * 
	 * @param aBase any object, i.e., no checks are performed whether the base object's
	 * 		class is bound by any role class in this team. 	
	 * @return
	 */
	public abstract boolean hasRole(Object aBase);

	/**
	 * Does given base object have a role in this team?
	 * The role must be an instance of the specified role type.
	 * 
	 * @param aBase any object, i.e., no checks are performed whether the base object's
	 * 		class is bound by any role class in this team.
	 * @param roleType Class instance specifying the required role type.
	 *      TODO (SH): is it legal to pass an unbound role class? 	
	 * @throws IllegalArgumentException if <code>roleType</code> does not represent a member type of this team.
	 * @return
	 */
	public abstract boolean hasRole(Object aBase, Class<?> roleType) throws IllegalArgumentException;

	/**
	 * Retrieve a role for a given base object.
	 * If more than one role exists, a DuplicateRoleException is thrown.
	 * 
	 * @param aBase
	 * @return
	 */
	public abstract Object getRole(Object aBase);

	/**
	 * Retrieve a role for a given base object.
	 * The role must be an instance of the specified role type.
	 * 
	 * @param aBase any object, i.e., no checks are performed whether the base object's
	 * 		class is bound by any role class in this team.
	 * @param roleType Class instance specifying the required role type.
	 * @return
	 * @throws IllegalArgumentException if <code>roleType</code> does not represent a member type of this team.
	 */
	public abstract <T> T getRole(Object aBase, Class<T> roleType) throws IllegalArgumentException;

	/**
	 * Retrieve all bound roles registered in the current team.
	 * 
	 * This method uses internal structures of weak references. 
	 * For that reason it may return role instances which were about to be reclaimed 
	 * by the garbage collector. 
	 * If performance permits, it is thus advisable to always call System.gc() 
	 * prior to calling getAllRoles() in order to achieve deterministic results
	 * 
	 * @return a non-null array.
	 */
	public abstract Object[] getAllRoles();

	/**
	 * Retrieve all bound roles registered in the current team that
	 * are instance of roleType or a subtype thereof.
	 * 
	 * This method uses internal structures of weak references. 
	 * For that reason it may return role instances which were about to be reclaimed 
	 * by the garbage collector. 
	 * If performance permits, it is thus advisable to always call System.gc() 
	 * prior to calling getAllRoles() in order to achieve deterministic results
	 * 
	 * @param roleType must be a top-most bound role of this team. 
	 * @return a non-null array.
	 * @throws IllegalArgumentException if <code>roleType</code> does not represent a member type of this team.
	 */
	public abstract <T> T[] getAllRoles(Class<T> roleType) throws IllegalArgumentException;

	/**
	 * Query whether any role instance of this team instance is currently executing a
	 * method due to a callin binding.
	 * @return
	 */
	public abstract boolean isExecutingCallin();

	/**
	 * Remove a role from the internal registry, which means that the role will no longer be
	 * considered during lifting.
	 *  
	 * @param aRole
	 */
	public abstract void unregisterRole(Object aRole);

	/**
	 * Remove a role from the internal registry, which means that the role will no longer be
	 * considered during lifting.
	 *  
	 * @param aRole
	 * @param roleType
	 * @throws IllegalArgumentException if <code>roleType</code> does not represent a member type of this team.
	 */
	public abstract void unregisterRole(Object aRole, Class<?> roleType) throws IllegalArgumentException;

	/**
	 * Not API.
	 * This method saves the activation state of the team  for the current thread.
	 * If active, it also saves, if the activation was explicit or implicit.
	 * This method has to be called by the generated code when entering a within block, 
	 * before the activation.
	 */
	public int _OT$saveActivationState();
	
	/**
	 * Not API.
	 * This method restores the former saved activation state of the team  for the current thread.
	 * If active, it also restores, if the activation was explicit or implicit.
	 * This method has to be called by the generated code when leaving a within block 
	 * (in the finally block).
	 */
	public void _OT$restoreActivationState(int old_state);
	
	/**
	 * Not API, for use by TeamThreadManager, only.
	 */
	public boolean internalIsActiveSpecificallyFor(Thread t);
	
	/**
	 * Not API, for use by TeamThreadManager, only.
	 */
	public void deactivateForEndedThread(Thread thread);
}

Back to the top