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

📄 netnode.java

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

	/** Gets a section of the node.
	 * @param Id Section identifier (constants defined in NodeSection).
	 * @return Node section.
	 * @throws jmt.common.exception.NetException EXCEPTION
	 */
	public NodeSection getSection(int Id) throws jmt.common.exception.NetException {
		switch (Id) {
			case NodeSection.INPUT:
				return inputSection;
			case NodeSection.SERVICE:
				return serviceSection;
			case NodeSection.OUTPUT:
				return outputSection;
			default:
				throw new jmt.common.exception.NetException(this, EXCEPTION_PROPERTY_NOT_AVAILABLE,
				        "required section is not available.");
		}
	}


	/** Gets the Network owner of this node.
	 * @return Value of property Network.
	 */
	public QueueNetwork getQueueNet() {
		return Network;
	}


    /** Analyzes a measure in the node.
	 * @param measureName name of the measure to be activated.
	 * @param jobClass Job class to be analyzed.
	 * @param measurement measure to be activated.
	 * @throws jmt.common.exception.NetException
	 */
    public void analyze(int measureName, JobClass jobClass, Measure measurement)
	        throws jmt.common.exception.NetException {
		switch (measureName) {
			case SimConstants.LIST_NUMBER_OF_JOBS:
                jobsList.analyzeQueueLength(jobClass, measurement);
                break;

            case SimConstants.LIST_RESIDENCE_TIME:
				//jobsList.analyzeResponseTime(jobClass, measurement);
                jobsList.analyzeResidenceTime(jobClass, measurement);
				break;
            //NEW Bertoli Marco
            case SimConstants.LIST_RESPONSE_TIME:
                jobsList.analyzeResponseTime(jobClass, measurement);
                break;
            //end NEW
  			default:
				throw new jmt.common.exception.NetException(this, EXCEPTION_MEASURE_DOES_NOT_EXIST,
				        "required analyzer does not exist!");
		}
	}

	public boolean isRunning() {
		return (state != SimEntity.FINISHED);
	}

	/** Gets the list of the job classes of the owner queue network.
	 * @return Queue network job classes.
	 */
	public JobClassList getJobClasses() {
		return Network.getJobClasses();
	}

	/** Gets the first NetMessage in the queue which validates a specific
	 * predicate.
	 * @param message Reference to a NetMessage buffer to be filled with
	 * the message information
	 * @throws jmt.common.exception.NetException
	 */
	protected void receive(NetMessage message)
	        throws jmt.common.exception.NetException {

        //COMMENT
        //@author Stefano Omini

        //We want to set some properties of NetMessage parameter using the
        //information contained in a tag of the received SimEvent
        //Remember that:
        //a >> b means to "right-shift" of "b" positions the bits of "a"
        //a << b means to "left-shift" of "b" positions the bits of "a"
        //
        //int type is made of 32 bit (= 4 Bytes = 8 words)
        //
        //
        //EVENT_MASK        = 0x0000FFFF;    (as defined in NetEvent)
        //SOURCE_MASK       = 0xFF000000;    (as defined in NodeSection)
        //DESTINATION_MASK  = 0x00FF0000;    (as defined in NodeSection)
        //
        //SOURCE_SHIFT      = 24;            (as defined in NodeSection)
        //DESTINATION_SHIFT = 16;            (as defined in NodeSection)

        //receiveBuffer, that is the received SimEvent, has a tag with this structure:
        //      0xSSDDEEEE
        // where    SS -> 1 byte (=2 words) referring to source
        //          DD -> 1 byte (=2 words) referring to destination
        //          EEEE -> 2 bytes (=4 words) referring to event
        //This tag contains some useful informations.

        //To set event, sourceSection and destinationSection of the parameter NetMessage
        //some binary shifts have to be realized (corresponding bits must be recognized
        //in simEvent tag using the correct mask and then they must be shifted as required by the
        //definitions of these properties)

        //set event (int)


        //END COMMENT

        int section;
        message.setEvent(receiveBuffer.getTag() & NetEvent.EVENT_MASK);

        //set sourceSection and destinationSection (byte)

		section = receiveBuffer.getTag() & NodeSection.SOURCE_MASK;
		section >>= NodeSection.SOURCE_SHIFT;
		message.setSourceSection((byte) section);

		section = receiveBuffer.getTag() & NodeSection.DESTINATION_MASK;
		section >>= NodeSection.DESTINATION_SHIFT;
		message.setDestinationSection((byte) section);

        //set other properties

		message.setData(receiveBuffer.getData());
		message.setTime(receiveBuffer.eventTime());
		message.setSource(NetSystem.getNode(receiveBuffer.getSrc()));
		message.setDestination(NetSystem.getNode(receiveBuffer.getDest()));


        //Look if message is a job message and if job is arriving at this node (from the node
        //itself or from another node)
        if (message.getEvent() == NetEvent.EVENT_JOB) {
            //event job
            if (message.getSource() != this) {
                //external source
                Job job = message.getJob();
			    jobsList.add(new JobInfo(job));
            } else if ((message.getSourceSection() == NodeSection.OUTPUT)
		        && (message.getDestinationSection() == NodeSection.INPUT)) {
                //internal source
                Job job = message.getJob();
			    jobsList.add(new JobInfo(job));
            }
        }
	}

	/** This method implements the body of a NetNode.
	 **/
	public final void body() {
		message = new NetMessage();

        try {
			receiveBuffer = getEvbuf();

            //receive a new messege
			receive(message);
			eventsCounter++;

            eventType = message.getEvent();

            //if the deferred queue(where we put messages when the node is busy)
			//contains an abort event then poison the node.
			//TODO: da togliere e' meglio mettere qualcosa che faccia lo stesso sul sistema quando viene lanciato un evento di questo genere
			if (simWaiting(new SimTypeP(NetEvent.EVENT_ABORT)) > 0)
				poison();

            //process last event
            if (eventType == NetEvent.EVENT_KEEP_AWAKE) {
				poison();
			}

            //receive a stop event
            if (!stopped && eventType == NetEvent.EVENT_STOP) {
				stopped = true;
			}

            // if this node has been stopped sends automatically acks
			// to the node which sent job to this one.
			if (stopped) {
                if (eventType == NetEvent.EVENT_JOB)
					send(NetEvent.EVENT_ACK, message.getJob(), 0.0,
					        NodeSection.NO_ADDRESS,
					        message.getSourceSection(),
					        message.getSource());
			} else {
				dispatch(message);
            }
			simGetNext(SimSystem.SIM_ANY);

		} catch (jmt.common.exception.NetException Exc) {
			Exc.printStackTrace();
		}

	}

	/** This method should be overridden to implement a own dispatch.
	 *  This method implements the events dispacther of the NetNode; it
	 *  <b><u>should never</u></b> remains busy for a long time.
	 *  Remember to call the superclass dispatch method if you want to inherit
	 *  all the superclass handled events.
	 */
	protected void dispatch(NetMessage message) throws jmt.common.exception.NetException {
		int processed = NodeSection.MSG_NOT_PROCESSED;
		int section = NodeSection.NO_ADDRESS;
		NetNode source = message.getSource();
		byte sourceSection = message.getSourceSection();
		byte destinationSection = message.getDestinationSection();

        //message goes through this switch depending on the destination section
		//if the message is correctly processed by the appropriate node section
		//then the pocessed variable contains a value different from the initial
		//MSG_NOT_PROCESSED.
		switch (destinationSection) {

            case NodeSection.INPUT:
				section = NodeSection.INPUT;
				// checks jobs routing
				if (message.getEvent() == NetEvent.EVENT_JOB)
					if (source != this) {
                        // If this message is JOB and we are reference node for that job, signals it
                        // This is needed for global measures - Bertoli Marco
                        if (message.getEvent() == NetEvent.EVENT_JOB && message.getJob().getJobClass().getReferenceNodeName().equals(this.getName()))
                            this.getQueueNet().getJobInfoList().recycleJob(message.getJob());
                        if (sourceSection != NodeSection.OUTPUT) {
                            //the exterior source section can be the input
                            // section only in case of redirecting queue
                            NodeSection sourceSect = source.getSection(sourceSection);

                            //check if this job has been redirected, otherwise the message
                            //cannot be dispatched
                            boolean redirected =
                                    (sourceSect instanceof Queue) &&
                                    (((Queue) sourceSect).isRedirectionON());
                            if (!redirected) {
                                break;
                            }
                        }
					}
				if (inputSection != null)
					processed = inputSection.receive(message);
				break;

            case NodeSection.SERVICE:
				section = NodeSection.SERVICE;
				// checks jobs routing
				if (message.getEvent() == NetEvent.EVENT_JOB)
					if (source != this)
						break;
				if (serviceSection != null)
					processed = serviceSection.receive(message);
				break;

            case NodeSection.OUTPUT:
				section = NodeSection.OUTPUT;
				// checks jobs routing
				if (message.getEvent() == NetEvent.EVENT_JOB)
					if (source != this)
						break;
					else if (sourceSection == NodeSection.INPUT)
						break;
				if (outputSection != null)
					processed = outputSection.receive(message);
				break;

            default:
				;
		}

        if (processed == NodeSection.MSG_NOT_PROCESSED) {
        }

	}


	/** Sends a message to a NetNode.
	 * @param Event Event tag.
	 * @param Data  Data to be attached to the message.
	 * @param Delay Scheduling delay.
	 * @param SourceSection The source section.
	 * @param DestinationSection The destination section.
	 * @param Destination The destination node.
	 * @throws jmt.common.exception.NetException Exception
	 */
	void send(int Event, Object Data, double Delay, byte SourceSection,
	          byte DestinationSection, NetNode Destination)
	        throws jmt.common.exception.NetException {
		int Tag;
		//TODO: vedi analogo problema per receive
        //Look if message is a job message and if job is leaving this node

        if ((Event == NetEvent.EVENT_JOB) &&
                ((Destination != this) ||
		        ((Destination == this) && (SourceSection == NodeSection.OUTPUT) &&
		        (DestinationSection == NodeSection.INPUT)))
        ) {
			Job job = (Job) Data;
			JobInfo JobInfo = jobsList.lookFor(job);
			if (JobInfo != null)
                jobsList.remove(JobInfo);
		}


        //TODO: forse se il job 

⌨️ 快捷键说明

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