Package jmt.engine.QueueNet

Examples of jmt.engine.QueueNet.WaitingRequest


          }

        } else {
          //coolStart is false: there are waiting jobs. Add the received job.
          waitingRequests.add(new WaitingRequest(message.getSource(), message.getSourceSection(), job));
        }
        break;

      case NetEvent.EVENT_ACK:

        //case EVENT_ACK:
        //if there are waiting jobs, takes the first, set its bornTime and
        //forwards it to the service section.
        //then it creates a new job and sends to itself a message whose delay is the time of
        //departure of that job.
        //otherwise, if there are no waiting jobs, sets coolstart=true

        if (waitingRequests.size() != 0) {
          WaitingRequest wr;
          wr = (WaitingRequest) waitingRequests.removeFirst();

          if (!isMyOwnerNode(wr.getNode())) {
            send(NetEvent.EVENT_ACK, wr.getJob(), 0.0, wr.getSection(), wr.getNode());

            //log.write(NetLog.LEVEL_ALL, message.getJob(), this, NetLog.ACK_JOB);
          }

          Job jobSent = wr.getJob();
          sendForward(jobSent, 0.0);

          //log.write(NetLog.LEVEL_DEBUG, jobSent, this, NetLog.JOB_OUT);
        } else {
          coolStart = true;
View Full Code Here


        //is set true.

        // if there is a waiting request send ack to the first node
        //(note that with infinite queue there are no waitinq requests)
        if (waitingRequests.size() != 0) {
          WaitingRequest wr;
          wr = (WaitingRequest) waitingRequests.removeFirst();

          // If the source is not the owner node sends ack if blocking is enabled. Otherwise
          // ack was already sent.
          if (!isMyOwnerNode(wr.getNode()) && block[wr.getJob().getJobClass().getId()]) {
            send(NetEvent.EVENT_ACK, wr.getJob(), 0.0, wr.getSection(), wr.getNode());
          }

          //the class ID of this job
          int c = wr.getJob().getJobClass().getId();
          //the job is put into the queue according to its own class put strategy
          putStrategy[c].put(wr.getJob(), queueJobInfoList, message.getSourceSection(), message.getSource(), this);
        }

        // if there is at least one job, sends it
        if (queueJobInfoList.size() > 0) {
          // Gets job using a specific strategy and sends job
          Job jobSent = getStrategy.get(queueJobInfoList);
          forward(jobSent);
        } else {
          // else set coolStart to true
          coolStart = true;

        }
        break;

      case NetEvent.EVENT_JOB:

        //EVENT_JOB
        //If the queue is a redirecting queue, jobs arriving from the outside of
        //the blocking region must be redirected to the region input station
        //
        //Otherwise the job is processed as usual.
        //
        //If coolStart is true, the queue is empty, so the job is added to the job list
        //and immediately forwarded to the next section. An ack is sent and coolStart is
        //set to false.
        //
        //If the queue is not empty, it should be distinguished between finite/infinite queue.
        //
        //If the queue is finite, checks the size: if it's not full the job is put into the
        //queue and an ack is sent. Else, if it's full, checks the owner node: if the
        //source node is the owner node of this section, an ack is sent and a waiting
        //request is created. If the source is another node the waiting request is created
        //only if drop is false, otherwise an ack is sent but the job is rejected.
        //
        //If the queue is infinite, the job is put into the queue and an ack is sent

        job = message.getJob();

        //----REDIRECTION BEHAVIOUR----------//
        if (isRedirectionON()) {

          NetNode source = message.getSource();
          boolean fromTheInside = myRegion.belongsToRegion(source);

          //the first time input station isn't known yet
          if (regionInputStation == null) {
            regionInputStation = myRegion.getInputStation();
          }

          if (!fromTheInside) {
            //this message has arrived from the outside of the blocking region
            if ((source != regionInputStation)) {
              //the external source is not the input station
              //the message must be redirected to the input station,
              //without processing it

              //redirects the message to the inputStation
              redirect(NetEvent.EVENT_JOB, job, 0.0, NodeSection.INPUT, regionInputStation);
              //send a ack to the source
              send(NetEvent.EVENT_ACK, job, 0.0, message.getSourceSection(), message.getSource());

              return MSG_PROCESSED;
            }
          }
        }
        //----END REDIRECTION BEHAVIOUR-------//

        //
        //two possible cases:
        //1 - the queue is a generic queue (redirectionOn == false)
        //2 - the queue is a redirecting queue, but the message has arrived
        //from the inside of the region or from the inputStation:
        //in this case the redirecting queue acts as a normal queue
        //
        //therefore in both cases the behaviour is the same
        //

        // Check if there is still capacity.
        // <= size because the arriving job hasn't been inserted in Queue
        // job list but has been inserted in NetNode job list !!
        if (infinite || nodeJobsList.size() <= size) {
          // Queue is not full. Okay.

          // If coolStart is true, this is the first job received or the
          // queue was empty: this job is sent immediately to the next
          // section and coolStart set to false.
          if (coolStart) {
            // No jobs in queue: Refresh jobsList and sends job (don't use put strategy, because queue is empty)
            queueJobInfoList.add(new JobInfo(job));
            //forward without any delay
            forward(queueJobInfoList.removeFirst().getJob());

            coolStart = false;
          } else {
            putStrategy[job.getJobClass().getId()].put(job, queueJobInfoList, message.getSourceSection(), message.getSource(), this);
          }
          //sends an ACK backward
          send(NetEvent.EVENT_ACK, job, 0.0, message.getSourceSection(), message.getSource());
        } else {
          // Queue is full. Now we use an additional queue or drop.

          // if the job has been sent by the owner node of this queue section
          if (isMyOwnerNode(message.getSource())) {
            send(NetEvent.EVENT_ACK, job, 0.0, message.getSourceSection(), message.getSource());

            waitingRequests.add(new WaitingRequest(message.getSource(), message.getSourceSection(), job));
          }
          // otherwise if job has been sent by another node
          else if (!drop[job.getJobClass().getId()]) {
            // if drop is true reject the job, else add the job to waitingRequests
            waitingRequests.add(new WaitingRequest(message.getSource(), message.getSourceSection(), job));
            //if blocking is disabled, sends ack otherwise router of the previous node remains busy
            if (!block[job.getJobClass().getId()]) {
              send(NetEvent.EVENT_ACK, job, 0.0, message.getSourceSection(), message.getSource());
            }
          } else {
View Full Code Here

TOP

Related Classes of jmt.engine.QueueNet.WaitingRequest

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.