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

📄 netnode.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.NodeSections.Queue;
import jmt.engine.dataAnalysis.Measure;
import jmt.engine.simEngine.SimEntity;
import jmt.engine.simEngine.SimEvent;
import jmt.engine.simEngine.SimSystem;
import jmt.engine.simEngine.SimTypeP;

import java.util.ListIterator;


/**
 * This class implements a generic QueueNetwork node.
 * @author Francesco Radaelli, Stefano Omini, Marco Bertoli
 */
public class NetNode extends SimEntity {

    //these constants are used in exception messages

    /** Unable to broadcast a message */
	public static final int EXCEPTION_UNABLE_TO_BROADCAST = 0x0001;
	/** Required measure does not exist */
	public static final int EXCEPTION_MEASURE_DOES_NOT_EXIST = 0x0002;
	/** Input section has been already defined. */
	public static final int EXCEPTION_INPUT_SECTION_ALREADY_DEFINED = 0x0003;
	/** Service section has been already defined.  */
	public static final int EXCEPTION_SERVICE_SECTION_ALREADY_DEFINED = 0x0004;
	/** Output section has been already defined. */
	public static final int EXCEPTION_OUTPUT_SECTION_ALREADY_DEFINED = 0x0005;
    /** Required property is not available */
	public static final int EXCEPTION_PROPERTY_NOT_AVAILABLE = 0x0006;


    //ID of properties

    /** Property ID: number of jobs which arrived to this node */
	public static final int PROPERTY_ID_ARRIVED_JOBS = 0x0001;
	/** Property ID: number of jobs which left this node */
	public static final int PROPERTY_ID_LEFT_JOBS = 0x0002;
	/** Property ID: number of events */
	public static final int PROPERTY_ID_EVENTS = 0x0003;
	/** Property ID: number of jobs inside the node*/
	public static final int PROPERTY_ID_RESIDENT_JOBS = 0x0004;
    /** Property ID: residence time */
	public static final int PROPERTY_ID_RESIDENCE_TIME = 0x0005;
	/** Property ID: throughput */
	public static final int PROPERTY_ID_THROUGHPUT = 0x0006;

	/**
     * The QueueNetwork which this NetNode belong to.
     */
	protected QueueNetwork Network;


	private JobInfoList jobsList;

	/** Input section of the NetNode.
     *
     */
	protected NodeSection inputSection;

	/** Service section of the NetNode.
     *
     */
	protected NodeSection serviceSection;

	/** Output section of the NetNode.
     *
     */
	protected NodeSection outputSection;

	private int eventsCounter;

	//DEK (Federico Granata)

	private SimEvent receiveBuffer;

    //temp variables to contain message and message event type
    private NetMessage message;
    private int eventType;

	private boolean stopped;

	private NodeList InputNodes;

	private NodeList OutputNodes;


	/** Creates a new instance of NetNode.
	 * @param name Name of the NetNode.
	 */
	public NetNode(String name) {
		super(name);
		InputNodes = new NodeList();
		OutputNodes = new NodeList();
		inputSection = serviceSection = outputSection = null;
		receiveBuffer = new SimEvent();
		stopped = false;
	}

	/** Adds a section to the node.
	 * @param  Section Reference to the section to be added.
	 * @throws jmt.common.exception.NetException if trying to add a section which has already been defined
	 */
	public void addSection(NodeSection Section) throws jmt.common.exception.NetException {
		switch (Section.getSectionID()) {
			case NodeSection.INPUT:
				if (inputSection == null)
					this.inputSection = Section;
				else
					throw new jmt.common.exception.NetException(this, EXCEPTION_INPUT_SECTION_ALREADY_DEFINED,
					        "input section has been already defined");
				break;
			case NodeSection.SERVICE:
				if (serviceSection == null)
					this.serviceSection = Section;
				else
					throw new jmt.common.exception.NetException(this, EXCEPTION_SERVICE_SECTION_ALREADY_DEFINED,
					        "service section has been already defined");
				break;
			case NodeSection.OUTPUT:
				if (outputSection == null)
					this.outputSection = Section;
				else
					throw new jmt.common.exception.NetException(this, EXCEPTION_OUTPUT_SECTION_ALREADY_DEFINED,
					        "output section has been already defined");
				break;
		}
		Section.setOwnerNode(this);
	}

	/** Connects the output of this netNode to the input of an another
	 *  netNode.
	 *  @param netNode netNode to be linked.
	 */
	public void connect(NetNode netNode) throws jmt.common.exception.NetException {
		OutputNodes.add(netNode);
		netNode.InputNodes.add(this);
	}


    //NEW
    //@author Stefano Omini
    /**
     * Gets the JobInfoList of this node.
     *
     */
    public JobInfoList getJobInfoList() {
        return jobsList;
    }
    //end NEW


    /** Gets input nodes.
	 * @return Input nodes linked to this node.
	 */
	public NodeList getInputNodes() {
		return InputNodes;
	}

	/** Gets output nodes.
	 * @return Output nodes linked to this node.
	 */
	public NodeList getOutputNodes() {
		return OutputNodes;
	}

	/** Gets an integer type property related to this node.
	 * @param Id Property identifier.
	 * @return Property value.
	 * @throws jmt.common.exception.NetException if the property is not available.
	 */
	public int getIntNodeProperty(int Id) throws jmt.common.exception.NetException {
		try {
			switch (Id) {
				case PROPERTY_ID_ARRIVED_JOBS:
					return jobsList.getJobsIn();
				case PROPERTY_ID_LEFT_JOBS:
					return jobsList.getJobsOut();
				case PROPERTY_ID_EVENTS:
					return eventsCounter;
				case PROPERTY_ID_RESIDENT_JOBS:
					return jobsList.size();
			}
		} catch (jmt.common.exception.NetException exc) {
			throw new jmt.common.exception.NetException(this, EXCEPTION_PROPERTY_NOT_AVAILABLE,
			        "required property is not available.", exc);
		}
		throw new jmt.common.exception.NetException(this, EXCEPTION_PROPERTY_NOT_AVAILABLE,
		        "required property is not available.");
	}

	/** Gets an integer type property of this node related to a specified
	 * job class.
	 * @param Id Property identifier.
	 * @param JobClass JobClass.
	 * @return Property value.
	 * @throws jmt.common.exception.NetException if the property is not available.
	 */
	public int getIntNodeProperty(int Id, JobClass JobClass) throws jmt.common.exception.NetException {
		try {
			switch (Id) {
				case PROPERTY_ID_ARRIVED_JOBS:
					return jobsList.getJobsInPerClass(JobClass);
				case PROPERTY_ID_LEFT_JOBS:
					return jobsList.getJobsOutPerClass(JobClass);
				case PROPERTY_ID_RESIDENT_JOBS:
					return jobsList.size(JobClass);
			}
		} catch (jmt.common.exception.NetException exc) {
			throw new jmt.common.exception.NetException(this, EXCEPTION_PROPERTY_NOT_AVAILABLE,
			        "required property is not available.", exc);
		}
		throw new jmt.common.exception.NetException(this, EXCEPTION_PROPERTY_NOT_AVAILABLE,
		        "required property is not available.");
	}

	/** Gets a double type property of this node.
	 * @param Id Property identifier.
	 * @return Property value.
	 * @throws jmt.common.exception.NetException if the property is not available.
	 */
	public double getDoubleNodeProperty(int Id) throws jmt.common.exception.NetException {
		try {
			switch (Id) {
				case PROPERTY_ID_RESIDENCE_TIME:
					return jobsList.getBusyTime() / jobsList.getJobsOut();
				case PROPERTY_ID_THROUGHPUT:
					return jobsList.getJobsOut() / NetSystem.getTime();
			}
		} catch (jmt.common.exception.NetException exc) {
			throw new jmt.common.exception.NetException(this, EXCEPTION_PROPERTY_NOT_AVAILABLE,
			        "required property is not available.", exc);
		}
		throw new jmt.common.exception.NetException(this, EXCEPTION_PROPERTY_NOT_AVAILABLE,
		        "required property is not available.");
	}

	/** Gets a double type property of this node related to a specified
	 * job class.
	 * @param Id Property identifier.
	 * @param JobClass JobClass.
	 * @return Property value.
	 * @throws jmt.common.exception.NetException if the property is not available.
	 */
	public double getDoubleNodeProperty(int Id, JobClass JobClass) throws jmt.common.exception.NetException {
		try {
			switch (Id) {
				case PROPERTY_ID_RESIDENCE_TIME:
					return jobsList.getBusyTimePerClass(JobClass) /
					        jobsList.getJobsOutPerClass(JobClass);
				case PROPERTY_ID_THROUGHPUT:
					return jobsList.getJobsOutPerClass(JobClass) /
					        NetSystem.getTime();
			}
		} catch (jmt.common.exception.NetException exc) {
			throw new jmt.common.exception.NetException(this, EXCEPTION_PROPERTY_NOT_AVAILABLE,
			        "required property is not available.", exc);
		}
		throw new jmt.common.exception.NetException(this, EXCEPTION_PROPERTY_NOT_AVAILABLE,
		        "required property is not available.");
	}


	/** Gets a generic object type property of this node.
	 * @param Id Property identifier.
	 * @return Property value.
	 * @throws jmt.common.exception.NetException if the property is not available.
	 */
	public Object getObjectNodeProperty(int Id) throws jmt.common.exception.NetException {
		switch (Id) {
            default:
				throw new jmt.common.exception.NetException(this, EXCEPTION_PROPERTY_NOT_AVAILABLE,
				        "required property is not available.");
		}
	}

	/** Gets a generic object type property of this node related to a
	 * specified job class.
	 * @param Id Property identifier.
	 * @param JobClass JobClass.
	 * @return Property value.
	 * @throws jmt.common.exception.NetException if the property is not available.
	 */
	public Object getObjectNodeProperty(int Id, JobClass JobClass) throws jmt.common.exception.NetException {
		switch (Id) {
            default:
				throw new jmt.common.exception.NetException(this, EXCEPTION_PROPERTY_NOT_AVAILABLE,
				        "required property is not available.");
		}

⌨️ 快捷键说明

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