io.netty.util.Timer类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(276)

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

Timer介绍

[英]Schedules TimerTasks for one-time future execution in a background thread.
[中]安排TimerTasks,以便将来在后台线程中一次性执行。

代码示例

代码示例来源:origin: AsyncHttpClient/async-http-client

private void scheduleNewIdleChannelDetector(TimerTask task) {
 nettyTimer.newTimeout(task, cleanerPeriod, TimeUnit.MILLISECONDS);
}

代码示例来源:origin: traccar/traccar

public static void release() {
  if (instance != null) {
    instance.stop();
  }
  instance = null;
}

代码示例来源:origin: mpusher/mpush

private void startHeartBeat(final int heartbeat) throws Exception {
  HASHED_WHEEL_TIMER.newTimeout(new TimerTask() {
    @Override
    public void run(Timeout timeout) throws Exception {
      if (connection.isConnected() && healthCheck()) {
        HASHED_WHEEL_TIMER.newTimeout(this, heartbeat, TimeUnit.MILLISECONDS);
      }
    }
  }, heartbeat, TimeUnit.MILLISECONDS);
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Override
public void close() {
 if (closed.compareAndSet(false, true)) {
  try {
   channelManager.close();
  } catch (Throwable t) {
   LOGGER.warn("Unexpected error on ChannelManager close", t);
  }
  if (allowStopNettyTimer) {
   try {
    nettyTimer.stop();
   } catch (Throwable t) {
    LOGGER.warn("Unexpected error on HashedWheelTimer close", t);
   }
  }
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

private Timeout newTimeout(TimerTask task, long delay) {
  return requestSender.isClosed() ? null : nettyTimer.newTimeout(task, delay, TimeUnit.MILLISECONDS);
 }
}

代码示例来源:origin: mpusher/mpush

@Override
  protected void doStop(Listener listener) throws Throwable {
    pool.close();
    workerGroup.shutdownGracefully();
    timer.stop();
    listener.onSuccess();
  }
}

代码示例来源:origin: mpusher/mpush

@Override
  public void run(Timeout timeout) throws Exception {
    if (connection.isConnected() && healthCheck()) {
      HASHED_WHEEL_TIMER.newTimeout(this, heartbeat, TimeUnit.MILLISECONDS);
    }
  }
}, heartbeat, TimeUnit.MILLISECONDS);

代码示例来源:origin: apache/pulsar

@Override
public void shutdown() throws PulsarClientException {
  try {
    lookup.close();
    cnxPool.close();
    timer.stop();
    externalExecutorProvider.shutdownNow();
    conf.getAuthentication().close();
  } catch (Throwable t) {
    log.warn("Failed to shutdown Pulsar client", t);
    throw new PulsarClientException(t);
  }
}

代码示例来源:origin: apache/pulsar

timeout = client.timer().newTimeout(new TimerTask() {
  @Override
  public void run(Timeout t) throws Exception {

代码示例来源:origin: apache/incubator-pinot

_timer.stop();
LOGGER.info("Timer shut down !!");

代码示例来源:origin: apache/pulsar

@Override
  public void run(Timeout t) throws Exception {
    Set<MessageId> messageIds = new HashSet<>();
    writeLock.lock();
    try {
      timePartitions.addLast(new ConcurrentOpenHashSet<>());
      ConcurrentOpenHashSet<MessageId> headPartition = timePartitions.removeFirst();
      if (!headPartition.isEmpty()) {
        log.warn("[{}] {} messages have timed-out", consumerBase, timePartitions.size());
        headPartition.forEach(messageId -> {
          messageIds.add(messageId);
          messageIdPartitionMap.remove(messageId);
        });
      }
    } finally {
      writeLock.unlock();
    }
    if (messageIds.size() > 0) {
      consumerBase.redeliverUnacknowledgedMessages(messageIds);
    }
    timeout = client.timer().newTimeout(this, tickDurationInMs, TimeUnit.MILLISECONDS);
  }
}, this.tickDurationInMs, TimeUnit.MILLISECONDS);

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
  * Hook invoked when the cluster is shutting down after a call to {@link Cluster#close()}.
  *
  * <p>This is guaranteed to be called only after all connections have been individually closed,
  * and their channels closed, and only once per {@link Timer} instance.
  *
  * <p>This gives the implementor a chance to close the {@link Timer} properly, if required.
  *
  * <p>The default implementation calls a {@link Timer#stop()} of the passed {@link Timer}
  * instance.
  *
  * <p>Implementation note: if the {@link Timer} instance is being shared, or used for other
  * purposes than to schedule actions for the current cluster, than it should not be stopped here;
  * subclasses would have to override this method accordingly to take the appropriate action.
  *
  * @param timer the timer used by the cluster being closed
  */
 public void onClusterClose(Timer timer) {
  timer.stop();
 }
}

代码示例来源:origin: redisson/redisson

private void reconnect(final RedisConnection connection, final int attempts){
  int timeout = 2 << attempts;
  if (bootstrap.config().group().isShuttingDown()) {
    return;
  }
  
  try {
    timer.newTimeout(new TimerTask() {
      @Override
      public void run(Timeout timeout) throws Exception {
        tryReconnect(connection, Math.min(BACKOFF_CAP, attempts + 1));
      }
    }, timeout, TimeUnit.MILLISECONDS);
  } catch (IllegalStateException e) {
    // skip
  }
}

代码示例来源:origin: lettuce-io/lettuce-core

timer.stop();

代码示例来源:origin: redisson/redisson

private void reconnect(final RedisConnection connection, final int attempts){
  int timeout = 2 << attempts;
  if (bootstrap.config().group().isShuttingDown()) {
    return;
  }
  
  try {
    timer.newTimeout(new TimerTask() {
      @Override
      public void run(Timeout timeout) throws Exception {
        tryReconnect(connection, Math.min(BACKOFF_CAP, attempts + 1));
      }
    }, timeout, TimeUnit.MILLISECONDS);
  } catch (IllegalStateException e) {
    // skip
  }
}

代码示例来源:origin: com.baidu/brpc-java

@Override
public void destroy() {
  if (timer != null) {
    timer.stop();
  }
}

代码示例来源:origin: redisson/redisson

protected void sendPing(final ChannelHandlerContext ctx) {
  final RedisConnection connection = RedisConnection.getFrom(ctx.channel());
  final RFuture<String> future = connection.async(StringCodec.INSTANCE, RedisCommands.PING);
  
  config.getTimer().newTimeout(new TimerTask() {
    @Override
    public void run(Timeout timeout) throws Exception {
      CommandData<?, ?> commandData = connection.getCurrentCommand();
      if ((commandData == null || !commandData.isBlockingCommand()) && 
          (future.cancel(false) || !future.isSuccess())) {
        ctx.channel().close();
        log.debug("channel: {} closed due to PING response timeout set in {} ms", ctx.channel(), config.getPingConnectionInterval());
      } else {
        sendPing(ctx);
      }
    }
  }, config.getPingConnectionInterval(), TimeUnit.MILLISECONDS);
}

代码示例来源:origin: baidu/brpc-java

@Override
public void destroy() {
  if (timer != null) {
    timer.stop();
  }
}

代码示例来源:origin: redisson/redisson

protected void sendPing(final ChannelHandlerContext ctx) {
  final RedisConnection connection = RedisConnection.getFrom(ctx.channel());
  final RFuture<String> future = connection.async(StringCodec.INSTANCE, RedisCommands.PING);
  
  config.getTimer().newTimeout(new TimerTask() {
    @Override
    public void run(Timeout timeout) throws Exception {
      CommandData<?, ?> commandData = connection.getCurrentCommand();
      if ((commandData == null || !commandData.isBlockingCommand()) && 
          (future.cancel(false) || !future.isSuccess())) {
        ctx.channel().close();
        log.debug("channel: {} closed due to PING response timeout set in {} ms", ctx.channel(), config.getPingConnectionInterval());
      } else {
        sendPing(ctx);
      }
    }
  }, config.getPingConnectionInterval(), TimeUnit.MILLISECONDS);
}

代码示例来源:origin: opendaylight/controller

@Override
public Set<Timeout> stop() {
  return this.timer.stop();
}

相关文章

微信公众号

最新文章

更多