/*
 * 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 java.util.Map;
import io.reactivex.Observable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.vertx.core.eventbus.DeliveryOptions;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;

Represents a stream of message that can be written to.

NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.
/** * Represents a stream of message that can be written to. * <p> * * <p/> * NOTE: This class has been automatically generated from the {@link io.vertx.core.eventbus.MessageProducer original} non RX-ified interface using Vert.x codegen. */
@io.vertx.lang.rx.RxGen(io.vertx.core.eventbus.MessageProducer.class) public class MessageProducer<T> implements io.vertx.reactivex.core.streams.WriteStream<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; MessageProducer that = (MessageProducer) o; return delegate.equals(that.delegate); } @Override public int hashCode() { return delegate.hashCode(); } public static final io.vertx.lang.rx.TypeArg<MessageProducer> __TYPE_ARG = new io.vertx.lang.rx.TypeArg<>( obj -> new MessageProducer((io.vertx.core.eventbus.MessageProducer) obj), MessageProducer::getDelegate ); private final io.vertx.core.eventbus.MessageProducer<T> delegate; public final io.vertx.lang.rx.TypeArg<T> __typeArg_0; public MessageProducer(io.vertx.core.eventbus.MessageProducer delegate) { this.delegate = delegate; this.__typeArg_0 = io.vertx.lang.rx.TypeArg.unknown(); } public MessageProducer(io.vertx.core.eventbus.MessageProducer delegate, io.vertx.lang.rx.TypeArg<T> typeArg_0) { this.delegate = delegate; this.__typeArg_0 = typeArg_0; } public io.vertx.core.eventbus.MessageProducer getDelegate() { return delegate; } private io.vertx.reactivex.WriteStreamObserver<T> observer; private io.vertx.reactivex.WriteStreamSubscriber<T> subscriber; public synchronized io.vertx.reactivex.WriteStreamObserver<T> toObserver() { if (observer == null) { java.util.function.Function<T, T> conv = (java.util.function.Function<T, T>) __typeArg_0.unwrap; observer = io.vertx.reactivex.RxHelper.toObserver(getDelegate(), conv); } return observer; } public synchronized io.vertx.reactivex.WriteStreamSubscriber<T> toSubscriber() { if (subscriber == null) { java.util.function.Function<T, T> conv = (java.util.function.Function<T, T>) __typeArg_0.unwrap; subscriber = io.vertx.reactivex.RxHelper.toSubscriber(getDelegate(), conv); } return subscriber; }
Same as end but writes some data to the stream before ending.
Params:
  • data – the data to write
/** * Same as {@link io.vertx.reactivex.core.eventbus.MessageProducer#end} but writes some data to the stream before ending. * @param data the data to write */
public void end(T data) { delegate.end(__typeArg_0.<T>unwrap(data)); }
Same as but with an handler called when the operation completes
Params:
  • data –
  • handler –
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @param handler */
public void end(T data, Handler<AsyncResult<Void>> handler) { delegate.end(__typeArg_0.<T>unwrap(data), handler); }
Same as but with an handler called when the operation completes
Params:
  • data –
Returns:
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @return */
public Completable rxEnd(T data) { return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> { end(data, handler); }); }
This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize
Returns:true if write queue is full
/** * This will return <code>true</code> if there are more bytes in the write queue than the value set using {@link io.vertx.reactivex.core.eventbus.MessageProducer#setWriteQueueMaxSize} * @return true if write queue is full */
public boolean writeQueueFull() { boolean ret = delegate.writeQueueFull(); return ret; }
This method actually sends a message using the send semantic regardless this producer is a sender or a publisher.
Params:
  • message – the message to send
Returns:reference to this for fluency
/** * This method actually sends a message using the send semantic regardless this producer * is a sender or a publisher. * @param message the message to send * @return reference to this for fluency */
@Deprecated() public io.vertx.reactivex.core.eventbus.MessageProducer<T> send(T message) { io.vertx.reactivex.core.eventbus.MessageProducer<T> ret = io.vertx.reactivex.core.eventbus.MessageProducer.newInstance(delegate.send(__typeArg_0.<T>unwrap(message)), __typeArg_0); return ret; }
Like send but specifying a replyHandler that will be called if the recipient subsequently replies to the message.
Params:
  • message – the message to send
  • replyHandler – reply handler will be called when any reply from the recipient is received, may be null
Returns:reference to this for fluency
/** * Like {@link io.vertx.reactivex.core.eventbus.MessageProducer#send} but specifying a <code>replyHandler</code> that will be called if the recipient * subsequently replies to the message. * @param message the message to send * @param replyHandler reply handler will be called when any reply from the recipient is received, may be <code>null</code> * @return reference to this for fluency */
@Deprecated() public <R> io.vertx.reactivex.core.eventbus.MessageProducer<T> send(T message, Handler<AsyncResult<io.vertx.reactivex.core.eventbus.Message<R>>> replyHandler) { io.vertx.reactivex.core.eventbus.MessageProducer<T> ret = io.vertx.reactivex.core.eventbus.MessageProducer.newInstance(delegate.send(__typeArg_0.<T>unwrap(message), new Handler<AsyncResult<io.vertx.core.eventbus.Message<R>>>() { public void handle(AsyncResult<io.vertx.core.eventbus.Message<R>> ar) { if (ar.succeeded()) { replyHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.reactivex.core.eventbus.Message.newInstance(ar.result(), io.vertx.lang.rx.TypeArg.unknown()))); } else { replyHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }), __typeArg_0); return ret; } public io.vertx.reactivex.core.eventbus.MessageProducer<T> exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return this; } public io.vertx.reactivex.core.eventbus.MessageProducer<T> write(T data) { delegate.write(__typeArg_0.<T>unwrap(data)); return this; } public io.vertx.reactivex.core.eventbus.MessageProducer<T> write(T data, Handler<AsyncResult<Void>> handler) { delegate.write(__typeArg_0.<T>unwrap(data), handler); return this; } public Completable rxWrite(T data) { return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> { write(data, handler); }); } public io.vertx.reactivex.core.eventbus.MessageProducer<T> setWriteQueueMaxSize(int maxSize) { delegate.setWriteQueueMaxSize(maxSize); return this; } public io.vertx.reactivex.core.eventbus.MessageProducer<T> drainHandler(Handler<Void> handler) { delegate.drainHandler(handler); return this; }
Update the delivery options of this producer.
Params:
  • options – the new options
Returns:this producer object
/** * Update the delivery options of this producer. * @param options the new options * @return this producer object */
public io.vertx.reactivex.core.eventbus.MessageProducer<T> deliveryOptions(DeliveryOptions options) { delegate.deliveryOptions(options); return this; }
Returns:The address to which the producer produces messages.
/** * @return The address to which the producer produces messages. */
public String address() { String ret = delegate.address(); return ret; }
Closes the producer, calls close
/** * Closes the producer, calls {@link io.vertx.reactivex.core.eventbus.MessageProducer#close} */
public void end() { delegate.end(); }
Closes the producer, calls close
Params:
  • handler –
/** * Closes the producer, calls {@link io.vertx.reactivex.core.eventbus.MessageProducer#close} * @param handler */
public void end(Handler<AsyncResult<Void>> handler) { delegate.end(handler); }
Closes the producer, calls close
Returns:
/** * Closes the producer, calls {@link io.vertx.reactivex.core.eventbus.MessageProducer#close} * @return */
public Completable rxEnd() { return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> { end(handler); }); }
Closes the producer, this method should be called when the message producer is not used anymore.
/** * Closes the producer, this method should be called when the message producer is not used anymore. */
public void close() { delegate.close(); }
Same as close but with an handler called when the operation completes
Params:
  • handler –
/** * Same as {@link io.vertx.reactivex.core.eventbus.MessageProducer#close} but with an <code>handler</code> called when the operation completes * @param handler */
public void close(Handler<AsyncResult<Void>> handler) { delegate.close(handler); }
Same as close but with an handler called when the operation completes
Returns:
/** * Same as {@link io.vertx.reactivex.core.eventbus.MessageProducer#close} but with an <code>handler</code> called when the operation completes * @return */
public Completable rxClose() { return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> { close(handler); }); } public static final int DEFAULT_WRITE_QUEUE_MAX_SIZE = io.vertx.core.eventbus.MessageProducer.DEFAULT_WRITE_QUEUE_MAX_SIZE; public static <T>MessageProducer<T> newInstance(io.vertx.core.eventbus.MessageProducer arg) { return arg != null ? new MessageProducer<T>(arg) : null; } public static <T>MessageProducer<T> newInstance(io.vertx.core.eventbus.MessageProducer arg, io.vertx.lang.rx.TypeArg<T> __typeArg_T) { return arg != null ? new MessageProducer<T>(arg, __typeArg_T) : null; } }