use of com.wavefront.agent.data.DataSubmissionTask in project java by wavefrontHQ.
the class QueueingFactoryImpl method getQueueController.
@SuppressWarnings("unchecked")
@Override
public <T extends DataSubmissionTask<T>> QueueController<T> getQueueController(@Nonnull HandlerKey handlerKey, int numThreads) {
ScheduledExecutorService executor = executors.computeIfAbsent(handlerKey, x -> Executors.newScheduledThreadPool(numThreads, new NamedThreadFactory("queueProcessor-" + handlerKey.getEntityType() + "-" + handlerKey.getHandle())));
List<QueueProcessor<T>> queueProcessors = IntStream.range(0, numThreads).mapToObj(i -> (QueueProcessor<T>) getQueueProcessor(handlerKey, executor, i)).collect(Collectors.toList());
return (QueueController<T>) queueControllers.computeIfAbsent(handlerKey, x -> new QueueController<>(handlerKey, queueProcessors, backlogSize -> entityPropsFactory.get(handlerKey.getEntityType()).reportBacklogSize(handlerKey.getHandle(), backlogSize)));
}
use of com.wavefront.agent.data.DataSubmissionTask in project java by wavefrontHQ.
the class TaskQueueFactoryImpl method createTaskQueue.
private <T extends DataSubmissionTask<T>> TaskQueue<T> createTaskQueue(@Nonnull HandlerKey handlerKey, int threadNum) {
String fileName = bufferFile + "." + handlerKey.getEntityType().toString() + "." + handlerKey.getHandle() + "." + threadNum;
String lockFileName = fileName + ".lck";
String spoolFileName = fileName + ".spool";
// iron-clad guarantee, but it works well in most cases.
try {
File lockFile = new File(lockFileName);
if (lockFile.exists()) {
Files.deleteIfExists(lockFile.toPath());
}
FileChannel channel = new RandomAccessFile(lockFile, "rw").getChannel();
if (channel.tryLock() == null) {
throw new OverlappingFileLockException();
}
} catch (SecurityException e) {
logger.severe("Error writing to the buffer lock file " + lockFileName + " - please make sure write permissions are correct for this file path and restart the " + "proxy: " + e);
return new TaskQueueStub<>();
} catch (OverlappingFileLockException e) {
logger.severe("Error requesting exclusive access to the buffer " + "lock file " + lockFileName + " - please make sure that no other processes " + "access this file and restart the proxy: " + e);
return new TaskQueueStub<>();
} catch (IOException e) {
logger.severe("Error requesting access to buffer lock file " + lockFileName + " Channel is " + "closed or an I/O error has occurred - please restart the proxy: " + e);
return new TaskQueueStub<>();
}
try {
File buffer = new File(spoolFileName);
if (purgeBuffer) {
if (buffer.delete()) {
logger.warning("Retry buffer has been purged: " + spoolFileName);
}
}
BiConsumer<Integer, Long> statsUpdater = (bytes, millis) -> {
bytesWritten.inc(bytes);
ioTimeWrites.inc(millis);
};
com.wavefront.agent.queueing.QueueFile queueFile = disableSharding ? new ConcurrentQueueFile(new TapeQueueFile(new QueueFile.Builder(new File(spoolFileName)).build(), statsUpdater)) : new ConcurrentShardedQueueFile(spoolFileName, ".spool", shardSize * 1024 * 1024, s -> new TapeQueueFile(new QueueFile.Builder(new File(s)).build(), statsUpdater));
// TODO: allow configurable compression types and levels
return new InstrumentedTaskQueueDelegate<>(new FileBasedTaskQueue<>(queueFile, new RetryTaskConverter<T>(handlerKey.getHandle(), TaskConverter.CompressionType.LZ4)), "buffer", ImmutableMap.of("port", handlerKey.getHandle()), handlerKey.getEntityType());
} catch (Exception e) {
logger.severe("WF-006: Unable to open or create queue file " + spoolFileName + ": " + e.getMessage());
return new TaskQueueStub<>();
}
}
Aggregations