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

co.decodable.sdk.pipeline.internal.DecodableStreamSinkImpl Maven / Gradle / Ivy

Go to download

A software development kit for implementing Apache Flink jobs and running them on Decodable

There is a newer version: 1.0.0.Beta7
Show newest version
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * Copyright Decodable, Inc.
 *
 * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
 */
package co.decodable.sdk.pipeline.internal;

import co.decodable.sdk.pipeline.DecodableStreamSink;
import co.decodable.sdk.pipeline.DecodableWriter;
import java.io.IOException;
import java.util.Collection;
import org.apache.flink.api.connector.sink2.Committer;
import org.apache.flink.api.connector.sink2.StatefulSink;
import org.apache.flink.api.connector.sink2.TwoPhaseCommittingSink;
import org.apache.flink.connector.kafka.sink.KafkaSink;
import org.apache.flink.core.io.SimpleVersionedSerializer;

@SuppressWarnings({"rawtypes", "unchecked"})
public class DecodableStreamSinkImpl implements DecodableStreamSink {

  private static final long serialVersionUID = 3654512984006560177L;

  // Can't use KafkaSink, as it exposes non-public types in its signatures
  private final StatefulSink delegate;

  public DecodableStreamSinkImpl(KafkaSink delegate) {
    this.delegate = delegate;
  }

  @Override
  public DecodableWriter createWriter(InitContext context) throws IOException {
    return new DelegatingStatefulSinkWriter(delegate.createWriter(context));
  }

  @Override
  public StatefulSinkWriter restoreWriter(
      InitContext context, Collection recoveredState) throws IOException {

    return delegate.restoreWriter(context, recoveredState);
  }

  @Override
  public SimpleVersionedSerializer getWriterStateSerializer() {
    return delegate.getWriterStateSerializer();
  }

  @Override
  public Committer createCommitter() throws IOException {
    return ((TwoPhaseCommittingSink) delegate).createCommitter();
  }

  @Override
  public SimpleVersionedSerializer getCommittableSerializer() {
    return ((TwoPhaseCommittingSink) delegate).getCommittableSerializer();
  }
}