use of io.servicetalk.concurrent.BlockingIterable in project servicetalk by apple.
the class ProtoBufSerializationProviderBuilder method build0.
@SuppressWarnings("unchecked")
private void build0() {
for (Map.Entry<Class<? extends MessageLite>, Parser<? extends MessageLite>> entry : types.entrySet()) {
Class<MessageLite> messageType = (Class<MessageLite>) entry.getKey();
Parser<MessageLite> parser = (Parser<MessageLite>) entry.getValue();
Map<ContentCodec, HttpSerializer> serializersForType = new HashMap<>();
Map<ContentCodec, HttpDeserializer> deserializersForType = new HashMap<>();
for (ContentCodec codec : supportedCodings) {
DefaultSerializer serializer = new DefaultSerializer(new ProtoBufSerializationProvider<>(messageType, codec, parser));
HttpSerializer<MessageLite> httpSerializer = new ProtoHttpSerializer<>(serializer, codec, messageType);
serializersForType.put(codec, httpSerializer);
deserializersForType.put(codec, new HttpDeserializer<MessageLite>() {
@Override
public MessageLite deserialize(final HttpHeaders headers, final Buffer payload) {
return serializer.deserializeAggregatedSingle(payload, messageType);
}
@Override
public BlockingIterable<MessageLite> deserialize(final HttpHeaders headers, final BlockingIterable<Buffer> payload) {
return serializer.deserialize(payload, messageType);
}
@Override
public Publisher<MessageLite> deserialize(final HttpHeaders headers, final Publisher<Buffer> payload) {
return serializer.deserialize(payload, messageType);
}
});
}
serializers.put(messageType, serializersForType);
deserializers.put(messageType, deserializersForType);
}
}
use of io.servicetalk.concurrent.BlockingIterable in project servicetalk by apple.
the class BlockingProtobufStreamingServer method main.
public static void main(String[] args) throws Exception {
HttpServers.forPort(8080).listenBlockingStreamingAndAwait((ctx, request, response) -> {
if (!"/protobuf".equals(request.requestTarget())) {
response.status(NOT_FOUND).sendMetaData().close();
} else if (!POST.equals(request.method())) {
response.status(METHOD_NOT_ALLOWED).addHeader(ALLOW, POST.name()).sendMetaData().close();
} else {
BlockingIterable<RequestMessage> values = request.payloadBody(REQ_STREAMING_SERIALIZER);
response.status(CREATED);
try (HttpPayloadWriter<ResponseMessage> writer = response.sendMetaData(RESP_STREAMING_SERIALIZER)) {
for (RequestMessage req : values) {
writer.write(ResponseMessage.newBuilder().setLength(req.getMessage().length()).build());
}
}
}
}).awaitShutdown();
}
use of io.servicetalk.concurrent.BlockingIterable in project servicetalk by apple.
the class BlockingPojoStreamingServer method main.
public static void main(String[] args) throws Exception {
HttpServers.forPort(8080).listenBlockingStreamingAndAwait((ctx, request, response) -> {
if (!"/pojos".equals(request.requestTarget())) {
response.status(NOT_FOUND).sendMetaData().close();
} else if (!POST.equals(request.method())) {
response.status(METHOD_NOT_ALLOWED).addHeader(ALLOW, POST.name()).sendMetaData().close();
} else {
BlockingIterable<CreatePojoRequest> values = request.payloadBody(REQ_STREAMING_SERIALIZER);
response.status(CREATED);
try (HttpPayloadWriter<PojoResponse> writer = response.sendMetaData(RESP_STREAMING_SERIALIZER)) {
for (CreatePojoRequest req : values) {
writer.write(new PojoResponse(ID_GENERATOR.getAndIncrement(), req.getValue()));
}
}
}
}).awaitShutdown();
}
Aggregations