⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jobinfolist.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**    
  * Copyright (C) 2006, Laboratorio di Valutazione delle Prestazioni - Politecnico di Milano

  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.

  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.

  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
  
package jmt.engine.QueueNet;

import jmt.engine.dataAnalysis.InverseMeasure;
import jmt.engine.dataAnalysis.Measure;

import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/** This class implements a job info list.
 * @author Francesco Radaelli, Stefano Omini.
 */
public class JobInfoList {

    private static final boolean DEBUG = false;

	/** Required property is not available*/
	public final int PROPERTY_NOT_AVAILABLE = 0x0001;

	//contain JobInfo objects
    private LinkedList List, ListPerClass[];

    //arrivals and completions
	private int JobsIn, JobsOut, JobsInPerClass[], JobsOutPerClass[];

    private double BusyTime, BusyTimePerClass[];

	private double LastJobOutTime, LastJobInTime,
	LastJobOutTimePerClass[], LastJobInTimePerClass[];

	private Measure Utilization, UtilizationPerClass[],
	ResponseTime, ResponseTimePerClass[],
	ResidenceTime, ResidenceTimePerClass[],
    QueueLength, QueueLengthPerClass[];
    //OLD
    //private Measure Throughput, ThroughputPerClass[];
    private InverseMeasure Throughput, ThroughputPerClass[];

 	/** Creates a new JobInfoList instance.
	 * @param NumberOfJobClasses number of job classes.
	 * @param Save True to create and use a list to add/remove
     * each job which arrives/departes, false otherwise.
	 */
	public JobInfoList(int NumberOfJobClasses, boolean Save) {
		int i;
		if (Save) {
			List = new LinkedList();
			ListPerClass = new LinkedList[NumberOfJobClasses];
			for (i = 0; i < NumberOfJobClasses; i++)
				ListPerClass[i] = new LinkedList();
		}

        JobsIn = 0;
		JobsInPerClass = new int[NumberOfJobClasses];
		for (i = 0; i < NumberOfJobClasses; i++)
			JobsInPerClass[i] = 0;

        JobsOut = 0;
		JobsOutPerClass = new int[NumberOfJobClasses];
		for (i = 0; i < NumberOfJobClasses; i++)
			JobsOutPerClass[i] = 0;

        BusyTimePerClass = new double[NumberOfJobClasses];
		for (i = 0; i < NumberOfJobClasses; i++)
			BusyTimePerClass[i] = 0;

        LastJobOutTime = LastJobInTime = 0;
		LastJobInTimePerClass = new double[NumberOfJobClasses];
		for (i = 0; i < NumberOfJobClasses; i++)
			LastJobInTimePerClass[i] = 0;

        LastJobOutTimePerClass = new double[NumberOfJobClasses];
		for (i = 0; i < NumberOfJobClasses; i++)
			LastJobOutTimePerClass[i] = 0;

        //NEW
        //@author Stefano Omini
        ThroughputPerClass = new InverseMeasure[NumberOfJobClasses];


	}

/**---------------------------------------------------------------------
 *-------------------- "GET" METHODS -----------------------------------
 *---------------------------------------------------------------------*/


	/** Gets list size.
	 * @return Number of job info object in the list.
	 * @throws jmt.common.exception.NetException
	 */
	public int size() throws jmt.common.exception.NetException {
		if (List != null)
			return List.size();
		else
			throw new jmt.common.exception.NetException(this, PROPERTY_NOT_AVAILABLE,
			        "property not available");
	}


	/**
	 * Returns the number of jobs of a specific job class in the list.
	 * @param JobClass Job class to look for.
	 * @return Number of jobs of a specified job class.
	 */
	public int size(JobClass JobClass) throws jmt.common.exception.NetException {
		if (ListPerClass != null)
			return ListPerClass[JobClass.getId()].size();
		else
			throw new jmt.common.exception.NetException(this, PROPERTY_NOT_AVAILABLE,
			        "property not available");
	}

	/** Gets the number of jobs added to the list.
	 * @return Arrived Jobs.
	 */
	public int getJobsIn() {
		return JobsIn;
	}

	/** Gets the number of jobs of a specific job class added to the list.
	 * @param JobClass Job class to look for.
	 * @return Arrived jobs of a specific job class.
	 */
	public int getJobsInPerClass(JobClass JobClass) {
		return JobsInPerClass[JobClass.getId()];
	}

	/** Gets the number of jobs added to the list for each job class.
	 * @return Arrived jobs for each job class.
	 */
	public int[] getJobsInPerClass() {
		return JobsInPerClass;
	}

	/** Gets the number of jobs removed from the list.
	 * @return Departed Jobs.
	 */
	public int getJobsOut() {
		return JobsOut;
	}

	/** Gets the number of jobs of a specific job class removed from the list.
	 * @param JobClass Job class to look for.
	 * @return Departed jobs of a specific job class.
	 */
	public int getJobsOutPerClass(JobClass JobClass) {
		return JobsOutPerClass[JobClass.getId()];
	}

	/** Gets the number of jobs added to the list for each job class.
	 * @return Arrived jobs per each job class.
	 */
	public int[] getJobsOutPerClass() {
		return JobsOutPerClass;
	}

	/** Gets busy time.
	 * @return Busy time.
	 * @throws jmt.common.exception.NetException
	 */
	public double getBusyTime() throws jmt.common.exception.NetException {
		if (List != null)
			return BusyTime;
		else
			throw new jmt.common.exception.NetException(this, PROPERTY_NOT_AVAILABLE,
			        "property not available");
	}

	/** Gets busy time for job class.
	 * @return Busy time for job class.
	 * @throws jmt.common.exception.NetException
	 */
	public double getBusyTimePerClass(JobClass JobClass) throws jmt.common.exception.NetException {
		if (ListPerClass != null)
			return BusyTimePerClass[JobClass.getId()];
		else
			throw new jmt.common.exception.NetException(this, PROPERTY_NOT_AVAILABLE,
			        "property not available");
	}

	/** Gets time of the last job arrived.
	 * @return Time of last job arrived.
	 */
	public double getLastJobInTime() {
		return LastJobInTime;
	}

	/** Gets time of the last job arrived of a specified job class.
	 * @return Time of last job arrived of a specified job class.
	 */
	public double getLastJobInTimePerClass(JobClass JobClass) {
		return LastJobInTimePerClass[JobClass.getId()];
	}

	/** Gets time of the last job departed.
	 * @return Time of last job departed.
	 */
	public double getLastJobOutTime() {
		return LastJobOutTime;
	}

	/** Gets time of the last job departed of a specified job class.
	 * @return Time of last job departed of a specified job class.
	 */
	public double getLastJobOutTimePerClass(JobClass JobClass) {
		return LastJobOutTimePerClass[JobClass.getId()];
	}

	/** Gets time of the last modify of the list.
	 * @return Time of last modify of the list.
	 */
	public double getLastModifyTime() {
		if (LastJobOutTime > LastJobInTime)
			return LastJobOutTime;
		else
			return LastJobInTime;
	}

	/** Gets time of the last modify of the list for a specified job class.
	 * @return Time of the last modify of the list for a specified job class.
	 */
	public double getLastModifyTimePerClass(JobClass JobClass) {
		if (LastJobOutTimePerClass[JobClass.getId()] >
		        LastJobInTimePerClass[JobClass.getId()])
			return LastJobOutTimePerClass[JobClass.getId()];
		else
			return LastJobInTimePerClass[JobClass.getId()];
	}

	/** Looks for an information job object which references to a specific job.
	 * @param Job The specified job.
	 * @return JobInfo object which references to the specified job, null otherwise.
	 */
	public JobInfo lookFor(Job Job) throws jmt.common.exception.NetException {
		if (ListPerClass == null)
			throw new jmt.common.exception.NetException(this, PROPERTY_NOT_AVAILABLE,
			        "property not available");
		ListIterator Iterator;
		//creates an iterator for the job class list of the job class of the specified job
        Iterator = ListPerClass[Job.getJobClass().getId()].listIterator();
		JobInfo jobInfo;
		while (Iterator.hasNext()) {
			jobInfo = (JobInfo) Iterator.next();
			if (jobInfo.getJob() == Job)
				return jobInfo;
		}
		return null;
	}


    /**
     * Gets the job info list
     */
	public List getJobList() {
		return List;
	}


/**---------------------------------------------------------------------
 *-------------------- "ADD" AND "REMOVE" METHODS ----------------------
 *---------------------------------------------------------------------*/

	/** Adds a new job info to the list.
	 * @param jobInfo Reference to the job info to be added.
	 * @return True if the job has been added (True if <tt>Save</tt> property is true,
     * otherwise no list was created by the constructor)
	 */
	public boolean add(JobInfo jobInfo) {
		if (List != null) {
			updateAdd(jobInfo);
			ListPerClass[jobInfo.getJob().getJobClass().getId()].add(jobInfo);
			List.add(jobInfo);
			return true;
		} else
			return false;
	}

	/** Adds a new job info to the top of the list.
	 * @param jobInfo reference to job info to be added.
	 * @return True if the job has been added (True if <tt>Save</tt> property is true,
     * otherwise no list was created by the constructor)
	 */
	public boolean addFirst(JobInfo jobInfo) {
		if (List != null) {
			updateAdd(jobInfo);
			ListPerClass[jobInfo.getJob().getJobClass().getId()].addFirst(jobInfo);
			List.addFirst(jobInfo);
			return true;
		} else
			return false;
	}



    //----------------METHODS USED BY PRIORITY BASED STRATEGIES---------------//

    //NEW
    //@author Stefano Omini

    /** Adds a new job info in the specified position.
     * The jobs must be inserted in both general and class jobs lists. The
     * specified position is relative to general list. In its own class job list, a job
     * can be put at the beginning (head) or at the end (tail).
     *
     * @param index the specified position
	 * @param jobInfo reference to job info to be added.
     * @param isClassTail if true, job will be put in the last position of its own class job list (tail
     * strategy); if false, it will be put in first position (head strategy)
	 * @return True if the job has been added (True if <tt>Save</tt> property is true,
     * otherwise no list was created by the constructor)
	 */
	public boolean add(int index, JobInfo jobInfo, boolean isClassTail) {

        if (List != null) {
			updateAdd(jobInfo);

            if (isClassTail) {
                ListPerClass[jobInfo.getJob().getJobClass().getId()].addLast(jobInfo);
            } else {
                ListPerClass[jobInfo.getJob().getJobClass().getId()].addFirst(jobInfo);
            }
			List.add(index, jobInfo);

			return true;
		} else
			return false;
	}


    /** Adds a new job info in the specified position.
     * The jobs must be inserted in both general and class jobs lists. The
     * specified position is relative to general list. In its own class job list, a job
     * can be put at the beginning (head) or at the end (tail).
     *
     * @param jobInfo reference to job info to be added.
     * @param isClassTail if true, job will be put in the last position of its own class job list (tail
     * strategy); if false, it will be put in first position (head strategy)
	 * @return True if the job has been added (True if <tt>Save</tt> property is true,
     * otherwise no list was created by the constructor)
	 */
	public boolean addFirst(JobInfo jobInfo, boolean isClassTail) {

        if (List != null) {
			updateAdd(jobInfo);

            if (isClassTail) {
                ListPerClass[jobInfo.getJob().getJobClass().getId()].addLast(jobInfo);
            } else {
                ListPerClass[jobInfo.getJob().getJobClass().getId()].addFirst(jobInfo);
            }
			List.addFirst(jobInfo);

			return true;
		} else
			return false;
	}

    /** Adds a new job info in the specified position.
     * The jobs must be inserted in both general and class jobs lists. The
     * specified position is relative to general list. In its own class job list, a job
     * can be put at the beginning (head) or at the end (tail).
     *
     * @param jobInfo reference to job info to be added.
     * @param isClassTail if true, job will be put in the last position of its own class job list (tail
     * strategy); if false, it will be put in first position (head strategy)
	 * @return True if the job has been added (True if <tt>Save</tt> property is true,
     * otherwise no list was created by the constructor)
	 */
	public boolean addLast(JobInfo jobInfo, boolean isClassTail) {

        if (List != null) {
			updateAdd(jobInfo);

            if (isClassTail) {
                ListPerClass[jobInfo.getJob().getJobClass().getId()].addLast(jobInfo);
            } else {
                ListPerClass[jobInfo.getJob().getJobClass().getId()].addFirst(jobInfo);
            }
			List.addLast(jobInfo);

			return true;
		} else
			return false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -