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

zipkin2.dependencies.cassandra3.CassandraRowsToDependencyLinks Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
/*
 * Copyright The OpenZipkin Authors
 * SPDX-License-Identifier: Apache-2.0
 */
package zipkin2.dependencies.cassandra3;

import com.datastax.spark.connector.japi.CassandraRow;
import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.annotation.Nullable;
import org.apache.spark.api.java.function.FlatMapFunction;
import zipkin2.DependencyLink;
import zipkin2.Span;

final class CassandraRowsToDependencyLinks
  implements Serializable, FlatMapFunction, DependencyLink> {
  private static final long serialVersionUID = 0L;

  @Nullable final Runnable logInitializer;
  final SpansToDependencyLinks spansToDependencyLinks;

  CassandraRowsToDependencyLinks(@Nullable Runnable logInitializer, long startTs, long endTs) {
    this.logInitializer = logInitializer;
    this.spansToDependencyLinks = new SpansToDependencyLinks(logInitializer, startTs, endTs);
  }

  @Override public Iterator call(Iterable rows) {
    if (logInitializer != null) logInitializer.run();
    // use a hash set to dedupe any redundantly accepted spans
    Set sameTraceId = new LinkedHashSet<>();
    for (CassandraRow row : rows) {
      Span span = CassandraRowToSpan.INSTANCE.call(row);
      sameTraceId.add(span);
    }

    return spansToDependencyLinks.call(sameTraceId);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy