Esempio n. 1
0
  /** @param Ty TyBase */
  public AgentThread(FrameWorkBase Ty, QueueHeader AH, QueueDetail AD, String tname, int int_nbr) {

    // name of thread
    super(tname);

    // set pointer to base storage
    T = Ty;

    // set pointer to Queue header to which this thread belongs
    area = AH;

    // set pointer to Queue detail to which this thread belongs
    me = AD;

    // set pointer to async table
    async_tbl = T.async_tbl;

    // set reference to remote object
    fw = T.Ti;

    // current instance number
    instance_nbr = int_nbr;

    que_nbr = area.getQueNumber(); // int name of this que
    th_nbr = me.getName(); // int name of this thread

    // the concatenated outputs, now input
    o_args = null;

    had_problem = false; // no problem
    posted = false; // not posted
  } // end-constructor
Esempio n. 2
0
  /**
   * Check the wait lists.
   *
   * <p>When there is work to do, call doWork.
   */
  private void checkWork() {

    int sub, type;
    boolean iswork = true;

    // spin when more work
    while (iswork) {

      // get a lock on the queue Area
      synchronized (area) {

        // status is "actively processing"
        me.setProcessing();

        // find first busy in waitlists
        sub = area.getFirstBusy();

        // When zero, nothing.
        if (sub == 0) {

          // no work
          iswork = false;
        } else {
          // async is complement
          sub = (sub * -1);
        } // endif

        // When no work was found:
        if (!iswork) {

          // set status to Waiting
          me.setWaiting();
        } // endif
      } // end-sync

      // When work was found
      if (iswork) {

        // do the request
        doWork(sub);

        // When something went wrong in doWork, get out
        if (had_problem) {

          // get out
          return;
        } // endif
      } // endif
    } // end-while
  } // end-method
Esempio n. 3
0
  public void run() {

    long wait_time = 0;
    int my_wait = 0;
    int working = 0;
    int detached = 0;

    // until shut down
    while (true) {

      // sync on area
      synchronized (area) {

        // get status
        working = me.getStatus();

        // max wait time in seconds
        my_wait = area.getWaitTime();
      } // end-sync

      // When 'posted' or 'started'
      if ((working == QueueDetail.POSTED) || (working == QueueDetail.STARTED)) {

        // reset the posted indicator
        posted = false;

        // check for work to do
        checkWork();

        // When something went wrong, (status=disabled), get out
        if (had_problem) {

          // finished
          return;
        } // endif

        // compute the max time to wait = seconds to milli-
        wait_time = my_wait * 1000;

        // sync on this
        synchronized (this) {

          // spin until posted
          while (!posted) {

            try {
              // wait for a posting or time out
              wait(wait_time);

              // When timed out
              if (!posted) {

                // set temp status as inactive
                detached = 1;

                // set is posted
                posted = true;
              } // endif
            } // end-try
            catch (InterruptedException e) {

            } // end-catch
          } // end-while

          // reset the posted indicator
          posted = false;
        } // end-sync

        // When a time out occurred
        if (detached == 1) {

          // reset
          detached = 0;

          // sync on area
          synchronized (area) {

            // When still in waiting status
            if (me.getStatus() == QueueDetail.WAITING) {

              // set status as inactive
              me.setDetached();
            } // endif
          } // end-sync
        } // end-if
      } else {
        // When disabled
        if (working == QueueDetail.DISABLED) {

          // all done
          return;
        } // endif

        // wait for activation
        // sync on this
        synchronized (this) {

          // wait for a posting
          while (!posted) {

            try {
              // wait for a post
              wait();
            } // end-try
            catch (InterruptedException e) {

            } // end-catch
          } // end-while

          // reset the posted indicator
          posted = false;
        } // end-sync
      } // endif
    } // end-while
  } // end-method