org.jboss.messaging.utils
Class VariableLatch

java.lang.Object
  extended by org.jboss.messaging.utils.VariableLatch

public class VariableLatch
extends java.lang.Object

This class will use the framework provided to by AbstractQueuedSynchronizer.

AbstractQueuedSynchronizer is the framework for any sort of concurrent synchronization, such as Semaphores, events, etc, based on AtomicIntegers.

The idea is, instead of providing each user specific Latch/Synchronization, java.util.concurrent provides the framework for reuses, based on an AtomicInteger (getState())

On JBossMessaging we have the requirement of increment and decrement a counter until the user fires a ready event (commit). At that point we just act as a regular countDown.

Note: This latch is reusable. Once it reaches zero, you can call up again, and reuse it on further waits.

For example: prepareTransaction will wait for the current completions, and further adds will be called on the latch. Later on when commit is called you can reuse the same latch.

Author:
Clebert Suconic

Constructor Summary
VariableLatch()
           
 
Method Summary
 void down()
           
 int getCount()
           
 void up()
           
 void waitCompletion()
           
 boolean waitCompletion(long milliseconds)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableLatch

public VariableLatch()
Method Detail

getCount

public int getCount()

up

public void up()

down

public void down()

waitCompletion

public void waitCompletion()
                    throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

waitCompletion

public boolean waitCompletion(long milliseconds)
                       throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException


Copyright © 2006 JBoss Inc. All Rights Reserved.