org.zodiac.sdk.nio.http.TransportProtocol Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zodiac-sdk-nio Show documentation
Show all versions of zodiac-sdk-nio Show documentation
Zodiac SDK NIO2(New Non-Blocking IO)
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;
}