Пример #1
0
  public void setExpiration() {
    long expiration =
        ((BasicContentHeaderProperties) _contentHeaderBody.getProperties()).getExpiration();
    long timestamp =
        ((BasicContentHeaderProperties) _contentHeaderBody.getProperties()).getTimestamp();

    if (SYNCHED_CLOCKS) {
      _expiration = expiration;
    } else {
      // Update TTL to be in broker time.
      if (expiration != 0L) {
        if (timestamp != 0L) {
          // todo perhaps use arrival time
          long diff = (System.currentTimeMillis() - timestamp);

          if ((diff > 1000L) || (diff < 1000L)) {
            _expiration = expiration + diff;
          }
        }
      }
    }
  }
Пример #2
0
  private IncomingMessage message(final boolean immediate, boolean persistent) throws AMQException {
    MessagePublishInfo publish =
        new MessagePublishInfo() {

          public AMQShortString getExchange() {
            return null;
          }

          public void setExchange(AMQShortString exchange) {
            throw new NotImplementedException();
          }

          public void setRoutingKey(AMQShortString routingKey) {
            throw new NotImplementedException();
          }

          public boolean isImmediate() {
            return immediate;
          }

          public boolean isMandatory() {
            return false;
          }

          public AMQShortString getRoutingKey() {
            return null;
          }
        };

    ContentHeaderBody contentHeaderBody = new ContentHeaderBody();
    contentHeaderBody.bodySize = MESSAGE_SIZE; // in bytes
    contentHeaderBody.setProperties(new BasicContentHeaderProperties());
    ((BasicContentHeaderProperties) contentHeaderBody.getProperties())
        .setDeliveryMode((byte) (persistent ? 2 : 1));
    IncomingMessage msg = new IncomingMessage(publish);
    msg.setContentHeaderBody(contentHeaderBody);
    return msg;
  }