reactor.util.context.Context.putAll()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(239)

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

Context.putAll介绍

[英]Create a new Context by merging the content of this context and a given Context. If the other context is empty, the same Context instance is returned.
[中]通过合并此上下文和给定上下文的内容来创建新上下文。如果另一个上下文为空,则返回相同的上下文实例。

代码示例

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

/**
 * Enrich a potentially empty downstream {@link Context} by adding all values
 * from the given {@link Context}, producing a new {@link Context} that is propagated
 * upstream.
 * <p>
 * The {@link Context} propagation happens once per subscription (not on each onNext):
 * it is done during the {@code subscribe(Subscriber)} phase, which runs from
 * the last operator of a chain towards the first.
 * <p>
 * So this operator enriches a {@link Context} coming from under it in the chain
 * (downstream, by default an empty one) and makes the new enriched {@link Context}
 * visible to operators above it in the chain.
 *
 * @param mergeContext the {@link Context} to merge with a previous {@link Context}
 * state, returning a new one.
 *
 * @return a contextualized {@link Flux}
 * @see Context
 */
public final Flux<T> subscriberContext(Context mergeContext) {
  return subscriberContext(c -> c.putAll(mergeContext));
}

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

/**
 * Enrich a potentially empty downstream {@link Context} by adding all values
 * from the given {@link Context}, producing a new {@link Context} that is propagated
 * upstream.
 * <p>
 * The {@link Context} propagation happens once per subscription (not on each onNext):
 * it is done during the {@code subscribe(Subscriber)} phase, which runs from
 * the last operator of a chain towards the first.
 * <p>
 * So this operator enriches a {@link Context} coming from under it in the chain
 * (downstream, by default an empty one) and makes the new enriched {@link Context}
 * visible to operators above it in the chain.
 *
 * @param mergeContext the {@link Context} to merge with a previous {@link Context}
 * state, returning a new one.
 *
 * @return a contextualized {@link Mono}
 * @see Context
 */
public final Mono<T> subscriberContext(Context mergeContext) {
  return subscriberContext(c -> c.putAll(mergeContext));
}

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

@Test
public void putAllOfEmpty() {
  Context m = Context.empty();
  Context put = c.putAll(m);
  assertThat(put).isSameAs(c);
}

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

@Test
public void putAllOfEmpty() {
  Context m = Context.empty();
  Context put = c.putAll(m);
  assertThat(put).isSameAs(c);
}

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

@Test
public void putAllOfContext3() {
  Context m = Context.of("A", 1, "B", 2, "C", 3);
  Context put = c.putAll(m);
  assertThat(put).isInstanceOf(ContextN.class);
  assertThat(put.stream().map(Map.Entry::getKey))
      .containsExactlyInAnyOrder(1, 2, 3, 4, 5, 6, "A", "B", "C");
}

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

@Test
public void putAllOfContextN() {
  Context m = new ContextN("A", 1, "B", 2, "C", 3,
      "D", 1, "E", 2, "F", 3);
  Context put = c.putAll(m);
  assertThat(put).isInstanceOf(ContextN.class);
  assertThat(put.stream().map(Map.Entry::getKey))
      .containsExactlyInAnyOrder(1, 2, 3, 4, 5, 6, "A", "B", "C", "D", "E", "F");
}

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

@Test
public void putAllOf() {
  Context m = Context.of("A", 1, "B", 2, "C", 3);
  Context put = c.putAll(m);
  assertThat(put).isInstanceOf(Context3.class)
          .hasToString("Context3{A=1, B=2, C=3}");
}

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

/**
 * Enrich a potentially empty downstream {@link Context} by adding all values
 * from the given {@link Context}, producing a new {@link Context} that is propagated
 * upstream.
 * <p>
 * The {@link Context} propagation happens once per subscription (not on each onNext):
 * it is done during the {@code subscribe(Subscriber)} phase, which runs from
 * the last operator of a chain towards the first.
 * <p>
 * So this operator enriches a {@link Context} coming from under it in the chain
 * (downstream, by default an empty one) and makes the new enriched {@link Context}
 * visible to operators above it in the chain.
 *
 * @param mergeContext the {@link Context} to merge with a previous {@link Context}
 * state, returning a new one.
 *
 * @return a contextualized {@link Flux}
 * @see Context
 */
public final Flux<T> subscriberContext(Context mergeContext) {
  return subscriberContext(c -> c.putAll(mergeContext));
}

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

/**
 * Enrich a potentially empty downstream {@link Context} by adding all values
 * from the given {@link Context}, producing a new {@link Context} that is propagated
 * upstream.
 * <p>
 * The {@link Context} propagation happens once per subscription (not on each onNext):
 * it is done during the {@code subscribe(Subscriber)} phase, which runs from
 * the last operator of a chain towards the first.
 * <p>
 * So this operator enriches a {@link Context} coming from under it in the chain
 * (downstream, by default an empty one) and makes the new enriched {@link Context}
 * visible to operators above it in the chain.
 *
 * @param mergeContext the {@link Context} to merge with a previous {@link Context}
 * state, returning a new one.
 *
 * @return a contextualized {@link Mono}
 * @see Context
 */
public final Mono<T> subscriberContext(Context mergeContext) {
  return subscriberContext(c -> c.putAll(mergeContext));
}

代码示例来源:origin: apache/servicemix-bundles

private Context withSecurityContext(Context mainContext, ServerWebExchange exchange) {
    return mainContext.putAll(this.repository.load(exchange)
      .as(ReactiveSecurityContextHolder::withSecurityContext));
  }
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public Context currentContext() {
  Context context = delegate.currentContext();
  if (context.hasKey(CONTEXT_DEFAULTED_ATTR_NAME)) {
    return context;
  }
  context = context.put(CONTEXT_DEFAULTED_ATTR_NAME, Boolean.TRUE);
  Authentication authentication = securityContext.getAuthentication();
  if (authentication == null) {
    return context;
  }
  Context toMerge = ReactiveSecurityContextHolder.withSecurityContext(
      Mono.just(this.securityContext));
  return toMerge.putAll(context);
}

代码示例来源:origin: org.springframework.security/spring-security-test

@Override
public Context currentContext() {
  Context context = delegate.currentContext();
  if (context.hasKey(CONTEXT_DEFAULTED_ATTR_NAME)) {
    return context;
  }
  context = context.put(CONTEXT_DEFAULTED_ATTR_NAME, Boolean.TRUE);
  Authentication authentication = securityContext.getAuthentication();
  if (authentication == null) {
    return context;
  }
  Context toMerge = ReactiveSecurityContextHolder.withSecurityContext(
      Mono.just(this.securityContext));
  return toMerge.putAll(context);
}

相关文章