📄 timerqueue.java
字号:
package dsr;import java.io.*;import java.util.*;import java.net.*;//this implements the queue of timed events.public class TimerQueue { static Vector timerQueue; //vector of entries //constructor TimerQueue() { timerQueue = new Vector(3,2); } //prints out the Timer queue entry public static void PrintTimerQueue(){ Iterator r = timerQueue.iterator(); System.out.println("************************************************************************"); System.out.println("The entries in the timer queue are"); System.out.println("************************************************************************"); while (r.hasNext()) { System.out.println(((TimerQueueEntry)r.next()).toString()); } System.out.println("************************************************************************"); } //insert the timer entry in the queue public static void insertInTimerQueue(long t, InetAddress s, InetAddress d, short r, short f) { TimerQueueEntry tmp = new TimerQueueEntry(t, s, d, r, f); timerQueue.addElement(tmp); } //checks to see if the RREQ packet is still valid in the timer queue. this is stop duplicate //RREQ request flowing in the network. returns true if and only if a new RREQ needs to be generated public static boolean checkForThisRREQInTimerQueue(InetAddress src, InetAddress dst, short f) { TimerQueueEntry tmp = new TimerQueueEntry(); Iterator t = timerQueue.iterator(); long currTime = System.currentTimeMillis(); while (t.hasNext()) { tmp = (TimerQueueEntry)t.next(); if (tmp.flags == f && tmp.destIP.equals(dst) && tmp.srcIP.equals(src) && currTime > tmp.validTime) { if (tmp.retries <= 0) return true; else { tmp.retries--; return false; } } } return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -