timerqueue.java
来自「DSr project for the java applications」· Java 代码 · 共 55 行
JAVA
55 行
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 + =
减小字号Ctrl + -
显示快捷键?