io.vertx.rxjava.ext.stomp.StompServerHandler 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.ext.stomp;
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;
/**
 * STOMP server handler implements the behavior of the STOMP server when a specific event occurs. For instance, if
 * let customize the behavior when specific STOMP frames arrives or when a connection is closed. This class has been
 * designed to let you customize the server behavior. The default implementation is compliant with the STOMP
 * specification. In this default implementation, not acknowledge frames are dropped.
 *
 * 
 * NOTE: This class has been automatically generated from the {@link io.vertx.ext.stomp.StompServerHandler original} non RX-ified interface using Vert.x codegen.
 */
@RxGen(io.vertx.ext.stomp.StompServerHandler.class)
public class StompServerHandler implements Handler {
  @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;
    StompServerHandler that = (StompServerHandler) o;
    return delegate.equals(that.delegate);
  }
  
  @Override
  public int hashCode() {
    return delegate.hashCode();
  }
  public static final TypeArg __TYPE_ARG = new TypeArg<>(    obj -> new StompServerHandler((io.vertx.ext.stomp.StompServerHandler) obj),
    StompServerHandler::getDelegate
  );
  private final io.vertx.ext.stomp.StompServerHandler delegate;
  
  public StompServerHandler(io.vertx.ext.stomp.StompServerHandler delegate) {
    this.delegate = delegate;
  }
  public StompServerHandler(Object delegate) {
    this.delegate = (io.vertx.ext.stomp.StompServerHandler)delegate;
  }
  public io.vertx.ext.stomp.StompServerHandler getDelegate() {
    return delegate;
  }
  private static final TypeArg TYPE_ARG_0 = new TypeArg(o1 -> io.vertx.rxjava.ext.stomp.Destination.newInstance((io.vertx.ext.stomp.Destination)o1), o1 -> o1.getDelegate());
  /**
   * Something has happened, so handle it.
   * @param event the event to handle
   */
  public void handle(io.vertx.rxjava.ext.stomp.ServerFrame event) { 
    delegate.handle(event.getDelegate());
  }
  /**
   * Creates an instance of {@link io.vertx.rxjava.ext.stomp.StompServerHandler} using the default (compliant) implementation.
   * @param vertx the vert.x instance to use
   * @return the created {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public static io.vertx.rxjava.ext.stomp.StompServerHandler create(io.vertx.rxjava.core.Vertx vertx) { 
    io.vertx.rxjava.ext.stomp.StompServerHandler ret = io.vertx.rxjava.ext.stomp.StompServerHandler.newInstance((io.vertx.ext.stomp.StompServerHandler)io.vertx.ext.stomp.StompServerHandler.create(vertx.getDelegate()));
    return ret;
  }
  /**
   * Configures a handler that get notified when a STOMP frame is received by the server.
   * This handler can be used for logging, debugging or ad-hoc behavior.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler receivedFrameHandler(io.vertx.core.Handler handler) { 
    delegate.receivedFrameHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when a CONNECT frame is received.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler connectHandler(io.vertx.core.Handler handler) { 
    delegate.connectHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when a STOMP frame is received.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler stompHandler(io.vertx.core.Handler handler) { 
    delegate.stompHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when a SUBSCRIBE frame is received.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler subscribeHandler(io.vertx.core.Handler handler) { 
    delegate.subscribeHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when a UNSUBSCRIBE frame is received.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler unsubscribeHandler(io.vertx.core.Handler handler) { 
    delegate.unsubscribeHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when a SEND frame is received.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler sendHandler(io.vertx.core.Handler handler) { 
    delegate.sendHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when a connection with the client is closed.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler closeHandler(io.vertx.core.Handler handler) { 
    delegate.closeHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.StompServerConnection event) {
        handler.handle(io.vertx.rxjava.ext.stomp.StompServerConnection.newInstance((io.vertx.ext.stomp.StompServerConnection)event));
      }
    });
    return this;
  }
  /**
   * Called when the connection is closed. This method executes a default behavior and must calls the configured
   * {@link io.vertx.rxjava.ext.stomp.StompServerHandler#closeHandler} if any.
   * @param connection the connection
   */
  public void onClose(io.vertx.rxjava.ext.stomp.StompServerConnection connection) { 
    delegate.onClose(connection.getDelegate());
  }
  /**
   * Configures the action to execute when a COMMIT frame is received.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler commitHandler(io.vertx.core.Handler handler) { 
    delegate.commitHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when a ABORT frame is received.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler abortHandler(io.vertx.core.Handler handler) { 
    delegate.abortHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when a BEGIN frame is received.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler beginHandler(io.vertx.core.Handler handler) { 
    delegate.beginHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when a DISCONNECT frame is received.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler disconnectHandler(io.vertx.core.Handler handler) { 
    delegate.disconnectHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when a ACK frame is received.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler ackHandler(io.vertx.core.Handler handler) { 
    delegate.ackHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when a NACK frame is received.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler nackHandler(io.vertx.core.Handler handler) { 
    delegate.nackHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.ServerFrame event) {
        handler.handle(io.vertx.rxjava.ext.stomp.ServerFrame.newInstance((io.vertx.ext.stomp.ServerFrame)event));
      }
    });
    return this;
  }
  /**
   * Called when the client connects to a server requiring authentication. It invokes the  configured
   * using {@link io.vertx.rxjava.ext.stomp.StompServerHandler#authProvider}.
   * @param connection server connection that contains session ID
   * @param login the login
   * @param passcode the password
   * @param handler handler receiving the authentication result
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler onAuthenticationRequest(io.vertx.rxjava.ext.stomp.StompServerConnection connection, java.lang.String login, java.lang.String passcode, io.vertx.core.Handler> handler) { 
    delegate.onAuthenticationRequest(connection.getDelegate(), login, passcode, handler);
    return this;
  }
  /**
   * Called when the client connects to a server requiring authentication. It invokes the  configured
   * using {@link io.vertx.rxjava.ext.stomp.StompServerHandler#authProvider}.
   * @param connection server connection that contains session ID
   * @param login the login
   * @param passcode the password
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler onAuthenticationRequest(io.vertx.rxjava.ext.stomp.StompServerConnection connection, java.lang.String login, java.lang.String passcode) {
    return 
onAuthenticationRequest(connection, login, passcode, ar -> { });
  }
    /**
   * Called when the client connects to a server requiring authentication. It invokes the  configured
   * using {@link io.vertx.rxjava.ext.stomp.StompServerHandler#authProvider}.
   * @param connection server connection that contains session ID
   * @param login the login
   * @param passcode the password
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public rx.Single rxOnAuthenticationRequest(io.vertx.rxjava.ext.stomp.StompServerConnection connection, java.lang.String login, java.lang.String passcode) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      onAuthenticationRequest(connection, login, passcode, fut);
    }));
  }
  /**
   * Provides for authorization matches on a destination level, this will return the User created by the .
   * @param session session ID for the server connection.
   * @return null if not authenticated.
   */
  public io.vertx.rxjava.ext.auth.User getUserBySession(java.lang.String session) { 
    io.vertx.rxjava.ext.auth.User ret = io.vertx.rxjava.ext.auth.User.newInstance((io.vertx.ext.auth.User)delegate.getUserBySession(session));
    return ret;
  }
  /**
   * Configures the  to be used to authenticate the user.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler authProvider(io.vertx.rxjava.ext.auth.authentication.AuthenticationProvider handler) { 
    delegate.authProvider(handler.getDelegate());
    return this;
  }
  /**
   * @return the list of destination managed by the STOMP server. Don't forget the STOMP interprets destination as opaque Strings.
   */
  public java.util.List getDestinations() { 
    java.util.List ret = delegate.getDestinations().stream().map(elt -> io.vertx.rxjava.ext.stomp.Destination.newInstance((io.vertx.ext.stomp.Destination)elt)).collect(Collectors.toList());
    return ret;
  }
  /**
   * Gets the destination with the given name.
   * @param destination the destination
   * @return the {@link io.vertx.rxjava.ext.stomp.Destination}, null if not existing.
   */
  public io.vertx.rxjava.ext.stomp.Destination getDestination(java.lang.String destination) { 
    io.vertx.rxjava.ext.stomp.Destination ret = io.vertx.rxjava.ext.stomp.Destination.newInstance((io.vertx.ext.stomp.Destination)delegate.getDestination(destination));
    return ret;
  }
  /**
   * Method called by single message (client-individual policy) or a set of message (client policy) are acknowledged.
   * Implementations must call the handler configured using {@link io.vertx.rxjava.ext.stomp.StompServerHandler#onAckHandler}.
   * @param connection the connection
   * @param subscribe the SUBSCRIBE frame
   * @param messages the acknowledge messages
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler onAck(io.vertx.rxjava.ext.stomp.StompServerConnection connection, io.vertx.ext.stomp.Frame subscribe, java.util.List messages) { 
    delegate.onAck(connection.getDelegate(), subscribe, messages);
    return this;
  }
  /**
   * Method called by single message (client-individual policy) or a set of message (client policy) are
   * not acknowledged. Not acknowledgment can result from a NACK frame or from a timeout (no
   * ACK frame received in a given time. Implementations must call the handler configured using
   * {@link io.vertx.rxjava.ext.stomp.StompServerHandler#onNackHandler}.
   * @param connection the connection
   * @param subscribe the SUBSCRIBE frame
   * @param messages the acknowledge messages
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler onNack(io.vertx.rxjava.ext.stomp.StompServerConnection connection, io.vertx.ext.stomp.Frame subscribe, java.util.List messages) { 
    delegate.onNack(connection.getDelegate(), subscribe, messages);
    return this;
  }
  /**
   * Configures the action to execute when messages are acknowledged.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler onAckHandler(io.vertx.core.Handler handler) { 
    delegate.onAckHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.Acknowledgement event) {
        handler.handle(io.vertx.rxjava.ext.stomp.Acknowledgement.newInstance((io.vertx.ext.stomp.Acknowledgement)event));
      }
    });
    return this;
  }
  /**
   * Configures the action to execute when messages are not acknowledged.
   * @param handler the handler
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler onNackHandler(io.vertx.core.Handler handler) { 
    delegate.onNackHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.Acknowledgement event) {
        handler.handle(io.vertx.rxjava.ext.stomp.Acknowledgement.newInstance((io.vertx.ext.stomp.Acknowledgement)event));
      }
    });
    return this;
  }
  /**
   * Allows customizing the action to do when the server needs to send a `PING` to the client. By default it send a
   * frame containing EOL (specification). However, you can customize this and send another frame. However,
   * be aware that this may requires a custom client.
   * 
   * The handler will only be called if the connection supports heartbeats.
   * @param handler the action to execute when a `PING` needs to be sent.
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler pingHandler(io.vertx.core.Handler handler) { 
    delegate.pingHandler(new Handler() {
      public void handle(io.vertx.ext.stomp.StompServerConnection event) {
        handler.handle(io.vertx.rxjava.ext.stomp.StompServerConnection.newInstance((io.vertx.ext.stomp.StompServerConnection)event));
      }
    });
    return this;
  }
  /**
   * Gets a {@link io.vertx.rxjava.ext.stomp.Destination} object if existing, or create a new one. The creation is delegated to the
   * {@link io.vertx.rxjava.ext.stomp.DestinationFactory}.
   * @param destination the destination
   * @return the {@link io.vertx.rxjava.ext.stomp.Destination} instance, may have been created.
   */
  public io.vertx.rxjava.ext.stomp.Destination getOrCreateDestination(java.lang.String destination) { 
    io.vertx.rxjava.ext.stomp.Destination ret = io.vertx.rxjava.ext.stomp.Destination.newInstance((io.vertx.ext.stomp.Destination)delegate.getOrCreateDestination(destination));
    return ret;
  }
  /**
   * Configures the {@link io.vertx.rxjava.ext.stomp.DestinationFactory} used to create {@link io.vertx.rxjava.ext.stomp.Destination} objects.
   * @param factory the factory
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}.
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler destinationFactory(io.vertx.rxjava.ext.stomp.DestinationFactory factory) { 
    delegate.destinationFactory(factory.getDelegate());
    return this;
  }
  /**
   * Configures the STOMP server to act as a bridge with the Vert.x event bus.
   * @param options the configuration options
   * @return the current {@link io.vertx.rxjava.ext.stomp.StompServerHandler}.
   */
  public io.vertx.rxjava.ext.stomp.StompServerHandler bridge(io.vertx.ext.stomp.BridgeOptions options) { 
    delegate.bridge(options);
    return this;
  }
  public static StompServerHandler newInstance(io.vertx.ext.stomp.StompServerHandler arg) {
    return arg != null ? new StompServerHandler(arg) : null;
  }
}
                                              © 2015 - 2025 Weber Informatics LLC | Privacy Policy