use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.
the class KafkaCacheMetaFactory 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;
}
use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.
the class KafkaCacheMetaFactory 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 = extension.get(extensionRO::tryWrap);
assert beginEx != null && beginEx.typeId() == kafkaTypeId;
final KafkaBeginExFW kafkaBeginEx = extension.get(kafkaBeginExRO::wrap);
assert kafkaBeginEx.kind() == KafkaBeginExFW.KIND_META;
final KafkaMetaBeginExFW kafkaMetaBeginEx = kafkaBeginEx.meta();
final String16FW beginTopic = kafkaMetaBeginEx.topic();
final String topicName = beginTopic.asString();
MessageConsumer newStream = null;
final KafkaBindingConfig binding = supplyBinding.apply(routeId);
final KafkaRouteConfig resolved = binding != null ? binding.resolve(authorization, topicName) : null;
if (resolved != null) {
final long resolvedId = resolved.id;
final KafkaCacheRoute cacheRoute = supplyCacheRoute.apply(resolvedId);
final int topicKey = cacheRoute.topicKey(topicName);
KafkaCacheMetaFanout fanout = cacheRoute.metaFanoutsByTopic.get(topicKey);
if (fanout == null) {
final long cacheId = supplyCacheId.applyAsLong(routeId, resolvedId);
final String cacheName = String.format("%s.%s", supplyNamespace.apply(cacheId), supplyLocalName.apply(cacheId));
final KafkaCache cache = supplyCache.apply(cacheName);
final KafkaCacheTopic topic = cache.supplyTopic(topicName);
final KafkaCacheMetaFanout newFanout = new KafkaCacheMetaFanout(resolvedId, authorization, topic);
cacheRoute.metaFanoutsByTopic.put(topicKey, newFanout);
fanout = newFanout;
}
if (fanout != null) {
newStream = new KafkaCacheMetaStream(fanout, sender, routeId, initialId, affinity, authorization)::onMetaMessage;
}
}
return newStream;
}
use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.
the class KafkaCacheServerAddressFactory 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();
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.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.
the class KafkaCacheServerFetchFactory 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;
}
use of io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW in project zilla by aklivity.
the class KafkaCacheServerFetchFactory 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 affinity = begin.affinity();
final long authorization = begin.authorization();
assert (initialId & 0x0000_0000_0000_0001L) != 0L;
final OctetsFW extension = begin.extension();
final ExtensionFW beginEx = extension.get(extensionRO::wrap);
assert beginEx != null && beginEx.typeId() == kafkaTypeId;
final KafkaBeginExFW kafkaBeginEx = extension.get(kafkaBeginExRO::wrap);
final KafkaFetchBeginExFW kafkaFetchBeginEx = kafkaBeginEx.fetch();
final String16FW beginTopic = kafkaFetchBeginEx.topic();
final KafkaOffsetFW progress = kafkaFetchBeginEx.partition();
final int partitionId = progress.partitionId();
final long partitionOffset = progress.partitionOffset();
final KafkaDeltaType deltaType = kafkaFetchBeginEx.deltaType().get();
final String topicName = beginTopic.asString();
MessageConsumer newStream = null;
final KafkaBindingConfig binding = supplyBinding.apply(routeId);
final KafkaRouteConfig resolved = binding != null ? binding.resolve(authorization, topicName) : null;
if (resolved != null) {
final long resolvedId = resolved.id;
final KafkaCacheRoute cacheRoute = supplyCacheRoute.apply(resolvedId);
final long partitionKey = cacheRoute.topicPartitionKey(topicName, partitionId);
KafkaCacheServerFetchFanout fanout = cacheRoute.serverFetchFanoutsByTopicPartition.get(partitionKey);
if (fanout == null) {
final KafkaTopicConfig topic = binding.topic(topicName);
final KafkaDeltaType routeDeltaType = topic != null ? topic.deltaType : deltaType;
final KafkaOffsetType defaultOffset = topic != null ? topic.defaultOffset : HISTORICAL;
final String cacheName = String.format("%s.%s", supplyNamespace.apply(routeId), supplyLocalName.apply(routeId));
final KafkaCache cache = supplyCache.apply(cacheName);
final KafkaCacheTopic cacheTopic = cache.supplyTopic(topicName);
final KafkaCachePartition partition = cacheTopic.supplyFetchPartition(partitionId);
final KafkaCacheServerFetchFanout newFanout = new KafkaCacheServerFetchFanout(resolvedId, authorization, affinity, partition, routeDeltaType, defaultOffset);
cacheRoute.serverFetchFanoutsByTopicPartition.put(partitionKey, newFanout);
fanout = newFanout;
}
final int leaderId = cacheRoute.leadersByPartitionId.get(partitionId);
newStream = new KafkaCacheServerFetchStream(fanout, sender, routeId, initialId, leaderId, authorization, partitionOffset)::onServerMessage;
}
return newStream;
}
Aggregations