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

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

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

Timer介绍

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

代码示例

代码示例来源:origin: io.netty/netty

/**
 * Stops the {@link Timer} which was specified in the constructor of this
 * handler.  You should not call this method if the {@link Timer} is in use
 * by other objects.
 */
public void releaseExternalResources() {
  timer.stop();
}

代码示例来源:origin: io.netty/netty

Channel channel = ctx.getChannel();
synchronized (this) {
  if (delay == 0 && messagesQueue.isEmpty()) {
    if (! channel.isConnected()) {
      trafficCounter.bytesRealWriteFlowControl(size);
    ctx.sendDownstream(evt);
    return;
    if (! channel.isConnected()) {
      trafficCounter.bytesRealWriteFlowControl(size);
    ctx.sendDownstream(evt);
    return;
  if (! channel.isConnected()) {
writeTimeout = timer.newTimeout(new TimerTask() {
  public void run(Timeout timeout) throws Exception {
    sendAllValid(ctx, futureNow);

代码示例来源:origin: kakaochatfriend/KakaoChatFriendAPI

public void run(Timeout timeout) {
 
 /**
  * 이전 ping시간과 pong시간을 체크
 * - ping과 pong이 다르면 응답을 안준 케이스임  => 재접속
  */
 if ( pingTime != pongTime ) {
   LOG.warn("ping/pong failed, ping:"+pingTime+", pong:"+pongTime+" ===> doing closed()");
   e.getChannel().close();
      resetTime ();
   return;
 }
 
 pingTime = System.currentTimeMillis();
 BSONObject ping = toPing(pingTime);
 e.getChannel().write(ping);
 LOG.debug("[send] ping:{}"+ping);
 
 if ( pingInterval > 0 ) {
  timer.newTimeout( new PingPongSchedule (e), pingInterval, TimeUnit.MILLISECONDS);
 }
}

代码示例来源:origin: io.netty/netty

return;
    Channel channel = ctx.getChannel();
    if (channel != null && channel.isConnected()) {
        logger.debug("Read suspend: " + wait + ':' + channel.isReadable() + ':' +
            rws.readSuspend);
        return;
      if (channel.isReadable() && ! rws.readSuspend) {
        rws.readSuspend = true;
        channel.setReadable(false);
          rws.reopenReadTimerTask = new ReopenReadTimerTask(ctx);
        timeout = timer.newTimeout(rws.reopenReadTimerTask, wait,
            TimeUnit.MILLISECONDS);
informReadOperation(ctx, now);
ctx.sendUpstream(evt);

代码示例来源:origin: io.netty/netty

public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled() || !ctx.getChannel().isOpen()) {
      return;
    }
    State state = (State) ctx.getAttachment();
    long currentTime = System.currentTimeMillis();
    long lastReadTime = state.lastReadTime;
    long nextDelay = readerIdleTimeMillis - (currentTime - lastReadTime);
    if (nextDelay <= 0) {
      // Reader is idle - set a new timeout and notify the callback.
      state.readerIdleTimeout =
        timer.newTimeout(this, readerIdleTimeMillis, TimeUnit.MILLISECONDS);
      fireChannelIdle(ctx, IdleState.READER_IDLE, lastReadTime);
    } else {
      // Read occurred before the timeout - set a new timeout with shorter delay.
      state.readerIdleTimeout =
        timer.newTimeout(this, nextDelay, TimeUnit.MILLISECONDS);
    }
  }
}

代码示例来源:origin: kakaochatfriend/KakaoChatFriendAPI

protected void handleRequest(TYPE type, final Channel channel, BSONObject bsonIn) {
 LOG.debug("REQUEST user(%d) ", (Long) bsonIn.get("user_key"));
 
 long  userKey = (Long) bsonIn.get("user_key");
 long  roomKey = (Long) bsonIn.get("room_key");
 int   msgId   = (Integer) bsonIn.get("msg_id");
 String message = (String) bsonIn.get("message");
 final BSONObject bsonOut = new BasicBSONObject();
 bsonOut.put("type", "response");
 bsonOut.put("room_key", roomKey);
 bsonOut.put("user_key", userKey);
 bsonOut.put("msg_id", msgId);
 bsonOut.put("message", "1:" + message);
 List<String> msgs = new ArrayList<String>();
 msgs.add("2:" + message);
 msgs.add("3:" +(new StringBuffer(message)).reverse().toString());
 if ( delay > 0 ) {
  timer.newTimeout( new TimerTask() {
   public void run(Timeout timeout) throws Exception {
    LOG.debug("OUT => " + bsonOut);
    channel.write(bsonOut);
   }
  }, delay, TimeUnit.MILLISECONDS);
 } else {
  LOG.debug("OUT => " + bsonOut);
  channel.write(bsonOut);
 }
 }

代码示例来源:origin: alibaba/wasp

ChannelFuture closeFuture = channelToClose.close();
timer.stop();
if (awaitCompletion && (closeFuture != null)) {
 closeFuture.awaitUninterruptibly(connectTimeoutMillis);

代码示例来源:origin: com.lambdaworks/lettuce

@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
  if (reconnect) {
    if (attempts < 8) attempts++;
    int timeout = 2 << attempts;
    timer.newTimeout(this, timeout, TimeUnit.MILLISECONDS);
  }
  ctx.sendUpstream(e);
}

代码示例来源:origin: io.netty/netty

final Channel channel = ctx.getChannel();
ChannelFuture handshakeFuture;
Exception exception = null;
  handshakeFuture = this.handshakeFuture = future(channel);
  if (handshakeTimeoutInMillis > 0) {
    handshakeTimeout = timer.newTimeout(new TimerTask() {
        public void run(Timeout timeout) throws Exception {
        ChannelFuture future = SslHandler.this.handshakeFuture;

代码示例来源:origin: io.netty/netty

/**
 * Start the monitoring process.
 */
public void start() {
  if (monitorActive) {
    return;
  }
  lastTime.set(milliSecondFromNano());
  // if executor is null, it means it is piloted by a GlobalChannelTrafficCounter, so no executor
  if (checkInterval.get() > 0 && timer != null) {
    monitorActive = true;
    timerTask = new TrafficMonitoringTask(trafficShapingHandler, this);
    timeout =
      timer.newTimeout(timerTask, checkInterval.get(), TimeUnit.MILLISECONDS);
  }
}

代码示例来源:origin: com.facebook.nifty/nifty-client

public void run(Timeout timeout) throws Exception
  {
    if (timeoutHandler == null) {
      return;
    }
    if (timeout.isCancelled()) {
      return;
    }
    if (!getNettyChannel().isOpen()) {
      return;
    }
    long currentTimeNanos = System.nanoTime();
    long timePassed = currentTimeNanos - timeoutHandler.getLastMessageReceivedNanos();
    long nextDelayNanos =  timeoutNanos - timePassed;
    if (nextDelayNanos <= 0) {
      onReadTimeoutFired(request);
    }
    else {
      request.setReadTimeout(timer.newTimeout(this, nextDelayNanos, TimeUnit.NANOSECONDS));
    }
  }
}

代码示例来源:origin: org.neociclo.accord.odetteftp/oftp-core

public synchronized void stop(boolean emergencyCloseDown) {
  LOGGER.info("[{}] Stopping Odette FTP service...", this);
  if (timer != null) {
  }
  if (channel != null) {
    // stop accepting incoming connections
    channel.unbind();
    if (emergencyCloseDown) {
      ChannelGroupFuture closeActiveChannels = activeChildChannels.close();
      // TODO send Emergency Close Down End Session to all channels open
      // TODO maybe safe to include a timeout argument here
      closeActiveChannels.awaitUninterruptibly();
    } else {

      ChannelGroupFuture activeChannelsCloseFuture = getChannelGroupCloseFuture(activeChildChannels);
      // TODO maybe safe to include a timeout argument here
      activeChannelsCloseFuture.awaitUninterruptibly();
    }
    timer.stop();
    channel.getFactory().releaseExternalResources();
    channel = null;
    timer = null;
  }
  LOGGER.info("[{}] Odette FTP is stopped.", this);
}

代码示例来源:origin: io.netty/netty

Integer key = ctx.getChannel().hashCode();
  PerChannel perChannel = channelQueues.get(key);
  long wait = 0;
      return;
    Channel channel = ctx.getChannel();
    if (channel != null && channel.isConnected()) {
        logger.debug("Read suspend: " + wait + ':' + channel.isReadable() + ':' +
            rws.readSuspend);
        return;
      if (channel.isReadable() && ! rws.readSuspend) {
        rws.readSuspend = true;
        channel.setReadable(false);
          rws.reopenReadTimerTask = new ReopenReadTimerTask(ctx);
        timeout = timer.newTimeout(rws.reopenReadTimerTask, wait,
            TimeUnit.MILLISECONDS);
informReadOperation(ctx, now);
ctx.sendUpstream(evt);

代码示例来源:origin: io.netty/netty

public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled() || !ctx.getChannel().isOpen()) {
      return;
    }
    State state = (State) ctx.getAttachment();
    long currentTime = System.currentTimeMillis();
    long lastWriteTime = state.lastWriteTime;
    long nextDelay = writerIdleTimeMillis - (currentTime - lastWriteTime);
    if (nextDelay <= 0) {
      // Writer is idle - set a new timeout and notify the callback.
      state.writerIdleTimeout =
        timer.newTimeout(this, writerIdleTimeMillis, TimeUnit.MILLISECONDS);
      fireChannelIdle(ctx, IdleState.WRITER_IDLE, lastWriteTime);
    } else {
      // Write occurred before the timeout - set a new timeout with shorter delay.
      state.writerIdleTimeout =
        timer.newTimeout(this, nextDelay, TimeUnit.MILLISECONDS);
    }
  }
}

代码示例来源:origin: wg/lettuce

@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
  if (reconnect) {
    if (attempts < 8) attempts++;
    int timeout = 2 << attempts;
    timer.newTimeout(this, timeout, TimeUnit.MILLISECONDS);
  }
  ctx.sendUpstream(e);
}

代码示例来源:origin: com.facebook.nifty/nifty-core

expireTimeout.set(taskTimeoutTimer.newTimeout(new TimerTask() {
    @Override
    public void run(Timeout timeout) throws Exception {
ConnectionContext connectionContext = ConnectionContexts.getContext(ctx.getChannel());
RequestContext requestContext = new NiftyRequestContext(connectionContext, inProtocol, outProtocol, messageTransport);
RequestContexts.setCurrentContext(requestContext);

代码示例来源:origin: io.netty/netty

/**
 * Start the monitoring process.
 */
@Override
public synchronized void start() {
  if (monitorActive) {
    return;
  }
  lastTime.set(milliSecondFromNano());
  long localCheckInterval = checkInterval.get();
  if (localCheckInterval > 0) {
    monitorActive = true;
    timerTask =
        new MixedTrafficMonitoringTask(
            (GlobalChannelTrafficShapingHandler) trafficShapingHandler, this);
    timeout = timer.newTimeout(timerTask, checkInterval.get(), TimeUnit.MILLISECONDS);
  }
}

代码示例来源:origin: io.netty/netty

final ToSend newToSend;
boolean globalSizeExceeded = false;
Channel channel = ctx.getChannel();
synchronized (perChannel) {
  if (writedelay == 0 && perChannel.messagesQueue.isEmpty()) {
    if (! channel.isConnected()) {
      trafficCounter.bytesRealWriteFlowControl(size);
    ctx.sendDownstream(evt);
    perChannel.lastWriteTimestamp = now;
    return;
    if (! ctx.getChannel().isConnected()) {
    return;
  if (! ctx.getChannel().isConnected()) {
timer.newTimeout(new TimerTask() {
  public void run(Timeout timeout) throws Exception {
    sendAllValid(ctx, forSchedule, futureNow);

代码示例来源:origin: io.netty/netty

public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled() || !ctx.getChannel().isOpen()) {
      return;
    }
    State state = (State) ctx.getAttachment();
    long currentTime = System.currentTimeMillis();
    long lastIoTime = Math.max(state.lastReadTime, state.lastWriteTime);
    long nextDelay = allIdleTimeMillis - (currentTime - lastIoTime);
    if (nextDelay <= 0) {
      // Both reader and writer are idle - set a new timeout and
      // notify the callback.
      state.allIdleTimeout =
        timer.newTimeout(this, allIdleTimeMillis, TimeUnit.MILLISECONDS);
      fireChannelIdle(ctx, IdleState.ALL_IDLE, lastIoTime);
    } else {
      // Either read or write occurred before the timeout - set a new
      // timeout with shorter delay.
      state.allIdleTimeout =
        timer.newTimeout(this, nextDelay, TimeUnit.MILLISECONDS);
    }
  }
}

代码示例来源:origin: org.onosproject/onos-of-ctl

@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
    throws Exception {
  if (timeoutNanos > 0) {
    timeout = timer.newTimeout(new HandshakeTimeoutTask(ctx),
                  timeoutNanos, TimeUnit.NANOSECONDS);
  }
  ctx.sendUpstream(e);
}

相关文章