All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ratpack.zipkin.TracedParallelBatch Maven / Gradle / Ivy

There is a newer version: 2.6.5
Show newest version
/*
 * Copyright 2016-2019 The OpenZipkin Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package ratpack.zipkin;

import brave.propagation.TraceContext;
import java.util.Arrays;
import ratpack.exec.Promise;
import ratpack.exec.util.ParallelBatch;
import ratpack.zipkin.internal.RatpackCurrentTraceContext;

/**
 * Provides factory methods for creating a RatPack {@link ParallelBatch}, with
 * the correct trace context.
 *
 * This is necessary because {@link ParallelBatch}es create forked executions
 * which do not "inherit" registries from the calling execution. Consequently,
 * the trace context must be passed explicitly to the forked executions.
 *
 * @deprecated As of 2.4 brave-ratpack is now providing an {@link ratpack.exec.ExecInitializer} bound in guice by {@link ServerTracingModule}
 * which will deal with passing tracing contexts around Ratpack executions. The propagation is done in {@link ratpack.zipkin.internal.RatpackCurrentTraceContext.TracingPropagationExecInitializer},
 * this kind of propagation is only possible with Ratpack version 1.6 and above as the parent execution is now avaialble.
 *
 * @param  the type of value produced by each promise in the batch.
 */
@Deprecated
public final class TracedParallelBatch {

  private final Iterable> promises;

  private TracedParallelBatch(Iterable> promises) {
    this.promises = promises;
  }

  /**
   * Create a {@link TracedParallelBatch} for list of {@link Promise}s.
   *
   * @param promises an iterable of Promises
   * @param  the type of value produced by each promise
   *
   * @return an instance of {@link TracedParallelBatch}.
   */
  public static  TracedParallelBatch of(Iterable> promises) {
    return new TracedParallelBatch<>(promises);
  }

  /**
   * Create a {@link TracedParallelBatch} for list of {@link Promise}s.
   *
   * @param promises vararg containing a list of {@link Promise}s.
   * @param  the type of value produced by each promise
   *
   * @return an instance of {@link TracedParallelBatch}.
   */
  public static  TracedParallelBatch of(Promise... promises) {
    return new TracedParallelBatch<>(Arrays.asList(promises));
  }

  /**
   * Create a {@link TracedParallelBatch} for list of {@link Promise}s,
   * with the specified trace context.
   *
   * @param context the trace context
   * @param promises an iterable of Promises
   * @param  the type of value produced by each promise
   *
   * @return an instance of {@link ParallelBatch}.
   */
  public static  ParallelBatch of(final TraceContext context, Iterable> promises) {
    return ParallelBatch.of(promises)
        .execInit(execution -> execution.add(RatpackCurrentTraceContext.wrap(context)));
  }

  /**
   * Create a {@link TracedParallelBatch} for list of {@link Promise}s,
   * with the specified trace context.
   *
   * @param context the trace context.
   * @param promises vararg containing a list of {@link Promise}s.
   * @param  the type of value produced by each promise
   *
   * @return an instance of {@link ParallelBatch}.
   */
  public static  ParallelBatch of(final TraceContext context, Promise... promises) {
    return of(context, Arrays.asList(promises));
  }

  /**
   * Set the trace context.
   *
   * @param context the trace context.
   * @return a ParallelBatch
   */
  public ParallelBatch withContext(final TraceContext context) {
    return of(context, promises);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy