io.vertx.rxjava.core.eventbus.EventBus Maven / Gradle / Ivy
/*
 * 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;
/**
 * A Vert.x event-bus is a light-weight distributed messaging system which allows different parts of your application,
 * or different applications and services to communicate with each in a loosely coupled way.
 * 
 * An event-bus supports publish-subscribe messaging, point-to-point messaging and request-response messaging.
 * 
 * Message delivery is best-effort and messages can be lost if failure of all or part of the event bus occurs.
 * 
 * Please refer to the documentation for more information on the event bus.
 *
 * 
 * NOTE: This class has been automatically generated from the {@link io.vertx.core.eventbus.EventBus original} non RX-ified interface using Vert.x codegen.
 */
@RxGen(io.vertx.core.eventbus.EventBus.class)
public class EventBus implements io.vertx.rxjava.core.metrics.Measured {
  @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;
    EventBus that = (EventBus) o;
    return delegate.equals(that.delegate);
  }
  
  @Override
  public int hashCode() {
    return delegate.hashCode();
  }
  public static final TypeArg __TYPE_ARG = new TypeArg<>(    obj -> new EventBus((io.vertx.core.eventbus.EventBus) obj),
    EventBus::getDelegate
  );
  private final io.vertx.core.eventbus.EventBus delegate;
  
  public EventBus(io.vertx.core.eventbus.EventBus delegate) {
    this.delegate = delegate;
  }
  public EventBus(Object delegate) {
    this.delegate = (io.vertx.core.eventbus.EventBus)delegate;
  }
  public io.vertx.core.eventbus.EventBus getDelegate() {
    return delegate;
  }
  /**
   * Whether the metrics are enabled for this measured object
   * @return true if metrics are enabled
   */
  public boolean isMetricsEnabled() { 
    boolean ret = delegate.isMetricsEnabled();
    return ret;
  }
  /**
   * Sends a message.
   * 
   * The message will be delivered to at most one of the handlers registered to the address.
   * @param address the address to send it to
   * @param message the message, may be null
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.core.eventbus.EventBus send(java.lang.String address, java.lang.Object message) { 
    delegate.send(address, message);
    return this;
  }
  /**
   * Like  but specifying options that can be used to configure the delivery.
   * @param address the address to send it to
   * @param message the message, may be null
   * @param options delivery options
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.core.eventbus.EventBus send(java.lang.String address, java.lang.Object message, io.vertx.core.eventbus.DeliveryOptions options) { 
    delegate.send(address, message, options);
    return this;
  }
  /**
   * Sends a message and specify a replyHandler that will be called if the recipient
   * subsequently replies to the message.
   * 
   * The message will be delivered to at most one of the handlers registered to the address.
   * @param address the address to send it to
   * @param message the message body, may be null
   * @param replyHandler reply handler will be called when any reply from the recipient is received
   * @return a reference to this, so the API can be used fluently
   */
  public  io.vertx.rxjava.core.eventbus.EventBus request(java.lang.String address, java.lang.Object message, io.vertx.core.Handler>> replyHandler) { 
    delegate.request(address, message, new Handler>>() {
      public void handle(AsyncResult> ar) {
        if (ar.succeeded()) {
          replyHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.eventbus.Message.newInstance((io.vertx.core.eventbus.Message)ar.result(), TypeArg.unknown())));
        } else {
          replyHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
    return this;
  }
  /**
   * Sends a message and specify a replyHandler that will be called if the recipient
   * subsequently replies to the message.
   * 
   * The message will be delivered to at most one of the handlers registered to the address.
   * @param address the address to send it to
   * @param message the message body, may be null
   * @return a reference to this, so the API can be used fluently
   */
  public  io.vertx.rxjava.core.eventbus.EventBus request(java.lang.String address, java.lang.Object message) {
    return 
request(address, message, ar -> { });
  }
    /**
   * Sends a message and specify a replyHandler that will be called if the recipient
   * subsequently replies to the message.
   * 
   * The message will be delivered to at most one of the handlers registered to the address.
   * @param address the address to send it to
   * @param message the message body, may be null
   * @return a reference to this, so the API can be used fluently
   */
  public  rx.Single> rxRequest(java.lang.String address, java.lang.Object message) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      request(address, message, fut);
    }));
  }
  /**
   * Like  but specifying options that can be used to configure the delivery.
   * @param address the address to send it to
   * @param message the message body, may be null
   * @param options delivery options
   * @param replyHandler reply handler will be called when any reply from the recipient is received
   * @return a reference to this, so the API can be used fluently
   */
  public  io.vertx.rxjava.core.eventbus.EventBus request(java.lang.String address, java.lang.Object message, io.vertx.core.eventbus.DeliveryOptions options, io.vertx.core.Handler>> replyHandler) { 
    delegate.request(address, message, options, new Handler>>() {
      public void handle(AsyncResult> ar) {
        if (ar.succeeded()) {
          replyHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.eventbus.Message.newInstance((io.vertx.core.eventbus.Message)ar.result(), TypeArg.unknown())));
        } else {
          replyHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
    return this;
  }
  /**
   * Like  but specifying options that can be used to configure the delivery.
   * @param address the address to send it to
   * @param message the message body, may be null
   * @param options delivery options
   * @return a reference to this, so the API can be used fluently
   */
  public  io.vertx.rxjava.core.eventbus.EventBus request(java.lang.String address, java.lang.Object message, io.vertx.core.eventbus.DeliveryOptions options) {
    return 
request(address, message, options, ar -> { });
  }
    /**
   * Like  but specifying options that can be used to configure the delivery.
   * @param address the address to send it to
   * @param message the message body, may be null
   * @param options delivery options
   * @return a reference to this, so the API can be used fluently
   */
  public  rx.Single> rxRequest(java.lang.String address, java.lang.Object message, io.vertx.core.eventbus.DeliveryOptions options) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      request(address, message, options, fut);
    }));
  }
  /**
   * Publish a message.
   * The message will be delivered to all handlers registered to the address.
   * @param address the address to publish it to
   * @param message the message, may be null
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.core.eventbus.EventBus publish(java.lang.String address, java.lang.Object message) { 
    delegate.publish(address, message);
    return this;
  }
  /**
   * Like  but specifying options that can be used to configure the delivery.
   * @param address the address to publish it to
   * @param message the message, may be null
   * @param options the delivery options
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.core.eventbus.EventBus publish(java.lang.String address, java.lang.Object message, io.vertx.core.eventbus.DeliveryOptions options) { 
    delegate.publish(address, message, options);
    return this;
  }
  /**
   * Create a message consumer against the specified address.
   * 
   * The returned consumer is not yet registered
   * at the address, registration will be effective when {@link io.vertx.rxjava.core.eventbus.MessageConsumer#handler}
   * is called.
   * @param address the address that it will register it at
   * @return the event bus message consumer
   */
  public  io.vertx.rxjava.core.eventbus.MessageConsumer consumer(java.lang.String address) { 
    io.vertx.rxjava.core.eventbus.MessageConsumer ret = io.vertx.rxjava.core.eventbus.MessageConsumer.newInstance((io.vertx.core.eventbus.MessageConsumer)delegate.consumer(address), TypeArg.unknown());
    return ret;
  }
  /**
   * Create a consumer and register it against the specified address.
   * @param address the address that will register it at
   * @param handler the handler that will process the received messages
   * @return the event bus message consumer
   */
  public  io.vertx.rxjava.core.eventbus.MessageConsumer consumer(java.lang.String address, io.vertx.core.Handler> handler) { 
    io.vertx.rxjava.core.eventbus.MessageConsumer ret = io.vertx.rxjava.core.eventbus.MessageConsumer.newInstance((io.vertx.core.eventbus.MessageConsumer)delegate.consumer(address, 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.unknown()));
      }
    }), TypeArg.unknown());
    return ret;
  }
  /**
   * Like {@link io.vertx.rxjava.core.eventbus.EventBus#consumer} but the address won't be propagated across the cluster.
   * @param address the address to register it at
   * @return the event bus message consumer
   */
  public  io.vertx.rxjava.core.eventbus.MessageConsumer localConsumer(java.lang.String address) { 
    io.vertx.rxjava.core.eventbus.MessageConsumer ret = io.vertx.rxjava.core.eventbus.MessageConsumer.newInstance((io.vertx.core.eventbus.MessageConsumer)delegate.localConsumer(address), TypeArg.unknown());
    return ret;
  }
  /**
   * Like {@link io.vertx.rxjava.core.eventbus.EventBus#consumer} but the address won't be propagated across the cluster.
   * @param address the address that will register it at
   * @param handler the handler that will process the received messages
   * @return the event bus message consumer
   */
  public  io.vertx.rxjava.core.eventbus.MessageConsumer localConsumer(java.lang.String address, io.vertx.core.Handler> handler) { 
    io.vertx.rxjava.core.eventbus.MessageConsumer ret = io.vertx.rxjava.core.eventbus.MessageConsumer.newInstance((io.vertx.core.eventbus.MessageConsumer)delegate.localConsumer(address, 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.unknown()));
      }
    }), TypeArg.unknown());
    return ret;
  }
  /**
   * Create a message sender against the specified address.
   * 
   * The returned sender will invoke the 
   * method when the stream {@link io.vertx.rxjava.core.streams.WriteStream#write} method is called with the sender
   * address and the provided data.
   * @param address the address to send it to
   * @return The sender
   */
  public  io.vertx.rxjava.core.eventbus.MessageProducer sender(java.lang.String address) { 
    io.vertx.rxjava.core.eventbus.MessageProducer ret = io.vertx.rxjava.core.eventbus.MessageProducer.newInstance((io.vertx.core.eventbus.MessageProducer)delegate.sender(address), TypeArg.unknown());
    return ret;
  }
  /**
   * Like {@link io.vertx.rxjava.core.eventbus.EventBus#sender} but specifying delivery options that will be used for configuring the delivery of
   * the message.
   * @param address the address to send it to
   * @param options the delivery options
   * @return The sender
   */
  public  io.vertx.rxjava.core.eventbus.MessageProducer sender(java.lang.String address, io.vertx.core.eventbus.DeliveryOptions options) { 
    io.vertx.rxjava.core.eventbus.MessageProducer ret = io.vertx.rxjava.core.eventbus.MessageProducer.newInstance((io.vertx.core.eventbus.MessageProducer)delegate.sender(address, options), TypeArg.unknown());
    return ret;
  }
  /**
   * Create a message publisher against the specified address.
   * 
   * The returned publisher will invoke the 
   * method when the stream {@link io.vertx.rxjava.core.streams.WriteStream#write} method is called with the publisher
   * address and the provided data.
   * @param address The address to publish it to
   * @return The publisher
   */
  public  io.vertx.rxjava.core.eventbus.MessageProducer publisher(java.lang.String address) { 
    io.vertx.rxjava.core.eventbus.MessageProducer ret = io.vertx.rxjava.core.eventbus.MessageProducer.newInstance((io.vertx.core.eventbus.MessageProducer)delegate.publisher(address), TypeArg.unknown());
    return ret;
  }
  /**
   * Like {@link io.vertx.rxjava.core.eventbus.EventBus#publisher} but specifying delivery options that will be used for configuring the delivery of
   * the message.
   * @param address the address to publish it to
   * @param options the delivery options
   * @return The publisher
   */
  public  io.vertx.rxjava.core.eventbus.MessageProducer publisher(java.lang.String address, io.vertx.core.eventbus.DeliveryOptions options) { 
    io.vertx.rxjava.core.eventbus.MessageProducer ret = io.vertx.rxjava.core.eventbus.MessageProducer.newInstance((io.vertx.core.eventbus.MessageProducer)delegate.publisher(address, options), TypeArg.unknown());
    return ret;
  }
  /**
   * Add an interceptor that will be called whenever a message is sent from Vert.x
   * @param interceptor the interceptor
   * @return a reference to this, so the API can be used fluently
   */
  public  io.vertx.rxjava.core.eventbus.EventBus addOutboundInterceptor(io.vertx.core.Handler> interceptor) { 
    delegate.addOutboundInterceptor(new Handler>() {
      public void handle(io.vertx.core.eventbus.DeliveryContext event) {
        interceptor.handle(io.vertx.rxjava.core.eventbus.DeliveryContext.newInstance((io.vertx.core.eventbus.DeliveryContext)event, TypeArg.unknown()));
      }
    });
    return this;
  }
  /**
   * Remove an interceptor that was added by {@link io.vertx.rxjava.core.eventbus.EventBus#addOutboundInterceptor}
   * @param interceptor the interceptor
   * @return a reference to this, so the API can be used fluently
   */
  public  io.vertx.rxjava.core.eventbus.EventBus removeOutboundInterceptor(io.vertx.core.Handler> interceptor) { 
    delegate.removeOutboundInterceptor(new Handler>() {
      public void handle(io.vertx.core.eventbus.DeliveryContext event) {
        interceptor.handle(io.vertx.rxjava.core.eventbus.DeliveryContext.newInstance((io.vertx.core.eventbus.DeliveryContext)event, TypeArg.unknown()));
      }
    });
    return this;
  }
  /**
   * Add an interceptor that will be called whenever a message is received by Vert.x
   * @param interceptor the interceptor
   * @return a reference to this, so the API can be used fluently
   */
  public  io.vertx.rxjava.core.eventbus.EventBus addInboundInterceptor(io.vertx.core.Handler> interceptor) { 
    delegate.addInboundInterceptor(new Handler>() {
      public void handle(io.vertx.core.eventbus.DeliveryContext event) {
        interceptor.handle(io.vertx.rxjava.core.eventbus.DeliveryContext.newInstance((io.vertx.core.eventbus.DeliveryContext)event, TypeArg.unknown()));
      }
    });
    return this;
  }
  /**
   * Remove an interceptor that was added by {@link io.vertx.rxjava.core.eventbus.EventBus#addInboundInterceptor}
   * @param interceptor the interceptor
   * @return a reference to this, so the API can be used fluently
   */
  public  io.vertx.rxjava.core.eventbus.EventBus removeInboundInterceptor(io.vertx.core.Handler> interceptor) { 
    delegate.removeInboundInterceptor(new Handler>() {
      public void handle(io.vertx.core.eventbus.DeliveryContext event) {
        interceptor.handle(io.vertx.rxjava.core.eventbus.DeliveryContext.newInstance((io.vertx.core.eventbus.DeliveryContext)event, TypeArg.unknown()));
      }
    });
    return this;
  }
  /**
   * Register a message codec.
   * 
   * You can register a message codec if you want to send any non standard message across the event bus.
   * E.g. you might want to send POJOs directly across the event bus.
   * 
   * To use a message codec for a send, you should specify it in the delivery options.
   * @param codec the message codec to register
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.core.eventbus.EventBus registerCodec(io.vertx.core.eventbus.MessageCodec codec) { 
    io.vertx.rxjava.core.eventbus.EventBus ret = io.vertx.rxjava.core.eventbus.EventBus.newInstance((io.vertx.core.eventbus.EventBus)delegate.registerCodec(codec));
    return ret;
  }
  /**
   * Unregister a message codec.
   * 
   * @param name the name of the codec
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.core.eventbus.EventBus unregisterCodec(java.lang.String name) { 
    io.vertx.rxjava.core.eventbus.EventBus ret = io.vertx.rxjava.core.eventbus.EventBus.newInstance((io.vertx.core.eventbus.EventBus)delegate.unregisterCodec(name));
    return ret;
  }
  public static EventBus newInstance(io.vertx.core.eventbus.EventBus arg) {
    return arg != null ? new EventBus(arg) : null;
  }
}