FileDocCategorySizeDatePackage
AsynchronousTaskImpl.javaAPI DocJBoss 4.2.15699Fri Jul 13 21:02:30 BST 2007org.jboss.aspects.asynchronous.concurrent

AsynchronousTaskImpl

public final class AsynchronousTaskImpl extends Object implements org.jboss.aspects.asynchronous.AsynchronousConstants, org.jboss.aspects.asynchronous.concurrent.AsynchronousTask
author
{Claude Hussenet Independent Consultant}.
version
$Revision: 57186 $

Fields Summary
private long
_timeout
private org.jboss.aspects.asynchronous.AsynchronousParameters
_inputParametersImpl
private org.jboss.aspects.asynchronous.AsynchronousUserTask
_oneInstance
private EDU.oswego.cs.dl.util.concurrent.FutureResult
_futureResult
private EDU.oswego.cs.dl.util.concurrent.Callable
_callable
private String
_id
Constructors Summary
AsynchronousTaskImpl(String id, String taskImpl, org.jboss.aspects.asynchronous.AsynchronousParameters inputParametersImpl, long timeout)


    

                         

                         

                         
   

      this._id = id;

      _futureResult = new FutureResult();

      _timeout = timeout;

      _inputParametersImpl = inputParametersImpl;

      try
      {

         Class aClass = Class.forName(taskImpl);

         _oneInstance = (AsynchronousUserTask) aClass.newInstance();

      }
      catch (Exception e)
      {
         e.printStackTrace();

      }

   
AsynchronousTaskImpl(String id, org.jboss.aspects.asynchronous.AsynchronousUserTask userTask, org.jboss.aspects.asynchronous.AsynchronousParameters inputParametersImpl, long timeout)


      this._id = id;

      _futureResult = new FutureResult();

      _timeout = timeout;

      _oneInstance = userTask;

      _inputParametersImpl = inputParametersImpl;

   
Methods Summary
public java.lang.Runnableadd()


      try
      {

         if (_timeout == 0)

            _callable =

            new AdapterTask(getId(),

            _inputParametersImpl,

            _oneInstance);

         else

            _callable =

            new TimedCallableImpl(new AdapterTask(getId(),

            _inputParametersImpl,

            _oneInstance),

            _timeout);

         return _futureResult.setter(_callable);


      }
      catch (Exception e)
      {


         throw e;

      }

   
public longgetEndingTime()


      return ((ProcessingTime) _callable).getEndingTime();

   
public java.lang.StringgetId()


      return _id;

   
public org.jboss.aspects.asynchronous.AsynchronousParametersgetInputParameters()


      return _inputParametersImpl;

   
public org.jboss.aspects.asynchronous.ThreadManagerResponsegetResponse()


      try
      {

         if (isDone())

            return (ThreadManagerResponse) _futureResult.get();

         else
         {

            Object value = _futureResult.get();

            if (value != null)

               return (ThreadManagerResponse) value;

            else

               return new ThreadManagerResponseImpl(getId(),

               NOVALUE,

               null,

               null);

         }

      }
      catch (TimeoutException e)
      {

         return new ThreadManagerResponseImpl(getId(),

         TIMEOUT,

         e.getMessage(),

         e,

         getStartingTime(),

         getEndingTime());

      }
      catch (InterruptedException e)
      {

         return new ThreadManagerResponseImpl(getId(),

         INTERRUPTED,

         e.getMessage(),

         e,

         getStartingTime(),

         getEndingTime());

      }
      catch (InvocationTargetException e)
      {

         int errorCode = INVOCATION;

         if (e.getTargetException()

         instanceof EDU.oswego.cs.dl.util.concurrent.TimeoutException)

            errorCode = TIMEOUT;

         return new ThreadManagerResponseImpl(getId(),

         errorCode,

         e.getTargetException().getMessage(),

         e.getTargetException(),

         getStartingTime(),

         getEndingTime());

      }

   
public longgetStartingTime()


      return ((ProcessingTime) _callable).getStartingTime();

   
public org.jboss.aspects.asynchronous.AsynchronousUserTaskgetTask()


      return _oneInstance;

   
public longgetTimeout()


      return _timeout;

   
public booleanisDone()


      return _futureResult.isReady();