io.vertx.rxjava.mqtt.MqttServer 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.mqtt;
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 MQTT server
 * 
 *    You can accept incoming MQTT connection requests providing a {@link io.vertx.rxjava.mqtt.MqttServer#endpointHandler}. As the
 *    requests arrive, the handler will be called with an instance of {@link io.vertx.rxjava.mqtt.MqttEndpoint} in order to manage the
 *    communication with the remote MQTT client.
 * 
 *
 * 
 * NOTE: This class has been automatically generated from the {@link io.vertx.mqtt.MqttServer original} non RX-ified interface using Vert.x codegen.
 */
@RxGen(io.vertx.mqtt.MqttServer.class)
public class MqttServer {
  @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;
    MqttServer that = (MqttServer) o;
    return delegate.equals(that.delegate);
  }
  
  @Override
  public int hashCode() {
    return delegate.hashCode();
  }
  public static final TypeArg __TYPE_ARG = new TypeArg<>(    obj -> new MqttServer((io.vertx.mqtt.MqttServer) obj),
    MqttServer::getDelegate
  );
  private final io.vertx.mqtt.MqttServer delegate;
  
  public MqttServer(io.vertx.mqtt.MqttServer delegate) {
    this.delegate = delegate;
  }
  public MqttServer(Object delegate) {
    this.delegate = (io.vertx.mqtt.MqttServer)delegate;
  }
  public io.vertx.mqtt.MqttServer getDelegate() {
    return delegate;
  }
  /**
   * Return an MQTT server instance
   * @param vertx Vert.x instance
   * @param options MQTT server options
   * @return MQTT server instance
   */
  public static io.vertx.rxjava.mqtt.MqttServer create(io.vertx.rxjava.core.Vertx vertx, io.vertx.mqtt.MqttServerOptions options) { 
    io.vertx.rxjava.mqtt.MqttServer ret = io.vertx.rxjava.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)io.vertx.mqtt.MqttServer.create(vertx.getDelegate(), options));
    return ret;
  }
  /**
   * Return an MQTT server instance using default options
   * @param vertx Vert.x instance
   * @return MQTT server instance
   */
  public static io.vertx.rxjava.mqtt.MqttServer create(io.vertx.rxjava.core.Vertx vertx) { 
    io.vertx.rxjava.mqtt.MqttServer ret = io.vertx.rxjava.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)io.vertx.mqtt.MqttServer.create(vertx.getDelegate()));
    return ret;
  }
  /**
   * Start the server listening for incoming connections on the port and host specified
   * It ignores any options specified through the constructor
   * @param port the port to listen on
   * @param host the host to listen on
   * @param listenHandler handler called when the asynchronous listen call ends
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.mqtt.MqttServer listen(int port, java.lang.String host, io.vertx.core.Handler> listenHandler) { 
    delegate.listen(port, host, new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          listenHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)ar.result())));
        } else {
          listenHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
    return this;
  }
  /**
   * Start the server listening for incoming connections on the port and host specified
   * It ignores any options specified through the constructor
   * @param port the port to listen on
   * @param host the host to listen on
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.mqtt.MqttServer listen(int port, java.lang.String host) {
    return 
listen(port, host, ar -> { });
  }
    /**
   * Start the server listening for incoming connections on the port and host specified
   * It ignores any options specified through the constructor
   * @param port the port to listen on
   * @param host the host to listen on
   * @return a reference to this, so the API can be used fluently
   */
  public rx.Single rxListen(int port, java.lang.String host) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      listen(port, host, fut);
    }));
  }
  /**
   * Start the server listening for incoming connections on the port specified but on
   * "0.0.0.0" as host. It ignores any options specified through the constructor
   * @param port the port to listen on
   * @param listenHandler handler called when the asynchronous listen call ends
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.mqtt.MqttServer listen(int port, io.vertx.core.Handler> listenHandler) { 
    delegate.listen(port, new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          listenHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)ar.result())));
        } else {
          listenHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
    return this;
  }
  /**
   * Start the server listening for incoming connections on the port specified but on
   * "0.0.0.0" as host. It ignores any options specified through the constructor
   * @param port the port to listen on
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.mqtt.MqttServer listen(int port) {
    return 
listen(port, ar -> { });
  }
    /**
   * Start the server listening for incoming connections on the port specified but on
   * "0.0.0.0" as host. It ignores any options specified through the constructor
   * @param port the port to listen on
   * @return a reference to this, so the API can be used fluently
   */
  public rx.Single rxListen(int port) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      listen(port, fut);
    }));
  }
  /**
   * Start the server listening for incoming connections using the specified options
   * through the constructor
   * @param listenHandler handler called when the asynchronous listen call ends
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.mqtt.MqttServer listen(io.vertx.core.Handler> listenHandler) { 
    delegate.listen(new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          listenHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)ar.result())));
        } else {
          listenHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
    return this;
  }
  /**
   * Start the server listening for incoming connections using the specified options
   * through the constructor
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.mqtt.MqttServer listen() {
    return 
listen(ar -> { });
  }
    /**
   * Start the server listening for incoming connections using the specified options
   * through the constructor
   * @return a reference to this, so the API can be used fluently
   */
  public rx.Single rxListen() { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      listen(fut);
    }));
  }
  /**
   * Set the endpoint handler for the server. If an MQTT client connect to the server a
   * new MqttEndpoint instance will be created and passed to the handler
   * @param handler the endpoint handler
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.mqtt.MqttServer endpointHandler(io.vertx.core.Handler handler) { 
    delegate.endpointHandler(new Handler() {
      public void handle(io.vertx.mqtt.MqttEndpoint event) {
        handler.handle(io.vertx.rxjava.mqtt.MqttEndpoint.newInstance((io.vertx.mqtt.MqttEndpoint)event));
      }
    });
    return this;
  }
  /**
   * Set an exception handler for the server, that will be called when an error happens independantly of an
   * accepted {@link io.vertx.rxjava.mqtt.MqttEndpoint}, like a rejected connection
   * @param handler the exception handler
   * @return a reference to this, so the API can be used fluently
   */
  public io.vertx.rxjava.mqtt.MqttServer exceptionHandler(io.vertx.core.Handler handler) { 
    delegate.exceptionHandler(handler);
    return this;
  }
  /**
   * The actual port the server is listening on. This is useful if you bound the server specifying 0 as port number
   * signifying an ephemeral port
   * @return the actual port the server is listening on.
   */
  public int actualPort() { 
    int ret = delegate.actualPort();
    return ret;
  }
  /**
   * Close the server supplying an handler that will be called when the server is actually closed (or has failed).
   * @param completionHandler the handler called on completion
   */
  public void close(io.vertx.core.Handler> completionHandler) { 
    delegate.close(completionHandler);
  }
  /**
   * Close the server supplying an handler that will be called when the server is actually closed (or has failed).
   */
  public void close() {
    close(ar -> { });
  }
    /**
   * Close the server supplying an handler that will be called when the server is actually closed (or has failed).
   * @return 
   */
  public rx.Single rxClose() { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      close(fut);
    }));
  }
  public static MqttServer newInstance(io.vertx.mqtt.MqttServer arg) {
    return arg != null ? new MqttServer(arg) : null;
  }
}
                      © 2015 - 2025 Weber Informatics LLC | Privacy Policy