Java Code Examples for reactor.core.Fuseable#SYNC

The following examples show how to use reactor.core.Fuseable#SYNC . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FluxFlatMap.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.setOnce(S, this, s)) {
		if (s instanceof Fuseable.QueueSubscription) {
			@SuppressWarnings("unchecked") Fuseable.QueueSubscription<R> f =
					(Fuseable.QueueSubscription<R>) s;
			int m = f.requestFusion(Fuseable.ANY | Fuseable.THREAD_BARRIER);
			if (m == Fuseable.SYNC) {
				sourceMode = Fuseable.SYNC;
				queue = f;
				done = true;
				parent.drain(null);
				return;
			}
			if (m == Fuseable.ASYNC) {
				sourceMode = Fuseable.ASYNC;
				queue = f;
			}
			// NONE is just fall-through as the queue will be created on demand
		}
		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example 2
Source File: FluxGenerate.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public int requestFusion(int requestedMode) {
	if ((requestedMode & Fuseable.SYNC) != 0 && (requestedMode & Fuseable.THREAD_BARRIER) == 0) {
		outputFused = true;
		return Fuseable.SYNC;
	}
	return Fuseable.NONE;
}
 
Example 3
Source File: FluxMergeSequential.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.setOnce(SUBSCRIPTION, this, s)) {
		if (s instanceof QueueSubscription) {
			@SuppressWarnings("unchecked")
			QueueSubscription<R> qs = (QueueSubscription<R>) s;

			int m = qs.requestFusion(Fuseable.ANY | Fuseable.THREAD_BARRIER);
			if (m == Fuseable.SYNC) {
				fusionMode = m;
				queue = qs;
				done = true;
				parent.innerComplete(this);
				return;
			}
			if (m == Fuseable.ASYNC) {
				fusionMode = m;
				queue = qs;
				s.request(Operators.unboundedOrPrefetch(prefetch));
				return;
			}
		}

		queue = Queues.<R>get(prefetch).get();
		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example 4
Source File: ParallelSource.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
void drain() {
	if (WIP.getAndIncrement(this) != 0) {
		return;
	}
	
	if (sourceMode == Fuseable.SYNC) {
		drainSync();
	} else {
		drainAsync();
	}
}
 
Example 5
Source File: FluxFlattenIterable.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.validate(this.s, s)) {
		this.s = s;

		if (s instanceof QueueSubscription) {
			@SuppressWarnings("unchecked") QueueSubscription<T> qs =
					(QueueSubscription<T>) s;

			int m = qs.requestFusion(Fuseable.ANY);

			if (m == Fuseable.SYNC) {
				fusionMode = m;
				this.queue = qs;
				done = true;

				actual.onSubscribe(this);

				return;
			}
			else if (m == Fuseable.ASYNC) {
				fusionMode = m;
				this.queue = qs;

				actual.onSubscribe(this);

				s.request(Operators.unboundedOrPrefetch(prefetch));
				return;
			}
		}

		queue = queueSupplier.get();

		actual.onSubscribe(this);

		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example 6
Source File: FluxPublishOn.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	if (outputFused) {
		runBackfused();
	}
	else if (sourceMode == Fuseable.SYNC) {
		runSync();
	}
	else {
		runAsync();
	}
}
 
Example 7
Source File: FluxPublishOn.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.validate(this.s, s)) {
		this.s = s;

		if (s instanceof QueueSubscription) {
			@SuppressWarnings("unchecked") QueueSubscription<T> f =
					(QueueSubscription<T>) s;

			int m = f.requestFusion(Fuseable.ANY | Fuseable.THREAD_BARRIER);

			if (m == Fuseable.SYNC) {
				sourceMode = Fuseable.SYNC;
				queue = f;
				done = true;

				actual.onSubscribe(this);
				return;
			}
			if (m == Fuseable.ASYNC) {
				sourceMode = Fuseable.ASYNC;
				queue = f;

				actual.onSubscribe(this);

				s.request(Operators.unboundedOrPrefetch(prefetch));

				return;
			}
		}

		queue = queueSupplier.get();

		actual.onSubscribe(this);

		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example 8
Source File: FluxPublishOn.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	if (outputFused) {
		runBackfused();
	}
	else if (sourceMode == Fuseable.SYNC) {
		runSync();
	}
	else {
		runAsync();
	}
}
 
Example 9
Source File: FluxPublish.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.setOnce(S, this, s)) {
		if (s instanceof Fuseable.QueueSubscription) {
			@SuppressWarnings("unchecked") Fuseable.QueueSubscription<T> f =
					(Fuseable.QueueSubscription<T>) s;

			int m = f.requestFusion(Fuseable.ANY | Fuseable.THREAD_BARRIER);
			if (m == Fuseable.SYNC) {
				sourceMode = m;
				queue = f;
				drain();
				return;
			}
			if (m == Fuseable.ASYNC) {
				sourceMode = m;
				queue = f;
				s.request(Operators.unboundedOrPrefetch(prefetch));
				return;
			}
		}

		queue = parent.queueSupplier.get();

		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example 10
Source File: AssertSubscriber.java    From RHub with Apache License 2.0 5 votes vote down vote up
/**
 * Assert that the fusion mode was granted.
 *
 * @return this
 */
public final AssertSubscriber<T> assertFusionEnabled() {
    if (establishedFusionMode != Fuseable.SYNC && establishedFusionMode != Fuseable.ASYNC) {
        throw new AssertionError("Fusion was not enabled");
    }
    return this;
}
 
Example 11
Source File: FluxPublishMulticast.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
void drain() {
	if (WIP.getAndIncrement(this) != 0) {
		return;
	}

	if (sourceMode == Fuseable.SYNC) {
		drainSync();
	}
	else {
		drainAsync();
	}
}
 
Example 12
Source File: DefaultStepVerifierBuilder.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
static String formatFusionMode(int m) {
	switch (m) {
		case Fuseable.ANY:
			return "(any)";
		case Fuseable.SYNC:
			return "(sync)";
		case Fuseable.ASYNC:
			return "(async)";
		case Fuseable.NONE:
			return "none";
		case Fuseable.THREAD_BARRIER:
			return "(thread-barrier)";
	}
	return "" + m;
}
 
Example 13
Source File: AssertSubscriber.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
protected final String fusionModeName(int mode) {
  switch (mode) {
    case -1:
      return "Disabled";
    case Fuseable.NONE:
      return "None";
    case Fuseable.SYNC:
      return "Sync";
    case Fuseable.ASYNC:
      return "Async";
    default:
      return "Unknown(" + mode + ")";
  }
}
 
Example 14
Source File: AssertSubscriber.java    From RHub with Apache License 2.0 5 votes vote down vote up
protected final String fusionModeName(int mode) {
    switch (mode) {
        case -1:
            return "Disabled";
        case Fuseable.NONE:
            return "None";
        case Fuseable.SYNC:
            return "Sync";
        case Fuseable.ASYNC:
            return "Async";
        default:
            return "Unknown(" + mode + ")";
    }
}
 
Example 15
Source File: FluxPublishMulticast.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.setOnce(S, this, s)) {

		if (s instanceof QueueSubscription) {
			@SuppressWarnings("unchecked") QueueSubscription<T> qs =
					(QueueSubscription<T>) s;

			int m = qs.requestFusion(Fuseable.ANY);
			if (m == Fuseable.SYNC) {
				sourceMode = m;

				queue = qs;
				done = true;
				connected = true;

				drain();

				return;
			}
			if (m == Fuseable.ASYNC) {
				sourceMode = m;

				queue = qs;
				connected = true;

				s.request(Operators.unboundedOrPrefetch(prefetch));

				return;
			}
		}

		queue = queueSupplier.get();
		connected = true;

		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example 16
Source File: FluxCharSequence.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Override
public int requestFusion(int requestedMode) {
	return requestedMode & Fuseable.SYNC;
}
 
Example 17
Source File: AssertSubscriber.java    From rsocket-java with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void onSubscribe(Subscription s) {
  subscriptionCount++;
  int requestMode = requestedFusionMode;
  if (requestMode >= 0) {
    if (!setWithoutRequesting(s)) {
      if (!isCancelled()) {
        errors.add(new IllegalStateException("Subscription already set: " + subscriptionCount));
      }
    } else {
      if (s instanceof Fuseable.QueueSubscription) {
        this.qs = (Fuseable.QueueSubscription<T>) s;

        int m = qs.requestFusion(requestMode);
        establishedFusionMode = m;

        if (m == Fuseable.SYNC) {
          for (; ; ) {
            T v = qs.poll();
            if (v == null) {
              onComplete();
              break;
            }

            onNext(v);
          }
        } else {
          requestDeferred();
        }
      } else {
        requestDeferred();
      }
    }
  } else {
    if (!set(s)) {
      if (!isCancelled()) {
        errors.add(new IllegalStateException("Subscription already set: " + subscriptionCount));
      }
    }
  }
}
 
Example 18
Source File: DefaultStepVerifierBuilder.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
final void startFusion(Subscription s) {
	if (s instanceof Fuseable.QueueSubscription) {
		@SuppressWarnings("unchecked") Fuseable.QueueSubscription<T> qs =
				(Fuseable.QueueSubscription<T>) s;

		this.qs = qs;

		int m = qs.requestFusion(requestedFusionMode);
		if (expectedFusionMode == Fuseable.NONE && m != Fuseable.NONE) {
			setFailure(null,
					"expected no fusion; actual: %s",
					formatFusionMode(m));
			return;
		}
		if (expectedFusionMode != Fuseable.NONE && m == Fuseable.NONE) {
			setFailure(null,
					"expected fusion: %s; actual does not support " + "fusion",
					formatFusionMode(expectedFusionMode));
			return;
		}
		if ((m & expectedFusionMode) != m) {
			setFailure(null, "expected fusion mode: %s; actual: %s",
					formatFusionMode(expectedFusionMode),
					formatFusionMode(m));
			return;
		}

		this.establishedFusionMode = m;

		if (m == Fuseable.SYNC) {
			T v;
			for (; ; ) {
				if(get() == Operators.cancelledSubscription()){
					return;
				}
				try {
					v = qs.poll();
				}
				catch (Throwable e) {
					Exceptions.throwIfFatal(e);
					cancel();
					onError(Exceptions.unwrap(e));
					return;
				}
				if (v == null) {
					onComplete();
					break;
				}

				onNext(v);
			}
		}
		else if (initialRequest != 0) {
			s.request(initialRequest);
		}
	}
	else if (expectedFusionMode != Fuseable.NONE) {
		setFailure(null,
				"expected fuseable source but actual Subscription " + "is " +
						"not: %s",
				expectedFusionMode,
				s);
	}
	else if (initialRequest != 0L) {
		s.request(initialRequest);
	}
}
 
Example 19
Source File: AssertSubscriber.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void onSubscribe(Subscription s) {
	subscriptionCount++;
	int requestMode = requestedFusionMode;
	if (requestMode >= 0) {
		if (!setWithoutRequesting(s)) {
			if (!isCancelled()) {
				errors.add(new IllegalStateException("Subscription already set: " +
						subscriptionCount));
			}
		} else {
			if (s instanceof Fuseable.QueueSubscription) {
				this.qs = (Fuseable.QueueSubscription<T>)s;

				int m = qs.requestFusion(requestMode);
				establishedFusionMode = m;

				if (m == Fuseable.SYNC) {
					for (;;) {
						T v = qs.poll();
						if (v == null) {
							onComplete();
							break;
						}

						onNext(v);
					}
				}
				else {
					requestDeferred();
				}
			}
			else {
				requestDeferred();
			}
		}
	} else {
		if (!set(s)) {
			if (!isCancelled()) {
				errors.add(new IllegalStateException("Subscription already set: " +
						subscriptionCount));
			}
		}
	}
}
 
Example 20
Source File: AssertSubscriber.java    From RHub with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void onSubscribe(Subscription s) {
    subscriptionCount++;
    int requestMode = requestedFusionMode;
    if (requestMode >= 0) {
        if (!setWithoutRequesting(s)) {
            if (!isCancelled()) {
                errors.add(new IllegalStateException("Subscription already push: " +
                        subscriptionCount));
            }
        } else {
            if (s instanceof Fuseable.QueueSubscription) {
                this.qs = (Fuseable.QueueSubscription<T>)s;

                int m = qs.requestFusion(requestMode);
                establishedFusionMode = m;

                if (m == Fuseable.SYNC) {
                    for (;;) {
                        T v = qs.poll();
                        if (v == null) {
                            onComplete();
                            break;
                        }

                        onNext(v);
                    }
                }
                else {
                    requestDeferred();
                }
            }
            else {
                requestDeferred();
            }
        }
    } else {
        if (!set(s)) {
            if (!isCancelled()) {
                errors.add(new IllegalStateException("Subscription already push: " +
                        subscriptionCount));
            }
        }
    }
}