如何从DeferredTask获得结果?

时间:2013-04-03 01:09:37

标签: google-app-engine

在DeferredTask的run方法结束时,我必须通知一个对象来提取run()方法的结果。我该怎么做?

// Not Serializable
public class DeferredTaskTrigger
{
  protected int resultAggregate_ = 0 ;

  protected void addToQueue()
  {  
    Queue queue = QueueFactory.getDefaultQueue() ;
    DeferredTaskTrial1 deferredTaskTrial1 = new DeferredTaskTrial1() ;
    TaskOptions taskOptions = TaskOptions.Builder.withPayload(deferredTaskTrial1) ;   
    TaskHandle taskHandle = queue.add(taskOptions) ;      
  }
  // This object calls addToQueue() hundreds of times and accumulates the results of  DeferredTaskTrial1 objects in resultAggregate_ .
}

public class DeferredTaskTrial1 implements DeferredTask
{
  protected int result_ = 0 ;

  public void run()
  {
    // processing code here.
    // .....

    // capture the result of processing.
    result_  = 1 ;

   //  how to get the reference of DeferredTaskTrigger here ? ( Apparently, no way.)
   //  how else I can notify the DeferredTaskTrigger object to extract the result_  ?
  }

}

由于 J.Ganesan

0 个答案:

没有答案