Implemented stream packets
This commit is contained in:
@@ -11,10 +11,9 @@ import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebS
|
|||||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamStartPacket;
|
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamStartPacket;
|
||||||
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
|
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
|
||||||
import org.openautonomousconnection.protocol.side.client.events.ConnectedToProtocolServerEvent;
|
import org.openautonomousconnection.protocol.side.client.events.ConnectedToProtocolServerEvent;
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseStatus;
|
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseStatus;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import org.openautonomousconnection.protocol.versions.v1_0_0.beta.WebRequestMeth
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -80,6 +83,33 @@ public final class OacWebRequestBroker {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assembles the response body from received chunks in ascending seq order.
|
||||||
|
*
|
||||||
|
* <p>Best-effort UDP behavior: gaps are ignored.</p>
|
||||||
|
*/
|
||||||
|
private static void assembleBestEffortLocked(ResponseState st) {
|
||||||
|
st.body.reset();
|
||||||
|
|
||||||
|
if (st.chunkBuffer.isEmpty() || st.maxSeqSeen < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int seq = 0; seq <= st.maxSeqSeen; seq++) {
|
||||||
|
byte[] chunk = st.chunkBuffer.get(seq);
|
||||||
|
if (chunk == null) continue; // gap accepted
|
||||||
|
st.body.write(chunk, 0, chunk.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sleepSilently(long millis) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(millis);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches the client used to send INS/Web packets.
|
* Attaches the client used to send INS/Web packets.
|
||||||
*
|
*
|
||||||
@@ -321,7 +351,7 @@ public final class OacWebRequestBroker {
|
|||||||
|
|
||||||
long deadlineNanos = System.nanoTime() + unit.toNanos(timeout);
|
long deadlineNanos = System.nanoTime() + unit.toNanos(timeout);
|
||||||
|
|
||||||
for (;;) {
|
for (; ; ) {
|
||||||
synchronized (responseLock) {
|
synchronized (responseLock) {
|
||||||
if (st.completed) {
|
if (st.completed) {
|
||||||
break;
|
break;
|
||||||
@@ -453,25 +483,6 @@ public final class OacWebRequestBroker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Assembles the response body from received chunks in ascending seq order.
|
|
||||||
*
|
|
||||||
* <p>Best-effort UDP behavior: gaps are ignored.</p>
|
|
||||||
*/
|
|
||||||
private static void assembleBestEffortLocked(ResponseState st) {
|
|
||||||
st.body.reset();
|
|
||||||
|
|
||||||
if (st.chunkBuffer.isEmpty() || st.maxSeqSeen < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int seq = 0; seq <= st.maxSeqSeen; seq++) {
|
|
||||||
byte[] chunk = st.chunkBuffer.get(seq);
|
|
||||||
if (chunk == null) continue; // gap accepted
|
|
||||||
st.body.write(chunk, 0, chunk.length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void failLocked(ResponseState st, String message) {
|
private void failLocked(ResponseState st, String message) {
|
||||||
st.completed = true;
|
st.completed = true;
|
||||||
st.success = false;
|
st.success = false;
|
||||||
@@ -479,14 +490,6 @@ public final class OacWebRequestBroker {
|
|||||||
st.done.countDown();
|
st.done.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sleepSilently(long millis) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(millis);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response DTO.
|
* Response DTO.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user