use of io.pravega.client.stream.Serializer in project pravega by pravega.
the class ClientFactoryImpl method createRevisionedStreamClient.
@Override
public <T> RevisionedStreamClient<T> createRevisionedStreamClient(String streamName, Serializer<T> serializer, SynchronizerConfig config) {
log.info("Creating revisioned stream client for stream: {} with synchronizer configuration: {}", streamName, config);
Segment segment = new Segment(scope, streamName, 0);
SegmentInputStream in = inFactory.createInputStreamForSegment(segment);
// Segment sealed is not expected for Revisioned Stream Client.
Consumer<Segment> segmentSealedCallBack = s -> {
throw new IllegalStateException("RevisionedClient: Segmentsealed exception observed for segment:" + s);
};
String delegationToken = Futures.getAndHandleExceptions(controller.getOrRefreshDelegationTokenFor(segment.getScope(), segment.getStreamName()), RuntimeException::new);
SegmentOutputStream out = outFactory.createOutputStreamForSegment(segment, segmentSealedCallBack, config.getEventWriterConfig(), delegationToken);
SegmentMetadataClient meta = metaFactory.createSegmentMetadataClient(segment, delegationToken);
return new RevisionedStreamClientImpl<>(segment, in, out, meta, serializer, controller, delegationToken);
}
use of io.pravega.client.stream.Serializer in project pravega by pravega.
the class EventStreamWriterImpl method writeEvents.
@Override
public CompletableFuture<Void> writeEvents(String routingKey, List<Type> events) {
Preconditions.checkNotNull(routingKey);
Preconditions.checkNotNull(events);
Exceptions.checkNotClosed(closed.get(), this);
List<ByteBuffer> data = events.stream().map(serializer::serialize).collect(Collectors.toList());
CompletableFuture<Void> ackFuture = new CompletableFuture<Void>();
synchronized (writeFlushLock) {
if (config.isEnableLargeEvents() && data.stream().mapToInt(m -> m.remaining()).sum() > Serializer.MAX_EVENT_SIZE) {
writeLargeEvent(routingKey, data, ackFuture);
} else {
synchronized (writeSealLock) {
SegmentOutputStream segmentWriter = getSegmentWriter(routingKey);
segmentWriter.write(PendingEvent.withHeader(routingKey, data, ackFuture));
}
}
}
return ackFuture;
}
Aggregations