Java Code Examples for software.amazon.awssdk.core.async.SdkPublisher#subscribe()
The following examples show how to use
software.amazon.awssdk.core.async.SdkPublisher#subscribe() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncBasicScanTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void scanLimit() { insertRecords(); SdkPublisher<Page<Record>> publisher = mappedTable.scan(r -> r.limit(5)); publisher.subscribe(page -> page.items().forEach(item -> System.out.println(item))); List<Page<Record>> results = drainPublisher(publisher, 3); Page<Record> page1 = results.get(0); Page<Record> page2 = results.get(1); Page<Record> page3 = results.get(2); assertThat(page1.items(), is(RECORDS.subList(0, 5))); assertThat(page1.lastEvaluatedKey(), is(getKeyMap(4))); assertThat(page2.items(), is(RECORDS.subList(5, 10))); assertThat(page2.lastEvaluatedKey(), is(getKeyMap(9))); assertThat(page3.items(), is(empty())); assertThat(page3.lastEvaluatedKey(), is(nullValue())); }
Example 2
Source File: LocalDynamoDbAsyncTestBase.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
public static <T> List<T> drainPublisher(SdkPublisher<T> publisher, int expectedNumberOfResults) { BufferingSubscriber<T> subscriber = new BufferingSubscriber<>(); publisher.subscribe(subscriber); subscriber.waitForCompletion(1000L); assertThat(subscriber.isCompleted(), is(true)); assertThat(subscriber.bufferedError(), is(nullValue())); assertThat(subscriber.bufferedItems().size(), is(expectedNumberOfResults)); return subscriber.bufferedItems(); }
Example 3
Source File: AsyncClientHandlerTransformerVerificationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public void onStream(SdkPublisher<ByteBuffer> publisher) { publisher.subscribe(new DrainingSubscriber<ByteBuffer>() { @Override public void onComplete() { transformFuture.complete(null); } }); }
Example 4
Source File: EventStreamAsyncResponseTransformer.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public void onStream(SdkPublisher<ByteBuffer> publisher) { CompletableFuture<Subscription> dataSubscriptionFuture = new CompletableFuture<>(); publisher.subscribe(new ByteSubscriber(dataSubscriptionFuture)); dataSubscriptionFuture.thenAccept(dataSubscription -> { SdkPublisher<EventT> eventPublisher = new EventPublisher(dataSubscription); try { eventStreamResponseHandler.onEventStream(eventPublisher); } catch (Throwable t) { exceptionOccurred(t); dataSubscription.cancel(); } }); }
Example 5
Source File: S3AsyncByteReader.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public void onStream(SdkPublisher<ByteBuffer> publisher) { publisher.subscribe(new Subscriber<ByteBuffer>() { @Override public void onSubscribe(Subscription s) { s.request(Long.MAX_VALUE); } @Override public void onNext(ByteBuffer b) { int len = b.remaining(); dst.setBytes(curOffset, b); curOffset += len; } @Override public void onError(Throwable error) { future.completeExceptionally(error); } @Override public void onComplete() { future.complete(null); } }); }
Example 6
Source File: FanOutRecordsPublisher.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
private void rejectSubscription(SdkPublisher<SubscribeToShardEventStream> publisher) { publisher.subscribe(new Subscriber<SubscribeToShardEventStream>() { Subscription localSub; @Override public void onSubscribe(Subscription s) { localSub = s; localSub.cancel(); } @Override public void onNext(SubscribeToShardEventStream subscribeToShardEventStream) { localSub.cancel(); } @Override public void onError(Throwable t) { localSub.cancel(); } @Override public void onComplete() { localSub.cancel(); } }); }
Example 7
Source File: FanOutRecordsPublisher.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Override public void onEventStream(SdkPublisher<SubscribeToShardEventStream> publisher) { synchronized (parent.lockObject) { log.debug("{}: [SubscriptionLifetime]: (RecordFlow#onEventStream) @ {} id: {} -- Subscribe", parent.shardId, connectionStartedAt, subscribeToShardId); if (!parent.isActiveFlow(this)) { this.isDisposed = true; log.debug( "{}: [SubscriptionLifetime]: (RecordFlow#onEventStream) @ {} id: {} -- parent is disposed", parent.shardId, connectionStartedAt, subscribeToShardId); parent.rejectSubscription(publisher); return; } try { log.debug( "{}: [SubscriptionLifetime]: (RecordFlow#onEventStream) @ {} id: {} -- creating record subscription", parent.shardId, connectionStartedAt, subscribeToShardId); subscription = new RecordSubscription(parent, this, connectionStartedAt, subscribeToShardId); publisher.subscribe(subscription); // // Only flip this once we succeed // parent.isFirstConnection = false; } catch (Throwable t) { log.debug( "{}: [SubscriptionLifetime]: (RecordFlow#onEventStream) @ {} id: {} -- throwable during record subscription: {}", parent.shardId, connectionStartedAt, subscribeToShardId, t.getMessage()); parent.errorOccurred(this, t); } } }
Example 8
Source File: AsyncFaultTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public void onStream(SdkPublisher<ByteBuffer> publisher) { publisher.subscribe(new CancelSubscriber(cf)); }
Example 9
Source File: FileAsyncResponseTransformer.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public void onStream(SdkPublisher<ByteBuffer> publisher) { // onStream may be called multiple times so reset the file channel every time this.fileChannel = invokeSafely(() -> createChannel(path)); publisher.subscribe(new FileSubscriber(this.fileChannel, path, cf, this::exceptionOccurred)); }
Example 10
Source File: ByteArrayAsyncResponseTransformer.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public void onStream(SdkPublisher<ByteBuffer> publisher) { publisher.subscribe(new BaosSubscriber(cf)); }
Example 11
Source File: EventStreamAsyncResponseTransformerTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public void onEventStream(SdkPublisher<Object> publisher) { publisher.subscribe(e -> { }); }