Package org.apache.lucene.monitor
Class ConcurrentQueryLoader
- java.lang.Object
-
- org.apache.lucene.monitor.ConcurrentQueryLoader
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class ConcurrentQueryLoader extends Object implements Closeable
Utility class for concurrently loading queries into a Monitor.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.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_QUEUE_SIZE
-
Constructor Summary
Constructors Constructor Description ConcurrentQueryLoader(Monitor monitor)
Create a new ConcurrentQueryLoader for aMonitor
ConcurrentQueryLoader(Monitor monitor, int threads, int queueSize)
Create a new ConcurrentQueryLoader
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(MonitorQuery mq)
Add a MonitorQuery to the loader's internal buffervoid
close()
-
-
-
Field Detail
-
DEFAULT_QUEUE_SIZE
public static final int DEFAULT_QUEUE_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ConcurrentQueryLoader
public ConcurrentQueryLoader(Monitor monitor)
Create a new ConcurrentQueryLoader for aMonitor
- Parameters:
monitor
- Monitor
-
ConcurrentQueryLoader
public ConcurrentQueryLoader(Monitor monitor, int threads, int queueSize)
Create a new ConcurrentQueryLoader- Parameters:
monitor
- the Monitor to load queries tothreads
- the number of threads to usequeueSize
- the size of the buffer to hold queries in
-
-
Method Detail
-
add
public void add(MonitorQuery mq) throws InterruptedException
Add a MonitorQuery to the loader's internal bufferIf the buffer is full, this will block until there is room to add the MonitorQuery
- Parameters:
mq
- the monitor query- Throws:
InterruptedException
- if interrupted while waiting
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-