net.sourceforge.domian.util.concurrent.locks
Class SemaphoreSynchronizer

java.lang.Object
  extended by net.sourceforge.domian.util.concurrent.locks.SemaphoreSynchronizer
All Implemented Interfaces:
Synchronizer

public final class SemaphoreSynchronizer
extends java.lang.Object
implements Synchronizer

A Synchronizer implementation using two Semaphore instances.

Since:
0.4
Author:
Eirik Torske

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.sourceforge.domian.util.concurrent.locks.Synchronizer
Synchronizer.MODE
 
Constructor Summary
SemaphoreSynchronizer()
           
 
Method Summary
<T,C extends java.util.concurrent.Callable<T>>
T
callConcurrently(C callable)
          Calls a Callable in a concurrent manner.
<T,C extends java.util.concurrent.Callable<T>>
T
callExclusively(C callable)
          Calls a Callable in an exclusive manner.
<R extends java.lang.Runnable>
void
runConcurrently(R runnable)
          Runs a Runnable in a concurrent manner.
<R extends java.lang.Runnable>
void
runExclusively(R runnable)
          Runs a Runnable in an exclusive manner.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SemaphoreSynchronizer

public SemaphoreSynchronizer()
Method Detail

runConcurrently

public <R extends java.lang.Runnable> void runConcurrently(R runnable)
Description copied from interface: Synchronizer
Runs a Runnable in a concurrent manner.

Specified by:
runConcurrently in interface Synchronizer
Parameters:
runnable - the runnable to invoke concurrently, managed by this class

callConcurrently

public <T,C extends java.util.concurrent.Callable<T>> T callConcurrently(C callable)
Description copied from interface: Synchronizer
Calls a Callable in a concurrent manner.

Specified by:
callConcurrently in interface Synchronizer
Parameters:
callable - the callable to invoke concurrently, managed by this class
Returns:
the Callable's return value, or null if no return value

runExclusively

public <R extends java.lang.Runnable> void runExclusively(R runnable)
Description copied from interface: Synchronizer
Runs a Runnable in an exclusive manner. Firstly, it will wait for all other exclusive Runnables and Callables to finish, if any. Then it will wait for already running concurrent Runnables and Callables to finish, if any. Finally it will run, queuing up all other Runnables and Callables managed by the same Synchronizer instance. When done, all queues are released.

Specified by:
runExclusively in interface Synchronizer
Parameters:
runnable - the runnable to invoke exclusively, managed by this class

callExclusively

public <T,C extends java.util.concurrent.Callable<T>> T callExclusively(C callable)
Description copied from interface: Synchronizer
Calls a Callable in an exclusive manner. Firstly, it will wait for all other exclusive Runnables and Callables to finish, if any. Then it will wait for already running concurrent Runnables and Callables to finish, if any. Finally it will run, queuing up all other Runnables and Callables managed by the same Synchronizer instance. When done, all queues are released.

Specified by:
callExclusively in interface Synchronizer
Parameters:
callable - the callable to invoke exclusively, managed by this class
Returns:
the Callable's return value, or null if no return value


Copyright © 2006-2010. All Rights Reserved.