Search in sources :

Example 1 with QueueingFactory

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;
}
Also used : QueueingReason(com.wavefront.agent.data.QueueingReason) Managed(com.wavefront.common.Managed) TaskQueueFactory(com.wavefront.agent.queueing.TaskQueueFactory) ArrayList(java.util.ArrayList) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) TaggedMetricName(com.wavefront.common.TaggedMetricName) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EntityPropertiesFactory(com.wavefront.agent.data.EntityPropertiesFactory) UUID(java.util.UUID) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) TaskSizeEstimator(com.wavefront.agent.queueing.TaskSizeEstimator) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) ReportableEntityType(com.wavefront.data.ReportableEntityType) PUSH_FORMAT_TRACING_SPAN_LOGS(com.wavefront.api.agent.Constants.PUSH_FORMAT_TRACING_SPAN_LOGS) NamedThreadFactory(com.wavefront.common.NamedThreadFactory) List(java.util.List) Gauge(com.yammer.metrics.core.Gauge) APIContainer(com.wavefront.agent.api.APIContainer) PUSH_FORMAT_WAVEFRONT(com.wavefront.api.agent.Constants.PUSH_FORMAT_WAVEFRONT) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Metrics(com.yammer.metrics.Metrics) PUSH_FORMAT_TRACING(com.wavefront.api.agent.Constants.PUSH_FORMAT_TRACING) QueueingFactory(com.wavefront.agent.queueing.QueueingFactory) QueueController(com.wavefront.agent.queueing.QueueController) PUSH_FORMAT_HISTOGRAM(com.wavefront.api.agent.Constants.PUSH_FORMAT_HISTOGRAM) TaskSizeEstimator(com.wavefront.agent.queueing.TaskSizeEstimator) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NamedThreadFactory(com.wavefront.common.NamedThreadFactory) ArrayList(java.util.ArrayList) ReportableEntityType(com.wavefront.data.ReportableEntityType)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 APIContainer (com.wavefront.agent.api.APIContainer)1 EntityPropertiesFactory (com.wavefront.agent.data.EntityPropertiesFactory)1 QueueingReason (com.wavefront.agent.data.QueueingReason)1 QueueController (com.wavefront.agent.queueing.QueueController)1 QueueingFactory (com.wavefront.agent.queueing.QueueingFactory)1 TaskQueueFactory (com.wavefront.agent.queueing.TaskQueueFactory)1 TaskSizeEstimator (com.wavefront.agent.queueing.TaskSizeEstimator)1 PUSH_FORMAT_HISTOGRAM (com.wavefront.api.agent.Constants.PUSH_FORMAT_HISTOGRAM)1 PUSH_FORMAT_TRACING (com.wavefront.api.agent.Constants.PUSH_FORMAT_TRACING)1 PUSH_FORMAT_TRACING_SPAN_LOGS (com.wavefront.api.agent.Constants.PUSH_FORMAT_TRACING_SPAN_LOGS)1 PUSH_FORMAT_WAVEFRONT (com.wavefront.api.agent.Constants.PUSH_FORMAT_WAVEFRONT)1 Managed (com.wavefront.common.Managed)1 NamedThreadFactory (com.wavefront.common.NamedThreadFactory)1 TaggedMetricName (com.wavefront.common.TaggedMetricName)1 ReportableEntityType (com.wavefront.data.ReportableEntityType)1 Metrics (com.yammer.metrics.Metrics)1 Gauge (com.yammer.metrics.core.Gauge)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1