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

📄 queue.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/**    
  * 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.NodeSections;

import java.util.Arrays;

import jmt.common.exception.NetException;
import jmt.engine.NetStrategies.QueueGetStrategies.FCFSstrategy;
import jmt.engine.NetStrategies.QueueGetStrategy;
import jmt.engine.NetStrategies.QueuePutStrategies.TailStrategy;
import jmt.engine.NetStrategies.QueuePutStrategy;
import jmt.engine.NetStrategies.ServiceStrategies.ZeroServiceTimeStrategy;
import jmt.engine.NetStrategies.ServiceStrategy;
import jmt.engine.QueueNet.*;
import jmt.engine.random.engine.RandomEngine;

/**
 * This class implements a generic finite/infinite queue. In finite queue, if
 * the queue is full, new jobs could be dropped or not. It could implement
 * different job strategy and/or waiting requests strategy.
 *
 * <br><br>
 * It can also define the queue of a station which is inside a blocking region.
 * When a job arrives at this node section, the source node of the message is found out.
 * If the source node is inside the same region, there are no problems and the message
 * is processed as usual.
 * Otherwise, if the source node is outside the blocking region, this message is not
 * processed but redirected to the fictitious station (called "region input station")
 * which controls the access to the blocking region.
 * <br><br>
 *
 * The class has different constructors to create a generic queue or a redirecting queue.
 * <br>
 * However it's also possible to create a generic queue and then to turn on/off the
 * "redirecting queue" behaviour using the <tt>redirectionTurnON(..)</tt> and
 * <tt>redirectionTurnOFF()</tt> methods.
 *
 * @author Francesco Radaelli, Stefano Omini, Bertoli Marco
 */
public class Queue extends InputSection {

	/** Property Identifier: infinite. */
	public static final int PROPERTY_ID_INFINITE = 0x0101;
	/** Property Identifier: drop.*/
	public static final int PROPERTY_ID_DROP = 0x0102;
	/** Property Identifier: size.*/
	public static final int PROPERTY_ID_SIZE = 0x0103;
	/** Property Identifier: Waiting request.*/
	public static final int PROPERTY_ID_WAITING_REQUESTS = 0x0104;
	/** Property Identifier: Queue get strategy.*/
	public static final int PROPERTY_ID_GET_STRATEGY = 0x0105;
	/** Property Identifier: Queue put strategy.*/
	public static final int PROPERTY_ID_PUT_STRATEGY = 0x0106;
    /** Property Identifier: Dropped jobs.*/
	public static final int PROPERTY_ID_DROPPED_JOBS = 0x0107;
    
    public static final String FINITE_DROP = "drop";
    public static final String FINITE_BLOCK = "BAS blocking";
    public static final String FINITE_WAITING = "waiting queue";
    
    private int size;

    //coolStart is true if there are no waiting jobs when the queue is started
	private boolean coolStart, infinite;
    
    private boolean[] drop, block;

    //the JobInfoList of the owner NetNode (use to control the number of jobs in
    //case of finite queue)
    private JobInfoList nodeJobsList;

    //number of dropped jobs
    private int droppedJobs;
    private int[] droppedJobsPerClass;

	private JobInfoList waitingRequests; 

	private QueueGetStrategy getStrategy;

	private QueuePutStrategy putStrategy[];


    //-------------------BLOCKING REGION PROPERTIES----------------------------//
    //@author Stefano Omini

    //true if the queue belongs to a blocking region and has to redirect the jobs
    //arriving from the outside of the region
    private boolean redirectionON;
    //the blocking region the node belongs to
    private BlockingRegion myRegion;
    //the input station of the blocking region
    private NetNode regionInputStation;

    //-------------------end BLOCKING REGION PROPERTIES----------------------------//


    //-------------------ZERO SERVICE TIME PROPERTIES------------------------------//
    //@author Stefano Omini

    //for each class, true if that class has a service time equal to zero and therefore
    //must be "tunnelled"
    private boolean hasZeroServiceTime[] = null;

    //-------------------end ZERO SERVICE TIME PROPERTIES--------------------------//





	/**
     * Creates a new instance of finite Queue.
	 * @param size Queue size (-1 = infinite queue).
	 * @param getStrategy Queue get strategy: if null FCFS strategy is used.
	 * @param putStrategy Queue put strategy: if null Tail strategy is used.
	 * @param drop True if the queue should rejects new jobs when it's full,
	 * false otherwise.
	 */
	public Queue(int size, boolean drop, QueueGetStrategy getStrategy,
                            QueuePutStrategy putStrategy[]) {

        //OLD
        //super();

        //NEW
        //auto = false, otherwise when a JOB message is received,
        //the corresponding Job object is automatically added to
        //JobInfoList

        super(false);
		//end NEW

        if (size == -1) {
            infinite = true;
		} else {
			this.size = size;
			infinite = false;
		}
		if (getStrategy == null)
			this.getStrategy = new FCFSstrategy();
		else
			this.getStrategy = getStrategy;
		this.putStrategy = putStrategy;
        // Uses putstrategy.length to extimate number of classes. It's a bit unclean but we are forced for compatibility.
        this.drop = new boolean[putStrategy.length];
        this.block = new boolean[putStrategy.length];
        Arrays.fill(this.drop, drop);
        Arrays.fill(this.block, false);
		coolStart = true;

        //this node doesn't belong to any blocking region
        redirectionON = false;
        myRegion = null;
        regionInputStation = null;

        //NEW
        //@author Stefano Omini
        //log = NetSystem.getLog();
        //end NEW
	}


    /**
     * Creates a new instance of finite Queue.
	 * @param size Queue size (-1 = infinite queue).
	 * @param getStrategy Queue get strategy: if null FCFS strategy is used.
	 * @param putStrategy Queue put strategy: if null Tail strategy is used.
	 * @param drop True if the queue should rejects new jobs when it's full,
	 * false otherwise.
	 */
	public Queue(Integer size, Boolean drop, QueueGetStrategy getStrategy,
                            QueuePutStrategy putStrategy[]) {
		this(size.intValue(), drop.booleanValue(), getStrategy, putStrategy );
	}



    /**
     * Creates a new instance of a infinite Queue.
	 * @param preLoad Queue preload: if null no preload is done.
	 * @param getStrategy Queue get strategy: if null FCFS strategy is used.
	 * @param putStrategy Queue put strategy: if null Tail strategy is used.
	 */
	public Queue(JobInfoList preLoad, QueueGetStrategy getStrategy,
	             QueuePutStrategy putStrategy[]) {

        //OLD
        //super();

        //NEW

        //auto = false, otherwise when a JOB message is received,
        //the corresponding Job object is automatically added to
        //JobInfoList

        super(false);
		//end NEW

		infinite = true;
		if (getStrategy == null)
			this.getStrategy = new FCFSstrategy();
		else
			this.getStrategy = getStrategy;
		if (preLoad != null)
			jobsList = preLoad;
		this.putStrategy = putStrategy;
		coolStart = true;

        //this node doesn't belong to any blocking region
        redirectionON = false;
        myRegion = null;
        regionInputStation = null;

        //NEW
        //@author Stefano Omini
        //log = NetSystem.getLog();
        //end NEW
	}

	/** Creates a new instance of finite Queue.
	 * @param preLoad Queue preload: if null no preload id done.
	 * @param size Queue size.
	 * @param getStrategy Queue get strategy: if null FCFS strategy is used.
	 * @param putStrategy Queue put strategy: if null Tail strategy is used.
	 * @param drop True if the queue should rejects new jobs when it's full,
	 * false otherwise.
	 */
	public Queue(int size, boolean drop, JobInfoList preLoad, QueueGetStrategy
            getStrategy, QueuePutStrategy putStrategy[]) {
		super(false);
		this.size = size;
		infinite = false;
		if (getStrategy == null)
			this.getStrategy = new FCFSstrategy();
		else
			this.getStrategy = getStrategy;
		if (preLoad != null)
			jobsList = preLoad;
		this.putStrategy = putStrategy;
        // Uses putstrategy.length to extimate number of classes. It's a bit unclean but we are forced for compatibility.
        this.drop = new boolean[putStrategy.length];
        this.block = new boolean[putStrategy.length];
        Arrays.fill(this.drop, drop);
        Arrays.fill(this.block, false);
		coolStart = true;

        //this node doesn't belong to any blocking region
        redirectionON = false;
        myRegion = null;
        regionInputStation = null;

        //NEW
        //@author Stefano Omini
        //log = NetSystem.getLog();
        //end NEW
	}



    /** Creates a new instance of finite redirecting Queue.
	 * @param size Queue size (-1 = infinite queue).
	 * @param getStrategy Queue get strategy: if null FCFS strategy is used.
	 * @param putStrategy Queue put strategy: if null Tail strategy is used.
	 * @param drop True if the queue should rejects new jobs when it's full,
	 * false otherwise.
     * @param myReg the blocking region to which the owner node of this queue belongs
	 */
	public Queue(int size, boolean drop, QueueGetStrategy getStrategy,
                            QueuePutStrategy putStrategy[], BlockingRegion myReg) {
		//uses constructor for generic queue
        this(size, drop, getStrategy, putStrategy);

        //sets blocking region properties
        redirectionON = true;
        myRegion = myReg;
        regionInputStation = myRegion.getInputStation();
	}


    /** Creates a new instance of finite redirecting Queue.
	 * @param size Queue size (-1 = infinite queue).
	 * @param getStrategy Queue get strategy: if null FCFS strategy is used.
	 * @param putStrategy Queue put strategy: if null Tail strategy is used.
	 * @param drop True if the queue should rejects new jobs when it's full,
	 * false otherwise.
     * @param myReg the blocking region to which the owner node of this queue belongs
	 */
	public Queue(Integer size, Boolean drop, QueueGetStrategy getStrategy,
                            QueuePutStrategy putStrategy[], BlockingRegion myReg) {
		this(size.intValue(), drop.booleanValue(),getStrategy, putStrategy, myReg);
	}


	/** Creates a new instance of a infinite redirecting Queue.
	 * @param preLoad Queue preload: if null no preload is done.
	 * @param getStrategy Queue get strategy: if null FCFS strategy is used.

⌨️ 快捷键说明

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