/*
 * 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.reactivex.core.eventbus;

import io.vertx.reactivex.RxHelper;
import io.vertx.reactivex.ObservableHelper;
import io.vertx.reactivex.FlowableHelper;
import io.vertx.reactivex.impl.AsyncResultMaybe;
import io.vertx.reactivex.impl.AsyncResultSingle;
import io.vertx.reactivex.impl.AsyncResultCompletable;
import io.vertx.reactivex.WriteStreamObserver;
import io.vertx.reactivex.WriteStreamSubscriber;
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;

An event bus consumer object representing a stream of message to an EventBus address that can be read from.

The EventBus.consumer or EventBus.localConsumer creates a new consumer, the returned consumer is not yet registered against the event bus. Registration is effective after the handler method is invoked.

The consumer is unregistered from the event bus using the unregister method or by calling the handler with a null value..

NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.
/** * An event bus consumer object representing a stream of message to an {@link io.vertx.reactivex.core.eventbus.EventBus} address that can * be read from. * <p> * The {@link io.vertx.reactivex.core.eventbus.EventBus#consumer} or {@link io.vertx.reactivex.core.eventbus.EventBus#localConsumer} * creates a new consumer, the returned consumer is not yet registered against the event bus. Registration * is effective after the {@link io.vertx.reactivex.core.eventbus.MessageConsumer#handler} method is invoked.<p> * * The consumer is unregistered from the event bus using the {@link io.vertx.reactivex.core.eventbus.MessageConsumer#unregister} method or by calling the * {@link io.vertx.reactivex.core.eventbus.MessageConsumer#handler} with a null value.. * * <p/> * NOTE: This class has been automatically generated from the {@link io.vertx.core.eventbus.MessageConsumer original} non RX-ified interface using Vert.x codegen. */
@RxGen(io.vertx.core.eventbus.MessageConsumer.class) public class MessageConsumer<T> implements io.vertx.reactivex.core.streams.ReadStream<io.vertx.reactivex.core.eventbus.Message<T>> { @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; MessageConsumer that = (MessageConsumer) o; return delegate.equals(that.delegate); } @Override public int hashCode() { return delegate.hashCode(); } public static final TypeArg<MessageConsumer> __TYPE_ARG = new TypeArg<>( obj -> new MessageConsumer((io.vertx.core.eventbus.MessageConsumer) obj), MessageConsumer::getDelegate ); private final io.vertx.core.eventbus.MessageConsumer<T> delegate; public final TypeArg<T> __typeArg_0; public MessageConsumer(io.vertx.core.eventbus.MessageConsumer delegate) { this.delegate = delegate; this.__typeArg_0 = TypeArg.unknown(); } public MessageConsumer(Object delegate, TypeArg<T> typeArg_0) { this.delegate = (io.vertx.core.eventbus.MessageConsumer)delegate; this.__typeArg_0 = typeArg_0; } public io.vertx.core.eventbus.MessageConsumer getDelegate() { return delegate; } private io.reactivex.Observable<io.vertx.reactivex.core.eventbus.Message<T>> observable; private io.reactivex.Flowable<io.vertx.reactivex.core.eventbus.Message<T>> flowable; public synchronized io.reactivex.Observable<io.vertx.reactivex.core.eventbus.Message<T>> toObservable() { if (observable == null) { Function<io.vertx.core.eventbus.Message<T>, io.vertx.reactivex.core.eventbus.Message<T>> conv = io.vertx.reactivex.core.eventbus.Message::newInstance; observable = ObservableHelper.toObservable(delegate, conv); } return observable; } public synchronized io.reactivex.Flowable<io.vertx.reactivex.core.eventbus.Message<T>> toFlowable() { if (flowable == null) { Function<io.vertx.core.eventbus.Message<T>, io.vertx.reactivex.core.eventbus.Message<T>> conv = io.vertx.reactivex.core.eventbus.Message::newInstance; flowable = FlowableHelper.toFlowable(delegate, conv); } return flowable; }
Pause this stream and return a to transfer the elements of this stream to a destination .

The stream will be resumed when the pipe will be wired to a WriteStream.
Returns:a pipe
/** * Pause this stream and return a to transfer the elements of this stream to a destination . * <p/> * The stream will be resumed when the pipe will be wired to a <code>WriteStream</code>. * @return a pipe */
public io.vertx.reactivex.core.streams.Pipe<io.vertx.reactivex.core.eventbus.Message<T>> pipe() { io.vertx.reactivex.core.streams.Pipe<io.vertx.reactivex.core.eventbus.Message<T>> ret = io.vertx.reactivex.core.streams.Pipe.newInstance((io.vertx.core.streams.Pipe)delegate.pipe(), new TypeArg<io.vertx.reactivex.core.eventbus.Message<T>>(o0 -> io.vertx.reactivex.core.eventbus.Message.newInstance((io.vertx.core.eventbus.Message)o0, __typeArg_0), o0 -> o0.getDelegate())); return ret; }
Pipe this ReadStream to the WriteStream.

Elements emitted by this stream will be written to the write stream until this stream ends or fails.

Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

Params:
  • dst – the destination write stream
  • handler –
/** * Pipe this <code>ReadStream</code> to the <code>WriteStream</code>. * <p> * Elements emitted by this stream will be written to the write stream until this stream ends or fails. * <p> * Once this stream has ended or failed, the write stream will be ended and the <code>handler</code> will be * called with the result. * @param dst the destination write stream * @param handler */
public void pipeTo(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.eventbus.Message<T>> dst, Handler<AsyncResult<Void>> handler) { delegate.pipeTo(dst.getDelegate(), handler); }
Pipe this ReadStream to the WriteStream.

Elements emitted by this stream will be written to the write stream until this stream ends or fails.

Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

Params:
  • dst – the destination write stream
/** * Pipe this <code>ReadStream</code> to the <code>WriteStream</code>. * <p> * Elements emitted by this stream will be written to the write stream until this stream ends or fails. * <p> * Once this stream has ended or failed, the write stream will be ended and the <code>handler</code> will be * called with the result. * @param dst the destination write stream */
public void pipeTo(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.eventbus.Message<T>> dst) { pipeTo(dst, ar -> { }); }
Pipe this ReadStream to the WriteStream.

Elements emitted by this stream will be written to the write stream until this stream ends or fails.

Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

Params:
  • dst – the destination write stream
Returns:
/** * Pipe this <code>ReadStream</code> to the <code>WriteStream</code>. * <p> * Elements emitted by this stream will be written to the write stream until this stream ends or fails. * <p> * Once this stream has ended or failed, the write stream will be ended and the <code>handler</code> will be * called with the result. * @param dst the destination write stream * @return */
public io.reactivex.Completable rxPipeTo(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.eventbus.Message<T>> dst) { return AsyncResultCompletable.toCompletable($handler -> { pipeTo(dst, $handler); }); } public io.vertx.reactivex.core.eventbus.MessageConsumer<T> exceptionHandler(Handler<java.lang.Throwable> handler) { delegate.exceptionHandler(handler); return this; } public io.vertx.reactivex.core.eventbus.MessageConsumer<T> handler(Handler<io.vertx.reactivex.core.eventbus.Message<T>> handler) { delegate.handler(new Handler<io.vertx.core.eventbus.Message<T>>() { public void handle(io.vertx.core.eventbus.Message<T> event) { handler.handle(io.vertx.reactivex.core.eventbus.Message.newInstance((io.vertx.core.eventbus.Message)event, __typeArg_0)); } }); return this; } public io.vertx.reactivex.core.eventbus.MessageConsumer<T> pause() { delegate.pause(); return this; } public io.vertx.reactivex.core.eventbus.MessageConsumer<T> resume() { delegate.resume(); return this; } public io.vertx.reactivex.core.eventbus.MessageConsumer<T> fetch(long amount) { delegate.fetch(amount); return this; } public io.vertx.reactivex.core.eventbus.MessageConsumer<T> endHandler(Handler<Void> endHandler) { delegate.endHandler(endHandler); return this; }
Returns:a read stream for the body of the message stream.
/** * @return a read stream for the body of the message stream. */
public io.vertx.reactivex.core.streams.ReadStream<T> bodyStream() { io.vertx.reactivex.core.streams.ReadStream<T> ret = io.vertx.reactivex.core.streams.ReadStream.newInstance((io.vertx.core.streams.ReadStream)delegate.bodyStream(), __typeArg_0); return ret; }
Returns:true if the current consumer is registered
/** * @return true if the current consumer is registered */
public boolean isRegistered() { boolean ret = delegate.isRegistered(); return ret; }
Returns:The address the handler was registered with.
/** * @return The address the handler was registered with. */
public String address() { String ret = delegate.address(); return ret; }
Set the number of messages this registration will buffer when this stream is paused. The default value is 1000.

When a new value is set, buffered messages may be discarded to reach the new value. The most recent messages will be kept.

Params:
  • maxBufferedMessages – the maximum number of messages that can be buffered
Returns:this registration
/** * Set the number of messages this registration will buffer when this stream is paused. The default * value is <code>1000</code>. * <p> * When a new value is set, buffered messages may be discarded to reach the new value. The most recent * messages will be kept. * @param maxBufferedMessages the maximum number of messages that can be buffered * @return this registration */
public io.vertx.reactivex.core.eventbus.MessageConsumer<T> setMaxBufferedMessages(int maxBufferedMessages) { io.vertx.reactivex.core.eventbus.MessageConsumer<T> ret = io.vertx.reactivex.core.eventbus.MessageConsumer.newInstance((io.vertx.core.eventbus.MessageConsumer)delegate.setMaxBufferedMessages(maxBufferedMessages), __typeArg_0); return ret; }
Returns:the maximum number of messages that can be buffered when this stream is paused
/** * @return the maximum number of messages that can be buffered when this stream is paused */
public int getMaxBufferedMessages() { int ret = delegate.getMaxBufferedMessages(); return ret; }
Optional method which can be called to indicate when the registration has been propagated across the cluster.
Params:
  • completionHandler – the completion handler
/** * Optional method which can be called to indicate when the registration has been propagated across the cluster. * @param completionHandler the completion handler */
public void completionHandler(Handler<AsyncResult<Void>> completionHandler) { delegate.completionHandler(completionHandler); }
Optional method which can be called to indicate when the registration has been propagated across the cluster.
/** * Optional method which can be called to indicate when the registration has been propagated across the cluster. */
public void completionHandler() { completionHandler(ar -> { }); }
Optional method which can be called to indicate when the registration has been propagated across the cluster.
Returns:
/** * Optional method which can be called to indicate when the registration has been propagated across the cluster. * @return */
public io.reactivex.Completable rxCompletionHandler() { return AsyncResultCompletable.toCompletable($handler -> { completionHandler($handler); }); }
Unregisters the handler which created this registration
Params:
  • completionHandler – the handler called when the unregister is done. For example in a cluster when all nodes of the event bus have been unregistered.
/** * Unregisters the handler which created this registration * @param completionHandler the handler called when the unregister is done. For example in a cluster when all nodes of the event bus have been unregistered. */
public void unregister(Handler<AsyncResult<Void>> completionHandler) { delegate.unregister(completionHandler); }
Unregisters the handler which created this registration
/** * Unregisters the handler which created this registration */
public void unregister() { unregister(ar -> { }); }
Unregisters the handler which created this registration
Returns:
/** * Unregisters the handler which created this registration * @return */
public io.reactivex.Completable rxUnregister() { return AsyncResultCompletable.toCompletable($handler -> { unregister($handler); }); } public static <T> MessageConsumer<T> newInstance(io.vertx.core.eventbus.MessageConsumer arg) { return arg != null ? new MessageConsumer<T>(arg) : null; } public static <T> MessageConsumer<T> newInstance(io.vertx.core.eventbus.MessageConsumer arg, TypeArg<T> __typeArg_T) { return arg != null ? new MessageConsumer<T>(arg, __typeArg_T) : null; } }