|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier
public class ConcurrentBarrier
A barrier used to execute code in a context where it is guarded by read/write locks. In addition, handles upgrading
read locks to write locks (and vice versa). Execution of code within a lock is in terms of a Runnable
object
(that returns no value), or a Invokable
object (which does return a value).
Constructor Summary | |
---|---|
ConcurrentBarrier()
|
Method Summary | ||
---|---|---|
boolean |
tryWithWrite(Runnable runnable,
long timeout,
TimeUnit timeoutUnit)
Try to aquire the exclusive write lock and invoke the Runnable. |
|
|
withRead(Invokable<T> invokable)
Invokes the object after acquiring the read lock (if necessary). |
|
void |
withRead(Runnable runnable)
As with withRead(Invokable) , creating an Invokable wrapper around the runnable object. |
|
|
withWrite(Invokable<T> invokable)
Acquires the exclusive write lock before invoking the Invokable. |
|
void |
withWrite(Runnable runnable)
As with withWrite(Invokable) , creating an Invokable wrapper around the runnable object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ConcurrentBarrier()
Method Detail |
---|
public <T> T withRead(Invokable<T> invokable)
T
- invokable
-
public void withRead(Runnable runnable)
withRead(Invokable)
, creating an Invokable
wrapper around the runnable object.
public <T> T withWrite(Invokable<T> invokable)
Invokable
object should
be prepared for cases where the state has changed slightly, despite holding the read lock. This usually manifests
as race conditions where either a) some parallel unrelated bit of work has occured or b) duplicate work has
occured. The latter is only problematic if the operation is very expensive.
T
- invokable
- public void withWrite(Runnable runnable)
withWrite(Invokable)
, creating an Invokable
wrapper around the runnable object.
public boolean tryWithWrite(Runnable runnable, long timeout, TimeUnit timeoutUnit)
withWrite(Runnable)
and will return true. If the write lock is not
obtained within the timeout then the runnable is never invoked and the method will return false.
runnable
- Runnable object to execute inside the write lock.timeout
- Time to wait for write lock.timeoutUnit
- Units of timeout.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |