Package org.jmock.lib.concurrent
Class Synchroniser
- java.lang.Object
-
- org.jmock.lib.concurrent.Synchroniser
-
- All Implemented Interfaces:
ThreadingPolicy
public class Synchroniser extends java.lang.Object implements ThreadingPolicy
A ThreadingPolicy that makes the Mockery thread-safe and helps tests synchronise with background threads.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ErrorfirstErrorprivate InvocationDispatcherinvocationDispatcherprivate java.lang.Objectsync
-
Constructor Summary
Constructors Constructor Description Synchroniser()Synchroniser(InvocationDispatcher dispatcher)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InvocationDispatcherdispatcher()InvokablesynchroniseAccessTo(Invokable mockObject)private java.lang.ObjectsynchroniseInvocation(Invokable mockObject, Invocation invocation)voidwaitUntil(StatePredicate p)Waits for a StatePredicate to become active.voidwaitUntil(StatePredicate p, long timeoutMs)Waits up to a timeout for a StatePredicate to become active.private voidwaitUntil(StatePredicate p, Timeout timeout)
-
-
-
Field Detail
-
sync
private final java.lang.Object sync
-
firstError
private java.lang.Error firstError
-
invocationDispatcher
private InvocationDispatcher invocationDispatcher
-
-
Constructor Detail
-
Synchroniser
public Synchroniser()
-
Synchroniser
public Synchroniser(InvocationDispatcher dispatcher)
-
-
Method Detail
-
waitUntil
public void waitUntil(StatePredicate p) throws java.lang.InterruptedException
Waits for a StatePredicate to become active. Warning: this will wait forever unless the test itself has a timeout.- Parameters:
p- the StatePredicate to wait for- Throws:
java.lang.InterruptedException
-
waitUntil
public void waitUntil(StatePredicate p, long timeoutMs) throws java.lang.InterruptedException
Waits up to a timeout for a StatePredicate to become active. Fails the test if the timeout expires.- Parameters:
p- the StatePredicate to wait fortimeoutMs- the timeout in milliseconds- Throws:
java.lang.InterruptedException
-
waitUntil
private void waitUntil(StatePredicate p, Timeout timeout) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
synchroniseAccessTo
public Invokable synchroniseAccessTo(Invokable mockObject)
- Specified by:
synchroniseAccessToin interfaceThreadingPolicy
-
synchroniseInvocation
private java.lang.Object synchroniseInvocation(Invokable mockObject, Invocation invocation) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
dispatcher
public InvocationDispatcher dispatcher()
- Specified by:
dispatcherin interfaceThreadingPolicy
-
-