Search in sources :

Example 1 with Serializer

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);
}
Also used : StateSynchronizer(io.pravega.client.state.StateSynchronizer) Segment(io.pravega.client.segment.impl.Segment) EventStreamWriter(io.pravega.client.stream.EventStreamWriter) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) Supplier(java.util.function.Supplier) SegmentMetadataClientFactory(io.pravega.client.segment.impl.SegmentMetadataClientFactory) Update(io.pravega.client.state.Update) Stream(io.pravega.client.stream.Stream) RevisionedStreamClient(io.pravega.client.state.RevisionedStreamClient) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) SegmentInputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentInputStreamFactoryImpl) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) RevisionedStreamClientImpl(io.pravega.client.state.impl.RevisionedStreamClientImpl) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Serializer(io.pravega.client.stream.Serializer) NameUtils(io.pravega.shared.NameUtils) BatchClientImpl(io.pravega.client.batch.impl.BatchClientImpl) SegmentInputStreamFactory(io.pravega.client.segment.impl.SegmentInputStreamFactory) StateSynchronizerImpl(io.pravega.client.state.impl.StateSynchronizerImpl) lombok.val(lombok.val) EventStreamReader(io.pravega.client.stream.EventStreamReader) InitialUpdate(io.pravega.client.state.InitialUpdate) Revisioned(io.pravega.client.state.Revisioned) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) Consumer(java.util.function.Consumer) Slf4j(lombok.extern.slf4j.Slf4j) SegmentInputStream(io.pravega.client.segment.impl.SegmentInputStream) SegmentOutputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl) UpdateOrInitSerializer(io.pravega.client.state.impl.UpdateOrInitSerializer) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) ClientFactory(io.pravega.client.ClientFactory) BatchClient(io.pravega.client.batch.BatchClient) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) ReaderConfig(io.pravega.client.stream.ReaderConfig) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) Futures(io.pravega.common.concurrent.Futures) ClientConfig(io.pravega.client.ClientConfig) SegmentInputStream(io.pravega.client.segment.impl.SegmentInputStream) RevisionedStreamClientImpl(io.pravega.client.state.impl.RevisionedStreamClientImpl) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) Segment(io.pravega.client.segment.impl.Segment) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient)

Example 2 with Serializer

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;
}
Also used : Segment(io.pravega.client.segment.impl.Segment) EventStreamWriter(io.pravega.client.stream.EventStreamWriter) Retry(io.pravega.common.util.Retry) Exceptions(io.pravega.common.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) SegmentSealedException(io.pravega.client.segment.impl.SegmentSealedException) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) ByteBufferUtils(io.pravega.common.util.ByteBufferUtils) Stream(io.pravega.client.stream.Stream) AccessOperation(io.pravega.shared.security.auth.AccessOperation) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ToString(lombok.ToString) ExecutorService(java.util.concurrent.ExecutorService) ReusableLatch(io.pravega.common.util.ReusableLatch) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Serializer(io.pravega.client.stream.Serializer) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) NoSuchSegmentException(io.pravega.client.segment.impl.NoSuchSegmentException) AuthenticationException(io.pravega.auth.AuthenticationException) DelegationTokenProviderFactory(io.pravega.client.security.auth.DelegationTokenProviderFactory) UUID(java.util.UUID) GuardedBy(javax.annotation.concurrent.GuardedBy) Collectors(java.util.stream.Collectors) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Preconditions(com.google.common.base.Preconditions) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) Collections(java.util.Collections) Controller(io.pravega.client.control.impl.Controller) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CompletableFuture(java.util.concurrent.CompletableFuture) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Preconditions (com.google.common.base.Preconditions)2 Segment (io.pravega.client.segment.impl.Segment)2 SegmentOutputStream (io.pravega.client.segment.impl.SegmentOutputStream)2 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)2 EventStreamWriter (io.pravega.client.stream.EventStreamWriter)2 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)2 Serializer (io.pravega.client.stream.Serializer)2 Stream (io.pravega.client.stream.Stream)2 ExecutorServiceHelpers (io.pravega.common.concurrent.ExecutorServiceHelpers)2 Consumer (java.util.function.Consumer)2 Slf4j (lombok.extern.slf4j.Slf4j)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 AuthenticationException (io.pravega.auth.AuthenticationException)1 ClientConfig (io.pravega.client.ClientConfig)1 ClientFactory (io.pravega.client.ClientFactory)1 BatchClient (io.pravega.client.batch.BatchClient)1 BatchClientImpl (io.pravega.client.batch.impl.BatchClientImpl)1 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)1 Controller (io.pravega.client.control.impl.Controller)1 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)1