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

org.zodiac.sdk.nio.http.TransportProtocol Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.sdk.nio.http;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import org.zodiac.sdk.nio.core.Packet;
import org.zodiac.sdk.nio.http.common.UDPSRProtocol;

public interface TransportProtocol {

    enum Type {
        UDP,
        TCP;

        public static Type of(final String name) {
            String _name = name;
            if (null == _name) {
                return null;
            }
            _name = _name.trim().toUpperCase();
            if (0 == _name.length()) {
                return null;
            }
            switch (name) {
                case "UDP":
                //case "udp":
                    return UDP;
                case "TCP":
                case "tcp":
                default:
                    return TCP;
            }
        }
    }

    static TransportProtocol of(final Type type) {
        switch (type) {
            case UDP:
                return new UDPSRProtocol();
            case TCP:
            default:
                return null;
        }
    }

    default int windowSize() {
        return 5;
    }

    default int maxPacketSize() {
        return Packet.MAX_LEN;
    }

    default int minPacketSize() {
        return Packet.MIN_LEN;
    }

    default int maxConsecutiveRetries() {
        return 20;
    }

    default ByteBuffer emptyBuffer() {
        return ByteBuffer
            .allocateDirect(maxPacketSize())
            .order(ByteOrder.BIG_ENDIAN);
    }

    default int packetTimeoutMs() {
        return 500;
    }

    boolean send(UDPSRProtocol.Agent sender, Packet[] packets) throws IOException, InterruptedException;

     T receive(UDPSRProtocol.Agent receiver) throws IOException, InterruptedException;
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy