org.apache.qpid.proton.engine.Transport.tick()方法的使用及代码示例

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

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

Transport.tick介绍

[英]Prompt the transport to perform work such as idle-timeout/heartbeat handling, and return an absolute deadline in milliseconds that tick must again be called by/at, based on the provided current time in milliseconds, to ensure the periodic work is carried out as necessary. A returned deadline of 0 indicates there is no periodic work necessitating tick be called, e.g. because neither peer has defined an idle-timeout value. The provided milliseconds time values can be from System#currentTimeMillis() or derived from System#nanoTime(), noting that for the later in particular that the returned deadline could be a different sign than the given time, and (if non-zero) the returned deadline should have the current time originally provided subtracted from it in order to establish a relative time delay to the next deadline.
[中]提示传输执行空闲超时/心跳处理等工作,并返回一个以毫秒为单位的绝对截止日期,该截止日期必须由/at根据提供的以毫秒为单位的当前时间再次调用,以确保在必要时执行定期工作。返回的截止日期为0表示没有需要调用的周期性工作,例如,因为两个对等方都没有定义空闲超时值。提供的毫秒时间值可以来自System#currentTimeMillis(),也可以来自System#nanoTime(),特别是对于后者,返回的截止日期可能是与给定时间不同的符号,并且(如果不为零),返回的截止日期应减去最初提供的当前时间,以便建立到下一个截止日期的相对时间延迟。

代码示例

代码示例来源:origin: org.apache.qpid/qpid-jms-client

void fireConnectionEstablished() {
  // The request onSuccess calls this method
  connectionRequest = null;
  // Using nano time since it is not related to the wall clock, which may change
  long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
  long deadline = protonTransport.tick(now);
  if (deadline != 0) {
    long delay = deadline - now;
    LOG.trace("IdleTimeoutCheck being initiated, initial delay: {}", delay);
    nextIdleTimeoutCheck = serializer.schedule(new IdleTimeoutCheck(), delay, TimeUnit.MILLISECONDS);
  }
  ProviderListener listener = this.listener;
  if (listener != null) {
    listener.onConnectionEstablished(remoteURI);
  }
}

代码示例来源:origin: apache/qpid-jms

void fireConnectionEstablished() {
  // The request onSuccess calls this method
  connectionRequest = null;
  // Using nano time since it is not related to the wall clock, which may change
  long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
  long deadline = protonTransport.tick(now);
  if (deadline != 0) {
    long delay = deadline - now;
    LOG.trace("IdleTimeoutCheck being initiated, initial delay: {}", delay);
    nextIdleTimeoutCheck = serializer.schedule(new IdleTimeoutCheck(), delay, TimeUnit.MILLISECONDS);
  }
  ProviderListener listener = this.listener;
  if (listener != null) {
    listener.onConnectionEstablished(remoteURI);
  }
}

代码示例来源:origin: io.vertx/vertx-proton

private void initiateIdleTimeoutChecks() {
 // Using nano time since it is not related to the wall clock, which may change
 long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
 long deadline = transport.tick(now);
 if (deadline != 0) {
  // timer treats 0 as error, ensure value is at least 1 as there was a deadline
  long delay = Math.max(deadline - now, 1);
  LOG.trace("IdleTimeoutCheck being initiated, initial delay: {0}", delay);
  idleTimeoutCheckTimerId = vertx.setTimer(delay, new IdleTimeoutCheck());
 }
}

代码示例来源:origin: org.apache.activemq/activemq-all

private void configureInactivityMonitor() {
    AmqpInactivityMonitor monitor = amqpTransport.getInactivityMonitor();
    if (monitor == null) {
      return;
    }

    // If either end has idle timeout requirements then the tick method
    // will give us a deadline on the next time we need to tick() in order
    // to meet those obligations.
    // Using nano time since it is not related to the wall clock, which may change
    long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
    long nextIdleCheck = protonTransport.tick(now);
    if (nextIdleCheck != 0) {
      // monitor treats <= 0 as no work, ensure value is at least 1 as there was a deadline
      long delay = Math.max(nextIdleCheck - now, 1);
      LOG.trace("Connection keep-alive processing starts in: {}", delay);
      monitor.startKeepAliveTask(delay);
    } else {
      LOG.trace("Connection does not require keep-alive processing");
    }
  }
}

代码示例来源:origin: org.apache.activemq/activemq-osgi

private void configureInactivityMonitor() {
    AmqpInactivityMonitor monitor = amqpTransport.getInactivityMonitor();
    if (monitor == null) {
      return;
    }

    // If either end has idle timeout requirements then the tick method
    // will give us a deadline on the next time we need to tick() in order
    // to meet those obligations.
    // Using nano time since it is not related to the wall clock, which may change
    long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
    long nextIdleCheck = protonTransport.tick(now);
    if (nextIdleCheck != 0) {
      // monitor treats <= 0 as no work, ensure value is at least 1 as there was a deadline
      long delay = Math.max(nextIdleCheck - now, 1);
      LOG.trace("Connection keep-alive processing starts in: {}", delay);
      monitor.startKeepAliveTask(delay);
    } else {
      LOG.trace("Connection does not require keep-alive processing");
    }
  }
}

代码示例来源:origin: com.ibm.mqlight/mqlight-api

@Override
  public void run() {
    final String methodName = "run";
    logger.entry(this, methodName);
    transport.process();
    transport.tick(System.currentTimeMillis());
    logger.exit(methodName);
  }
};

代码示例来源:origin: org.apache.activemq/artemis-proton-plug

@Override
public long tick(boolean firstTick) {
 if (!firstTick) {
   try {
    if (connection.getLocalState() != EndpointState.CLOSED) {
      long rescheduleAt = transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
      if (transport.isClosed()) {
       throw new IllegalStateException("Channel was inactive for to long");
      }
      return rescheduleAt;
    }
   }
   catch (Exception e) {
    transport.close();
    connection.setCondition(new ErrorCondition());
   }
   return 0;
 }
 return transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
}

代码示例来源:origin: apache/activemq-artemis

public Long tick(boolean firstTick) {
 requireHandler();
 if (!firstTick) {
   try {
    if (connection.getLocalState() != EndpointState.CLOSED) {
      long rescheduleAt = transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
      if (transport.isClosed()) {
       throw new IllegalStateException("Channel was inactive for to long");
      }
      return rescheduleAt;
    }
   } catch (Exception e) {
    log.warn(e.getMessage(), e);
    transport.close();
    connection.setCondition(new ErrorCondition());
   } finally {
    flush();
   }
   return 0L;
 }
 return transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
}

代码示例来源:origin: org.apache.qpid/qpid-jms-client

@Override
  public void run() {
    boolean checkScheduled = false;
    if (connection.getLocalState() == EndpointState.ACTIVE) {
      // Using nano time since it is not related to the wall clock, which may change
      long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
      long deadline = protonTransport.tick(now);
      boolean pumpSucceeded = pumpToProtonTransport();
      if (protonTransport.isClosed()) {
        LOG.info("IdleTimeoutCheck closed the transport due to the peer exceeding our requested idle-timeout.");
        if (pumpSucceeded) {
          fireProviderException(new IOException("Transport closed due to the peer exceeding our requested idle-timeout"));
        }
      } else {
        if (deadline != 0) {
          long delay = deadline - now;
          checkScheduled = true;
          LOG.trace("IdleTimeoutCheck rescheduling with delay: {}", delay);
          nextIdleTimeoutCheck = serializer.schedule(this, delay, TimeUnit.MILLISECONDS);
        }
      }
    } else {
      LOG.trace("IdleTimeoutCheck skipping check, connection is not active.");
    }
    if (!checkScheduled) {
      nextIdleTimeoutCheck = null;
      LOG.trace("IdleTimeoutCheck exiting");
    }
  }
}

代码示例来源:origin: org.apache.activemq/artemis-amqp-protocol

try {
     if (connection.getLocalState() != EndpointState.CLOSED) {
      long rescheduleAt = transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
      if (transport.isClosed()) {
        throw new IllegalStateException("Channel was inactive for to long");
  return transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
} finally {
  lock.unlock();

代码示例来源:origin: apache/qpid-jms

@Override
  public void run() {
    boolean checkScheduled = false;
    if (connection.getLocalState() == EndpointState.ACTIVE) {
      // Using nano time since it is not related to the wall clock, which may change
      long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
      long deadline = protonTransport.tick(now);
      boolean pumpSucceeded = pumpToProtonTransport();
      if (protonTransport.isClosed()) {
        LOG.info("IdleTimeoutCheck closed the transport due to the peer exceeding our requested idle-timeout.");
        if (pumpSucceeded) {
          fireProviderException(new IOException("Transport closed due to the peer exceeding our requested idle-timeout"));
        }
      } else {
        if (deadline != 0) {
          long delay = deadline - now;
          checkScheduled = true;
          LOG.trace("IdleTimeoutCheck rescheduling with delay: {}", delay);
          nextIdleTimeoutCheck = serializer.schedule(this, delay, TimeUnit.MILLISECONDS);
        }
      }
    } else {
      LOG.trace("IdleTimeoutCheck skipping check, connection is not active.");
    }
    if (!checkScheduled) {
      nextIdleTimeoutCheck = null;
      LOG.trace("IdleTimeoutCheck exiting");
    }
  }
}

代码示例来源:origin: org.apache.qpid/proton-j

private static long deadline(SelectableImpl selectable) {
  Reactor reactor = selectable.getReactor();
  Transport transport = selectable.getTransport();
  long deadline = transport.tick(reactor.now());
  return deadline;
}

代码示例来源:origin: org.apache.activemq/activemq-all

@Override
public long keepAlive() throws IOException {
  long rescheduleAt = 0l;
  LOG.trace("Performing connection:{} keep-alive processing", amqpTransport.getRemoteAddress());
  if (protonConnection.getLocalState() != EndpointState.CLOSED) {
    // Using nano time since it is not related to the wall clock, which may change
    long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
    long deadline = protonTransport.tick(now);
    pumpProtonToSocket();
    if (protonTransport.isClosed()) {
      LOG.debug("Transport closed after inactivity check.");
      throw new InactivityIOException("Channel was inactive for too long");
    } else {
      if(deadline != 0) {
        // caller treats 0 as no-work, ensure value is at least 1 as there was a deadline
        rescheduleAt = Math.max(deadline - now, 1);
      }
    }
  }
  LOG.trace("Connection:{} keep alive processing done, next update in {} milliseconds.",
       amqpTransport.getRemoteAddress(), rescheduleAt);
  return rescheduleAt;
}

代码示例来源:origin: com.microsoft.azure.iot/proton-j-azure-iot

private static long deadline(SelectableImpl selectable) {
  Reactor reactor = selectable.getReactor();
  Transport transport = selectable.getTransport();
  long deadline = transport.tick(reactor.now());
  return deadline;
}

代码示例来源:origin: org.apache.activemq/activemq-osgi

@Override
public long keepAlive() throws IOException {
  long rescheduleAt = 0l;
  LOG.trace("Performing connection:{} keep-alive processing", amqpTransport.getRemoteAddress());
  if (protonConnection.getLocalState() != EndpointState.CLOSED) {
    // Using nano time since it is not related to the wall clock, which may change
    long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
    long deadline = protonTransport.tick(now);
    pumpProtonToSocket();
    if (protonTransport.isClosed()) {
      LOG.debug("Transport closed after inactivity check.");
      throw new InactivityIOException("Channel was inactive for too long");
    } else {
      if(deadline != 0) {
        // caller treats 0 as no-work, ensure value is at least 1 as there was a deadline
        rescheduleAt = Math.max(deadline - now, 1);
      }
    }
  }
  LOG.trace("Connection:{} keep alive processing done, next update in {} milliseconds.",
       amqpTransport.getRemoteAddress(), rescheduleAt);
  return rescheduleAt;
}

代码示例来源:origin: com.ibm.mqlight/mqlight-api

private void writeToNetwork(EngineConnection engineConnection) {
 final String methodName = "writeToNetwork";
 logger.entry(this, methodName, engineConnection);
  if (engineConnection.transport.pending() > 0) {
    ByteBuffer head = engineConnection.transport.head();
    int amount = head.remaining();
    engineConnection.channel.write(head, new NetworkWritePromiseImpl(this, amount, engineConnection));
    engineConnection.transport.pop(amount);
    engineConnection.transport.tick(System.currentTimeMillis());
  }
  logger.exit(this, methodName);
}

代码示例来源:origin: apache/activemq-artemis

@Override
 public void run() {
   try {
    if (getEndpoint().getLocalState() != EndpointState.CLOSED) {
      LOG.debug("Client performing next idle check");
      // Using nano time since it is not related to the wall clock, which may change
      long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
      long deadline = protonTransport.tick(now);
      pumpToProtonTransport();
      if (protonTransport.isClosed()) {
       LOG.debug("Transport closed after inactivity check.");
       throw new InactivityIOException("Channel was inactive for too long");
      } else {
       if (deadline != 0) {
         getScheduler().schedule(this, deadline - now, TimeUnit.MILLISECONDS);
       }
      }
    }
   } catch (Exception e) {
    try {
      transport.close();
    } catch (IOException e1) {
    }
    fireClientException(e);
   }
 }
}, initialKeepAliveDeadline - initialNow, TimeUnit.MILLISECONDS);

代码示例来源:origin: io.vertx/vertx-proton

@Override
 public void handle(Long event) {
  boolean checkScheduled = false;
  if (connection.getLocalState() == EndpointState.ACTIVE) {
   // Using nano time since it is not related to the wall clock, which may change
   long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
   long deadline = transport.tick(now);
   flush();
   if (transport.isClosed()) {
    LOG.info("IdleTimeoutCheck closed the transport due to the peer exceeding our requested idle-timeout.");
    disconnect();
   } else {
    if (deadline != 0) {
     // timer treats 0 as error, ensure value is at least 1 as there was a deadline
     long delay = Math.max(deadline - now, 1);
     checkScheduled = true;
     LOG.trace("IdleTimeoutCheck rescheduling with delay: {0}", delay);
     idleTimeoutCheckTimerId = vertx.setTimer(delay, this);
    }
   }
  } else {
   LOG.trace("IdleTimeoutCheck skipping check, connection is not active.");
  }
  if (!checkScheduled) {
   idleTimeoutCheckTimerId = null;
   LOG.trace("IdleTimeoutCheck exiting");
  }
 }
}

代码示例来源:origin: com.microsoft.azure.iot/proton-j-azure-iot

@Override
  public void run(Selectable selectable) {
    Reactor reactor = selectable.getReactor();
    Transport transport = ((SelectableImpl)selectable).getTransport();
    long deadline = transport.tick(reactor.now());
    selectable.setDeadline(deadline);
    int c = capacity(selectable);
    int p = pending(selectable);
    selectable.setReading(c > 0);
    selectable.setWriting(p > 0);
    reactor.update(selectable);
  }
};

代码示例来源:origin: org.apache.qpid/proton-j

@Override
  public void run(Selectable selectable) {
    Reactor reactor = selectable.getReactor();
    Transport transport = ((SelectableImpl)selectable).getTransport();
    long deadline = transport.tick(reactor.now());
    selectable.setDeadline(deadline);
    int c = capacity(selectable);
    int p = pending(selectable);
    selectable.setReading(c > 0);
    selectable.setWriting(p > 0);
    reactor.update(selectable);
  }
};

相关文章