Package wowodc.eof

Examples of wowodc.eof.TaskInfo


  public TaskInfoController(WORequest request) {
    super(request);
  }

  public WOActionResults createAction() throws Throwable {
    TaskInfo taskInfo = ERXEOControlUtilities.createAndInsertObject(editingContext(), TaskInfo.class);
    taskInfo.setDuration(Long.valueOf(15000));
    taskInfo.setStartNumber(Utilities.newStartNumber());
    taskInfo.setStartTime(new NSTimestamp());

    editingContext().saveChanges();
   
    T10RestEOFTask taskInfoGID = new T10RestEOFTask();
    taskInfoGID.setTaskGID(taskInfo.__globalID());

    ERXFutureTask<?> _future = new ERXFutureTask(taskInfoGID);
    ERXExecutorService.executorService().execute(_future);

    ERXRouteResults results = (ERXRouteResults)response(taskInfo, ERXKeyFilter.filterWithAttributesAndToOneRelationships());   
View Full Code Here


    response.setStatus(ERXHttpStatusCodes.ACCEPTED);
    return response; 
  }
 
  public WOActionResults showAction() throws Throwable {
    TaskInfo taskInfo = routeObjectForKey("taskInfo");
    if (TaskInfo.WORKFLOW_PRIME_CHECKED.equals(taskInfo.workflowState())) {
      ERXRouteResults results = (ERXRouteResults)response(taskInfo, ERXKeyFilter.filterWithNone());   
      WOResponse response = results.generateResponse();
      String location = hostName() + ERXRouteUrlUtils.actionUrlForRecord(_context, taskInfo, "results", format().name(), new NSDictionary(), request().isSecure(), request().isSessionIDInRequest());
      response.setHeader(location, "Content-Location");
      response.setStatus(ERXHttpStatusCodes.SEE_OTHER);
      return response;
    }
    return response(taskInfo.workflowState(), ERXKeyFilter.filterWithAttributes());
  }
View Full Code Here

    }
    return response(taskInfo.workflowState(), ERXKeyFilter.filterWithAttributes());
  }
 
  public WOActionResults resultsAction() throws Throwable {
    TaskInfo taskInfo = routeObjectForKey("taskInfo");
    return response(taskInfo, ERXKeyFilter.filterWithAttributesAndToOneRelationships());
  }
View Full Code Here

    ec.lock();
    try {
      // Array for monitoring completed tasks to ensure normal completion
      NSMutableArray<Future<?>> childFutures = new NSMutableArray<Future<?>>();
      // Create the new TaskInfo
      TaskInfo taskInfo = ERXEOControlUtilities.createAndInsertObject(ec, TaskInfo.class);
     
      // Task start time
      taskInfo.setStartTime(new NSTimestamp(startTime));
     
      taskInfo.setStartNumber(_startNumber);
      taskInfo.setDuration(_taskDuration);
     
      ec.saveChanges();
      _resultGid = ec.globalIDForObject(taskInfo);
      _parentTaskPrimaryKey = (Integer) taskInfo.rawPrimaryKey();
     
      // Initialize loop variables
      long childTaskStartNumber = _startNumber;
      int incrementQuantity = _childBatchBaseQuantity + Utilities.sharedRandom().nextInt(_childBatchBaseQuantity);
      long childTaskEndNumber =  childTaskStartNumber + incrementQuantity;
     
     
      // Loop for a period of time
      while (_elapsedTime < _taskDuration && !_isStopped) {
        ChildPrimeTask childTask = new ChildPrimeTask(_nextChildIDValue, _resultGid, childTaskStartNumber, childTaskEndNumber);
        _nextChildIDValue++;
       
        boolean isRejected = true;
        while (isRejected && !ChildTaskPool.EXECUTOR_SERVICE.isShutdown() && !_isStopped) {
          try {
            Future<?> future = ChildTaskPool.EXECUTOR_SERVICE.submit(childTask);
           
            if (log.isInfoEnabled())
              log.info("Submitted task corresponding to " + future);
            isRejected = false;
            childFutures.add(future);
           
            // For the sake of demo, we assume all child tasks complete their work.
            _endNumber = childTaskEndNumber;
          } catch (RejectedExecutionException e) {
            try {
              Thread.sleep(2000);
              removeCompletedFutures(childFutures);
            } catch (InterruptedException e1) {
              stop();
            }
          }
        }
       
        childTaskStartNumber = childTaskEndNumber + 1;
        incrementQuantity = _childBatchBaseQuantity + Utilities.sharedRandom().nextInt(_childBatchBaseQuantity * 2);
        childTaskEndNumber =  childTaskStartNumber + incrementQuantity;

        _elapsedTime = System.currentTimeMillis() - startTime;
       
        // Update progress variables
        _percentComplete = (double)(_elapsedTime) / (double)_taskDuration;
        _status = wholeNumberFormatter.format(_count) + " numbers checked for prime qualification";

      }
     
      if (_isStopped) {
        _status = "Stopped";
      }
     
      // Wait for all child tasks to finish
      while (childFutures.count() > 0) {
        removeCompletedFutures(childFutures);
        Thread.sleep(1000);
      }
     
      // Complete the stats
      // Refresh it since the object has been already updated (its relationship) and saved on ChildThreads
      ERXEOControlUtilities.refreshObject(taskInfo);
      taskInfo.setEndNumber(_endNumber);
      taskInfo.setEndTime(new NSTimestamp());
      taskInfo.setWorkflowState(TaskInfo.WORKFLOW_PRIME_CHECKED);
      ec.saveChanges();
     
      _resultGid = ec.globalIDForObject(taskInfo);
     
    } finally {
View Full Code Here

      EOEditingContext ec = newEditingContext();
      ec.lock();
      try {
        log.info("Started child in " + Thread.currentThread().getName() + " with OSC " + ec.parentObjectStore());
       
        TaskInfo taskInfo = (TaskInfo) ec.faultForGlobalID(_childTaskInfoGID, ec);
       
        while (_childCurrentNumber <= _childToNumber) {
          ResultItem resultItem = ERXEOControlUtilities.createAndInsertObject(ec, ResultItem.class);
          resultItem.setTaskInfo(taskInfo);
         
View Full Code Here

    // Create an EC and lock/try/finally/unlock.
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {
      //
      TaskInfo taskInfo = (TaskInfo)ERXEOGlobalIDUtilities.fetchObjectWithGlobalID(ec, taskGID);

      // Loop for a period of time
      while (_elapsedTime < DURATION && !_isStopped) {
        ResultItem resultItem = ERXEOControlUtilities.createAndInsertObject(taskInfo.editingContext(), ResultItem.class);
        resultItem.setTaskInfo(taskInfo);  

        resultItem.setNumberToCheck(_numberToCheck);

        if (Utilities.isPrime(_numberToCheck)) {
          log.info("==>> " + _numberToCheck + " is a PRIME number.");
          resultItem.setIsPrime(Boolean.TRUE);
        } else {
          log.debug(_numberToCheck + " is not a prime number but is a COMPOSITE number.");
          resultItem.setIsPrime(Boolean.FALSE);
        }
       
        ec.saveChanges();
       
        _elapsedTime = System.currentTimeMillis() - startTime;
       
        // Update progress variables
        _count++;
        _percentComplete = (double)(_elapsedTime) / (double)DURATION;
        _status = wholeNumberFormatter.format(_count) + " numbers checked for prime qualification";

        _numberToCheck++;
      }
     
      // Complete the stats
      taskInfo.setEndNumber(_numberToCheck - 1);
      taskInfo.setEndTime(new NSTimestamp());
      taskInfo.setWorkflowState(TaskInfo.WORKFLOW_PRIME_CHECKED);
     
      ec.saveChanges();
     
      _resultGid = ec.globalIDForObject(taskInfo);
     
View Full Code Here

      // We create an ec just for the sake of the constructor API on
      // T06EOFFactorialUpdateTask
      EOEditingContext ec = newEditingContext();
      ec.lock();
      try {
        TaskInfo taskInfo = (TaskInfo) ec.faultForGlobalID(_taskInfoGID, ec);
        _task2 = new T06EOFFactorialUpdateTask(taskInfo);
      } finally {
        ec.unlock();
      }
     
      // Sometimes it ise useful to share the parent OSC with a subtask to avoid data out of sync issues
      _task2.setParentObjectStore(parentObjectStore());
     
      // Here we show how the second task can be executed in yet another thread while this
      // thread waits for the result
     
     
      Future<EOGlobalID> future = ERXExecutorService.executorService().submit(_task2);
      // This next statement blocks until the task, running in another thread, is complete.
      _taskInfoGID = future.get();
     
      // Finally, overwrite the startTime and Duration to reflect this combo task
      // rather than the last task.
      ec = newEditingContext();
      ec.lock();
      try {
        TaskInfo taskInfo = (TaskInfo) ec.faultForGlobalID(_taskInfoGID, ec);
        taskInfo.setStartTime(new NSTimestamp(startTime));
        taskInfo.setDuration(Long.valueOf(taskInfo.endTime().getTime() - startTime));
        ec.saveChanges();
      } finally {
        ec.unlock();
      }
    }
View Full Code Here

    // Note we use the superclass convenience method here.
    EOEditingContext ec = newEditingContext();
    ec.lock();
    try {
      // Fetch the TaskInfo
      TaskInfo taskInfo = (TaskInfo) ec.faultForGlobalID(_taskInfoGID, ec);
      _totalCount = taskInfo.countResultItems().longValue();
     
      // Task start time
      // This is a demo, so we are going to replace the prime processing times with the factorial processing times
      taskInfo.setStartTime(new NSTimestamp(startTime));
     
      // For demo purposes we will use batches and EC recycling, which would be common for processing huge data sets
      ERXFetchSpecification<ResultItem> fs = taskInfo.fetchSpecificationForResultItems();
     
      // Batch iterator
      ERXFetchSpecificationBatchIterator fsIterator = new ERXFetchSpecificationBatchIterator(fs, ec);

      // Loop for a period of time
      while (fsIterator.hasNext() && !_isStopped) {
        @SuppressWarnings("unchecked")
        NSArray<ResultItem> batch = fsIterator.nextBatch();
       
        for (ResultItem resultItem : batch) {
          resultItem.setWorkflowState(ResultItem.WORKFLOW_CHECKING_FACTORIAL);
          performFactorialProcessing(resultItem);
          resultItem.setWorkflowState(ResultItem.WORKFLOW_PROCESSING_COMPLETE);

          ec.saveChanges();
         
         
          _elapsedTime = System.currentTimeMillis() - startTime;
         
          // Update progress variables
          _countCompleted++;
          _percentComplete = (double)(_countCompleted) / (double)_totalCount;
          _status = wholeNumberFormatter.format(_countCompleted) + " numbers checked for factorial proximity";
         
          if (_isStopped) {
            break;
          }

        }
       
        // Swap in a fresh EC for the next batch to help with memory management
        EOEditingContext freshEC = newEditingContext();
        ec.unlock();
        ec = freshEC;
        freshEC.lock();
       
        fsIterator.setEditingContext(ec);
       
        // We need to refault taskInfo into the new EC after swapping
        taskInfo = (TaskInfo) ec.faultForGlobalID(_taskInfoGID, ec);
       
      }
     
      // Complete the stats
      taskInfo.setEndTime(new NSTimestamp());
      taskInfo.setWorkflowState(TaskInfo.WORKFLOW_PROCESSING_COMPLETE);
     
      long duration = taskInfo.endTime().getTime() - taskInfo.startTime().getTime();
      taskInfo.setDuration(duration);
     
      ec.saveChanges();
     
    } finally {
      ec.unlock();
View Full Code Here

    // Create an EC and lock/try/finally/unlock.
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {
      // Create the new TaskInfo
      TaskInfo taskInfo = ERXEOControlUtilities.createAndInsertObject(ec, TaskInfo.class);
     
      // Task start time
      taskInfo.setStartTime(new NSTimestamp(startTime));
     
      taskInfo.setStartNumber(_numberToCheck);
      taskInfo.setDuration(DURATION);
     
      // Loop for a period of time
      while (_elapsedTime < DURATION && !_isStopped) {
        ResultItem resultItem = ERXEOControlUtilities.createAndInsertObject(ec, ResultItem.class);
        resultItem.setTaskInfo(taskInfo);
       
        resultItem.setNumberToCheck(_numberToCheck);

        if (Utilities.isPrime(_numberToCheck)) {
          log.info("==>> " + _numberToCheck + " is a PRIME number.");
          resultItem.setIsPrime(Boolean.TRUE);
        } else {
          log.debug(_numberToCheck + " is not a prime number but is a COMPOSITE number.");
          resultItem.setIsPrime(Boolean.FALSE);
        }
       
        ec.saveChanges();
       
       
        _elapsedTime = System.currentTimeMillis() - startTime;
       
        // Update progress variables
        _count++;
        _percentComplete = (double)(_elapsedTime) / (double)DURATION;
        _status = wholeNumberFormatter.format(_count) + " numbers checked for prime qualification";

        _numberToCheck++;
      }
     
      // Complete the stats
      taskInfo.setEndNumber(_numberToCheck - 1);
      taskInfo.setEndTime(new NSTimestamp());
      taskInfo.setWorkflowState(TaskInfo.WORKFLOW_PRIME_CHECKED);
     
      ec.saveChanges();
     
      _resultGid = ec.globalIDForObject(taskInfo);
     
View Full Code Here

TOP

Related Classes of wowodc.eof.TaskInfo

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.