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

📄 jobinfolist.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}
    
    //end NEW

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

	/** Adds a new job info to the bottom 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 addLast(JobInfo jobInfo) throws jmt.common.exception.NetException {
		if (List != null) {
			updateAdd(jobInfo);
			ListPerClass[jobInfo.getJob().getJobClass().getId()].addLast(jobInfo);
			List.addLast(jobInfo);
			return true;
		} else
			return false;
	}





	/** Removes a job info from the list and updates the measures related to
     * throughput, utilization and response time.
	 * @param jobInfo reference to job info to be removed.
	 * @return True if the job has been removed (True if <tt>Save</tt> property is true,
     * otherwise no list was created by the constructor)
	 */
	public boolean remove(JobInfo jobInfo) throws jmt.common.exception.NetException {
		if (List != null) {
			Job job = jobInfo.getJob();
			JobClass jobClass = job.getJobClass();
            int c = jobClass.getId();

            updateThroughput(job);
			updateUtilization(jobClass);

            //NEW
            //@author Stefano Omini
            updateQueueLength(jobClass);
            updateResidenceTime(jobInfo);
            //end NEW

            updateResponseTime(jobInfo);

			ListPerClass[c].remove(jobInfo);
			List.remove(jobInfo);
			LastJobOutTimePerClass[c] = LastJobOutTime = NetSystem.getTime();
			double time = LastJobOutTime - jobInfo.getTime();
			JobsOut++;
			JobsOutPerClass[c]++;
			BusyTime += time;
			BusyTimePerClass[c] += time;

			return true;
		} else
			return false;
	}




	/** Removes a job info from the top of the list and updates the measures related to
     * throughput, utilization and response time.
	 * @return A Job info object if it has been found, null otherwise (list
	 * empty or Save property is false)
	 */
	public JobInfo removeFirst() throws jmt.common.exception.NetException {
		if (List != null) {
			JobInfo jobInfo = ((JobInfo) List.getFirst());
			if (jobInfo != null) {
				remove(jobInfo);
				return jobInfo;
			} else
				return null;
		} else
			return null;
	}

	/** Removes a job info of a specified job class from the top of the list and updates the measures related to
     * throughput, utilization and response time.
	 * @return A Job info object if it has been found, null otherwise (list
	 * empty or Save property is false)
	 */
	public JobInfo removeFirst(JobClass jobClass) throws jmt.common.exception.NetException {
		if (List != null) {
			int c = jobClass.getId();
			JobInfo JobInfo = ((JobInfo) ListPerClass[c].getFirst());
			if (JobInfo != null) {
				remove(JobInfo);
				return JobInfo;
			} else
				return null;
		} else
			return null;
	}

	/** Removes a job info from the bottom of the list and updates the measures related to
     * throughput, utilization and response time.
	 * @return A Job info object if it has been found, null otherwise (list
	 * empty or Save property is false)
	 */
	public JobInfo removeLast() throws jmt.common.exception.NetException {
		if (List != null) {
			JobInfo JobInfo = (JobInfo) List.getLast();
			if (JobInfo != null) {
				remove(JobInfo);
				return JobInfo;
			} else
				return null;
		} else
			return null;
	}

	/** Removes a job info of a specified job class from the bottom of the list  and updates the measures related to
     * throughput, utilization and response time.
	 * @return A Job info object if it has been found, null otherwise (list
	 * empty or Save property is false)
	 */
	public JobInfo removeLast(JobClass jobClass) throws jmt.common.exception.NetException {
		if (List != null) {
			int c = jobClass.getId();
			JobInfo JobInfo = (JobInfo) ListPerClass[c].getLast();
			if ((JobInfo != null)) {
				remove(JobInfo);
				return JobInfo;
			} else
				return null;
		} else
			return null;
	}

/**---------------------------------------------------------------------
 *---------------- "ANALYZE" AND "UPDATE" METHODS ----------------------
 *---------------------------------------------------------------------*/

	/** Analyzes class utilization.
	 * @param jobClass Job class to be analyzed. If null, measure will be
	 * job class independent.
	 * @param Measurement Reference to a measure object.
	 */
	public void analyzeUtilization(JobClass jobClass, Measure Measurement) {
		if (jobClass != null) {
			if (UtilizationPerClass == null)
				UtilizationPerClass = new Measure[ListPerClass.length];
			UtilizationPerClass[jobClass.getId()] = Measurement;
		} else
			Utilization = Measurement;
	}

	/** Analyzes class response time.
	 * @param jobClass Job class to be analyzed. If null, measure will be
	 * job class independent.
	 * @param Measurement Reference to a measure object.
	 */
	public void analyzeResponseTime(JobClass jobClass, Measure Measurement) {
		if (jobClass != null) {
			if (ResponseTimePerClass == null)
				ResponseTimePerClass = new Measure[ListPerClass.length];
			ResponseTimePerClass[jobClass.getId()] = Measurement;
		} else
			ResponseTime = Measurement;
	}

    //NEW
    //@author Stefano Omini
    //

    /**
     *
     * Analyzes class throughput. <br>
     * WARNING: An InverseMeasure must be used.
     * The aim is to save computational time: in fact it's easier to analyze throughput
     * by passing samples which are equals to 1/X,
     * instead of doing one division for each sample (this would make simulation much slower).
     * At the end the correct value is passed.
	 * @param JobClass Job class to be analyzed. If null, measure will be
	 * job class independent.
	 * @param Measurement Reference to a InverseMeasure object.
     *
     *
	 */

    public void analyzeThroughput(JobClass JobClass, InverseMeasure Measurement) {
		if (JobClass != null) {
			if (ThroughputPerClass == null)
                ThroughputPerClass = new InverseMeasure[ListPerClass.length];
            ThroughputPerClass[JobClass.getId()] = Measurement;
		} else
            Throughput = Measurement;
	}

    //end NEW



	/** Analyzes class residence time.
	 * @param JobClass Job class to be analyzed. If null, measure will be
	 * job class independent.
	 * @param Measurement Reference to a measure object.
	 */
	public void analyzeResidenceTime(JobClass JobClass, Measure Measurement) {
		if (JobClass != null) {
			if (ResidenceTimePerClass == null)
				ResidenceTimePerClass = new Measure[ListPerClass.length];
			ResidenceTimePerClass[JobClass.getId()] = Measurement;
		} else
			ResidenceTime = Measurement;
	}

    /**
     * Updates Response time measure
     * <br>Author: Bertoli Marco
     * @param JobInfo current JobInfo
     */
    private void updateResponseTime(JobInfo JobInfo) {
		int c = JobInfo.getJob().getJobClass().getId();
		double ArriveTime = JobInfo.getTime();
		if (ResponseTimePerClass != null) {
			Measure m = ResponseTimePerClass[c];
			if (m != null)
				m.update(NetSystem.getTime() - ArriveTime, 1.0);
		}
		if (ResponseTime != null)
			ResponseTime.update(NetSystem.getTime() - ArriveTime, 1.0);
	}

    private void updateUtilization(JobClass JobClass) {
            if (UtilizationPerClass != null) {
                int c = JobClass.getId();
                Measure m = UtilizationPerClass[c];
                if (m != null) {

                    m.update(ListPerClass[c].size(), NetSystem.getTime() - getLastModifyTimePerClass(JobClass));
                }
            }
            if (Utilization != null)
                Utilization.update(List.size(), NetSystem.getTime() - getLastModifyTime());
        }


	private void updateResidenceTime(JobInfo JobInfo) {
		int c = JobInfo.getJob().getJobClass().getId();
		double ArriveTime = JobInfo.getTime();
		if (ResidenceTimePerClass != null) {
			Measure m = ResidenceTimePerClass[c];
			if (m != null)
				m.update(NetSystem.getTime() - ArriveTime, 1.0);
		}
		if (ResidenceTime != null)
			ResidenceTime.update(NetSystem.getTime() - ArriveTime, 1.0);
	}





    private void updateThroughput(Job Job) {
		int c = Job.getJobClass().getId();
		if (ThroughputPerClass != null) {
			Measure m = ThroughputPerClass[c];
			if (m != null)
                // new sample is the inter-departures time (1/throughput)
                // Inverse measure must be used to compute throughput
                m.update(NetSystem.getTime() - getLastJobOutTimePerClass(Job.getJobClass()), 1.0);
            if(DEBUG)
                System.out.println(NetSystem.getTime() - getLastJobOutTimePerClass(Job.getJobClass()));
		}
		if (Throughput != null)
			Throughput.update(NetSystem.getTime() - getLastJobOutTime(), 1.0);
	}

	private void updateAdd(JobInfo JobInfo) {
		Job job = JobInfo.getJob();
        JobClass jobClass = job.getJobClass();
		int c = jobClass.getId();

        updateUtilization(jobClass);
        updateQueueLength(jobClass);

        JobsIn++;
		JobsInPerClass[c]++;
		LastJobInTimePerClass[c] = LastJobInTime = NetSystem.getTime();

	}



    //NEW
    //@author Stefano Omini
    //modified 21/5/2004

    /** Analyzes list residence time.
	 * @param JobClass Job class to be analyzed. If null, measure will be
	 * job class independent.
	 * @param Measurement Reference to a measure object.
	 */
	public void analyzeQueueLength(JobClass JobClass, Measure Measurement) {
		if (JobClass != null) {
			if (QueueLengthPerClass == null)
				QueueLengthPerClass = new Measure[ListPerClass.length];
			QueueLengthPerClass[JobClass.getId()] = Measurement;
		} else
			QueueLength = Measurement;
	}

    /**
     * WARNING: updateQueueLength is implemented exactly as updateUtilization: the
     * difference is that in the former case the resident jobs counted
     * ( ListPerClass[c].size() ) are all the jobs in the node, in the latter case
     * are only the jobs in the service sections.
     * This difference must be guaranteed at upper level (in Simulation class) where
     * "analyze" methods are called
     * @param JobClass
     */
    private void updateQueueLength(JobClass JobClass) {
		if (QueueLengthPerClass != null) {
			int c = JobClass.getId();
			Measure m = QueueLengthPerClass[c];
            if (m != null) {
                m.update(ListPerClass[c].size(), NetSystem.getTime() - getLastModifyTimePerClass(JobClass));
            }
		}
		if (QueueLength != null)
			QueueLength.update(List.size(), NetSystem.getTime() - getLastModifyTime());
	}


    //END NEW



    //NEW
    //@author Stefano Omini

    /** Removes a job info from the list without updating measures.
     *
	 * @param JobInfo reference to job info to be removed.
	 * @return True if the job has been removed (True if <tt>Save</tt> property is true,
     * otherwise no list was created by the constructor)
	 */
	public boolean removeAfterRedirect(JobInfo JobInfo) throws jmt.common.exception.NetException {
		if (List != null) {
			Job job = JobInfo.getJob();
			JobClass jobClass = job.getJobClass();
            int c = jobClass.getId();

			ListPerClass[c].remove(JobInfo);
			List.remove(JobInfo);

            //the job has been redirected: it shouldn't be counted
            JobsIn--;
            JobsInPerClass[c]--;

			return true;
		} else
			return false;
	}


    /** Removes a job info from the list without updating measures.
     *
	 * @param JobInfo reference to job info to be removed.
	 * @return True if the job has been removed (True if <tt>Save</tt> property is true,
     * otherwise no list was created by the constructor)
	 */
	public boolean removeAfterDrop(JobInfo JobInfo) throws jmt.common.exception.NetException {
		if (List != null) {
			Job job = JobInfo.getJob();
			JobClass jobClass = job.getJobClass();
            int c = jobClass.getId();

			ListPerClass[c].remove(JobInfo);
            List.remove(JobInfo);

            //TODO: aggiornare solo alcune misure???
			//updateUtilization(jobClass);
            updateQueueLength(jobClass);

            //TODO: va aggiornato???
            LastJobOutTimePerClass[c] = LastJobOutTime = NetSystem.getTime();
			/*
            double time = LastJobOutTime - JobInfo.getTime();
			JobsOut++;
			JobsOutPerClass[c]++;
			BusyTime += time;
			BusyTimePerClass[c] += time;
            */

			return true;
		} else
			return false;
	}

    //end NEW


}

⌨️ 快捷键说明

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