ObjectTeams/Java Language Definition - §5.
|
|
Table of |
§6. Object Teams API |
| §5. Team activation |
The concept of Activation
![]() |
|
| Binding activation | All callin bindings of a team only have effect if the team is active. Activation may be caused by explicit statements and also happens implicitly at certain points during program execution. |
![]() |
|
| Guard predicates |
Callin bindings can further be controlled using guard predicates,
which can be attached to roles and teams at different levels. If a guard
predicate evaluates to false, all affected callin bindings
are disabled.
|
![]() |
|
§5.1. Effect of team activation
Activating a team instance has the effect of enabling all its callin bindings. All effects defined in §4. apply only if a corresponding team instance is active.
The order of team activation controls the order of callin executions. If more than one team intercepts calls to the same base method, the most recently activated team has highest priority in that its before or replace callins are executed first while its after callins are executed last.
The order of team activation controls the order of callin executions. If more than one team intercepts calls to the same base method, the most recently activated team has highest priority in that its before or replace callins are executed first while its after callins are executed last.
§5.2. Explicit team activation
(a) Activation block
A team can be activated thread local by the block construct
If stmts has only one statement this can be abbreviated to
In these statements,
(b) Imperative activationwithin (myTeam) { stmts }within (myTeam) stmtmyTeam must denote a team instance. For the time of executing this block, this team instance is activated for the current thread,
which has entered the within block.
The within block statement guarentees that it leaves
the team in exactly the same activation state as it was in when
entering this block. This includes the cases of exceptions, meaning
that deactivation will also occur if the execution of the block
terminates abnormally.
Each team class inherits methods from the predefined class
If a team should be de-/activated for another thread this can be done by the methods
Note, that this methods make no guarantees with respect to exceptions.
(c) Multiple and mixed activationsorg.objectteams.Team (super class of all team classes) to control team activation disregarding the block structure of the program.
The methods activate() and deactivate() are used to activate and deactivate a team instance for the current thread. If a team should be de-/activated for another thread this can be done by the methods
activate(Thread aThread) and deactivate(Thread aThread).
In order to achieve global activation for all threads the predefined constant Team.ALL_THREADS is passed to these methods (e.g. activate(Team.ALL_THREADS)).Note, that this methods make no guarantees with respect to exceptions.
- If
activate()is invoked on a team instance that has been explicitly activated before, this statement has no effect at all (note the difference in §5.3(a) below).
The same applies to deactivating an inactive team. - If a team was already active when entering a
withinblock, it will remain active after leaving the block. - If the team was active on entry of a
withinblock and ifdeactivate()is invoked on the same team instance from within thewithinblock, leaving the block will re-activate the team.
§5.3. Implicit team activation
When the control flow is passed to a team or one of its roles, the
team is implicitly activated for the current thread. So a programmer may in general assume,
that whenever a role forwards calls to its base object via callout,
the callin bindings of the same role will be active at that time.
Exceptions to this rule have to be programmed explicitly.
(a) Team level methods
While executing a team level method, the target team
is always active. Activation is reset to the previous state
when leaving the team method, unless the team has been explicitly activated during
execution of the team method by a call to
(b) Methods of externalized rolesactivate().
Explicit activation is stronger than implicit activation and thus persists after the
team level method terminates. Ie., leaving a team level method will never reset
an explicit activation.
Invoking a method on an externalized role
(see §1.2.2) also has the
effect of temporary activation of the team containing the role for the current thread.
Regarding deactivation the rule of §5.3(a) above applies accordingly.
(c) Nested teams
Implicit activation has additional consequences for nested teams (see §1.5):
- Implicit activation of a team causes the activation of its outer teams.
- Implicit deactivation of a team causes the dectivation of its inner teams.
Note that among the different mechanisms for activation,
within is strongest, followed by (de)activate(), weakest is implicit activation. In this sense, explicit imperative (de)activation may override the block structure of implicit
activation (by explicit activation within a team level method), but not that of a within block (by deactivation from a within block).
§5.4. Guard predicates
The effect of callins can further be controlled using so called guard predicates.
Guards appear at four different levels:
(a) General syntax for guards- callin method binding
- role method
- role class
- team class
base guards,
which affects the exact point in the control flow, where the guard will
be evaluated.
A guard is declared using the keyword
Depending on the kind of guard different objects are in scope using
special identifiers like
Any predicate expression that evaluates to
when followed by
a boolean expression in parentheses:when (predicateExpression)this, base.Any predicate expression that evaluates to
true enables
the callin binding(s) to which it applies.
Evaluation to false disables the callin binding(s).
§5.4.1. Regular guards
This group of guards evaluates within the context of a given role.
These guards are evaluated after a callin target is lifted and
before a callin bound role method is invoked.
(a) Method binding guards
A guard may be attached to a callin method binding as in:
Such a guard only affects the callin binding to which it is attached,
i.e., this specific callin binding is only effective,
if the predicate evaluates to
The following values are within the scope of the predicate expression, and thus can be used to express the condition:
(b) Method guardsvoid roleMethod(int ir) <- after void baseMethod(int ib)
when (ir > MyTeam.this.threshold);true.The following values are within the scope of the predicate expression, and thus can be used to express the condition:
- The role instance denoted by
this.
Features of the role instance can also be accessed relative tothiswith or without explicit qualifyingthis. - The team instance denoted by a qualified this reference as in
MyTeam.this. - If the callin binding includes signatures (as in the example above): Parameters of the role method.
If parameter mappings are involved, they will be evaluated before evaluating the guard.
Furthermore, if the modifier of the callin binding isafter: The result (denoted by the special identifierresult) of the role method, if it is notvoid.
A method guard is similar to a method binding guard, but it applies
to all callin method bindings of this method.
A method guard is declared between the method signature and the method body:
(c) Role level guardsA method guard is declared between the method signature and the method body:
void roleMethod(int ir)
when (ir > MyTeam.this.threshold) { body statements }
When a guard is specified at the role level, i.e., directly before the
class body of a role class, it applies to all callin method bindings of
the role class:
The following values are within the scope of the predicate expression:
(d) Team level guardsprotected class MyRole
when (value > MyTeam.this.threshold)
{
int value;
other class body declarations
}- The role instance denoted by
this(explicit or implicit, see above). Thus, in the examplevaluewill be interpreted as a field of the enclosing role. - The team instance denoted by a qualified this reference as in
MyTeam.this
A guard specified in the header of a team class may disable the callin
bindings of all contained role classes. The syntax corresponds to the
syntax of role level guards.
The only value directly available within team level guard is the team instance (denoted by
The only value directly available within team level guard is the team instance (denoted by
this) and its features.
Of course all guards can also access any visible static feature of a visible class.
Even if a guard has no direct effect, because, e.g., a role class has no callin bindings (maybe not even a role-base binding), predicates at such abstract levels are useful, because all predicates are inherited by all sub classes (explicit and implicit).
§5.4.2. Base guards
The intention behind base guards is to prevent lifting of a callin-target
if a guard evaluates to
However, different scoping rules apply for the identifiers
that can be used in a
(a) Base object referencefalse and thus refuses to invoke the
callin bound role method. Using base guards it is easier to prevent any
side-effects caused by a callin binding, because lifting could cause side-effect
at two levels:
- Creating a role on-demand already is a side-effect (observable
by the reflective function
hasRole, e.g. - Role creation triggers execution of a role constructor (see §2.3.1(c): custom lifting constructor) which could produce arbitrary side-effects.
Future feature:
The OT/J compiler will include a read-only analysis, that will check whether all predicate expressions in guards are actually free of side-effects.
Any guard (5.4.1 (b)-(e)) can be turned into a base guard by adding
the modifier The OT/J compiler will include a read-only analysis, that will check whether all predicate expressions in guards are actually free of side-effects.
base as in:
protected class MyRole playedBy MyBase
base when (base.value > MyTeam.this.threshold)
{
class body declarations
}base guard:
In all base guard predicates the special identifier
(b) Method binding guardsbase
can be used to denote the base object that is about to be lifted.
A base method binding guard may access parameters as passed to the
base method. Parameter mappings are not considered.
Additionally, for
(c) Method guardsAdditionally, for
after callin bindings, the
identifier result may be used to refer to the
result of the base method (if any).Note: In order to achieve the same effect of accessing
the base method's result, a regular binding guard (not a base guard)
must use a suitable parameter mapping (see §4.4(c)).
In contrast to regular method guards, a base guard attached to a role method cannot access any method parameters. See the next item (d) for values that are actually in
scope.
(d) Role level guards
Role level base guards may use these values:
(e) Team level guards- The base instance using the special identifier
base. - The team instance using a qualified this references
(
MyTeam.this).
Team level base guards have the same scope as role level
base guards (d). However, the type of the role instance is not
known here, i.e., here
(f) Unbound rolesbase has the static type
java.lang.Object.
In contrast to regular guards, base guards cannot be attached to
unbound role classes nor to their methods.
Only team level base guards are independent of role binding.
Only team level base guards are independent of role binding.

§5.4.3. Multiple guards
Due to the different ranges of applicability different guards
may affect the same method binding. In that case all applicable
guards are conjoined using a logical
Any guard is interpreted as the conjunction of these predicates (if present):
and.Any guard is interpreted as the conjunction of these predicates (if present):
- The direct predicate expression of the guard.
- The next outer guard along the chain method binding -> method -> role level -> team level
- The guard at the same level that is inherited from the implicit super role.
- The guard at the same level that is inherited from the explicit super role.
Example code:
|
Effects:
-
The team in this example causes, that an additional fee has to be payed while debiting less than 1000 euro from a "foreign"
account.
-
The base guard in line 4 ensures that
Accountobjects only getForeignAccountroles, if they belong to a different bank than the surroundingATMteam.
It accesses the bank of the base via thebaseidentifier. -
The method binding guard in line 10 restricts the callin to
debitWithFeeto calls where the base method argumentamountis lower than 1000. - A call to
Account.debitcauses a replace callin todebitWithFeeONLY if BOTH predicates evaluate to true.
§5.5. Unanticipated team activation
If an application should be adapted unanticipatedly by one or more teams, this can be achieved without
explicitly changing the program code of this application.
| General activation via config file: Instead of adding the team initialization and activation code to the main program, it is possible to add the respective teams via a config file. Every line of this text file contains the fully qualified name of a compiled team, which has to be available on the classpath. For the instantiation of these teams the default constuctor is used, which means adding a team to an application this way requires the team to provide a default constructor. The activation order (see §5.1) for these teams corresponds to the order in which they are listed in the config file. Lines starting with a '#' denote comment lines. Example config file:
'-Dot.teamconfig=<config_file_name>' has to be used when starting the application. Note: In the ObjectTeams Development Tooling (OTDT) teams are activated unanticipatedly via a special tab in the "Run-Configuration" (see OTDT features), instead. |
||||||
| Activation adjustment example: Teams added via the config file mechanism are activated by default. Because no reference to them is stored anywhere, it is not possible do deactivate them later. If deactivation of unanticipated added teams is required, this can be archieved by adding a manager team via config file and encapsulate the actual functionality in another team managed by the manager team. This way a functional team can be activated and deactivated as needed. Example code: |
|
|
Effects:
startMethodandstopMethodare methods which demand the activation and deactivation respectively.- If the activation/deactivation depends on other conditions these can be checked in addition.
|
|
Table of |
§6. Object Teams API |
© Stephan Herrmann, Christine Hundt
OT/J Version 1.0 — Last modified: Fri Mar 30 2007

