use of io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer in project zilla by aklivity.
the class HttpServerFactory method newStream.
private MessageConsumer newStream(MessageConsumer sender, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Flyweight extension) {
final BeginFW begin = beginRW.wrap(writeBuffer, 0, writeBuffer.capacity()).routeId(routeId).streamId(streamId).sequence(sequence).acknowledge(acknowledge).maximum(maximum).traceId(traceId).authorization(authorization).affinity(affinity).extension(extension.buffer(), extension.offset(), extension.sizeof()).build();
MessageConsumer receiver = streamFactory.newStream(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof(), sender);
receiver.accept(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof());
return receiver;
}
use of io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer in project zilla by aklivity.
the class HttpServerFactory method newStream.
@Override
public MessageConsumer newStream(int msgTypeId, DirectBuffer buffer, int index, int length, MessageConsumer network) {
final BeginFW begin = beginRO.wrap(buffer, index, index + length);
final long routeId = begin.routeId();
HttpBindingConfig binding = bindings.get(routeId);
MessageConsumer newStream = null;
if (binding != null) {
final long initialId = begin.streamId();
final long affinity = begin.affinity();
HttpVersion version = null;
boolean secure = false;
ProxyBeginExFW beginEx = begin.extension().get(proxyBeginExRO::tryWrap);
if (beginEx != null && beginEx.typeId() == proxyTypeId) {
Array32FW<ProxyInfoFW> infos = beginEx.infos();
ProxyInfoFW alpn = infos.matchFirst(i -> i.kind() == ALPN);
secure = infos.matchFirst(i -> i.kind() == SECURE && i.secure().kind() == VERSION) != null;
if (secure && alpn != null) {
version = HttpVersion.of(alpn.alpn().asString());
}
}
SortedSet<HttpVersion> supportedVersions = binding.versions();
if (version == null && !supportedVersions.isEmpty()) {
// defaults to HTTP/1.1 if supported
version = supportedVersions.first();
}
if (supportedVersions.contains(version)) {
switch(version) {
case HTTP_1_1:
final boolean upgrade = !secure && supportedVersions.contains(HttpVersion.HTTP_2);
final HttpServer http11 = new HttpServer(binding, network, routeId, initialId, affinity, secure, upgrade);
newStream = upgrade ? http11::onNetworkUpgradeable : http11::onNetwork;
break;
case HTTP_2:
final Http2Server http2 = new Http2Server(binding, network, routeId, initialId, affinity);
newStream = http2::onNetwork;
break;
}
}
}
return newStream;
}
use of io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer in project zilla by aklivity.
the class FanServerFactory method newStream.
@Override
public MessageConsumer newStream(int msgTypeId, DirectBuffer buffer, int index, int length, MessageConsumer replyTo) {
final BeginFW begin = beginRO.wrap(buffer, index, index + length);
final long routeId = begin.routeId();
final BindingConfig binding = bindings.get(routeId);
MessageConsumer newStream = null;
if (binding != null) {
final long initialId = begin.streamId();
final long replyId = supplyReplyId.applyAsLong(initialId);
final FanServerGroup group = supplyFanServerGroup(binding.exit.id);
newStream = new FanServer(group, routeId, initialId, replyId, replyTo)::onMemberMessage;
}
return newStream;
}
use of io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer in project zilla by aklivity.
the class EchoServerFactory method newStream.
@Override
public MessageConsumer newStream(int msgTypeId, DirectBuffer buffer, int index, int length, MessageConsumer sender) {
final BeginFW begin = beginRO.wrap(buffer, index, index + length);
final long routeId = begin.routeId();
final long authorization = begin.authorization();
final BindingConfig binding = router.resolve(routeId, authorization);
MessageConsumer newStream = null;
if (binding != null) {
final long initialId = begin.streamId();
newStream = new EchoServer(sender, routeId, initialId)::onMessage;
}
return newStream;
}
use of io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer in project zilla by aklivity.
the class HttpClientFactory method newStream.
@Override
public MessageConsumer newStream(int msgTypeId, DirectBuffer buffer, int index, int length, MessageConsumer application) {
final BeginFW begin = beginRO.wrap(buffer, index, index + length);
final long routeId = begin.routeId();
final long authorization = begin.authorization();
final HttpBeginExFW beginEx = begin.extension().get(beginExRO::tryWrap);
final HttpBindingConfig binding = bindings.get(routeId);
HttpRouteConfig route = null;
if (binding != null) {
// TODO: avoid object creation
final Map<String, String> headers = beginEx != null ? asHeadersMap(beginEx.headers()) : EMPTY_HEADERS;
route = binding.resolve(authorization, headers::get);
}
MessageConsumer newStream = null;
if (route != null) {
final long resolvedId = route.id;
final Map<String8FW, String16FW> overrides = binding.options != null && binding.options.overrides != null ? binding.options.overrides : EMPTY_OVERRIDES;
final HttpClientPool clientPool = clientPools.computeIfAbsent(resolvedId, HttpClientPool::new);
newStream = clientPool.newStream(application, begin, overrides);
}
return newStream;
}
Aggregations