operator/src/main/java/oracle/kubernetes/operator/work/FiberGate.java
public synchronized Fiber startFiberIfLastFiberMatches(
      String key, Fiber old, Step strategy, Packet packet, CompletionCallback callback) {
    Fiber f = engine.createFiber();
    WaitForOldFiberStep wfofs;
    if (old != null) {
      if (old == placeholder) {
        if (gateMap.putIfAbsent(key, f) != null) {
          return null;
        }
      } else if (!gateMap.replace(key, old, f)) {
        return null;
      }
    } else {
      old = gateMap.put(key, f);
    }
    wfofs = new WaitForOldFiberStep(old, strategy);
    f.getComponents().put(ProcessingConstants.FIBER_COMPONENT_NAME, Component.createFor(wfofs));
    f.start(
        wfofs,
        packet,
        new CompletionCallback() {
          @Override
          public void onCompletion(Packet packet) {
            gateMap.remove(key, f);
            callback.onCompletion(packet);
          }

          @Override
          public void onThrowable(Packet packet, Throwable throwable) {
            gateMap.remove(key, f);
            callback.onThrowable(packet, throwable);
          }
        });
    return f;
  }
/**
   * Starts Fiber only if the last started Fiber matches the given old Fiber.
   *
   * @param key Key
   * @param old Expected last Fiber
   * @param strategy Step for Fiber to begin with
   * @param packet Packet
   * @param callback Completion callback
   * @return started Fiber, or null, if no Fiber started
   */
Starts Fiber only if the last started Fiber matches the given old Fiber.
Starts Fiber only if the last started Fiber matches the given old Fiber .
public synchronized Fiber startFiberIfLastFiberMatches(
      String key, Fiber old, Step strategy, Packet packet, CompletionCallback callback) {
    Fiber f = engine.createFiber();
    WaitForOldFiberStep wfofs;
    if (old != null) {
      if (old == placeholder) {
        if (gateMap.putIfAbsent(key, f) != null) {
          return null;
        }
      } else if (!gateMap.replace(key, old, f)) {
        return null;
      }
    } else {
      old = gateMap.put(key, f);
    }
    wfofs = new WaitForOldFiberStep(old, strategy);
    f.getComponents().put(ProcessingConstants.FIBER_COMPONENT_NAME, Component.createFor(wfofs));
    f.start(
        wfofs,
        packet,
        new CompletionCallback() {
          @Override
          public void onCompletion(Packet packet) {
            gateMap.remove(key, f);
            callback.onCompletion(packet);
          }
          @Override
          public void onThrowable(Packet packet, Throwable throwable) {
            gateMap.remove(key, f);
            callback.onThrowable(packet, throwable);
          }
        });
    return f;
  }
public synchronized Fiber startFiberIfLastFiberMatches ( String key , Fiber old , Step strategy , Packet packet , CompletionCallback callback ) { Fiber f = engine . createFiber ( ) ; WaitForOldFiberStep wfofs ; if ( old != null ) { if ( old == placeholder ) { if ( gateMap . putIfAbsent ( key , f ) != null ) { return null ; } } else if ( ! gateMap . replace ( key , old , f ) ) { return null ; } } else { old = gateMap . put ( key , f ) ; } wfofs = new WaitForOldFiberStep ( old , strategy ) ; f . getComponents ( ) . put ( ProcessingConstants . FIBER_COMPONENT_NAME , Component . createFor ( wfofs ) ) ; f . start ( wfofs , packet , new CompletionCallback ( ) { @ Override public void onCompletion ( Packet packet ) { gateMap . remove ( key , f ) ; callback . onCompletion ( packet ) ; } @ Override public void onThrowable ( Packet packet , Throwable throwable ) { gateMap . remove ( key , f ) ; callback . onThrowable ( packet , throwable ) ; } } ) ; return f ; }
Starts Fiber only if the last started Fiber matches the given old Fiber.
Starts Fiber only if the last started Fiber matches the given old Fiber .