com.google.code.yanf4j.core.impl
Class FutureLockImpl<R>

java.lang.Object
  extended by com.google.code.yanf4j.core.impl.FutureLockImpl<R>
All Implemented Interfaces:
java.util.concurrent.Future<R>

public class FutureLockImpl<R>
extends java.lang.Object
implements java.util.concurrent.Future<R>

Simple Future implementation, which uses ReentrantLock to synchronize during the lifecycle.

Author:
Alexey Stashok
See Also:
Future, ReentrantLock

Field Summary
protected  R result
           
 
Constructor Summary
FutureLockImpl()
           
FutureLockImpl(java.util.concurrent.locks.ReentrantLock lock)
           
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
          
 void failure(java.lang.Throwable failure)
          Notify about the failure, occured during asynchronous operation execution.
 R get()
          
 R get(long timeout, java.util.concurrent.TimeUnit unit)
          
 R getResult()
          Get current result value without any blocking.
 boolean isCancelled()
          
 boolean isDone()
          
protected  void notifyHaveResult()
          Notify blocked listeners threads about operation completion.
 void setResult(R result)
          Set the result value and notify about operation completion.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

result

protected R result
Constructor Detail

FutureLockImpl

public FutureLockImpl()

FutureLockImpl

public FutureLockImpl(java.util.concurrent.locks.ReentrantLock lock)
Method Detail

getResult

public R getResult()
Get current result value without any blocking.

Returns:
current result value without any blocking.

setResult

public void setResult(R result)
Set the result value and notify about operation completion.

Parameters:
result - the result value

cancel

public boolean cancel(boolean mayInterruptIfRunning)

Specified by:
cancel in interface java.util.concurrent.Future<R>

isCancelled

public boolean isCancelled()

Specified by:
isCancelled in interface java.util.concurrent.Future<R>

isDone

public boolean isDone()

Specified by:
isDone in interface java.util.concurrent.Future<R>

get

public R get()
      throws java.lang.InterruptedException,
             java.util.concurrent.ExecutionException

Specified by:
get in interface java.util.concurrent.Future<R>
Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException

get

public R get(long timeout,
             java.util.concurrent.TimeUnit unit)
      throws java.lang.InterruptedException,
             java.util.concurrent.ExecutionException,
             java.util.concurrent.TimeoutException

Specified by:
get in interface java.util.concurrent.Future<R>
Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException

failure

public void failure(java.lang.Throwable failure)
Notify about the failure, occured during asynchronous operation execution.

Parameters:
failure -

notifyHaveResult

protected void notifyHaveResult()
Notify blocked listeners threads about operation completion.



Copyright © 2011. All Rights Reserved.