implemented streaming request/response streaming
added metadata to cache values added cache servlet for comparison
This commit is contained in:
@@ -6,6 +6,7 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
api catalog.netty.buffer
|
||||
api catalog.netty.handler
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
@@ -2,7 +2,9 @@ module net.woggioni.rbcs.api {
|
||||
requires static lombok;
|
||||
requires java.xml;
|
||||
requires io.netty.buffer;
|
||||
requires io.netty.handler;
|
||||
requires io.netty.transport;
|
||||
exports net.woggioni.rbcs.api;
|
||||
exports net.woggioni.rbcs.api.exception;
|
||||
exports net.woggioni.rbcs.api.event;
|
||||
exports net.woggioni.rbcs.api.message;
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package net.woggioni.rbcs.api;
|
||||
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
public interface Cache extends AutoCloseable {
|
||||
|
||||
default void get(String key, ResponseHandle responseHandle, ByteBufAllocator alloc) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
default CompletableFuture<RequestHandle> put(String key, ResponseHandle responseHandle, ByteBufAllocator alloc) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package net.woggioni.rbcs.api;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
|
||||
public interface CacheHandlerFactory extends AutoCloseable {
|
||||
ChannelHandler newHandler();
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package net.woggioni.rbcs.api;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class CacheValueMetadata implements Serializable {
|
||||
private final String contentDisposition;
|
||||
private final String mimeType;
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package net.woggioni.rbcs.api;
|
||||
|
||||
|
||||
import io.netty.channel.ChannelInboundHandler;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
@@ -10,6 +11,7 @@ import java.security.cert.X509Certificate;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Value
|
||||
@@ -135,7 +137,7 @@ public class Configuration {
|
||||
}
|
||||
|
||||
public interface Cache {
|
||||
net.woggioni.rbcs.api.Cache materialize();
|
||||
CacheHandlerFactory materialize();
|
||||
String getNamespaceURI();
|
||||
String getTypeName();
|
||||
}
|
||||
|
@@ -1,8 +0,0 @@
|
||||
package net.woggioni.rbcs.api;
|
||||
|
||||
import net.woggioni.rbcs.api.event.RequestStreamingEvent;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RequestHandle {
|
||||
void handleEvent(RequestStreamingEvent evt);
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
package net.woggioni.rbcs.api;
|
||||
|
||||
import net.woggioni.rbcs.api.event.ResponseStreamingEvent;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ResponseHandle {
|
||||
void handleEvent(ResponseStreamingEvent evt);
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
package net.woggioni.rbcs.api.event;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public sealed interface RequestStreamingEvent {
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
non-sealed class ChunkReceived implements RequestStreamingEvent {
|
||||
private final ByteBuf chunk;
|
||||
}
|
||||
|
||||
final class LastChunkReceived extends ChunkReceived {
|
||||
public LastChunkReceived(ByteBuf chunk) {
|
||||
super(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
final class ExceptionCaught implements RequestStreamingEvent {
|
||||
private final Throwable exception;
|
||||
}
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
package net.woggioni.rbcs.api.event;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
public sealed interface ResponseStreamingEvent {
|
||||
|
||||
final class ResponseReceived implements ResponseStreamingEvent {
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
non-sealed class ChunkReceived implements ResponseStreamingEvent {
|
||||
private final ByteBuf chunk;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
non-sealed class FileReceived implements ResponseStreamingEvent {
|
||||
private final FileChannel file;
|
||||
}
|
||||
|
||||
final class LastChunkReceived extends ChunkReceived {
|
||||
public LastChunkReceived(ByteBuf chunk) {
|
||||
super(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
final class ExceptionCaught implements ResponseStreamingEvent {
|
||||
private final Throwable exception;
|
||||
}
|
||||
|
||||
final class NotFound implements ResponseStreamingEvent { }
|
||||
|
||||
NotFound NOT_FOUND = new NotFound();
|
||||
ResponseReceived RESPONSE_RECEIVED = new ResponseReceived();
|
||||
}
|
@@ -0,0 +1,161 @@
|
||||
package net.woggioni.rbcs.api.message;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufHolder;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.woggioni.rbcs.api.CacheValueMetadata;
|
||||
|
||||
public sealed interface CacheMessage {
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
final class CacheGetRequest implements CacheMessage {
|
||||
private final String key;
|
||||
}
|
||||
|
||||
abstract sealed class CacheGetResponse implements CacheMessage {
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
final class CacheValueFoundResponse extends CacheGetResponse {
|
||||
private final String key;
|
||||
private final CacheValueMetadata metadata;
|
||||
}
|
||||
|
||||
final class CacheValueNotFoundResponse extends CacheGetResponse {
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
final class CachePutRequest implements CacheMessage {
|
||||
private final String key;
|
||||
private final CacheValueMetadata metadata;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
final class CachePutResponse implements CacheMessage {
|
||||
private final String key;
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
non-sealed class CacheContent implements CacheMessage, ByteBufHolder {
|
||||
protected final ByteBuf chunk;
|
||||
|
||||
@Override
|
||||
public ByteBuf content() {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheContent copy() {
|
||||
return replace(chunk.copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheContent duplicate() {
|
||||
return new CacheContent(chunk.duplicate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheContent retainedDuplicate() {
|
||||
return new CacheContent(chunk.retainedDuplicate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheContent replace(ByteBuf content) {
|
||||
return new CacheContent(content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheContent retain() {
|
||||
chunk.retain();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheContent retain(int increment) {
|
||||
chunk.retain(increment);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheContent touch() {
|
||||
chunk.touch();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheContent touch(Object hint) {
|
||||
chunk.touch(hint);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int refCnt() {
|
||||
return chunk.refCnt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean release() {
|
||||
return chunk.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean release(int decrement) {
|
||||
return chunk.release(decrement);
|
||||
}
|
||||
}
|
||||
|
||||
final class LastCacheContent extends CacheContent {
|
||||
public LastCacheContent(ByteBuf chunk) {
|
||||
super(chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LastCacheContent copy() {
|
||||
return replace(chunk.copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LastCacheContent duplicate() {
|
||||
return new LastCacheContent(chunk.duplicate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LastCacheContent retainedDuplicate() {
|
||||
return new LastCacheContent(chunk.retainedDuplicate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LastCacheContent replace(ByteBuf content) {
|
||||
return new LastCacheContent(chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LastCacheContent retain() {
|
||||
super.retain();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LastCacheContent retain(int increment) {
|
||||
super.retain(increment);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LastCacheContent touch() {
|
||||
super.touch();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LastCacheContent touch(Object hint) {
|
||||
super.touch(hint);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user