Package jmt.engine.QueueNet

Examples of jmt.engine.QueueNet.Job


        break;
    }

    Job[] jobs = new Job[10];

    jobs[0] = new Job(class1);
    jobs[1] = new Job(class3);
    jobs[2] = new Job(class2);
    jobs[3] = new Job(class2);
    jobs[4] = new Job(class1);
    jobs[5] = new Job(class1);
    jobs[6] = new Job(class1);
    jobs[7] = new Job(class2);
    jobs[8] = new Job(class3);
    jobs[9] = new Job(class3);

    byte b = 0x01;

    for (Job job : jobs) {
      try {
View Full Code Here


  @Override
  protected int process(NetMessage message) throws jmt.common.exception.NetException {
    switch (message.getEvent()) {
      case NetEvent.EVENT_JOB:
        Job job = message.getJob();

        if (isMine(message)) {
          // I sent the message, so it ended servicing
          updateServiceTimes(lastMessageSentTime);
          lastMessageSent = null;
          // forwards the completed jobs to the output section
          JobData data = jobs.peek();
          handleJobInfoLists(data, PSEvent.JOB_OUT);
          jobs.poll();
          sendForward(data.getJob(), 0.0);
          waitingAcks++;
        } else {
          // Check if a job is running
          if (lastMessageSent != null) {
            // We need to preempt the last message
            removeMessage(lastMessageSent);
            updateServiceTimes(lastMessageSentTime);
            lastMessageSent = null;
          }
          // Estimate the job service time, puts it in the queue and sends a message to itself
          // with the minimum service time of all the jobs to perform processing
          double serviceTime = serviceStrategy[job.getJobClass().getId()].wait(this);
          JobData data = new JobData(job, serviceTime);
          handleJobInfoLists(data, PSEvent.JOB_IN);
          jobs.add(data);

          // Sends an ACK to the input section as we will always accept new jobs.
View Full Code Here

    //  jobsList = new JobInfoList(getJobClasses().size(), true);
  }

  @Override
  protected int process(NetMessage message) throws NetException {
    Job job;
    int c;
    switch (message.getEvent()) {

      case NetEvent.EVENT_START:

        //case EVENT_START:
        //the terminal creates all the jobs requested by each class.
        //for each job created, it sends to itself a message with delay 0

        //log.write(NetLog.LEVEL_RELEASE, null, this, NetLog.EVENT_START);
        ListIterator<JobClass> jobClasses = getJobClasses().listIterator();
        JobClass jobClass;

        //generator of random numbers (uses the same engine of
        //distributions and strategies) used to mix the order of
        //leaving jobs, otherwise they leave in order of class
        //(i.e. c1, c1, c1, ...c2, c2, c2, ... c3....)
        RandomEngine randomEng = RandomEngine.makeDefault();

        //delay used to mix leaving order
        double mixRandomDelay = 0.0;

        while (jobClasses.hasNext()) {
          jobClass = jobClasses.next();

          //NEW
          //@author Stefano Omini
          if (jobClass.getType() == JobClass.OPEN_CLASS) {
            //open class: no jobs to be generated
            continue;
          }
          //end NEW

          c = jobClass.getId();

          if (jobsPerClass != null) {

            //terminal of a closed system
            //generates all the jobs
            for (int i = 0; i < jobsPerClass[c]; i++) {
              //note that if jobsPerClass[c] = -1 (open class) the instructions
              //of this for are not performed

              //each job is created and sent to the terminal itself
              job = new Job(jobClass);

              //OLD
              // the delay of departure is set to 0
              //sendMe(job, 0);

              //NEW
              //@author Stefano Omini
              //sets a random (very small) delay to mix the jobs
              //of different classes

              //mixRandomDelay = (randomEng.nextDouble()) * 0.00001;
              mixRandomDelay = (randomEng.raw()) * 0.00001;

              sendMe(job, mixRandomDelay);
              //end NEW

              //log.write(NetLog.LEVEL_DEBUG, job, this, NetLog.JOB_CREATED);
            }
          }
        }
        break;

      case NetEvent.EVENT_JOB:

        //case EVENT_JOB
        //if coolStart=false adds the job to the list of waiting jobs.
        //
        //if coolStart=true (no waiting jobs) checks the source
        //If the message has been received from the terminal itself, the job's
        //bornTime is set, then the job is forwarded. Otherwise, if it has been
        //received from the outside, an ack message is sent to the source of the
        //message, the job's bornTime is set, then the job is forwarded.
        //

        //log.write(NetLog.LEVEL_DEBUG, message.getJob(), this, NetLog.JOB_IN);

        // Gets the job from the message
        job = message.getJob();

        //TODO: serve questa coolStart????
        if (coolStart) {
          //the queue of waiting jobs is empty

          if (message.getSource() == this.getOwnerNode() && message.getSourceSection() == this.getSectionID()) {

            //message sent by the terminal itself
            job.born();
            sendForward(job, 0.0);

            //log.write(NetLog.LEVEL_DEBUG, job, this, NetLog.JOB_OUT);

            coolStart = false;

            return MSG_PROCESSED;
          } else {

            //job received from the outside

            //send an ack
            send(NetEvent.EVENT_ACK, job, 0.0, message.getSourceSection(), message.getSource());

            //job goes on
            job.born();
            sendForward(job, 0.0);

            //log.write(NetLog.LEVEL_DEBUG, job, this, NetLog.JOB_OUT);

            coolStart = false;

            return MSG_PROCESSED;

          }

        } 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

  }

  @Override
  protected int process(NetMessage message) throws jmt.common.exception.NetException {
    int c;
    Job job;
    double serviceTime;
    switch (message.getEvent()) {

      case NetEvent.EVENT_ACK:
        //EVENT_ACK
        //If there are no jobs in the service section, message is not processed.
        //Otherwise an ack is sent backward to the input section and
        //the counter of jobs in service is decreased.
        if (busyCounter == 0) {
          //it wasn't waiting for any job
          return NodeSection.MSG_NOT_PROCESSED;
        } else if (busyCounter == numberOfServers) {
          // Sends a request to the input section
          sendBackward(NetEvent.EVENT_ACK, message.getJob(), 0.0);
          busyCounter--;
        } else {
          // Avoid ACK as we already sent ack
          busyCounter--;
        }
        break;

      case NetEvent.EVENT_JOB:

        //EVENT_JOB
        //If the message has been sent by the server itself,
        // then the job is forwarded.
        //
        //If the message has been sent by another section, the server, if
        //is not completely busy, sends to itself a message containing the
        //job and with delay equal to the service time calculated using
        //the service strategy.
        //The counter of jobs in service is increased and, if further service
        //capacity is left, an ack is sent to the input section.

        // Gets the job from the message
        job = message.getJob();

        if (isMine(message)) {
          // this job has been just served (the message has been sent by the server itself)
          // forwards the job to the output section
          sendForward(job, 0.0);
        } else {
          //message received from another node section: if the server is not completely busy,
          //it sends itself a message with this job
          if (busyCounter < numberOfServers) {
            // Gets the class of the job
            c = job.getJobClass().getId();
            // Auto-sends the job with delay equal to "serviceTime"
            serviceTime = serviceStrategy[c].wait(this);
            // Calculates the service time of job
            sendMe(job, serviceTime);
View Full Code Here

  }

  @Override
  protected int process(NetMessage message)
      throws jmt.common.exception.NetException {
    Job job;
    job = message.getJob();
    switch (message.getEvent()) {
      case NetEvent.EVENT_START:
        break;
      case NetEvent.EVENT_ACK:
View Full Code Here

   * @throws NetException if something goes wrong
   * @return message processing result.
   */
  @Override
  protected int process(NetMessage message) throws NetException {
    Job job;
    job = message.getJob();
    // Finds event type
    switch (message.getEvent()) {
      case NetEvent.EVENT_JOB:
        NodeList output = getOwnerNode().getOutputNodes();
View Full Code Here

          if (logger != null) {
            logger.close();
          }
          break;
        case NetEvent.EVENT_JOB:
          Job job = message.getJob();
          // Build logger and default values if needed
          if (logger == null) {
            initLoggerParameters();
            logger = JSimLoggerFactory.getCSVLogger(
                new File(lp.path, lp.name),
                COLUMNS,
                intReplacePolicy == LoggerParameters.LOGGER_AR_APPEND,
                String.valueOf(chDelimiter),
                decimalSeparator
            );
            defaultValues = new HashMap<String, String>();
            if (lp.boolLoggername) {
              defaultValues.put(COLUMN_LOGGERNAME, message.getSource().getName());
            }
            if (lp.boolExecTimestamp) {
              defaultValues.put(COLUMN_START_TIME, strTimestampValue);
            }
          }
          // Fills the values for the log column
          Map<String, Object> values = new HashMap<String, Object>();
          if (lp.boolTimeStamp) {
            values.put(COLUMN_TIMESTAMP, message.getTime());
          }

          if (lp.boolJobID) {
            values.put(COLUMN_JOBID, job.getId());
          }

          if (lp.boolJobClass) {
            values.put(COLUMN_CLASSID, job.getJobClass().getName());
          }

          if (lp.boolTimeSameClass.booleanValue() == true) {
            double interarrivalSame = message.getTime() - jobsList.getLastJobOutTimePerClass(job.getJobClass());
            values.put(COLUMN_INTERARRIVAL_SAMECLASS, interarrivalSame);
          }

          if (lp.boolTimeAnyClass.booleanValue() == true) {
            double interarrivalAny = message.getTime() - jobsList.getLastJobOutTime();
View Full Code Here

        //case EVENT_JOB
        //an ack message is sent to the source of the received message.
        //then the job is killed

        Job job = message.getJob();
        send(NetEvent.EVENT_ACK, job, 0.0, message.getSourceSection(), message.getSource());

        //NEW
        //@author Stefano Omini
View Full Code Here

   */
  @Override
  protected int process(NetMessage message) throws NetException {
    switch (message.getEvent()) {
      case NetEvent.EVENT_JOB:
        Job job = message.getJob();
        // Sends ACK back
        send(NetEvent.EVENT_ACK, job, 0.0, message.getSourceSection(), message.getSource());

        if (job instanceof ForkJob) {
          ForkJob fJob = (ForkJob) job;
View Full Code Here

    coolStart = true;
  }

  @Override
  protected int process(NetMessage message) throws jmt.common.exception.NetException {
    Job job;
    switch (message.getEvent()) {

      case NetEvent.EVENT_JOB:

        //EVENT_JOB
        //If the message has been sent by this section, it means that the job
        //has been already delayed. Therefore, if there are no waiting jobs (coolStart true)
        //the job is forwarded and coolStart becomes false, otherwise the job is added to
        //the existing waiting jobs.
        //
        //If the message has been sent by the input section, delay section sends to
        //itself a message with the job and with a delay calculated using the
        //service strategy; then an ack is sent to the message source.

        double serviceTime;
        int c;
        // Gets the job from the message
        job = message.getJob();
        // If the message source is this section, the job has been
        // delayed and it should be forwarded to the next section
        if (isMine(message)) {
          if (coolStart) {
            // Sends job
            sendForward(job, 0.0);
            coolStart = false;
          } else {
            waitingJobs.add(job);
          }
        }
        // else delays the job
        else {
          // Gets the class of the job
          c = job.getJobClass().getId();
          // Calculates the service time of job
          serviceTime = serviceStrategy[c].wait(this);
          // Sends to itself the job with delay equal to "serviceTime"
          sendMe(job, serviceTime);
          // Sends backward the job ack
View Full Code Here

TOP

Related Classes of jmt.engine.QueueNet.Job

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.