Queue of external events. This class also takes care of buffering the events and preloading only a proper amount of them.
| 15 | * the events and preloading only a proper amount of them. |
| 16 | */ |
| 17 | public class ExternalEventsQueue implements EventQueue { |
| 18 | /** ExternalEvents namespace ({@value})*/ |
| 19 | public static final String SETTINGS_NAMESPACE = "ExternalEvents"; |
| 20 | /** number of event to preload -setting id ({@value})*/ |
| 21 | public static final String PRELOAD_SETTING = "nrofPreload"; |
| 22 | /** path of external events file -setting id ({@value})*/ |
| 23 | public static final String PATH_SETTING = "filePath"; |
| 24 | |
| 25 | /** default number of preloaded events */ |
| 26 | public static final int DEFAULT_NROF_PRELOAD = 500; |
| 27 | |
| 28 | private File eventsFile; |
| 29 | private ExternalEventsReader reader; |
| 30 | private int nextEventIndex; |
| 31 | private int nrofPreload; |
| 32 | private List<ExternalEvent> queue; |
| 33 | private boolean allEventsRead = false; |
| 34 | |
| 35 | /** |
| 36 | * Creates a new Queue from a file |
| 37 | * @param filePath Path to the file where the events are read from. If |
| 38 | * file ends with extension defined in {@link BinaryEventsReader#BINARY_EXT} |
| 39 | * the file is assumed to be a binary file. |
| 40 | * @param nrofPreload How many events to preload |
| 41 | * @see BinaryEventsReader#BINARY_EXT |
| 42 | * @see BinaryEventsReader#storeToBinaryFile(String, List) |
| 43 | */ |
| 44 | public ExternalEventsQueue(String filePath, int nrofPreload) { |
| 45 | setNrofPreload(nrofPreload); |
| 46 | init(filePath); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Create a new Queue based on the given settings: {@link #PRELOAD_SETTING} |
| 51 | * and {@link #PATH_SETTING}. The path setting supports value filling. |
| 52 | * @param s The settings |
| 53 | */ |
| 54 | public ExternalEventsQueue(Settings s) { |
| 55 | if (s.contains(PRELOAD_SETTING)) { |
| 56 | setNrofPreload(s.getInt(PRELOAD_SETTING)); |
| 57 | } |
| 58 | else { |
| 59 | setNrofPreload(DEFAULT_NROF_PRELOAD); |
| 60 | } |
| 61 | String eeFilePath = s.valueFillString(s.getSetting(PATH_SETTING)); |
| 62 | init(eeFilePath); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Sets maximum number of events that are read when the next preload occurs |
| 67 | * @param nrof Maximum number of events to read. If less than 1, default |
| 68 | * value ( {@value DEFAULT_NROF_PRELOAD} ) is used. |
| 69 | */ |
| 70 | public void setNrofPreload(int nrof) { |
| 71 | if (nrof < 1) { |
| 72 | nrof = DEFAULT_NROF_PRELOAD; |
| 73 | } |
| 74 | this.nrofPreload = nrof; |
nothing calls this directly
no outgoing calls
no test coverage detected