use of com.wavefront.agent.queueing.QueueingFactory in project java by wavefrontHQ.
the class SenderTaskFactoryImpl method createSenderTasks.
@SuppressWarnings("unchecked")
public Collection<SenderTask<?>> createSenderTasks(@Nonnull HandlerKey handlerKey) {
ReportableEntityType entityType = handlerKey.getEntityType();
int numThreads = entityPropsFactory.get(entityType).getFlushThreads();
List<SenderTask<?>> toReturn = new ArrayList<>(numThreads);
TaskSizeEstimator taskSizeEstimator = new TaskSizeEstimator(handlerKey.getHandle());
taskSizeEstimators.put(handlerKey, taskSizeEstimator);
ScheduledExecutorService scheduler = executors.computeIfAbsent(handlerKey, x -> Executors.newScheduledThreadPool(numThreads, new NamedThreadFactory("submitter-" + handlerKey.getEntityType() + "-" + handlerKey.getHandle())));
for (int threadNo = 0; threadNo < numThreads; threadNo++) {
SenderTask<?> senderTask;
switch(entityType) {
case POINT:
case DELTA_COUNTER:
senderTask = new LineDelimitedSenderTask(handlerKey, PUSH_FORMAT_WAVEFRONT, apiContainer.getProxyV2API(), proxyId, entityPropsFactory.get(entityType), scheduler, threadNo, taskSizeEstimator, taskQueueFactory.getTaskQueue(handlerKey, threadNo));
break;
case HISTOGRAM:
senderTask = new LineDelimitedSenderTask(handlerKey, PUSH_FORMAT_HISTOGRAM, apiContainer.getProxyV2API(), proxyId, entityPropsFactory.get(entityType), scheduler, threadNo, taskSizeEstimator, taskQueueFactory.getTaskQueue(handlerKey, threadNo));
break;
case SOURCE_TAG:
senderTask = new SourceTagSenderTask(handlerKey, apiContainer.getSourceTagAPI(), threadNo, entityPropsFactory.get(entityType), scheduler, taskQueueFactory.getTaskQueue(handlerKey, threadNo));
break;
case TRACE:
senderTask = new LineDelimitedSenderTask(handlerKey, PUSH_FORMAT_TRACING, apiContainer.getProxyV2API(), proxyId, entityPropsFactory.get(entityType), scheduler, threadNo, taskSizeEstimator, taskQueueFactory.getTaskQueue(handlerKey, threadNo));
break;
case TRACE_SPAN_LOGS:
senderTask = new LineDelimitedSenderTask(handlerKey, PUSH_FORMAT_TRACING_SPAN_LOGS, apiContainer.getProxyV2API(), proxyId, entityPropsFactory.get(entityType), scheduler, threadNo, taskSizeEstimator, taskQueueFactory.getTaskQueue(handlerKey, threadNo));
break;
case EVENT:
senderTask = new EventSenderTask(handlerKey, apiContainer.getEventAPI(), proxyId, threadNo, entityPropsFactory.get(entityType), scheduler, taskQueueFactory.getTaskQueue(handlerKey, threadNo));
break;
default:
throw new IllegalArgumentException("Unexpected entity type " + handlerKey.getEntityType().name() + " for " + handlerKey.getHandle());
}
toReturn.add(senderTask);
senderTask.start();
}
if (queueingFactory != null) {
QueueController<?> controller = queueingFactory.getQueueController(handlerKey, numThreads);
managedServices.put(handlerKey, controller);
controller.start();
}
managedTasks.put(handlerKey, toReturn);
entityTypes.computeIfAbsent(handlerKey.getHandle(), x -> new ArrayList<>()).add(handlerKey.getEntityType());
return toReturn;
}
Aggregations