Search in sources :

Example 41 with BeginFW

use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.

the class KafkaMergedFactory method doBegin.

private void doBegin(MessageConsumer receiver, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Consumer<OctetsFW.Builder> 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).build();
    receiver.accept(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof());
}
Also used : BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW)

Example 42 with BeginFW

use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.

the class KafkaMergedFactory 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 initialId = begin.streamId();
    final long authorization = begin.authorization();
    final long affinity = begin.affinity();
    assert (initialId & 0x0000_0000_0000_0001L) != 0L;
    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;
    assert kafkaBeginEx != null;
    assert kafkaBeginEx.kind() == KafkaBeginExFW.KIND_MERGED;
    final KafkaMergedBeginExFW kafkaMergedBeginEx = kafkaBeginEx.merged();
    final KafkaCapabilities capabilities = kafkaMergedBeginEx.capabilities().get();
    final String16FW beginTopic = kafkaMergedBeginEx.topic();
    final String topicName = beginTopic.asString();
    final KafkaDeltaType deltaType = kafkaMergedBeginEx.deltaType().get();
    MessageConsumer newStream = null;
    final KafkaBindingConfig binding = supplyBinding.apply(routeId);
    if (binding != null && binding.merged(topicName)) {
        final long resolvedId = routeId;
        final ArrayFW<KafkaOffsetFW> partitions = kafkaMergedBeginEx.partitions();
        final KafkaOffsetFW partition = partitions.matchFirst(p -> p.partitionId() == -1L);
        final long defaultOffset = partition != null ? partition.partitionOffset() : HISTORICAL.value();
        final Long2LongHashMap initialOffsetsById = new Long2LongHashMap(-3L);
        partitions.forEach(p -> {
            final long partitionId = p.partitionId();
            if (partitionId >= 0L) {
                final long partitionOffset = p.partitionOffset();
                initialOffsetsById.put(partitionId, partitionOffset);
            }
        });
        newStream = new KafkaMergedStream(sender, routeId, initialId, affinity, authorization, topicName, resolvedId, capabilities, initialOffsetsById, defaultOffset, deltaType)::onMergedMessage;
    }
    return newStream;
}
Also used : ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) KafkaDeltaType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType) OctetsFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW) KafkaMergedBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaMergedBeginExFW) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW) KafkaBindingConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig) KafkaBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW) Long2LongHashMap(org.agrona.collections.Long2LongHashMap) KafkaCapabilities(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaCapabilities) KafkaOffsetFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetFW) String16FW(io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)

Example 43 with BeginFW

use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.

the class KafkaMergedFactory method newStream.

private MessageConsumer newStream(MessageConsumer sender, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Consumer<OctetsFW.Builder> 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).build();
    final 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;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW)

Example 44 with BeginFW

use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.

the class KafkaMergedFactory method doBegin.

private void doBegin(MessageConsumer receiver, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Flyweight.Builder.Visitor 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(b -> b.set(extension)).build();
    receiver.accept(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof());
}
Also used : BindingHandler(io.aklivity.zilla.runtime.engine.binding.BindingHandler) KafkaBinding(io.aklivity.zilla.runtime.binding.kafka.internal.KafkaBinding) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) Flyweight(io.aklivity.zilla.runtime.binding.kafka.internal.types.Flyweight) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) KafkaFetchDataExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaFetchDataExFW) KafkaBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW) KafkaBindingConfig(io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig) Array32FW(io.aklivity.zilla.runtime.binding.kafka.internal.types.Array32FW) DEFAULT_MINIMUM(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.WindowFW.Builder.DEFAULT_MINIMUM) KafkaDeltaFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaFW) KafkaKeyFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaKeyFW) KafkaResetExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaResetExFW) PRODUCE_ONLY(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaCapabilities.PRODUCE_ONLY) KafkaValueMatchFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaValueMatchFW) KafkaFilterFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaFilterFW) KafkaOffsetFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetFW) ResetFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ResetFW) KafkaMergedFlushExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaMergedFlushExFW) EngineContext(io.aklivity.zilla.runtime.engine.EngineContext) EndFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.EndFW) KafkaHeaderFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaHeaderFW) KafkaDataExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaDataExFW) Objects(java.util.Objects) FETCH_ONLY(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaCapabilities.FETCH_ONLY) List(java.util.List) KafkaMergedBeginExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaMergedBeginExFW) HISTORICAL(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetType.HISTORICAL) String16FW(io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW) MergedBudgetCreditor(io.aklivity.zilla.runtime.binding.kafka.internal.budget.MergedBudgetCreditor) MutableDirectBuffer(org.agrona.MutableDirectBuffer) Long2LongHashMap(org.agrona.collections.Long2LongHashMap) KafkaConditionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaConditionFW) KafkaNotFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaNotFW) KafkaMetaDataExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaMetaDataExFW) DirectBuffer(org.agrona.DirectBuffer) DataFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.DataFW) Int2IntHashMap(org.agrona.collections.Int2IntHashMap) LIVE(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetType.LIVE) ArrayList(java.util.ArrayList) ArrayFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.ArrayFW) KafkaCapabilities(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaCapabilities) OctetsFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW) KafkaOffsetType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetType) KafkaFlushExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaFlushExFW) AbortFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.AbortFW) MutableInteger(org.agrona.collections.MutableInteger) KafkaMergedDataExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaMergedDataExFW) NO_CREDITOR_INDEX(io.aklivity.zilla.runtime.engine.budget.BudgetCreditor.NO_CREDITOR_INDEX) FlushFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.FlushFW) KafkaConfiguration(io.aklivity.zilla.runtime.binding.kafka.internal.KafkaConfiguration) WindowFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.WindowFW) LongFunction(java.util.function.LongFunction) KafkaPartitionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaPartitionFW) KafkaConfigFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaConfigFW) KafkaHeadersFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaHeadersFW) LongConsumer(java.util.function.LongConsumer) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW) Consumer(java.util.function.Consumer) KafkaDeltaType(io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType) LongUnaryOperator(java.util.function.LongUnaryOperator) Collections(java.util.Collections) ExtensionFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW) KafkaDescribeDataExFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaDescribeDataExFW) BeginFW(io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW)

Aggregations

BeginFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW)44 MessageConsumer (io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer)31 OctetsFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.OctetsFW)17 ExtensionFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.ExtensionFW)17 KafkaBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaBeginExFW)17 KafkaBindingConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig)14 String16FW (io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW)14 KafkaRouteConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig)11 KafkaCache (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCache)6 KafkaCacheTopic (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCacheTopic)6 KafkaOffsetFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetFW)5 KafkaCachePartition (io.aklivity.zilla.runtime.binding.kafka.internal.cache.KafkaCachePartition)4 KafkaDeltaType (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaDeltaType)4 BindingHandler (io.aklivity.zilla.runtime.engine.binding.BindingHandler)4 ArrayList (java.util.ArrayList)4 KafkaOffsetType (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaOffsetType)3 KafkaDescribeBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaDescribeBeginExFW)3 KafkaFetchBeginExFW (io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.KafkaFetchBeginExFW)3 KafkaTopicConfig (io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaTopicConfig)2 KafkaCapabilities (io.aklivity.zilla.runtime.binding.kafka.internal.types.KafkaCapabilities)2