Search in sources :

Example 1 with BindingHandler

use of io.aklivity.zilla.runtime.engine.binding.BindingHandler in project zilla by aklivity.

the class KafkaCacheClientFactory 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 OctetsFW extension = begin.extension();
    final ExtensionFW beginEx = extensionRO.tryWrap(extension.buffer(), extension.offset(), extension.limit());
    final KafkaBeginExFW kafkaBeginEx = beginEx != null && beginEx.typeId() == kafkaTypeId ? kafkaBeginExRO.tryWrap(extension.buffer(), extension.offset(), extension.limit()) : null;
    MessageConsumer newStream = null;
    if (kafkaBeginEx != null) {
        final BindingHandler factory = factories.get(kafkaBeginEx.kind());
        if (factory != null) {
            newStream = factory.newStream(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof(), sender);
        }
    }
    return newStream;
}
Also used : ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) OctetsFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW) KafkaBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW) BindingHandler(io.aklivity.zilla.runtime.engine.binding.BindingHandler)

Example 2 with BindingHandler

use of io.aklivity.zilla.runtime.engine.binding.BindingHandler in project zilla by aklivity.

the class KafkaCacheServerFactory 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 OctetsFW extension = begin.extension();
    final ExtensionFW beginEx = extension.get(extensionRO::tryWrap);
    assert beginEx != null;
    final int typeId = beginEx.typeId();
    assert beginEx != null && typeId == kafkaTypeId;
    MessageConsumer newStream = null;
    final KafkaBeginExFW kafkaBeginEx = extension.get(kafkaBeginExRO::tryWrap);
    if (kafkaBeginEx != null) {
        final BindingHandler streamFactory = factories.get(kafkaBeginEx.kind());
        if (streamFactory != null) {
            newStream = streamFactory.newStream(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof(), sender);
        }
    }
    return newStream;
}
Also used : ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) OctetsFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW) KafkaBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW) BindingHandler(io.aklivity.zilla.runtime.engine.binding.BindingHandler)

Example 3 with BindingHandler

use of io.aklivity.zilla.runtime.engine.binding.BindingHandler in project zilla by aklivity.

the class TestBindingFactory method newStream.

private MessageConsumer newStream(MessageConsumer source, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId) {
    MutableDirectBuffer writeBuffer = context.writeBuffer();
    BindingHandler streamFactory = context.streamFactory();
    BeginFW begin = beginRW.wrap(writeBuffer, 0, writeBuffer.capacity()).routeId(routeId).streamId(streamId).sequence(sequence).acknowledge(acknowledge).maximum(maximum).traceId(traceId).affinity(0L).build();
    MessageConsumer stream = streamFactory.newStream(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof(), source);
    stream.accept(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof());
    return stream;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) BeginFW(io.aklivity.zilla.runtime.engine.test.internal.k3po.ext.types.stream.BeginFW) MutableDirectBuffer(org.agrona.MutableDirectBuffer) BindingHandler(io.aklivity.zilla.runtime.engine.binding.BindingHandler)

Example 4 with BindingHandler

use of io.aklivity.zilla.runtime.engine.binding.BindingHandler in project zilla by aklivity.

the class KafkaClientFactory 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 OctetsFW extension = begin.extension();
    final ExtensionFW beginEx = extensionRO.tryWrap(extension.buffer(), extension.offset(), extension.limit());
    final KafkaBeginExFW kafkaBeginEx = beginEx != null && beginEx.typeId() == kafkaTypeId ? kafkaBeginExRO.tryWrap(extension.buffer(), extension.offset(), extension.limit()) : null;
    MessageConsumer newStream = null;
    if (kafkaBeginEx != null) {
        final BindingHandler factory = factories.get(kafkaBeginEx.kind());
        if (factory != null) {
            newStream = factory.newStream(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof(), application);
        }
    }
    return newStream;
}
Also used : ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) OctetsFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW) KafkaBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW) BindingHandler(io.aklivity.zilla.runtime.engine.binding.BindingHandler)

Example 5 with BindingHandler

use of io.aklivity.zilla.runtime.engine.binding.BindingHandler in project zilla by aklivity.

the class DispatchAgent method handleBeginInitial.

private MessageConsumer handleBeginInitial(int msgTypeId, DirectBuffer buffer, int index, int length) {
    final BeginFW begin = beginRO.wrap(buffer, index, index + length);
    final long routeId = begin.routeId();
    final long initialId = begin.streamId();
    MessageConsumer newStream = null;
    BindingRegistry binding = configuration.resolveBinding(routeId);
    final BindingHandler streamFactory = binding != null ? binding.streamFactory() : null;
    if (streamFactory != null) {
        final MessageConsumer replyTo = supplyReplyTo(initialId);
        newStream = streamFactory.newStream(msgTypeId, buffer, index, length, replyTo);
        if (newStream != null) {
            final long replyId = supplyReplyId(initialId);
            streams[streamIndex(initialId)].put(instanceId(initialId), newStream);
            throttles[throttleIndex(replyId)].put(instanceId(replyId), newStream);
            supplyLoadEntry.apply(routeId).initialOpened(1L);
        }
    }
    return newStream;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) BeginFW(io.aklivity.zilla.runtime.engine.internal.types.stream.BeginFW) BindingHandler(io.aklivity.zilla.runtime.engine.binding.BindingHandler)

Aggregations

BindingHandler (io.aklivity.zilla.runtime.engine.binding.BindingHandler)5 MessageConsumer (io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer)5 OctetsFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW)3 BeginFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW)3 ExtensionFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW)3 KafkaBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW)3 BeginFW (io.aklivity.zilla.runtime.engine.internal.types.stream.BeginFW)1 BeginFW (io.aklivity.zilla.runtime.engine.test.internal.k3po.ext.types.stream.BeginFW)1 MutableDirectBuffer (org.agrona.MutableDirectBuffer)1