Improvements on EventListener Event ...

This commit is contained in:
7u83
2018-12-25 18:16:45 +01:00
parent 0397dc44a9
commit 99fea69520
10 changed files with 168 additions and 57 deletions

View File

@ -35,6 +35,8 @@ import java.util.TreeSet;
import opensesim.world.RealWorld;
import opensesim.sesim.interfaces.Configurable;
import opensesim.sesim.interfaces.GetJson;
import opensesim.world.scheduler.FiringEvent;
import opensesim.world.scheduler.EventListener;
import org.json.JSONObject;
/**
@ -145,14 +147,22 @@ public class Exchange implements Configurable, GetJson {
}
}
@Override
public Order createOrder(Account account, Order.Type type, double volume, double limit) {
Order o = new opensesim.world.Order(world, account, pair, type, volume, limit);
synchronized (this){
order_books.get(o.type).add(o);
}
for (FiringEvent e:book_listener){
e.fire();
}
return o;
}
@ -160,6 +170,12 @@ public class Exchange implements Configurable, GetJson {
public Set getOrderBook(Order.Type type) {
return Collections.unmodifiableSet(order_books.get(type));
}
HashSet <FiringEvent> book_listener = new HashSet<>();
@Override
public void addOrderBookListener(EventListener listener) {
book_listener.add(new FiringEvent(listener));
}