io.vertx.reactivex.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.reactivex.mqtt;
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.function.Supplier;
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.reactivex.mqtt.MqttServer#endpointHandler}. As the
* requests arrive, the handler will be called with an instance of {@link io.vertx.reactivex.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;
}
private static final TypeArg TYPE_ARG_0 = new TypeArg(o1 -> io.vertx.reactivex.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)o1), o1 -> o1.getDelegate());
private static final TypeArg TYPE_ARG_1 = new TypeArg(o1 -> io.vertx.reactivex.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)o1), o1 -> o1.getDelegate());
private static final TypeArg TYPE_ARG_2 = new TypeArg(o1 -> io.vertx.reactivex.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)o1), o1 -> o1.getDelegate());
/**
* Return an MQTT server instance
* @param vertx Vert.x instance
* @param options MQTT server options
* @return MQTT server instance
*/
public static io.vertx.reactivex.mqtt.MqttServer create(io.vertx.reactivex.core.Vertx vertx, io.vertx.mqtt.MqttServerOptions options) {
io.vertx.reactivex.mqtt.MqttServer ret = io.vertx.reactivex.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.reactivex.mqtt.MqttServer create(io.vertx.reactivex.core.Vertx vertx) {
io.vertx.reactivex.mqtt.MqttServer ret = io.vertx.reactivex.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)io.vertx.mqtt.MqttServer.create(vertx.getDelegate()));
return ret;
}
/**
* Start the server listening for incoming connections using the specified options
* through the constructor
* @return a Future
completed with this server instance
*/
public io.vertx.core.Future listen() {
io.vertx.core.Future ret = delegate.listen().map(val -> io.vertx.reactivex.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)val));
return ret;
}
/**
* Start the server listening for incoming connections using the specified options
* through the constructor
* @return a Future
completed with this server instance
*/
public io.reactivex.Single rxListen() {
return AsyncResultSingle.toSingle($handler -> {
this.listen().onComplete($handler);
});
}
/**
* Start the server listening for incoming connections on the port and host specified
* @param port the port to listen on
* @param host the host to listen on
* @return a Future
completed with this server instance
*/
public io.vertx.core.Future listen(int port, java.lang.String host) {
io.vertx.core.Future ret = delegate.listen(port, host).map(val -> io.vertx.reactivex.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)val));
return ret;
}
/**
* Start the server listening for incoming connections on the port and host specified
* @param port the port to listen on
* @param host the host to listen on
* @return a Future
completed with this server instance
*/
public io.reactivex.Single rxListen(int port, java.lang.String host) {
return AsyncResultSingle.toSingle($handler -> {
this.listen(port, host).onComplete($handler);
});
}
/**
* 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 Future
completed with this server instance
*/
public io.vertx.core.Future listen(int port) {
io.vertx.core.Future ret = delegate.listen(port).map(val -> io.vertx.reactivex.mqtt.MqttServer.newInstance((io.vertx.mqtt.MqttServer)val));
return ret;
}
/**
* 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 Future
completed with this server instance
*/
public io.reactivex.Single rxListen(int port) {
return AsyncResultSingle.toSingle($handler -> {
this.listen(port).onComplete($handler);
});
}
/**
* 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.reactivex.mqtt.MqttServer endpointHandler(io.vertx.core.Handler handler) {
delegate.endpointHandler(new io.vertx.lang.rx.DelegatingHandler<>(handler, event -> io.vertx.reactivex.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.reactivex.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.reactivex.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.
*
* The close happens asynchronously and the server may not be closed until some time after the call has returned.
* @return a Future
completed with this server is closed
*/
public io.vertx.core.Future close() {
io.vertx.core.Future ret = delegate.close().map(val -> val);
return ret;
}
/**
* Close the server.
*
* The close happens asynchronously and the server may not be closed until some time after the call has returned.
* @return a Future
completed with this server is closed
*/
public io.reactivex.Completable rxClose() {
return AsyncResultCompletable.toCompletable($handler -> {
this.close().onComplete($handler);
});
}
public static MqttServer newInstance(io.vertx.mqtt.MqttServer arg) {
return arg != null ? new MqttServer(arg) : null;
}
}