Fire off a thread to asynchronously collect stats.
@param medium Add result to medium set?
@param large Add result to large set?
420454
public static synchronized void asyncSampleSystemNow(final boolean medium, final boolean large) {
        // slow mode starts an async thread
        if (mode == GetRSSMode.PS) {
            if (thread != null) {
                if (thread.isAlive()) return;
                else thread = null;
            }

            thread = new Thread(new Runnable() {
                @Override
                public void run() { sampleSystemNow(medium, large); }
            });
            thread.start();
        }
        // fast mode doesn't spawn a thread
        else {
            sampleSystemNow(medium, large);
        }
    }
711115
@Override
    public void setMaxBatchSize(final Integer maxBatchSize) {
        if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled()) {
            SibTr.debug(this, TRACE, "setMaxBatchSize", maxBatchSize);
        }
        _maxBatchSize = maxBatchSize;
    }
436710
public final static void fireProbe(long probeId, Object instance, Object target, Object args) {
        // Load statics onto the stack to avoid a window where they can be cleared
        // between the test for null and the invocation of the method
        Object proxyTarget = fireProbeTarget;
        Method method = fireProbeMethod;
        if (proxyTarget == null || method == null) {
            return;
        }
        try {
            method.invoke(proxyTarget, probeId, instance, target, args);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
43590
public void trigger(String sEvent) {
        if (sEvent.equals("about")) {
            final AboutThread aboutthread = new AboutThread(this.m_xContext);
            aboutthread.start();
        }
    }
986468
public void forceGatherAllMetrics() {
    LOG.info("Forcing to gather all metrics and flush out.");
    Metrics.MetricPublisherPublishMessage.Builder builder =
        Metrics.MetricPublisherPublishMessage.newBuilder();

    for (List<String> metricNames : timeBucketToMetricNames.values()) {
      for (String metricName : metricNames) {
        gatherOneMetric(metricName, builder);
      }
    }

    metricCollectionCount.incr();
    addDataToMetricPublisher(builder, COLLECTION_COUNT_NAME, metricCollectionCount);

    Metrics.MetricPublisherPublishMessage msg = builder.build();

    queue.offer(msg);
  }
965232
@Override
    public void aggregate(Aggregate op, long key) {
        int deviceId = Nd4j.getAffinityManager().getDeviceForCurrentThread();
        if (opCounter.get() == null)
            opCounter.set(new AtomicLong(0));

        // we enqueue op for specific device here
        aggregates.get(deviceId).add(new AggregateDescriptor(op, key, opCounter.get().getAndIncrement()));
    }
1268601
private void addManagementMetrics(Collection<Metric<?>> result) {
        try {
            // Add JVM up time in ms
            result.add(new Metric<>("uptime", ManagementFactory.getRuntimeMXBean().getUptime()));
            result.add(new Metric<>("systemload.average", ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage()));
            this.addHeapMetrics(result);
            addNonHeapMetrics(result);
            this.addThreadMetrics(result);
            this.addClassLoadingMetrics(result);
            this.addGarbageCollectionMetrics(result);
        } catch (NoClassDefFoundError ex) {
            // Expected on Google App Engine
        }
    }
834732
@SuppressWarnings("unused")
  public void addAll(ScalingStats stats)
  {
    synchronized (lock) {
      synchronized (stats.lock) {
        recentEvents.addAll(stats.recentEvents);
      }
    }
  }
58898
protected void processResult(RHI aggregatedResult) {
        // Process the result with all result handlers
        for (ResultHandler<RHI> resultHandler : resultHandlers) {
            resultHandler.handleResult(aggregatedResult);
        }
    }
899227
@Override
	public void invoke(IN next, Context context) throws Exception {
		// propagate asynchronous errors
		checkErroneous();

		byte[] serializedKey = schema.serializeKey(next);
		byte[] serializedValue = schema.serializeValue(next);
		String targetTopic = schema.getTargetTopic(next);
		if (targetTopic == null) {
			targetTopic = defaultTopicId;
		}

		int[] partitions = this.topicPartitionsMap.get(targetTopic);
		if (null == partitions) {
			partitions = getPartitionsByTopic(targetTopic, producer);
			this.topicPartitionsMap.put(targetTopic, partitions);
		}

		ProducerRecord<byte[], byte[]> record;
		if (flinkKafkaPartitioner == null) {
			record = new ProducerRecord<>(targetTopic, serializedKey, serializedValue);
		} else {
			record = new ProducerRecord<>(
					targetTopic,
					flinkKafkaPartitioner.partition(next, serializedKey, serializedValue, targetTopic, partitions),
					serializedKey,
					serializedValue);
		}
		if (flushOnCheckpoint) {
			synchronized (pendingRecordsLock) {
				pendingRecords++;
			}
		}
		producer.send(record, callback);
	}
558982
@Override
  public void close()
  {
    long timeout = 10000;
    long expires = System.currentTimeMillis() + timeout;
    
    if (_logQueue.size() > 0 && System.currentTimeMillis() < expires) {
      _logQueue.wake();
      
      //try { Thread.sleep(1); } catch (Exception e) {}
    }
  }
965173
@Override
    public void registerAsynchConsumerCallback(
                                               AsynchConsumerCallback callback,
                                               int maxActiveMessages,
                                               long messageLockExpiry,
                                               int maxBatchSize,
                                               OrderingContext context)
                    throws SISessionUnavailableException, SISessionDroppedException,
                    SIErrorException,
                    SIIncorrectCallException
    {
        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConsumerSession.tc.isEntryEnabled())
            SibTr.entry(CoreSPIConsumerSession.tc, "registerAsynchConsumerCallback",
                        new Object[] { this,
                                      callback,
                                      new Integer(maxActiveMessages),
                                      new Long(messageLockExpiry),
                                      new Integer(maxBatchSize),
                                      context });
        registerAsynchConsumerCallback(callback,
                                       maxActiveMessages,
                                       messageLockExpiry,
                                       maxBatchSize,
                                       null,
                                       false,
                                       context);

        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConsumerSession.tc.isEntryEnabled())
            SibTr.exit(CoreSPIConsumerSession.tc, "registerAsynchConsumerCallback");
    }
336986
final void waitForSizeQueue(final int queueSize) {
    synchronized (this.queue) {
      while (this.queue.size() > queueSize) {
        try {
          this.queue.wait(250L);
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
        }
      }
      try {
        Thread.sleep(500L);
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
      }
      this.queue.notifyAll();
    }
  }
949116
@Override
  public void reportMetric(final IMetric<?> metric) throws MetricException {
    final String metricName = metric.getName();
    if (!this.historyListMapping.containsKey(metricName)) {
      logger.info("First time capturing metric: " + metricName);
      this.historyListMapping.put(metricName, new LinkedBlockingDeque<>());
    }
    synchronized (this.historyListMapping.get(metricName)) {
      logger.debug("Ingesting metric: " + metricName);
      this.historyListMapping.get(metricName).add(new InMemoryHistoryNode(metric.getValue()));
      cleanUsingTime(metricName, this.historyListMapping.get(metricName).peekLast().getTimestamp());
    }
  }
951028
public final void setMaxFile(final int m) {
        if (SwingUtilities.isEventDispatchThread()) {
            setMaxFileIntern(m);
        } else {
            try {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        setMaxFileIntern(m);
                    }
                });
            } catch (final Exception ex) {
                ignore();
            }
        }
    }
1329741
protected void addThreadMetrics(Collection<Metric<?>> result) {
        ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
        result.add(new Metric<>("threads.peak", (long) threadMxBean.getPeakThreadCount()));
        result.add(new Metric<>("threads.daemon", (long) threadMxBean.getDaemonThreadCount()));
        result.add(new Metric<>("threads.totalStarted", threadMxBean.getTotalStartedThreadCount()));
        result.add(new Metric<>("threads", (long) threadMxBean.getThreadCount()));
    }
454735
@Override
    protected void onSizeChanged(int newWidth, int newHeight, int oldWidth, int oldHeight) {
        super.onSizeChanged(newWidth, newHeight, oldWidth, oldHeight);
        if(!isInEditMode()) {
            totalWidth = newWidth;
            drawAll();
            postDelayed(new Runnable() {
                @Override
                public void run() {
                    drawPrimaryProgress();
                    drawSecondaryProgress();
                }
            }, 5);
        }
    }