|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||
@Documented @Target(value=METHOD) public @interface ReturnsLock
Declares that the object returned by the method to which this annotation is applied is the named lock. This allows the representation of the lock to be concealed from clients of the object, but still makes the lock accessible to them. It is a modeling error if the return type of the annotated method is a primitive type.
Methods that override a method annotated with
@ReturnsLock("l") must also be
explicitly annotated @ReturnsLock("l").
It is a modeling error if they are not.
null
and reference the lock object declared in the RegionLock or PolicyLock declaration
for the named lock.
Thing, returns a lock used to protected subclass
state.
@Region("protected ThingState")
@RegionLock("ThingLock is thingLock protects ThingState")
class Thing {
private final Object thingLock = new Object();
@ReturnsLock("ThingLock")
protected Object getThingLock() {
return thingLock;
}
...
}
The lock getter method can then be used in subclasses such as the
Player below.
class Player extends Thing {
@InRegion("ThingState")
private long x, y;
public void setPosition(long x, long y) {
synchronized (getThingLock()) {
this.x = x;
this.y = y;
}
}
...
}
A lock getter method may return a policy lock:
@PolicyLock("InitLock is initLock")
public class System {
private final Object initLock = new Object();
...
@ReturnsLock("InitLock")
protected Object getInitLock() {
return initLock;
}
}
@annotate tag.
/**
* @annotate Region("protected ThingState")
* @annotate RegionLock("ThingLock is thingLock protects ThingState")
*/
class Thing {
private final Object thingLock = new Object();
/**
* @annotate ReturnsLock("ThingLock")
*/
protected Object getThingLock() {
return thingLock;
}
...
}
RegionLock| Required Element Summary | |
|---|---|
String |
value
The name of the lock returned by the annotated method. |
| Element Detail |
|---|
public abstract String value
value = lockSpecification
lockSpecification = qualifiedLockSpecification / simpleLockSpecification
simpleLockSpecification = simpleLockName ["." ("readLock" / "writeLock")]
qualifiedLockSpecification = qualifiedLockName ["." ("readLock" / "writeLock")]
simpleLockName = IDENTIFIER ; Lock from the receiver (same as "this:IDENTIFIER")
qualifiedLockName = parameterLockName / typeQualifiedLockName / innerClassLockName
parameterLockName = simpleExpression ":" IDENTIFIER ; Lock from a method/constructor parameter
simpleExpression = "this" / IDENTIFER ; Receiver or parameter name
typeQualifiedLockName = typeExpression ":" IDENTIFIER ; Static lock qualified by a class name
typeExpression = IDENTIFIER *("." IDENTIFIER)
innerClassLockName = namedType "." "this" ":" IDENTIFIER ; Lock from an enclosing instance
namedType = IDENTIFIER *("." IDENTIFIER)
IDENTIFIER = Legal Java Identifier
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||