public class ConcurrentQueryLoader extends Object implements Closeable
This is useful to speed up startup times for a Monitor. You can use multiple threads to parse and index queries before starting matches.
Use as follows:
List<QueryError> errors = new ArrayList<>(); try (ConcurrentQueryLoader loader = new ConcurrentQueryLoader(monitor, errors)) { for (MonitorQuery mq : getQueries()) { loader.add(mq); } }
The Monitor's MonitorQueryParser must be thread-safe for this to work correctly.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_QUEUE_SIZE |
Constructor and Description |
---|
ConcurrentQueryLoader(Monitor monitor)
Create a new ConcurrentQueryLoader for a
Monitor |
ConcurrentQueryLoader(Monitor monitor,
int threads,
int queueSize)
Create a new ConcurrentQueryLoader
|
Modifier and Type | Method and Description |
---|---|
void |
add(MonitorQuery mq)
Add a MonitorQuery to the loader's internal buffer
|
void |
close() |
public static final int DEFAULT_QUEUE_SIZE
public ConcurrentQueryLoader(Monitor monitor)
Monitor
monitor
- Monitorpublic ConcurrentQueryLoader(Monitor monitor, int threads, int queueSize)
monitor
- the Monitor to load queries tothreads
- the number of threads to usequeueSize
- the size of the buffer to hold queries inpublic void add(MonitorQuery mq) throws InterruptedException
If the buffer is full, this will block until there is room to add the MonitorQuery
mq
- the monitor queryInterruptedException
- if interrupted while waitingpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.