org.elasticsearch.threadpool.ThreadPool.schedule()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(185)

本文整理了Java中org.elasticsearch.threadpool.ThreadPool.schedule()方法的一些代码示例,展示了ThreadPool.schedule()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPool.schedule()方法的具体详情如下:
包路径:org.elasticsearch.threadpool.ThreadPool
类名称:ThreadPool
方法名:schedule

ThreadPool.schedule介绍

[英]Schedules a one-shot command to run after a given delay. The command is not run in the context of the calling thread. To preserve the context of the calling thread you may call threadPool.getThreadContext().preserveContext on the runnable before passing it to this method.
[中]计划在给定延迟后运行一次性命令。该命令不在调用线程的上下文中运行。要保留调用线程的上下文,在将其传递给此方法之前,可以在runnable上调用threadPool.getThreadContext().preserveContext

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
protected void doStart() {
  // Start thread that will manage cleaning the field data cache periodically
  threadPool.schedule(this.cleanInterval, ThreadPool.Names.SAME, this.cacheCleaner);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public void handleResponse(PingResponse response) {
  if (!running()) {
    return;
  }
  retryCount = 0;
  threadPool.schedule(pingInterval, ThreadPool.Names.SAME, NodeFD.this);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public void schedule() {
  future = threadPool.schedule(nextDelay, ThreadPool.Names.SAME, new AbstractRunnable() {
    @Override
    protected void doRun() throws Exception {
      if (cancelScheduling.get()) {
        return;
      }
      clusterService.submitStateUpdateTask(CLUSTER_UPDATE_TASK_SOURCE, DelayedRerouteTask.this);
    }
    @Override
    public void onFailure(Exception e) {
      logger.warn("failed to submit schedule/execute reroute post unassigned shard", e);
      removeIfSameTask(DelayedRerouteTask.this);
    }
  });
}

代码示例来源:origin: org.elasticsearch/elasticsearch

void ensureStarted() {
  if (isStarted.get() == false && isStarted.compareAndSet(false, true)) {
    threadPool.schedule(pingInterval, ThreadPool.Names.GENERIC, this);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

DelayedPrepareBulkRequest(ThreadPool threadPool, float requestsPerSecond, TimeValue delay, Runnable command) {
  this.threadPool = threadPool;
  this.requestsPerSecond = requestsPerSecond;
  this.command = command;
  this.future = threadPool.schedule(delay, ThreadPool.Names.GENERIC, () -> {
    throttledNanos.addAndGet(delay.nanos());
    command.run();
  });
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  public void run() {
    try {
      nodesSampler.sample();
      if (!closed) {
        nodesSamplerFuture = threadPool.schedule(nodesSamplerInterval, ThreadPool.Names.GENERIC, this);
      }
    } catch (Exception e) {
      logger.warn("failed to sample", e);
    }
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  public void onAfter() {
    if (lifecycle.started()) {
      backgroundFuture = threadPool.schedule(reconnectInterval, ThreadPool.Names.GENERIC, this);
    }
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
protected void onAfterInLifecycle() {
  try {
    threadPool.schedule(pingInterval, ThreadPool.Names.GENERIC, this);
  } catch (EsRejectedExecutionException ex) {
    if (ex.isExecutorShutdown()) {
      logger.debug("couldn't schedule new ping execution, executor is shutting down", ex);
    } else {
      throw ex;
    }
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
protected void doStart() {
  backgroundFuture = threadPool.schedule(reconnectInterval, ThreadPool.Names.GENERIC, new ConnectionChecker());
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  public void onFailure(Exception e) {
    if (false == (e instanceof EsRejectedExecutionException)
        || false == backoff.hasNext()) {
      listener.onFailure(e);
    } else {
      TimeValue wait = backoff.next();
      logger.warn(() -> new ParameterizedMessage("failed to store task result, retrying in [{}]", wait), e);
      threadPool.schedule(wait, ThreadPool.Names.SAME, () -> doStoreResult(backoff, index, listener));
    }
  }
});

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  public void run() {
    if (timeout != null) {
      NotifyTimeout notifyTimeout = new NotifyTimeout(listener, timeout);
      notifyTimeout.future = threadPool.schedule(timeout, ThreadPool.Names.GENERIC, notifyTimeout);
      onGoingTimeouts.add(notifyTimeout);
    }
    timeoutClusterStateListeners.add(listener);
    listener.postAdded();
  }
});

代码示例来源:origin: org.elasticsearch/elasticsearch

private void innerStart(final DiscoveryNode masterNode) {
  this.masterNode = masterNode;
  this.retryCount = 0;
  this.notifiedMasterFailure.set(false);
  if (masterPinger != null) {
    masterPinger.stop();
  }
  this.masterPinger = new MasterPinger();
  // we start pinging slightly later to allow the chosen master to complete it's own master election
  threadPool.schedule(pingInterval, ThreadPool.Names.SAME, masterPinger);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public void handleResponse(MasterPingResponseResponse response) {
  if (!running) {
    return;
  }
  // reset the counter, we got a good result
  MasterFaultDetection.this.retryCount = 0;
  // check if the master node did not get switched on us..., if it did, we simply return with no reschedule
  if (masterToPing.equals(MasterFaultDetection.this.masterNode())) {
    // we don't stop on disconnection from master, we keep pinging it
    threadPool.schedule(pingInterval, ThreadPool.Names.SAME, MasterPinger.this);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private UnicastPingResponse handlePingRequest(final UnicastPingRequest request) {
  assert clusterName.equals(request.pingResponse.clusterName()) :
    "got a ping request from a different cluster. expected " + clusterName + " got " + request.pingResponse.clusterName();
  temporalResponses.add(request.pingResponse);
  // add to any ongoing pinging
  activePingingRounds.values().forEach(p -> p.addPingResponseToCollection(request.pingResponse));
  threadPool.schedule(TimeValue.timeValueMillis(request.timeout.millis() * 2), ThreadPool.Names.SAME,
    () -> temporalResponses.remove(request.pingResponse));
  List<PingResponse> pingResponses = CollectionUtils.iterableAsArrayList(temporalResponses);
  pingResponses.add(createPingResponse(contextProvider.clusterState()));
  return new UnicastPingResponse(request.id, pingResponses.toArray(new PingResponse[pingResponses.size()]));
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private void retryRecovery(final long recoveryId, final TimeValue retryAfter, final TimeValue activityTimeout) {
  RecoveryTarget newTarget = onGoingRecoveries.resetRecovery(recoveryId, activityTimeout);
  if (newTarget != null) {
    threadPool.schedule(retryAfter, ThreadPool.Names.GENERIC, new RecoveryRunner(newTarget.recoveryId()));
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private void startRecoveryInternal(RecoveryTarget recoveryTarget, TimeValue activityTimeout) {
  RecoveryTarget existingTarget = onGoingRecoveries.putIfAbsent(recoveryTarget.recoveryId(), recoveryTarget);
  assert existingTarget == null : "found two RecoveryStatus instances with the same id";
  logger.trace("{} started recovery from {}, id [{}]", recoveryTarget.shardId(), recoveryTarget.sourceNode(),
    recoveryTarget.recoveryId());
  threadPool.schedule(activityTimeout, ThreadPool.Names.GENERIC,
      new RecoveryMonitor(recoveryTarget.recoveryId(), recoveryTarget.lastAccessTime(), activityTimeout));
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public IngestService(ClusterService clusterService, ThreadPool threadPool,
           Environment env, ScriptService scriptService, AnalysisRegistry analysisRegistry,
           List<IngestPlugin> ingestPlugins) {
  this.clusterService = clusterService;
  this.scriptService = scriptService;
  this.processorFactories = processorFactories(
    ingestPlugins,
    new Processor.Parameters(
      env, scriptService, analysisRegistry,
      threadPool.getThreadContext(), threadPool::relativeTimeInMillis,
      (delay, command) -> threadPool.schedule(
        TimeValue.timeValueMillis(delay), ThreadPool.Names.GENERIC, command
      ), this
    )
  );
  this.threadPool = threadPool;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public void onMaster() {
  this.isMaster = true;
  if (logger.isTraceEnabled()) {
    logger.trace("I have been elected master, scheduling a ClusterInfoUpdateJob");
  }
  try {
    // Submit a job that will start after DEFAULT_STARTING_INTERVAL, and reschedule itself after running
    threadPool.schedule(updateFrequency, executorName(), new SubmitReschedulingClusterInfoUpdatedJob());
    if (clusterService.state().getNodes().getDataNodes().size() > 1) {
      // Submit an info update job to be run immediately
      threadPool.executor(executorName()).execute(() -> maybeRefresh());
    }
  } catch (EsRejectedExecutionException ex) {
    if (logger.isDebugEnabled()) {
      logger.debug("Couldn't schedule cluster info update task - node might be shutting down", ex);
    }
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

TransportClientNodesService(Settings settings, TransportService transportService,
                  ThreadPool threadPool, TransportClient.HostFailureListener hostFailureListener) {
  this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
  this.transportService = transportService;
  this.threadPool = threadPool;
  this.minCompatibilityVersion = Version.CURRENT.minimumCompatibilityVersion();
  this.nodesSamplerInterval = TransportClient.CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL.get(settings);
  this.pingTimeout = TransportClient.CLIENT_TRANSPORT_PING_TIMEOUT.get(settings).millis();
  this.ignoreClusterName = TransportClient.CLIENT_TRANSPORT_IGNORE_CLUSTER_NAME.get(settings);
  if (logger.isDebugEnabled()) {
    logger.debug("node_sampler_interval[{}]", nodesSamplerInterval);
  }
  if (TransportClient.CLIENT_TRANSPORT_SNIFF.get(settings)) {
    this.nodesSampler = new SniffNodesSampler();
  } else {
    this.nodesSampler = new SimpleNodeSampler();
  }
  this.hostFailureListener = hostFailureListener;
  this.nodesSamplerFuture = threadPool.schedule(nodesSamplerInterval, ThreadPool.Names.GENERIC, new ScheduledNodeSampler());
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public void onCommit(TimeValue commitTime) {
  TimeValue ackTimeout = ackedTaskListener.ackTimeout();
  if (ackTimeout == null) {
    ackTimeout = TimeValue.ZERO;
  }
  final TimeValue timeLeft = TimeValue.timeValueNanos(Math.max(0, ackTimeout.nanos() - commitTime.nanos()));
  if (timeLeft.nanos() == 0L) {
    onTimeout();
  } else if (countDown.countDown()) {
    finish();
  } else {
    this.ackTimeoutCallback = threadPool.schedule(timeLeft, ThreadPool.Names.GENERIC, this::onTimeout);
    // re-check if onNodeAck has not completed while we were scheduling the timeout
    if (countDown.isCountedDown()) {
      FutureUtils.cancel(ackTimeoutCallback);
    }
  }
}

相关文章