Java Code Examples for reactor.core.Scannable#isScanAvailable()

The following examples show how to use reactor.core.Scannable#isScanAvailable() . 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: FluxMetrics.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
/**
 * Extract the name from the upstream, and detect if there was an actual name (ie. distinct from {@link
 * Scannable#stepName()}) set by the user.
 *
 * @param source the upstream
 *
 * @return a name
 */
static String resolveName(Publisher<?> source) {
	Scannable scannable = Scannable.from(source);
	if (scannable.isScanAvailable()) {
		String nameOrDefault = scannable.name();
		if (scannable.stepName()
		             .equals(nameOrDefault)) {
			return REACTOR_DEFAULT_NAME;
		}
		else {
			return nameOrDefault;
		}
	}
	else {
		log.warn("Attempting to activate metrics but the upstream is not Scannable. " + "You might want to use `name()` (and optionally `tags()`) right before `metrics()`");
		return REACTOR_DEFAULT_NAME;
	}

}
 
Example 2
Source File: FluxMetrics.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
/**
 * Extract the tags from the upstream
 *
 * @param source the upstream
 *
 * @return a {@link Tags} of {@link Tag}
 */
static Tags resolveTags(Publisher<?> source, Tags tags, String sequenceName) {
	Scannable scannable = Scannable.from(source);
	tags = tags.and(Tag.of(FluxMetrics.TAG_SEQUENCE_NAME, sequenceName));

	if (scannable.isScanAvailable()) {
		return scannable.tags()
		                //Note the combiner below is for parallel streams, which won't be used
		                //For the identity, `commonTags` should be ok (even if reduce uses it multiple times)
		                //since it deduplicates
		                .reduce(tags, TAG_ACCUMULATOR, TAG_COMBINER);
	}

	return tags;
}
 
Example 3
Source File: FluxTimeout.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Nullable
static String addNameToTimeoutDescription(Publisher<?> source,
		@Nullable  String timeoutDescription) {
	if (timeoutDescription == null) {
		return null;
	}

	Scannable s = Scannable.from(source);
	if (s.isScanAvailable()) {
		return timeoutDescription + " in '" + s.name() + "'";
	}
	else {
		return timeoutDescription;
	}
}
 
Example 4
Source File: SingleWorkerScheduler.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    Scannable mainScannable = Scannable.from(main);
    if (mainScannable.isScanAvailable()) {
        return Schedulers.SINGLE + "Worker(" + mainScannable.scanUnsafe(Attr.NAME) + ")";
    }
    return Schedulers.SINGLE + "Worker(" + main.toString() + ")";
}