All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.crossbar.autobahn.wamp.interfaces.ISession Maven / Gradle / Ivy

The newest version!
///////////////////////////////////////////////////////////////////////////////
//
//   AutobahnJava - http://crossbar.io/autobahn
//
//   Copyright (c) Crossbar.io Technologies GmbH and contributors
//
//   Licensed under the MIT License.
//   http://www.opensource.org/licenses/mit-license.php
//
///////////////////////////////////////////////////////////////////////////////

package io.crossbar.autobahn.wamp.interfaces;

import com.fasterxml.jackson.core.type.TypeReference;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import io.crossbar.autobahn.wamp.Session;
import io.crossbar.autobahn.wamp.types.CallOptions;
import io.crossbar.autobahn.wamp.types.CallResult;
import io.crossbar.autobahn.wamp.types.CloseDetails;
import io.crossbar.autobahn.wamp.types.EventDetails;
import io.crossbar.autobahn.wamp.types.InvocationDetails;
import io.crossbar.autobahn.wamp.types.Publication;
import io.crossbar.autobahn.wamp.types.PublishOptions;
import io.crossbar.autobahn.wamp.types.ReceptionResult;
import io.crossbar.autobahn.wamp.types.RegisterOptions;
import io.crossbar.autobahn.wamp.types.Registration;
import io.crossbar.autobahn.wamp.types.SessionDetails;
import io.crossbar.autobahn.wamp.types.SubscribeOptions;
import io.crossbar.autobahn.wamp.types.Subscription;


public interface ISession {

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(String topic, Runnable handler);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param options options for the subscribe
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            Runnable handler,
            SubscribeOptions options);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            Consumer> handler);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            Consumer> handler,
            SubscribeOptions options);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param resultType TypeReference encapsulating the class of the first
     *                   parameter of the callback method
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
     CompletableFuture subscribe(
            String topic,
            Consumer handler,
            TypeReference resultType);

     CompletableFuture subscribe(
            String topic,
            Consumer handler,
            Class resultType);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param resultType TypeReference encapsulating the class of the first
     *                   parameter of the callback method
     * @param options options for the subscribe
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
     CompletableFuture subscribe(
            String topic,
            Consumer handler,
            TypeReference resultType,
            SubscribeOptions options);

     CompletableFuture subscribe(
            String topic,
            Consumer handler,
            Class resultType,
            SubscribeOptions options);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            Function, CompletableFuture> handler);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param options options for the subscribe
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            Function, CompletableFuture> handler,
            SubscribeOptions options);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param resultType TypeReference encapsulating the class of the first
     *                   parameter of the callback method
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
     CompletableFuture subscribe(
            String topic,
            Function> handler,
            TypeReference resultType);

     CompletableFuture subscribe(
            String topic,
            Function> handler,
            Class resultType);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param resultType TypeReference encapsulating the class of the first
     *                   parameter of the callback method
     * @param options options for the subscribe
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
     CompletableFuture subscribe(
            String topic,
            Function> handler,
            TypeReference resultType,
            SubscribeOptions options);

     CompletableFuture subscribe(
            String topic,
            Function> handler,
            Class resultType,
            SubscribeOptions options);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            BiConsumer, EventDetails> handler);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param options options for the subscribe
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            BiConsumer, EventDetails> handler,
            SubscribeOptions options);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param resultType TypeReference encapsulating the class of the first
     *                   parameter of the callback method
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
     CompletableFuture subscribe(
            String topic,
            BiConsumer handler,
            TypeReference resultType);

     CompletableFuture subscribe(
            String topic,
            BiConsumer handler,
            Class resultType);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param resultType TypeReference encapsulating the class of the first
     *                   parameter of the callback method
     * @param options options for the subscribe
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
     CompletableFuture subscribe(
            String topic,
            BiConsumer handler,
            TypeReference resultType,
            SubscribeOptions options);

     CompletableFuture subscribe(
            String topic,
            BiConsumer handler,
            Class resultType,
            SubscribeOptions options);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            BiFunction, EventDetails, CompletableFuture> handler);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param options options for the subscribe
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            BiFunction, EventDetails, CompletableFuture> handler,
            SubscribeOptions options);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param resultType TypeReference encapsulating the class of the first
     *                   parameter of the callback method
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
     CompletableFuture subscribe(
            String topic,
            BiFunction> handler,
            TypeReference resultType);

     CompletableFuture subscribe(
            String topic,
            BiFunction> handler,
            Class resultType);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param resultType TypeReference encapsulating the class of the first
     *                   parameter of the callback method
     * @param options options for the subscribe
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
     CompletableFuture subscribe(
            String topic,
            BiFunction> handler,
            TypeReference resultType,
            SubscribeOptions options);

     CompletableFuture subscribe(
            String topic,
            BiFunction> handler,
            Class resultType,
            SubscribeOptions options);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            TriConsumer, Map, EventDetails> handler);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param options options for the subscribe
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            TriConsumer, Map, EventDetails> handler,
            SubscribeOptions options);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            TriFunction, Map, EventDetails,
                    CompletableFuture> handler);

    /**
     * Subscribes to a WAMP topic.
     * @param topic URI of the topic to subscribe
     * @param handler callback method for results of publication to the topic
     * @param options options for the subscribe
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Subscription}
     */
    CompletableFuture subscribe(
            String topic,
            TriFunction, Map, EventDetails,
                    CompletableFuture> handler,
            SubscribeOptions options);

    CompletableFuture unsubscribe(Subscription subscription);

    /**
     * Publishes to a WAMP topic.
     * @param topic URI of the topic
     * @param args positional arguments for the topic
     * @param kwargs keyword arguments for the topic
     * @param options options for the publication
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Publication}
     */
    CompletableFuture publish(
            String topic,
            List args,
            Map kwargs,
            PublishOptions options);

    /**
     * Publishes to a WAMP topic.
     * @param topic URI of the topic
     * @param arg Positional argument for the topic
     * @param options options for the publication
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Publication}
     */
    CompletableFuture publish(String topic, Object arg, PublishOptions options);

    /**
     * Publishes to a WAMP topic.
     * @param topic URI of the topic
     * @param options options for the publication
     * @param args positional arguments for the topic
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Publication}
     */
    CompletableFuture publish(
            String topic,
            PublishOptions options,
            Object... args);

    /**
     * Publishes to WAMP topic.
     * @param topic URI of the topic
     * @param args positional arguments for the topic
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Publication}
     */
    CompletableFuture publish(String topic, Object... args);

    /**
     * Publishes to a WAMP topic.
     * @param topic URI of the topic
     * @param options options for the publication
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Publication}
     */
    CompletableFuture publish(String topic, PublishOptions options);

    /**
     * Publishes to a WAMP topic
     * @param topic URI of the topic
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Publication}
     */
    CompletableFuture publish(String topic);

    /**
     * Registers a WAMP procedure.
     * @param procedure name of the procedure
     * @param endpoint the callee for the remote procedure
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Registration}
     */
     CompletableFuture register(
            String procedure,
            Supplier endpoint);

    /**
     * Registers a WAMP procedure.
     * @param procedure name of the procedure
     * @param endpoint the callee for the remote procedure
     * @param options options for the procedure registration
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Registration}
     */
     CompletableFuture register(
            String procedure,
            Supplier endpoint,
            RegisterOptions options);

    /**
     * Registers a WAMP procedure.
     * @param procedure name of the procedure
     * @param endpoint the callee for the remote procedure
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Registration}
     */
    CompletableFuture register(
            String procedure,
            IInvocationHandler endpoint);

    /**
     * Registers a WAMP procedure.
     * @param procedure name of the procedure
     * @param endpoint the callee for the remote procedure
     * @param options options for the procedure registration
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Registration}
     */
    CompletableFuture register(
            String procedure,
            IInvocationHandler endpoint,
            RegisterOptions options);

    /**
     * Registers a WAMP procedure.
     * @param procedure name of the procedure
     * @param endpoint the callee for the remote procedure
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Registration}
     */
     CompletableFuture register(
            String procedure,
            Function endpoint);

    /**
     * Registers a WAMP procedure.
     * @param procedure name of the procedure
     * @param endpoint the callee for the remote procedure
     * @param options options for the procedure registration
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Registration}
     */
     CompletableFuture register(
            String procedure,
            Function endpoint,
            RegisterOptions options);

    /**
     * Registers a WAMP procedure.
     * @param procedure name of the procedure
     * @param endpoint the callee for the remote procedure
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Registration}
     */
     CompletableFuture register(
            String procedure,
            BiFunction endpoint);

    /**
     * Registers a WAMP procedure.
     * @param procedure name of the procedure
     * @param endpoint the callee for the remote procedure
     * @param options options for the procedure registration
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Registration}
     */
     CompletableFuture register(
            String procedure,
            BiFunction endpoint,
            RegisterOptions options);

    /**
     * Registers a WAMP procedure.
     * @param procedure name of the procedure
     * @param endpoint the callee for the remote procedure
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Registration}
     */
     CompletableFuture register(
            String procedure,
            TriFunction endpoint);

    /**
     * Registers a WAMP procedure.
     * @param procedure name of the procedure
     * @param endpoint the callee for the remote procedure
     * @param options options for the procedure registration
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.Registration}
     */
     CompletableFuture register(
            String procedure,
            TriFunction endpoint,
            RegisterOptions options);

    CompletableFuture unregister(Registration registration);

    /**
     * Calls a remote procedure.
     * @param procedure URI of the procedure to call
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.CallResult}
     */
    CompletableFuture call(String procedure);

    /**
     * Calls a remote procedure.
     * @param procedure URI of the procedure to call
     * @param args positional arguments for the procedure
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.CallResult}
     */
    CompletableFuture call(String procedure, Object... args);

     CompletableFuture call(String procedure, TypeReference resultType);

     CompletableFuture call(String procedure, Class resultType);

    /**
     * Calls a remote procedure.
     * @param procedure URI of the procedure to call
     * @param options options for the WAMP call
     * @param args positional arguments for the procedure
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.CallResult}
     */
    CompletableFuture call(String procedure, CallOptions options, Object... args);

     CompletableFuture call(
            String procedure,
            TypeReference resultType,
            CallOptions options);

     CompletableFuture call(String procedure, Class resultType, CallOptions options);

     CompletableFuture call(
            String procedure,
            List args,
            TypeReference resultType);

     CompletableFuture call(String procedure, List args, Class resultType);

     CompletableFuture call(
            String procedure,
            List args,
            TypeReference resultType,
            CallOptions options);

     CompletableFuture call(
            String procedure,
            List args,
            Class resultType,
            CallOptions options);

    /**
     * Calls a remote procedure.
     * @param procedure URI of the procedure to call
     * @param kwargs keyword arguments for the procedure
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.CallResult}
     */
    CompletableFuture call(String procedure, Map kwargs);

     CompletableFuture call(
            String procedure,
            Map kwargs,
            TypeReference resultType);

     CompletableFuture call(
            String procedure,
            Map kwargs,
            Class resultType);

     CompletableFuture call(
            String procedure,
            Map kwargs,
            TypeReference resultType,
            CallOptions options);

     CompletableFuture call(
            String procedure,
            Map kwargs,
            Class resultType,
            CallOptions options);

    /**
     * Calls a remote procedure.
     * @param procedure URI of the procedure to call
     * @param kwargs keyword arguments for the procedure
     * @param options options for the WAMP call
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.CallResult}
     */
    CompletableFuture call(String procedure,
                                       Map kwargs,
                                       CallOptions options);

    /**
     * Calls a remote procedure.
     * @param procedure URI of the procedure to call
     * @param args positional arguments for the procedure
     * @param kwargs keyword arguments for the procedure
     * @param options options for the WAMP call
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.CallResult}
     */
    CompletableFuture call(String procedure,
                                       List args,
                                       Map kwargs,
                                       CallOptions options);

     CompletableFuture call(String procedure,
                                  List args,
                                  Map kwargs,
                                  TypeReference resultType);

     CompletableFuture call(String procedure,
                                  List args,
                                  Map kwargs,
                                  Class resultType);

    /**
     * Calls a remote procedure where the result needs to be resolved to a
     * POJO.
     * @param procedure URI of the procedure to call
     * @param args positional arguments for the procedure
     * @param kwargs keyword arguments for the procedure
     * @param resultType TypeReference encapsulating the class that the
     *                   returned CompletableFuture should resolve to
     * @param options options for the WAMP call
     * @return a CompletableFuture that resolves to an instance of
     * the class provided with resultType
     */
     CompletableFuture call(String procedure,
                                  List args,
                                  Map kwargs,
                                  TypeReference resultType,
                                  CallOptions options);

     CompletableFuture call(String procedure,
                                  List args,
                                  Map kwargs,
                                  Class resultType,
                                  CallOptions options);

    /**
     * Calls a remote procedure where the result needs to be resolved to a
     * POJO. This is a convenience method to pass positional arguments
     * directly to the method call.
     * @param procedure URI of the procedure to call
     * @param resultType TypeReference encapsulating the class that the
     *                   returned CompletableFuture should resolve to
     * @param options options for the WAMP call
     * @param args positional arguments for the procedure
     * @return a CompletableFuture that resolves to an instance of
     * the class provided with resultType
     */
     CompletableFuture call(String procedure,
                                  TypeReference resultType,
                                  CallOptions options,
                                  Object... args);

     CompletableFuture call(String procedure,
                                  TypeReference resultType,
                                  Object... args);

    /**
     * Joins a realm on the WAMP router
     * @param realm name of the realm to join
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.SessionDetails}
     */
    CompletableFuture join(String realm);

    /**
     * Joins a realm on the WAMP router
     * @param realm name of the realm to join
     * @param authenticators list of authentication methods to try
     * @return a CompletableFuture that resolves to an instance of
     * {@link io.crossbar.autobahn.wamp.types.SessionDetails}
     */
    CompletableFuture join(String realm, List authenticators);

    /**
     * Leaves the currently joined WAMP session.
     */
    void leave();

    /**
     * Leaves the currently joined WAMP session.
     * @param reason URI representing the reason to leave
     */
    void leave(String reason);

    /**
     * Leaves the currently joined WAMP session.
     * @param reason URI representing the reason to leave
     * @param message the leave message
     */
    void leave(String reason, String message);

    boolean isConnected();

    interface OnJoinListener {
        void onJoin(Session session, SessionDetails details);
    }

    interface OnReadyListener {
        void onReady(Session session);
    }

    interface OnLeaveListener {
        void onLeave(Session session, CloseDetails details);
    }

    interface OnConnectListener {
        void onConnect(Session session);
    }

    interface OnDisconnectListener {
        void onDisconnect(Session session, boolean wasClean);
    }

    // FIXME: come up with an equivalent of txaio.IFailedFuture as first arg.
    interface OnUserErrorListener {
        void onUserError(Session session, String message);
    }
}