public boolean putMetricsImmediate(MetricsBuffer buffer) { WaitableMetricsBuffer waitableBuffer = new WaitableMetricsBuffer(buffer); if (!queue.enqueue(waitableBuffer)) { LOG.warn(name + " has a full queue and can't consume the given metrics."); dropped.incr(); return false; } if (!waitableBuffer.waitTillNotified(oobPutTimeout)) { LOG.warn( name + " couldn't fulfill an immediate putMetrics request in time." + " Abandoning."); return false; } return true; }
void publishMetrics(MetricsBuffer buffer) { long ts = 0; for (MetricsBuffer.Entry entry : buffer) { LOG.debug("sourceFilter=" + sourceFilter); if (sourceFilter == null || sourceFilter.accepts(entry.name())) { for (MetricsRecordImpl record : entry.records()) { if ((context == null || context.equals(record.context())) && (recordFilter == null || recordFilter.accepts(record))) { if (LOG.isDebugEnabled()) { LOG.debug( "Pushing record " + entry.name() + "." + record.context() + "." + record.name() + " to " + name); } sink.putMetrics( metricFilter == null ? record : new MetricsRecordFiltered(record, metricFilter)); if (ts == 0) { ts = record.timestamp(); } } } } } if (ts > 0) { sink.flush(); latency.add(System.currentTimeMillis() - ts); } if (buffer instanceof WaitableMetricsBuffer) { ((WaitableMetricsBuffer) buffer).notifyAnyWaiters(); } LOG.debug("Done"); }