ibspan.ecap.merchant.shopdecisions.forecasting
Class ScheduledForecastRunner

java.lang.Object
  extended by ibspan.ecap.merchant.shopdecisions.forecasting.ScheduledForecastRunner

public class ScheduledForecastRunner
extends java.lang.Object

A class responsible for running forecast tasks at the specified times.

Author:
Micha³ Drozdowicz

Constructor Summary
ScheduledForecastRunner()
           
 
Method Summary
 void cancelProductForecasts(java.lang.String productId)
          Cancels forecasts for the specified product.
 java.util.concurrent.Future<ForecastDescription> executeForecast(ForecastTask task)
          Immediately executes the specified task.
 ForecastTask pollForecastResult()
          Performs a non-blocking receive of a finished task.
 ForecastTask pollForecastResult(long millisecondsTimeout)
          Performs a blocking receive of a finished task with a timeout.
 java.util.concurrent.Future<ForecastDescription> scheduleForecast(ForecastTask task)
          Schedules a ForecastTask for execution.
 ForecastTask takeCompletedTask()
          Performs a blocking receive of a finished task.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScheduledForecastRunner

public ScheduledForecastRunner()
Method Detail

scheduleForecast

public java.util.concurrent.Future<ForecastDescription> scheduleForecast(ForecastTask task)
Schedules a ForecastTask for execution. The task will be run at the time specified by its forecast start date retrieved with the task.getForecastStart method.

Parameters:
task - the task to be executed
Returns:
the Future describing the future result of the task.

executeForecast

public java.util.concurrent.Future<ForecastDescription> executeForecast(ForecastTask task)
Immediately executes the specified task.

Parameters:
task - the task to be executed
Returns:
the Future describing the future result of the task.

takeCompletedTask

public ForecastTask takeCompletedTask()
                               throws java.lang.InterruptedException
Performs a blocking receive of a finished task. Blocks the execution of the calling thread until a task completes and the result is available.

Returns:
a completed forecast task.
Throws:
java.lang.InterruptedException - when the calling thread has been interrupted while waiting for the result

pollForecastResult

public ForecastTask pollForecastResult(long millisecondsTimeout)
                                throws java.lang.InterruptedException
Performs a blocking receive of a finished task with a timeout. Blocks the execution of the calling thread until a task completes and the result is available or until the timeout has elapsed.

Parameters:
millisecondsTimeout - the timeout in millis after which the method should return regardless of the availability of the result.
Returns:
a completed forecast task or null if the method timed out before receiving a result.
Throws:
java.lang.InterruptedException - when the calling thread has been interrupted while waiting for the result

pollForecastResult

public ForecastTask pollForecastResult()
Performs a non-blocking receive of a finished task.

Returns:
a completed forecast task if it was available at the time of calling the method or null otherwise

cancelProductForecasts

public void cancelProductForecasts(java.lang.String productId)
Cancels forecasts for the specified product.

Parameters:
productId - the global id of the product, which forecasts are to be cancelled.