I am creating a demo stock exchange distributed program in Java using jgroups as middleware. My Stock class has a priority queue which has a comparator, and results in Stock$1.class
and Stock$2.class
along with Stock.class
. Jgroups can send only serializable data but from what I understand $1.class
and $2.class
result from inner classes that are inferred because of comparator's and are not serializable thus causing exceptions with JGroups, can someone help me as to how to make them serializable too or some other tweek to not to make it look like inner classes.
import java.io.*;
import java.util.*;
import java.io.Serializable;
public class Stock implements Serializable
{
public String name;
public String symbol;
public int shares = 10000;
public int price = 100;
public PriorityQueue<Order> sellList = new PriorityQueue<Order>(100, new Comparator<Order>()
{
public int compare(Order oldOrder, Order newOrder)
{
int i = oldOrder.price;
int j = newOrder.price;
if(i > j)
return 1;
else if(i < j)
return -1;
else
return 0;
}
}
);
public PriorityQueue<Order> buyList = new PriorityQueue<Order>(100, new Comparator<Order>()
{
public int compare(Order oldOrder, Order newOrder)
{
int i = oldOrder.price;
int j = newOrder.price;
if(i > j)
return -1;
else if(i < j)
return 1;
else
return 0;
}
}
);
}