Cancels any existing periodic ping task if there is one and schedules a new ping task if
pingInterval is greater then zero.

@param delta the delta to the last received stanza in seconds
559583
private synchronized void maybeSchedulePingServerTask(int delta) {
        maybeStopPingServerTask();
        if (pingInterval > 0) {
            int nextPingIn = pingInterval - delta;
            LOGGER.fine("Scheduling ServerPingTask in " + nextPingIn + " seconds (pingInterval="
                            + pingInterval + ", delta=" + delta + ")");
            nextAutomaticPing = schedule(pingServerRunnable, nextPingIn, TimeUnit.SECONDS);
        }
    }
969378
public synchronized void onTransportTermination() {
    if (state != State.DISCONNECTED) {
      state = State.DISCONNECTED;
      if (shutdownFuture != null) {
        shutdownFuture.cancel(false);
      }
      if (pingFuture != null) {
        pingFuture.cancel(false);
        pingFuture = null;
      }
    }
  }
1180269
public void runNextPendingCommand() {
        ScheduledTask<?> scheduledTask = deltaQueue.pop();
        
        scheduledTask.run();
        
        if (!scheduledTask.isCancelled() && scheduledTask.repeats()) {
            deltaQueue.add(scheduledTask.repeatDelay, scheduledTask);
        }
    }
984990
async def __check_last_ping(self, run_listen):
        
        if self.__last_ping < time.time()-10:
            self._logger.warning("Last ping too old. Restarting the agent.")
            run_listen.cancel()
            self.__cancel_remaining_safe_tasks()
        else:
            self._loop.call_later(1, self._create_safe_task, self.__check_last_ping(run_listen))
921259
private void destroyPingExecutor() {
        synchronized (pingExecutor) {
            if (!pingExecutor.isShutdown()) {
                try {
                    log.debugf("Shutting down WebSocket ping executor");
                    pingExecutor.shutdown();
                    if (!pingExecutor.awaitTermination(1, TimeUnit.SECONDS)) {
                        pingExecutor.shutdownNow();
                    }
                } catch (Throwable t) {
                    log.warnf("Cannot shut down WebSocket ping executor. Cause=%s", t.toString());
                }
            }
        }
    }
818515
public void deltaTotalPoolTime(long delta)
   {
      if (enabled.get() && delta > 0)
      {
         totalPoolTime.addAndGet(delta);
         totalPoolTimeInvocations.incrementAndGet();

         if (delta > maxPoolTime.get())
            maxPoolTime.set(delta);
      }
   }
1203269
public static synchronized void cancel(TimerTask task) {
        if (task == null) {
            return;
        }
        task.cancel();
        usageCount.decrementAndGet();
        if (usageCount.get() == 0) {
            timer.cancel();
            timer = null;
        }
    }
1225044
public void cancel() {
        if(actionInBackground != null) {
            if(executorService != null) {
               asyncFutureTask.cancel(true);
            } else {
                asyncThread.interrupt();
            }
        }
    }
1092863
private void cancelPendingSlotRequest(PendingSlotRequest pendingSlotRequest) {
		CompletableFuture<Acknowledge> request = pendingSlotRequest.getRequestFuture();

		returnPendingTaskManagerSlotIfAssigned(pendingSlotRequest);

		if (null != request) {
			request.cancel(false);
		}
	}
1350683
protected void cancelScheduledTasks() {
        assert inEventLoop();
        PriorityQueue<ScheduledFutureTask<?>> scheduledTaskQueue = this.scheduledTaskQueue;
        if (isNullOrEmpty(scheduledTaskQueue)) {
            return;
        }

        final ScheduledFutureTask<?>[] scheduledTasks =
                scheduledTaskQueue.toArray(new ScheduledFutureTask<?>[0]);

        for (ScheduledFutureTask<?> task: scheduledTasks) {
            task.cancelWithoutRemove(false);
        }

        scheduledTaskQueue.clearIgnoringIndexes();
    }
1119337
public static void cancelTasks(final Context context,
      Class<? extends GroundyService> groundyServiceClass, final int groupId, final int reason,
      final CancelListener cancelListener) {
    if (groupId <= 0) {
      throw new IllegalStateException("Group id must be greater than zero");
    }
    new GroundyServiceConnection(context, groundyServiceClass) {
      @Override
      protected void onGroundyServiceBound(GroundyService.GroundyServiceBinder binder) {
        GroundyService.CancelGroupResponse cancelGroupResponse =
            binder.cancelTasks(groupId, reason);
        if (cancelListener != null) {
          cancelListener.onCancelResult(groupId, cancelGroupResponse);
        }
      }
    }.start();
  }
233450
public synchronized void onDataReceived() {
    stopwatch.reset().start();
    // We do not cancel the ping future here. This avoids constantly scheduling and cancellation in
    // a busy transport. Instead, we update the status here and reschedule later. So we actually
    // keep one sendPing task always in flight when there're active rpcs.
    if (state == State.PING_SCHEDULED) {
      state = State.PING_DELAYED;
    } else if (state == State.PING_SENT || state == State.IDLE_AND_PING_SENT) {
      // Ping acked or effectively ping acked. Cancel shutdown, and then if not idle,
      // schedule a new keep-alive ping.
      if (shutdownFuture != null) {
        shutdownFuture.cancel(false);
      }
      if (state == State.IDLE_AND_PING_SENT) {
        // not to schedule new pings until onTransportActive
        state = State.IDLE;
        return;
      }
      // schedule a new ping
      state = State.PING_SCHEDULED;
      checkState(pingFuture == null, "There should be no outstanding pingFuture");
      pingFuture = scheduler.schedule(sendPing, keepAliveTimeInNanos, TimeUnit.NANOSECONDS);
    }
  }
1084725
public void cancelQueuedTasks() {
      ArrayList<QueueingTask> queuedTasks = new ArrayList<QueueingTask>();
      queue.drainTo(queuedTasks);
      for (QueueingTask task : queuedTasks) {
         task.cancel(false);
      }
   }
432717
public void plusNanoSeconds(long delta)
    {
        if (delta != 0)
        {
            long result = getNanoSecond() + delta;
            setNanoSecond((int) Math.floorMod(result, 1000000000));
            plusSeconds(Math.floorDiv(result, 1000000000));
        }
    }
850986
public void removeShutdownHook(final Runnable task) {
        if (inEventLoop()) {
            shutdownHooks.remove(task);
        } else {
            execute(new Runnable() {
                @Override
                public void run() {
                    shutdownHooks.remove(task);
                }
            });
        }
    }
487237
public TimerTask cancel(Serializable taskID) {
		
		if (logger.isDebugEnabled()) {
			logger.debug("Canceling task with timer id "+taskID);
		}
		
		TimerTask task = localRunningTasks.get(taskID);
		if (task != null) {
			// remove task data
			new TimerTaskCacheData(taskID, baseFqn, cluster).remove();

			final SetTimerAfterTxCommitRunnable setAction = task.getSetTimerTransactionalAction();
			if (setAction != null) {
				// we have a tx action scheduled to run when tx commits, to set the timer, lets simply cancel it
				setAction.cancel();
			}
			else {
				// do cancellation
				AfterTxCommitRunnable runnable = new CancelTimerAfterTxCommitRunnable(task,this);
				if (txManager != null) {
					try {
						Transaction tx = txManager.getTransaction();
						if (tx != null) {
							TransactionContext txContext = TransactionContextThreadLocal.getTransactionContext();
							if (txContext == null) {
								txContext = new TransactionContext();
								tx.registerSynchronization(new TransactionSynchronization(txContext));
							}
							txContext.put(taskID, runnable);					
						}
						else {
							runnable.run();
						}
					}
					catch (Throwable e) {
						throw new RuntimeException("Unable to register tx synchronization object",e);
					}
				}
				else {
					runnable.run();
				}			
			}		
		}
		else {
			// not found locally
			// if there is a tx context there may be a set timer action there
			if (txManager != null) {
				try {
					Transaction tx = txManager.getTransaction();
					if (tx != null) {
						TransactionContext txContext = TransactionContextThreadLocal.getTransactionContext();
						if (txContext != null) {
							final AfterTxCommitRunnable r = txContext.remove(taskID);
							if (r != null) {
								task = r.task;
								// remove from cluster
								new TimerTaskCacheData(taskID, baseFqn, cluster).remove();
							}							
						}											
					}
				}
				catch (Throwable e) {
					throw new RuntimeException("Failed to check tx context.",e);
				}
			}			
		}
		
		return task;
	}
561390
@Override
  final CancellableTask<K, T> scheduleImpl(final T task, long period, TimeUnit unit) {
    final ScheduledFuture<?> future = this.executorService.scheduleAtFixedRate(new RunnableTask(task), 0, period, unit);
    return new CancellableScheduledFuture<>(task, future);
  }