Interface Poller<T>

  • All Known Implementing Classes:
    DirectPoller

    public interface Poller<T>
    Interface for polling a Callable instance provided by the user. Use when you need to put something in the background (e.g. a remote invocation) and wait for the result, e.g.
     Poller<Result> poller = ...
     
     final long id = remoteService.execute(); // do something remotely
     
     Future<Result> future = poller.poll(new Callable<Result> {
         public Object call() {
               // Look for the result (null if not ready)
               return remoteService.get(id);
         }
     });
     
     Result result = future.get(1000L, TimeUnit.MILLISECONDS);
     
    Author:
    Dave Syer, Mahmoud Ben Hassine
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and TypeMethodDescription
      java.util.concurrent.Future<T>poll​(java.util.concurrent.Callable<T> callable)
      Use the callable provided to poll for a non-null result.
    • Method Detail

      • poll

        java.util.concurrent.Future<T> poll​(java.util.concurrent.Callable<T> callable)
                                     throws java.lang.Exception
        Use the callable provided to poll for a non-null result. The callable might be executed multiple times searching for a result, but once either a result or an exception has been observed the polling stops.
        Parameters:
        callable - a Callable to use to retrieve a result
        Returns:
        a future which itself can be used to get the result
        Throws:
        java.lang.Exception - allows for checked exceptions