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

io.vertx.rxjava.kafka.client.producer.KafkaProducer Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR2
Show newest version
/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you 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 io.vertx.rxjava.kafka.client.producer;

import rx.Observable;
import rx.Single;
import io.vertx.rx.java.RxHelper;
import io.vertx.rx.java.WriteStreamSubscriber;
import io.vertx.rx.java.SingleOnSubscribeAdapter;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;

/**
 * Vert.x Kafka producer.
 * 

* The provides global control over writing a record. * *

* NOTE: This class has been automatically generated from the {@link io.vertx.kafka.client.producer.KafkaProducer original} non RX-ified interface using Vert.x codegen. */ @RxGen(io.vertx.kafka.client.producer.KafkaProducer.class) public class KafkaProducer implements io.vertx.rxjava.core.streams.WriteStream> { @Override public String toString() { return delegate.toString(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; KafkaProducer that = (KafkaProducer) o; return delegate.equals(that.delegate); } @Override public int hashCode() { return delegate.hashCode(); } public static final TypeArg __TYPE_ARG = new TypeArg<>( obj -> new KafkaProducer((io.vertx.kafka.client.producer.KafkaProducer) obj), KafkaProducer::getDelegate ); private final io.vertx.kafka.client.producer.KafkaProducer delegate; public final TypeArg __typeArg_0; public final TypeArg __typeArg_1; public KafkaProducer(io.vertx.kafka.client.producer.KafkaProducer delegate) { this.delegate = delegate; this.__typeArg_0 = TypeArg.unknown(); this.__typeArg_1 = TypeArg.unknown(); } public KafkaProducer(Object delegate, TypeArg typeArg_0, TypeArg typeArg_1) { this.delegate = (io.vertx.kafka.client.producer.KafkaProducer)delegate; this.__typeArg_0 = typeArg_0; this.__typeArg_1 = typeArg_1; } public io.vertx.kafka.client.producer.KafkaProducer getDelegate() { return delegate; } private WriteStreamSubscriber> subscriber; public synchronized WriteStreamSubscriber> toSubscriber() { if (subscriber == null) { Function> conv = io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord::getDelegate; subscriber = RxHelper.toSubscriber(getDelegate(), conv); } return subscriber; } /** * Ends the stream. *

* Once the stream has ended, it cannot be used any more. */ public void end() { delegate.end(); } /** * Same as {@link io.vertx.rxjava.core.streams.WriteStream#end} but with an handler called when the operation completes * @param handler */ public void end(Handler> handler) { delegate.end(handler); } /** * Same as {@link io.vertx.rxjava.core.streams.WriteStream#end} but with an handler called when the operation completes * @return */ public Single rxEnd() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { end(fut); })); } /** * Same as {@link io.vertx.rxjava.core.streams.WriteStream#end} but writes some data to the stream before ending. * @param data the data to write */ public void end(io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord data) { delegate.end(data.getDelegate()); } /** * Same as but with an handler called when the operation completes * @param data * @param handler */ public void end(io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord data, Handler> handler) { delegate.end(data.getDelegate(), handler); } /** * Same as but with an handler called when the operation completes * @param data * @return */ public Single rxEnd(io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord data) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { end(data, fut); })); } /** * Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same name * @param vertx Vert.x instance to use * @param name the producer name to identify it * @param config Kafka producer configuration * @return an instance of the KafkaProducer */ public static io.vertx.rxjava.kafka.client.producer.KafkaProducer createShared(io.vertx.rxjava.core.Vertx vertx, String name, java.util.Map config) { io.vertx.rxjava.kafka.client.producer.KafkaProducer ret = io.vertx.rxjava.kafka.client.producer.KafkaProducer.newInstance((io.vertx.kafka.client.producer.KafkaProducer)io.vertx.kafka.client.producer.KafkaProducer.createShared(vertx.getDelegate(), name, config), TypeArg.unknown(), TypeArg.unknown()); return ret; } /** * Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same name * @param vertx Vert.x instance to use * @param name the producer name to identify it * @param config Kafka producer configuration * @param keyType class type for the key serialization * @param valueType class type for the value serialization * @return an instance of the KafkaProducer */ public static io.vertx.rxjava.kafka.client.producer.KafkaProducer createShared(io.vertx.rxjava.core.Vertx vertx, String name, java.util.Map config, java.lang.Class keyType, java.lang.Class valueType) { io.vertx.rxjava.kafka.client.producer.KafkaProducer ret = io.vertx.rxjava.kafka.client.producer.KafkaProducer.newInstance((io.vertx.kafka.client.producer.KafkaProducer)io.vertx.kafka.client.producer.KafkaProducer.createShared(vertx.getDelegate(), name, config, io.vertx.lang.rxjava.Helper.unwrap(keyType), io.vertx.lang.rxjava.Helper.unwrap(valueType)), TypeArg.of(keyType), TypeArg.of(valueType)); return ret; } /** * Create a new KafkaProducer instance * @param vertx Vert.x instance to use * @param config Kafka producer configuration * @return an instance of the KafkaProducer */ public static io.vertx.rxjava.kafka.client.producer.KafkaProducer create(io.vertx.rxjava.core.Vertx vertx, java.util.Map config) { io.vertx.rxjava.kafka.client.producer.KafkaProducer ret = io.vertx.rxjava.kafka.client.producer.KafkaProducer.newInstance((io.vertx.kafka.client.producer.KafkaProducer)io.vertx.kafka.client.producer.KafkaProducer.create(vertx.getDelegate(), config), TypeArg.unknown(), TypeArg.unknown()); return ret; } /** * Create a new KafkaProducer instance * @param vertx Vert.x instance to use * @param config Kafka producer configuration * @param keyType class type for the key serialization * @param valueType class type for the value serialization * @return an instance of the KafkaProducer */ public static io.vertx.rxjava.kafka.client.producer.KafkaProducer create(io.vertx.rxjava.core.Vertx vertx, java.util.Map config, java.lang.Class keyType, java.lang.Class valueType) { io.vertx.rxjava.kafka.client.producer.KafkaProducer ret = io.vertx.rxjava.kafka.client.producer.KafkaProducer.newInstance((io.vertx.kafka.client.producer.KafkaProducer)io.vertx.kafka.client.producer.KafkaProducer.create(vertx.getDelegate(), config, io.vertx.lang.rxjava.Helper.unwrap(keyType), io.vertx.lang.rxjava.Helper.unwrap(valueType)), TypeArg.of(keyType), TypeArg.of(valueType)); return ret; } public io.vertx.rxjava.kafka.client.producer.KafkaProducer exceptionHandler(Handler handler) { delegate.exceptionHandler(handler); return this; } public io.vertx.rxjava.kafka.client.producer.KafkaProducer write(io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord kafkaProducerRecord) { delegate.write(kafkaProducerRecord.getDelegate()); return this; } public io.vertx.rxjava.kafka.client.producer.KafkaProducer setWriteQueueMaxSize(int i) { delegate.setWriteQueueMaxSize(i); return this; } public boolean writeQueueFull() { boolean ret = delegate.writeQueueFull(); return ret; } public io.vertx.rxjava.kafka.client.producer.KafkaProducer drainHandler(Handler handler) { delegate.drainHandler(handler); return this; } public io.vertx.rxjava.kafka.client.producer.KafkaProducer write(io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord data, Handler> handler) { delegate.write(data.getDelegate(), handler); return this; } public Single rxWrite(io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord data) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { write(data, fut); })); } /** * Asynchronously write a record to a topic * @param record record to write * @return current KafkaWriteStream instance */ public io.vertx.rxjava.kafka.client.producer.KafkaProducer send(io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord record) { delegate.send(record.getDelegate()); return this; } /** * Asynchronously write a record to a topic * @param record record to write * @param handler handler called on operation completed * @return current KafkaWriteStream instance */ public io.vertx.rxjava.kafka.client.producer.KafkaProducer send(io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord record, Handler> handler) { delegate.send(record.getDelegate(), handler); return this; } /** * Asynchronously write a record to a topic * @param record record to write * @return current KafkaWriteStream instance */ public Single rxSend(io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord record) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { send(record, fut); })); } /** * Get the partition metadata for the give topic. * @param topic topic partition for which getting partitions info * @param handler handler called on operation completed * @return current KafkaProducer instance */ public io.vertx.rxjava.kafka.client.producer.KafkaProducer partitionsFor(String topic, Handler>> handler) { delegate.partitionsFor(topic, handler); return this; } /** * Get the partition metadata for the give topic. * @param topic topic partition for which getting partitions info * @return current KafkaProducer instance */ public Single> rxPartitionsFor(String topic) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { partitionsFor(topic, fut); })); } /** * Invoking this method makes all buffered records immediately available to write * @param completionHandler handler called on operation completed * @return current KafkaProducer instance */ public io.vertx.rxjava.kafka.client.producer.KafkaProducer flush(Handler completionHandler) { delegate.flush(completionHandler); return this; } /** * Close the producer */ public void close() { delegate.close(); } /** * Close the producer * @param completionHandler handler called on operation completed */ public void close(Handler> completionHandler) { delegate.close(completionHandler); } /** * Close the producer * @return */ public Single rxClose() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { close(fut); })); } /** * Close the producer * @param timeout timeout to wait for closing * @param completionHandler handler called on operation completed */ public void close(long timeout, Handler> completionHandler) { delegate.close(timeout, completionHandler); } /** * Close the producer * @param timeout timeout to wait for closing * @return */ public Single rxClose(long timeout) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { close(timeout, fut); })); } public static KafkaProducer newInstance(io.vertx.kafka.client.producer.KafkaProducer arg) { return arg != null ? new KafkaProducer(arg) : null; } public static KafkaProducer newInstance(io.vertx.kafka.client.producer.KafkaProducer arg, TypeArg __typeArg_K, TypeArg __typeArg_V) { return arg != null ? new KafkaProducer(arg, __typeArg_K, __typeArg_V) : null; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy