reactor.core.publisher.Operators.subOrZero()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(3.0k)|赞(0)|评价(0)|浏览(130)

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

Operators.subOrZero介绍

[英]Cap a subtraction to 0
[中]将减法上限设为0

代码示例

代码示例来源:origin: reactor/reactor-core

/**
 * Concurrent subtraction bound to 0 and Long.MAX_VALUE.
 * Any concurrent write will "happen" before this operation.
 *
 * @param sequence current atomic to update
 * @param toSub    delta to sub
 * @return value before subscription, 0 or Long.MAX_VALUE
 */
public static long getAndSub(AtomicLong sequence, long toSub) {
  long r, u;
  do {
    r = sequence.get();
    if (r == 0 || r == Long.MAX_VALUE) {
      return r;
    }
    u = Operators.subOrZero(r, toSub);
  } while (!sequence.compareAndSet(r, u));
  return r;
}

代码示例来源:origin: reactor/reactor-core

/**
 * Concurrent subtraction bound to 0 and Long.MAX_VALUE. Any concurrent write will
 * "happen" before this operation.
 *
 * @param sequence current sequence to update
 * @param toSub delta to sub
 *
 * @return value before subscription, 0 or Long.MAX_VALUE
 */
static long getAndSub(RingBuffer.Sequence sequence, long toSub) {
  long r, u;
  do {
    r = sequence.getAsLong();
    if (r == 0 || r == Long.MAX_VALUE) {
      return r;
    }
    u = Operators.subOrZero(r, toSub);
  }
  while (!sequence.compareAndSet(r, u));
  return r;
}

代码示例来源:origin: reactor/reactor-core

/**
 * Concurrent subtraction bound to 0, mostly used to decrement a request tracker by
 * the amount produced by the operator. Any concurrent write will "happen before"
 * this operation.
 *
 * @param <T> the parent instance type
 * @param updater  current field updater
 * @param instance current instance to update
 * @param toSub    delta to subtract
 * @return value after subtraction or zero
 */
public static <T> long produced(AtomicLongFieldUpdater<T> updater, T instance, long toSub) {
  long r, u;
  do {
    r = updater.get(instance);
    if (r == 0 || r == Long.MAX_VALUE) {
      return r;
    }
    u = subOrZero(r, toSub);
  } while (!updater.compareAndSet(instance, r, u));
  return u;
}

代码示例来源:origin: io.projectreactor/reactor-core

/**
 * Concurrent subtraction bound to 0 and Long.MAX_VALUE. Any concurrent write will
 * "happen" before this operation.
 *
 * @param sequence current sequence to update
 * @param toSub delta to sub
 *
 * @return value before subscription, 0 or Long.MAX_VALUE
 */
static long getAndSub(RingBuffer.Sequence sequence, long toSub) {
  long r, u;
  do {
    r = sequence.getAsLong();
    if (r == 0 || r == Long.MAX_VALUE) {
      return r;
    }
    u = Operators.subOrZero(r, toSub);
  }
  while (!sequence.compareAndSet(r, u));
  return r;
}

代码示例来源:origin: io.projectreactor/reactor-core

/**
 * Concurrent subtraction bound to 0, mostly used to decrement a request tracker by
 * the amount produced by the operator. Any concurrent write will "happen before"
 * this operation.
 *
 * @param <T> the parent instance type
 * @param updater  current field updater
 * @param instance current instance to update
 * @param toSub    delta to subtract
 * @return value after subtraction or zero
 */
public static <T> long produced(AtomicLongFieldUpdater<T> updater, T instance, long toSub) {
  long r, u;
  do {
    r = updater.get(instance);
    if (r == 0 || r == Long.MAX_VALUE) {
      return r;
    }
    u = subOrZero(r, toSub);
  } while (!updater.compareAndSet(instance, r, u));
  return u;
}

相关文章