public class Synchronizer<K>
extends java.lang.Object
| Constructor and Description |
|---|
Synchronizer() |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
synchronizeOn(K key,
java.util.concurrent.Callable<T> action)
Executes the provided
Callable and returning its output value,
while making sure that only one action can be run for the provided key |
<T> T |
synchronizeOn(K key,
long time,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.Callable<T> action)
Will attempt to executes the provided
Callable and return its output value,
while making sure that only one action can be run for the provided key. |
void |
synchronizeOn(K key,
long time,
java.util.concurrent.TimeUnit unit,
Task action)
Will attempt to executes the provided
Task while making sure that only one action
can be run for the provided key. |
void |
synchronizeOn(K key,
Task action)
Executes the provided
Task while making sure that only one action
can be run for the provided key |
void |
synchronizeRunnableOn(K key,
long time,
java.util.concurrent.TimeUnit unit,
java.lang.Runnable action)
Will attempt to executes the provided
Runnable while making sure that only one action
can be run for the provided key. |
void |
synchronizeRunnableOn(K key,
java.lang.Runnable action)
Executes the provided
Runnable while making sure that only one action
can be run for the provided key |
public <T> T synchronizeOn(K key, java.util.concurrent.Callable<T> action) throws WrappedException
Callable and returning its output value,
while making sure that only one action can be run for the provided keykey - value should be used for synchronization/locking purposesaction - action that should be executedaction parameterWrappedException - any exception thrown from the provided action is wrapped into a WrappedExceptionpublic <T> T synchronizeOn(K key, long time, java.util.concurrent.TimeUnit unit, java.util.concurrent.Callable<T> action) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException, WrappedException
Callable and return its output value,
while making sure that only one action can be run for the provided key.
In case the lock can't be acquired within given time an TimeoutException is thrown.key - value should be used for synchronization/locking purposestime - the maximum time to wait for the lockunit - the time unit of the time argumentaction - action that should be executedaction parameterjava.util.concurrent.TimeoutException - if we can't acquire lock within the defined timejava.lang.InterruptedException - if the current thread is interrupted before acquiring the lockWrappedException - any exception thrown from the provided action is wrapped into a WrappedExceptionpublic void synchronizeRunnableOn(K key, java.lang.Runnable action) throws WrappedException
Runnable while making sure that only one action
can be run for the provided keykey - value should be used for synchronization/locking purposesaction - action that should be executedWrappedException - any exception thrown from the provided action is wrapped into a WrappedExceptionpublic void synchronizeRunnableOn(K key, long time, java.util.concurrent.TimeUnit unit, java.lang.Runnable action) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException, WrappedException
Runnable while making sure that only one action
can be run for the provided key.
In case the lock can't be acquired within given time an TimeoutException is thrown.key - value should be used for synchronization/locking purposestime - the maximum time to wait for the lockunit - the time unit of the time argumentaction - action that should be executedjava.util.concurrent.TimeoutException - if we can't acquire lock within the defined timejava.lang.InterruptedException - if the current thread is interrupted before acquiring the lockWrappedException - any exception thrown from the provided action is wrapped into a WrappedExceptionpublic void synchronizeOn(K key, Task action) throws WrappedException
Task while making sure that only one action
can be run for the provided keykey - value should be used for synchronization/locking purposesaction - action that should be executedWrappedException - any exception thrown from the provided action is wrapped into a WrappedExceptionpublic void synchronizeOn(K key, long time, java.util.concurrent.TimeUnit unit, Task action) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException, WrappedException
Task while making sure that only one action
can be run for the provided key.
In case the lock can't be acquired within given time an TimeoutException is thrown.key - value should be used for synchronization/locking purposestime - the maximum time to wait for the lockunit - the time unit of the time argumentaction - action that should be executedjava.util.concurrent.TimeoutException - if we can't acquire lock within the defined timejava.lang.InterruptedException - if the current thread is interrupted before acquiring the lockWrappedException - any exception thrown from the provided action is wrapped into a WrappedException