floodidqueue.java

来自「DSr project for the java applications」· Java 代码 · 共 78 行

JAVA
78
字号
package dsr;//this class is implemented to store the info about the RREQ packets that have been sent out//so that we don't have duplicate entries floating around in the networkimport java.io.*;import java.util.*;import java.net.*;public class FloodIDQueue {  public static List IDQueue;      //List  //constructor  public FloodIDQueue() {    IDQueue = Collections.synchronizedList(new LinkedList());  }  //print out the entries in the flood Queue  public static void PrintFloodIDQueue() {    Iterator r = IDQueue.iterator();    System.out.println("************************************************************************");    System.out.println("The entries in the flood id queue are");    System.out.println("************************************************************************");    while (r.hasNext()) {      System.out.println(((FloodIDQueueEntry)r.next()).toString());    }    System.out.println("************************************************************************");  }  //find a particular Entry in the queue. Returns the entry if found, null otherwise  public static FloodIDQueueEntry findFloodIDQueueEntry(InetAddress dstIP, int floodID) {    FloodIDQueueEntry tmpEntry = new FloodIDQueueEntry();    for (int i = 0; i < IDQueue.size(); ++i) {      tmpEntry = (FloodIDQueueEntry)IDQueue.get(i);      //the combination of destination address and the flood ID uniquely identifies an entry      if (tmpEntry.dstIP.equals(dstIP) && tmpEntry.floodID == floodID)        return tmpEntry;    }    return null;  }  //clean up the whole queue  public void cleanUpFloodIDQueue() {    IDQueue.clear();  }  //insert an entry into the FloodID Queue  public static void insertFloodIDQueueEntry(InetAddress srcIP, InetAddress dstIP, int floodID,      long lifetime) {    FloodIDQueueEntry tmpEntry = new FloodIDQueueEntry(srcIP, dstIP, lifetime);    IDQueue.add(tmpEntry);  }  //find out if this entry is valid. After the lifetime is over the entry is no more valid  public boolean isFloodIDQueueEntryValid(FloodIDQueueEntry tmpEntry) {    if (tmpEntry.lifetime < System.currentTimeMillis())      return false;    else      return true;  }  //goes through the list and deletes the entries that are no more valid  public void deleteInvalidFloodIDQueueEntry() {    FloodIDQueueEntry tmpEntry = new FloodIDQueueEntry();    for (int i=0; i < IDQueue.size(); ++i) {      tmpEntry = (FloodIDQueueEntry)IDQueue.get(i);      if (tmpEntry.lifetime < System.currentTimeMillis())        IDQueue.remove(i);    }  }  //delete this particular entry in the food ID queue  public void deleteThisFloodIDQueueEntry(FloodIDQueueEntry tmpEntry) {    IDQueue.remove(tmpEntry);  }}

⌨️ 快捷键说明

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