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

io.vertx.rxjava.core.eventbus.MessageConsumer Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR1
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.core.eventbus;

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;

/**
 * An event bus consumer object representing a stream of message to an {@link io.vertx.rxjava.core.eventbus.EventBus} address that can
 * be read from.
 * 

* The {@link io.vertx.rxjava.core.eventbus.EventBus#consumer} or {@link io.vertx.rxjava.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.rxjava.core.eventbus.MessageConsumer#handler} method is invoked.

* * The consumer is unregistered from the event bus using the {@link io.vertx.rxjava.core.eventbus.MessageConsumer#unregister} method or by calling the * {@link io.vertx.rxjava.core.eventbus.MessageConsumer#handler} with a null value.. * *

* 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 implements io.vertx.rxjava.core.streams.ReadStream> { @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 __TYPE_ARG = new TypeArg<>( obj -> new MessageConsumer((io.vertx.core.eventbus.MessageConsumer) obj), MessageConsumer::getDelegate ); private final io.vertx.core.eventbus.MessageConsumer delegate; public final TypeArg __typeArg_0; public MessageConsumer(io.vertx.core.eventbus.MessageConsumer delegate) { this.delegate = delegate; this.__typeArg_0 = TypeArg.unknown(); } public MessageConsumer(Object delegate, TypeArg 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 Observable> observable; public synchronized Observable> toObservable() { if (observable == null) { Function, io.vertx.rxjava.core.eventbus.Message> conv = io.vertx.rxjava.core.eventbus.Message::newInstance; observable = RxHelper.toObservable(delegate, conv); } return observable; } /** * 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. * @return a pipe */ public io.vertx.rxjava.core.streams.Pipe> pipe() { io.vertx.rxjava.core.streams.Pipe> ret = io.vertx.rxjava.core.streams.Pipe.newInstance((io.vertx.core.streams.Pipe)delegate.pipe(), new TypeArg>(o0 -> io.vertx.rxjava.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. * @param dst the destination write stream * @param handler */ public void pipeTo(io.vertx.rxjava.core.streams.WriteStream> dst, Handler> 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. * @param dst the destination write stream */ public void pipeTo(io.vertx.rxjava.core.streams.WriteStream> 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. * @param dst the destination write stream * @return */ public Single rxPipeTo(io.vertx.rxjava.core.streams.WriteStream> dst) { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { pipeTo(dst, fut); })); } public io.vertx.rxjava.core.eventbus.MessageConsumer exceptionHandler(Handler handler) { delegate.exceptionHandler(handler); return this; } public io.vertx.rxjava.core.eventbus.MessageConsumer handler(Handler> handler) { delegate.handler(new Handler>() { public void handle(io.vertx.core.eventbus.Message event) { handler.handle(io.vertx.rxjava.core.eventbus.Message.newInstance((io.vertx.core.eventbus.Message)event, __typeArg_0)); } }); return this; } public io.vertx.rxjava.core.eventbus.MessageConsumer pause() { delegate.pause(); return this; } public io.vertx.rxjava.core.eventbus.MessageConsumer resume() { delegate.resume(); return this; } public io.vertx.rxjava.core.eventbus.MessageConsumer fetch(long amount) { delegate.fetch(amount); return this; } public io.vertx.rxjava.core.eventbus.MessageConsumer endHandler(Handler endHandler) { delegate.endHandler(endHandler); return this; } /** * @return a read stream for the body of the message stream. */ public io.vertx.rxjava.core.streams.ReadStream bodyStream() { io.vertx.rxjava.core.streams.ReadStream ret = io.vertx.rxjava.core.streams.ReadStream.newInstance((io.vertx.core.streams.ReadStream)delegate.bodyStream(), __typeArg_0); return ret; } /** * @return true if the current consumer is registered */ public boolean isRegistered() { boolean ret = delegate.isRegistered(); return ret; } /** * @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. * @param maxBufferedMessages the maximum number of messages that can be buffered * @return this registration */ public io.vertx.rxjava.core.eventbus.MessageConsumer setMaxBufferedMessages(int maxBufferedMessages) { io.vertx.rxjava.core.eventbus.MessageConsumer ret = io.vertx.rxjava.core.eventbus.MessageConsumer.newInstance((io.vertx.core.eventbus.MessageConsumer)delegate.setMaxBufferedMessages(maxBufferedMessages), __typeArg_0); return ret; } /** * @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. * @param completionHandler the completion handler */ public void completionHandler(Handler> completionHandler) { delegate.completionHandler(completionHandler); } /** * 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. * @return */ public Single rxCompletionHandler() { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { completionHandler(fut); })); } /** * 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> completionHandler) { delegate.unregister(completionHandler); } /** * Unregisters the handler which created this registration */ public void unregister() { unregister(ar -> { }); } /** * Unregisters the handler which created this registration * @return */ public Single rxUnregister() { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { unregister(fut); })); } public static MessageConsumer newInstance(io.vertx.core.eventbus.MessageConsumer arg) { return arg != null ? new MessageConsumer(arg) : null; } public static MessageConsumer newInstance(io.vertx.core.eventbus.MessageConsumer arg, TypeArg __typeArg_T) { return arg != null ? new MessageConsumer(arg, __typeArg_T) : null; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy