ibspan.ecap.merchant.shopdecisions.forecasting
Class ForecastingModule

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

public class ForecastingModule
extends java.lang.Object

A subsystem responsible for preparing product sales forecasts. Designed as a singleton.

Author:
Micha³ Drozdowicz

Method Summary
static ForecastingModule getInstance()
           
 boolean isRecordsForecasts()
           
 ForecastDescription pollResult(long millisecondsTimeout)
          Performs a blocking receive of a completed forecasting task with a timeout.
 void prepareForecast(java.lang.String productId)
          Schedules an immediate preparation of a sales forecast for the specified product.
 void setRecordsForecasts(boolean recordsForecasts)
           
 void startForecasting(java.lang.String productId)
          Starts forecasting of the given product.
 void stopForecasting(java.lang.String productId)
          Withdraws the product from periodic sales forecasting and cancels all the scheduled forecasts.
 ForecastDescription takeResult()
          Performs a blocking receive of a completed forecasting task.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ForecastingModule getInstance()
Returns:
the instance of the ForecastingModule class.

startForecasting

public void startForecasting(java.lang.String productId)
Starts forecasting of the given product. Registers the product for periodic forecast updates and schedules an immediate preparation of the forecast.

Parameters:
productId - the id of the product to be forecasted.

stopForecasting

public void stopForecasting(java.lang.String productId)
Withdraws the product from periodic sales forecasting and cancels all the scheduled forecasts.

Parameters:
productId - the id of the product to be withdrawn from forecast.

prepareForecast

public void prepareForecast(java.lang.String productId)
Schedules an immediate preparation of a sales forecast for the specified product.

Parameters:
productId - the id of the product to be forecasted.

takeResult

public ForecastDescription takeResult()
                               throws java.lang.InterruptedException,
                                      java.util.concurrent.ExecutionException
Performs a blocking receive of a completed forecasting task. Returns only after a task has completed or when the thread has been interrupted.

Returns:
a forecast task result
Throws:
java.lang.InterruptedException - when the thread has been interrupted while it was waiting for a result
java.util.concurrent.ExecutionException - when an exception occurred during the calculation of the forecast.

pollResult

public ForecastDescription pollResult(long millisecondsTimeout)
                               throws java.lang.InterruptedException,
                                      java.util.concurrent.ExecutionException
Performs a blocking receive of a completed forecasting task with a timeout. Returns after a task has completed, when the timeout period specified in millisecondsTimeout has elapsed or when the thread has been interrupted.

Parameters:
millisecondsTimeout - the timeout after which the method should return regardless of whether a result has been completed
Returns:
a forecast task result if it has completed or null if the timeout has elapsed
Throws:
java.lang.InterruptedException - when the thread has been interrupted while it was waiting for a result
java.util.concurrent.ExecutionException - when an exception occurred during the calculation of the forecast.

isRecordsForecasts

public boolean isRecordsForecasts()

setRecordsForecasts

public void setRecordsForecasts(boolean recordsForecasts)