I have developed a server-to-server protocol called CCMN and different drop policies for the messages cached by each server. The PEERSIM simulator creates a template node with the CCMN protocol and then clones this template node.
The CCMN class includes different data structures maintaining the states required to implement the drop policies. For instance, Pmap resolves a content identifier to a content object, and freq a content identifier to the number of times a content object has been used.
public HashMap <String, Content> Pmap;
public HashMap<String, Integer> freq;
The initialization of these data structures is done in the clone method of CCMN. In order to support the drop policies, I use a priorityQueue initialized with a comparator corresponding to the policy to use. In the clone method:
if(dp.equals(DroppingPolicy.LFU)){
lfu less_frequent=new lfu(); av.raw_drop=new PriorityQueue(1, less_frequent); } The comparator are declared as follows:
public class lfu implements Comparator<String> {
public int compare(String s0, String s1) { if(freq.get(s0) > freq.get(s1)) return 1; else if(freq.get(s0) < freq.get(s1)) return -1; else return 0; } }
The problem is that I get a NullPointerException exception when i call :
raw_drop.add(ct.getID());
By debugging, I found that the add works for the first element, but the exception occurs when a second element is added. I traced the exception to the compare method, by checking the variables I find that the freq variable (and the other variables initialized in the clone method) equals null, while the variables defined in the constructor are well defined.
Moreover, I check that freq is well initialized before the add call.
I guess that there is a problem between the definition of the comparators as embedded classes and the clone method.
Any help is welcome.
Regards, Mohamed