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

com.firefly.net.tcp.codec.flex.stream.Session Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.net.tcp.codec.flex.stream;

import com.firefly.net.tcp.codec.flex.protocol.ControlFrame;
import com.firefly.net.tcp.codec.flex.protocol.DisconnectionFrame;
import com.firefly.net.tcp.codec.flex.protocol.Frame;
import com.firefly.net.tcp.codec.flex.protocol.PingFrame;
import com.firefly.utils.concurrent.Callback;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
 * @author Pengtao Qiu
 */
public interface Session extends ContextAttribute {

    Stream getStream(int streamId);

    Map getAllStreams();

    /**
     * Create a new stream and send the first control frame to the remote endpoint.
     *
     * @param controlFrame The first control frame of the stream.
     * @param callback     The callback of sending the first control frame
     * @param listener     The stream listener.
     * @return The new stream.
     */
    Stream newStream(ControlFrame controlFrame, Callback callback, Stream.Listener listener);

    void setListener(Listener listener);

    CompletableFuture ping(PingFrame pingFrame);

    CompletableFuture disconnect(DisconnectionFrame disconnectionFrame);

    CompletableFuture sendFrame(Frame frame);

    CompletableFuture sendFrames(List frames);

    void sendFrame(Frame frame, Callback callback);

    void sendFrames(List frames, Callback callback);

    interface Listener {

        /**
         * Receive a new stream that is created by remote endpoint.
         *
         * @param stream       The new stream that is created by remote endpoint.
         * @param controlFrame The first control frame of the stream.
         * @return The stream listener.
         */
        Stream.Listener onNewStream(Stream stream, ControlFrame controlFrame);

        void onPing(Session session, PingFrame pingFrame);

        void onDisconnect(Session session, DisconnectionFrame disconnectionFrame);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy