org.jvnet.hk2.component
Class AsyncWaiter

java.lang.Object
  extended by org.jvnet.hk2.component.AsyncWaiter

public class AsyncWaiter
extends Object

Helper class that will manage all AsyncPostConstruct services and Futures for completion.

Once a service or Future is found to be completed, it is dropped.

Author:
Jeff Trent

Constructor Summary
AsyncWaiter()
           
 
Method Summary
 void clear()
          Clear the collection of watches, regardless of state.
 Inhabitant<?> getLastInhabitantWorkingOn()
          Returns the last Inhabitant that was working on, provided that we are not in a "done" state.
 int getWatches()
           
 boolean isDone()
          A non-blocking call that returns true when we are done waiting.
 void waitForDone()
          Waits for all watches to be done.
 boolean waitForDone(long timeout, TimeUnit unit)
          Wait's for all inhabitants being watched to be done, giving each up to timeout/unit's to be done.
 void watchIfNecessary(Future<?> f)
          Watches a Future for completion.
 void watchIfNecessary(Inhabitant<?> i)
          Watches an inhabitant if the service implements AsyncPostConstruct.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncWaiter

public AsyncWaiter()
Method Detail

clear

public void clear()
Clear the collection of watches, regardless of state.


watchIfNecessary

public void watchIfNecessary(Inhabitant<?> i)
Watches an inhabitant if the service implements AsyncPostConstruct.


watchIfNecessary

public void watchIfNecessary(Future<?> f)
Watches a Future for completion.


waitForDone

public void waitForDone()
                 throws ExecutionException,
                        TimeoutException,
                        InterruptedException
Waits for all watches to be done. This might be a blocking operation.

Throws:
ExecutionException
TimeoutException
InterruptedException

waitForDone

public boolean waitForDone(long timeout,
                           TimeUnit unit)
                    throws ExecutionException,
                           TimeoutException,
                           InterruptedException
Wait's for all inhabitants being watched to be done, giving each up to timeout/unit's to be done. If there are any TimeoutExceptions the result will be false.

Throws:
ExecutionException
TimeoutException
InterruptedException

getWatches

public int getWatches()

isDone

public boolean isDone()
A non-blocking call that returns true when we are done waiting.


getLastInhabitantWorkingOn

public Inhabitant<?> getLastInhabitantWorkingOn()
Returns the last Inhabitant that was working on, provided that we are not in a "done" state.



Copyright © 2011 Oracle Corporation. All Rights Reserved.