📄 eventqueue.java
字号:
/* * project: RebecaSim * package: sim * file: EventQueue.java * * version: 0.1 * date: 03.05.2005 * * This software is part of the diploma thesis "Ein adaptives Brokernetz * für Publish/Subscribe Systeme". */package sim;import broker.*;import java.util.*;import com.Broadcast;import com.Notification;/** * TODO Insert class description here. * * @version 03.05.2005 * @author parzy */public class EventQueue { private TreeSet queue; public EventQueue(){ queue = new TreeSet(); } public void enqueue(Event e){ if(!queue.add(e)){ throw new IllegalStateException("Unable to enqueue event."); } } public Event dequeue(){ Event e = (Event)queue.first(); if(!queue.remove(e)){ throw new IllegalStateException("Unable to remove dequeued event."); } return e; } public boolean remove(Event e){ return queue.remove(e); } public boolean isEmpty(){ return queue.isEmpty(); } public int size() { return queue.size(); } public void clear() { queue.clear(); } // TODO remove public void stats(){ int b = 0; int n = 0; for(Iterator it = queue.iterator(); it.hasNext();){ Event e = (Event)it.next(); if(e instanceof ReceiveEvent){ ReceiveEvent r = (ReceiveEvent)e; if(r.message instanceof Broadcast){ b++; } if(r.message instanceof Notification){ n++; } } } System.out.println("Broadcasts: "+b+" Notification: "+n); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -