Package commonj.work

Examples of commonj.work.WorkItem


      if ( work == null )
      {
         throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_WORK) );
      }

      WorkItem workItem = new WorkItemImpl(  );

      this.workItems.put( work, workItem );

      try
      {
View Full Code Here


   public boolean waitForAll( Collection workItems,
                              long       timeout )
   {
      Iterator workItemsIterator = workItems.iterator(  );
      Object   current;
      WorkItem workItem;
      int      status;

      if ( timeout == WorkManager.IMMEDIATE )
      {
         while ( workItemsIterator.hasNext(  ) )
         {
            current = workItemsIterator.next(  );
            if ( current instanceof WorkItem )
            {
               status = ( (WorkItem) current ).getStatus(  );
               if ( ( status != WorkEvent.WORK_COMPLETED ) && ( status != WorkEvent.WORK_REJECTED ) )
               {
                  return false;
               }
            }
         }
      }
      else if ( timeout == WorkManager.INDEFINITE )
      {
         while ( workItemsIterator.hasNext(  ) )
         {
            current = workItemsIterator.next(  );
            if ( current instanceof WorkItem )
            {
               workItem = (WorkItem) current;
               synchronized ( workItem )
               {
                  status = workItem.getStatus(  );
                  while ( ( status != WorkEvent.WORK_COMPLETED ) && ( status != WorkEvent.WORK_REJECTED ) )
                  {
                     try
                     {
                        workItem.wait(  );
                     }
                     catch ( InterruptedException e )
                     {
                        // not sure if this is the right thing to do
                        return false;
                     }

                     status = workItem.getStatus(  );
                  }
               }
            }
         }
      }
      else
      {
         long absTimeout = System.currentTimeMillis(  ) + timeout;
         while ( workItemsIterator.hasNext(  ) )
         {
            current = workItemsIterator.next(  );
            if ( current instanceof WorkItem )
            {
               workItem = (WorkItem) current;
               synchronized ( workItem )
               {
                  status = workItem.getStatus(  );
                  while ( ( status != WorkEvent.WORK_COMPLETED ) && ( status != WorkEvent.WORK_REJECTED ) )
                  {
                     if ( timeout > 0 )
                     {
                        try
                        {
                           workItem.wait( timeout );
                        }
                        catch ( InterruptedException e )
                        {
                           // not sure if this is the right thing to do
                           return false;
                        }

                        timeout = absTimeout - System.currentTimeMillis(  );
                     }
                     else
                     {
                        return false;
                     }

                     status = workItem.getStatus(  );
                  }
               }
            }
         }
      }
View Full Code Here

   public Collection waitForAny( Collection workItems,
                                 long       timeout )
   {
      Iterator   workItemsIterator = workItems.iterator(  );
      Object     current;
      WorkItem   workItem;
      int        status;
      Collection result = new Vector(  );

      if ( timeout == WorkManager.IMMEDIATE )
      {
         while ( workItemsIterator.hasNext(  ) )
         {
            current = workItemsIterator.next(  );
            if ( current instanceof WorkItem )
            {
               workItem    = (WorkItem) current;
               status      = workItem.getStatus(  );
               if ( ( status == WorkEvent.WORK_COMPLETED ) || ( status == WorkEvent.WORK_REJECTED ) )
               {
                  result.add( workItem );
               }
            }
         }
      }
      else if ( timeout == WorkManager.INDEFINITE )
      {
         if ( this.waitForAll( workItems, timeout ) )
         {
            return workItems;
         }
         else
         {
            return null;
         }
      }
      else
      {
         long absTimeout = System.currentTimeMillis(  ) + timeout;
         while ( workItemsIterator.hasNext(  ) )
         {
            current = workItemsIterator.next(  );
            if ( current instanceof WorkItem )
            {
               workItem = (WorkItem) current;
               synchronized ( workItem )
               {
                  status = workItem.getStatus(  );
                  while ( ( status != WorkEvent.WORK_COMPLETED )
                          && ( status != WorkEvent.WORK_REJECTED )
                          && ( timeout > 0 ) )
                  {
                     try
                     {
                        workItem.wait( timeout );
                     }
                     catch ( InterruptedException e )
                     {
                        // not sure if this is the right thing to do
                        return null;
                     }

                     timeout    = absTimeout - System.currentTimeMillis(  );
                     status     = workItem.getStatus(  );
                  }

                  if ( ( status == WorkEvent.WORK_COMPLETED ) || ( status == WorkEvent.WORK_REJECTED ) )
                  {
                     result.add( workItem );
View Full Code Here

      /* (non-Javadoc)
       * @see java.lang.Runnable#run()
       */
      public void run(  )
      { //todo fix this
         WorkItem  workItem = new WorkItemImpl(  );

         WorkEvent event = new WorkEventImpl( WorkEvent.WORK_STARTED, workItem );
         processEvent( event );
         if ( this.listener != null )
         {
View Full Code Here

      if ( work == null )
      {
         throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_WORK) );
      }

      WorkItem workItem = new WorkItemImpl(  );

      this.workItems.put( work, workItem );

      try
      {
View Full Code Here

   public boolean waitForAll( Collection workItems,
                              long       timeout )
   {
      Iterator workItemsIterator = workItems.iterator(  );
      Object   current;
      WorkItem workItem;
      int      status;

      if ( timeout == WorkManager.IMMEDIATE )
      {
         while ( workItemsIterator.hasNext(  ) )
         {
            current = workItemsIterator.next(  );
            if ( current instanceof WorkItem )
            {
               status = ( (WorkItem) current ).getStatus(  );
               if ( ( status != WorkEvent.WORK_COMPLETED ) && ( status != WorkEvent.WORK_REJECTED ) )
               {
                  return false;
               }
            }
         }
      }
      else if ( timeout == WorkManager.INDEFINITE )
      {
         while ( workItemsIterator.hasNext(  ) )
         {
            current = workItemsIterator.next(  );
            if ( current instanceof WorkItem )
            {
               workItem = (WorkItem) current;
               synchronized ( workItem )
               {
                  status = workItem.getStatus(  );
                  while ( ( status != WorkEvent.WORK_COMPLETED ) && ( status != WorkEvent.WORK_REJECTED ) )
                  {
                     try
                     {
                        workItem.wait(  );
                     }
                     catch ( InterruptedException e )
                     {
                        // not sure if this is the right thing to do
                        return false;
                     }

                     status = workItem.getStatus(  );
                  }
               }
            }
         }
      }
      else
      {
         long absTimeout = System.currentTimeMillis(  ) + timeout;
         while ( workItemsIterator.hasNext(  ) )
         {
            current = workItemsIterator.next(  );
            if ( current instanceof WorkItem )
            {
               workItem = (WorkItem) current;
               synchronized ( workItem )
               {
                  status = workItem.getStatus(  );
                  while ( ( status != WorkEvent.WORK_COMPLETED ) && ( status != WorkEvent.WORK_REJECTED ) )
                  {
                     if ( timeout > 0 )
                     {
                        try
                        {
                           workItem.wait( timeout );
                        }
                        catch ( InterruptedException e )
                        {
                           // not sure if this is the right thing to do
                           return false;
                        }

                        timeout = absTimeout - System.currentTimeMillis(  );
                     }
                     else
                     {
                        return false;
                     }

                     status = workItem.getStatus(  );
                  }
               }
            }
         }
      }
View Full Code Here

   public Collection waitForAny( Collection workItems,
                                 long       timeout )
   {
      Iterator   workItemsIterator = workItems.iterator(  );
      Object     current;
      WorkItem   workItem;
      int        status;
      Collection result = new Vector(  );

      if ( timeout == WorkManager.IMMEDIATE )
      {
         while ( workItemsIterator.hasNext(  ) )
         {
            current = workItemsIterator.next(  );
            if ( current instanceof WorkItem )
            {
               workItem    = (WorkItem) current;
               status      = workItem.getStatus(  );
               if ( ( status == WorkEvent.WORK_COMPLETED ) || ( status == WorkEvent.WORK_REJECTED ) )
               {
                  result.add( workItem );
               }
            }
         }
      }
      else if ( timeout == WorkManager.INDEFINITE )
      {
         if ( this.waitForAll( workItems, timeout ) )
         {
            return workItems;
         }
         else
         {
            return null;
         }
      }
      else
      {
         long absTimeout = System.currentTimeMillis(  ) + timeout;
         while ( workItemsIterator.hasNext(  ) )
         {
            current = workItemsIterator.next(  );
            if ( current instanceof WorkItem )
            {
               workItem = (WorkItem) current;
               synchronized ( workItem )
               {
                  status = workItem.getStatus(  );
                  while ( ( status != WorkEvent.WORK_COMPLETED )
                          && ( status != WorkEvent.WORK_REJECTED )
                          && ( timeout > 0 ) )
                  {
                     try
                     {
                        workItem.wait( timeout );
                     }
                     catch ( InterruptedException e )
                     {
                        // not sure if this is the right thing to do
                        return null;
                     }

                     timeout    = absTimeout - System.currentTimeMillis(  );
                     status     = workItem.getStatus(  );
                  }

                  if ( ( status == WorkEvent.WORK_COMPLETED ) || ( status == WorkEvent.WORK_REJECTED ) )
                  {
                     result.add( workItem );
View Full Code Here

      /* (non-Javadoc)
       * @see java.lang.Runnable#run()
       */
      public void run(  )
      { //todo fix this
         WorkItem  workItem = new WorkItemImpl(  );

         WorkEvent event = new WorkEventImpl( WorkEvent.WORK_STARTED, workItem );
         processEvent( event );
         if ( this.listener != null )
         {
View Full Code Here

        job.setWorkerAttribute(ACCESS_CONTROL_CONTEXT_WORKER_ATTR, context);
       
        try
        {
            RenderingJobCommonjWork jobWork = new RenderingJobCommonjWork(job);
            WorkItem workItem = this.workManager.schedule(jobWork, this);
            job.setWorkerAttribute(COMMONJ_WORK_ITEM_ATTR, workItem);
           
            if (this.jobWorksMonitorEnabled)
            {
                this.jobWorksMonitored.put(workItem, jobWork);
View Full Code Here

                    Object lock = new Object();
                    MonitoringJobCommonjWork monitoringWork = new MonitoringJobCommonjWork(lock, renderingJobs);
                   
                    synchronized (lock)
                    {
                        WorkItem monitorWorkItem = this.workManager.schedule(monitoringWork, this);
                        lock.wait();
                    }
                }
            }
            catch (Exception e)
View Full Code Here

TOP

Related Classes of commonj.work.WorkItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.