本文整理汇总了Java中io.pravega.client.stream.EventRead类的典型用法代码示例。如果您正苦于以下问题:Java EventRead类的具体用法?Java EventRead怎么用?Java EventRead使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventRead类属于io.pravega.client.stream包,在下文中一共展示了EventRead类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEndOfSegmentWithoutSuccessors
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
@Test(timeout = 10000)
public void testEndOfSegmentWithoutSuccessors() throws SegmentSealedException, ReinitializationRequiredException {
AtomicLong clock = new AtomicLong();
MockSegmentStreamFactory segmentStreamFactory = new MockSegmentStreamFactory();
Orderer orderer = new Orderer();
ReaderGroupStateManager groupState = Mockito.mock(ReaderGroupStateManager.class);
EventStreamReaderImpl<byte[]> reader = new EventStreamReaderImpl<>(segmentStreamFactory, segmentStreamFactory,
new ByteArraySerializer(), groupState,
orderer, clock::get,
ReaderConfig.builder().build());
Segment segment = Segment.fromScopedName("Foo/Bar/0");
Mockito.when(groupState.acquireNewSegmentsIfNeeded(0L))
.thenReturn(ImmutableMap.of(segment, 0L))
.thenReturn(Collections.emptyMap());
SegmentOutputStream stream = segmentStreamFactory.createOutputStreamForSegment(segment, segmentSealedCallback, writerConfig);
ByteBuffer buffer = writeInt(stream, 1);
EventRead<byte[]> read = reader.readNextEvent(0);
byte[] event = read.getEvent();
assertEquals(buffer, ByteBuffer.wrap(event));
read = reader.readNextEvent(0);
assertNull(read.getEvent());
read = reader.readNextEvent(0);
assertNull(read.getEvent());
assertEquals(0, reader.getReaders().size());
reader.close();
}
示例2: testCheckpoint
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
@Test(timeout = 10000)
public void testCheckpoint() throws SegmentSealedException, ReinitializationRequiredException {
AtomicLong clock = new AtomicLong();
MockSegmentStreamFactory segmentStreamFactory = new MockSegmentStreamFactory();
Orderer orderer = new Orderer();
ReaderGroupStateManager groupState = Mockito.mock(ReaderGroupStateManager.class);
EventStreamReaderImpl<byte[]> reader = new EventStreamReaderImpl<>(segmentStreamFactory, segmentStreamFactory,
new ByteArraySerializer(), groupState,
orderer, clock::get,
ReaderConfig.builder().build());
Segment segment = Segment.fromScopedName("Foo/Bar/0");
Mockito.when(groupState.acquireNewSegmentsIfNeeded(0L)).thenReturn(ImmutableMap.of(segment, 0L)).thenReturn(Collections.emptyMap());
SegmentOutputStream stream = segmentStreamFactory.createOutputStreamForSegment(segment, segmentSealedCallback, writerConfig);
ByteBuffer buffer = writeInt(stream, 1);
Mockito.when(groupState.getCheckpoint()).thenReturn("Foo").thenReturn(null);
EventRead<byte[]> eventRead = reader.readNextEvent(0);
assertTrue(eventRead.isCheckpoint());
assertNull(eventRead.getEvent());
assertEquals("Foo", eventRead.getCheckpointName());
assertEquals(buffer, ByteBuffer.wrap(reader.readNextEvent(0).getEvent()));
assertNull(reader.readNextEvent(0).getEvent());
reader.close();
}
示例3: createCheckPointAndVerify
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
private Checkpoint createCheckPointAndVerify(final ReaderGroup readerGroup, final String checkPointName) {
log.info("Create and verify check point {}", checkPointName);
String readerId = "checkPointReader";
CompletableFuture<Checkpoint> checkpoint = null;
try (ClientFactory clientFactory = ClientFactory.withScope(SCOPE, controllerURI);
EventStreamReader<Integer> reader = clientFactory.createReader(readerId, READER_GROUP_NAME,
new JavaSerializer<Integer>(), readerConfig)) {
checkpoint = readerGroup.initiateCheckpoint(checkPointName, executor); //create checkpoint
//verify checkpoint event.
EventRead<Integer> event = reader.readNextEvent(READ_TIMEOUT);
assertTrue("Read for Checkpoint event", (event != null) && (event.isCheckpoint()));
assertEquals("CheckPoint Name", checkPointName, event.getCheckpointName());
} catch (ReinitializationRequiredException e) {
log.error("Exception while reading event using readerId: {}", readerId, e);
fail("Reinitialization Exception is not expected");
}
return checkpoint.join();
}
示例4: run
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
public void run() {
StreamManager streamManager = StreamManager.create(controllerURI);
final boolean scopeIsNew = streamManager.createScope(scope);
StreamConfiguration streamConfig = StreamConfiguration.builder()
.scalingPolicy(ScalingPolicy.fixed(1))
.build();
final boolean streamIsNew = streamManager.createStream(scope, streamName, streamConfig);
final String readerGroup = UUID.randomUUID().toString().replace("-", "");
final ReaderGroupConfig readerGroupConfig = ReaderGroupConfig.builder()
.build();
try (ReaderGroupManager readerGroupManager = ReaderGroupManager.withScope(scope, controllerURI)) {
readerGroupManager.createReaderGroup(readerGroup, readerGroupConfig, Collections.singleton(streamName));
}
try (ClientFactory clientFactory = ClientFactory.withScope(scope, controllerURI);
EventStreamReader<String> reader = clientFactory.createReader("reader",
readerGroup,
new JavaSerializer<String>(),
ReaderConfig.builder().build())) {
System.out.format("Reading all the events from %s/%s%n", scope, streamName);
EventRead<String> event = null;
do {
try {
event = reader.readNextEvent(READER_TIMEOUT_MS);
if (event.getEvent() != null) {
System.out.format("Read event '%s'%n", event.getEvent());
}
} catch (ReinitializationRequiredException e) {
//There are certain circumstances where the reader needs to be reinitialized
e.printStackTrace();
}
} while (event.getEvent() != null);
System.out.format("No more events from %s/%s%n", scope, streamName);
}
}
示例5: run
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
public void run() {
setRunning(true);
final String readerGroup = UUID.randomUUID().toString().replace("-", "");
final ReaderGroupConfig readerGroupConfig = ReaderGroupConfig.builder().startingPosition(Sequence.MIN_VALUE)
.build();
try (ReaderGroupManager readerGroupManager = ReaderGroupManager.withScope(scope, controllerURI)) {
readerGroupManager.createReaderGroup(readerGroup, readerGroupConfig, Collections.singleton(streamName));
}
try (ClientFactory clientFactory = ClientFactory.withScope(scope, controllerURI);
EventStreamReader<T> reader = clientFactory.createReader("reader",
readerGroup, serializer, ReaderConfig.builder().build())) {
while (isRunning()) {
try {
EventRead<T> event = reader.readNextEvent(READER_TIMEOUT_MS);
T eventData = event.getEvent();
if (eventData != null) {
onNext.accept(event.getEvent());
}
}
catch (ReinitializationRequiredException e) {
onError.accept(e);
}
}
}
}
示例6: run
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
public void run() {
final String readerGroup = UUID.randomUUID().toString().replace("-", "");
final ReaderGroupConfig readerGroupConfig = ReaderGroupConfig.builder().startingPosition(Sequence.MIN_VALUE)
.build();
StreamManager streamManager = StreamManager.create(controllerURI);
streamManager.createScope(scope);
StreamConfiguration streamConfig = StreamConfiguration.builder().scope(scope).streamName(streamName)
.scalingPolicy(ScalingPolicy.fixed(1))
.build();
streamManager.createStream(scope, streamName, streamConfig);
try (ReaderGroupManager readerGroupManager = ReaderGroupManager.withScope(scope, controllerURI)) {
readerGroupManager.createReaderGroup(readerGroup, readerGroupConfig, Collections.singleton(streamName));
}
try (ClientFactory clientFactory = ClientFactory.withScope(scope, controllerURI);
EventStreamReader<String> reader = clientFactory.createReader("reader",
readerGroup,
new JavaSerializer<String>(),
ReaderConfig.builder().build())) {
System.out.format("******** Reading events from %s/%s%n", scope, streamName);
EventRead<String> event = null;
do {
try {
event = reader.readNextEvent(READER_TIMEOUT_MS);
if(event != null) {
System.out.format("'%s'%n", event.getEvent());
}
} catch (ReinitializationRequiredException e) {
//There are certain circumstances where the reader needs to be reinitialized
e.printStackTrace();
}
}while(true);
}
}
示例7: testEventPointer
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
@Test
public void testEventPointer() throws SegmentSealedException, NoSuchEventException, ReinitializationRequiredException {
AtomicLong clock = new AtomicLong();
MockSegmentStreamFactory segmentStreamFactory = new MockSegmentStreamFactory();
Orderer orderer = new Orderer();
ReaderGroupStateManager groupState = Mockito.mock(ReaderGroupStateManager.class);
EventStreamReaderImpl<byte[]> reader = new EventStreamReaderImpl<>(segmentStreamFactory, segmentStreamFactory,
new ByteArraySerializer(), groupState,
orderer, clock::get,
ReaderConfig.builder().build());
Segment segment = Segment.fromScopedName("Foo/Bar/0");
Mockito.when(groupState.acquireNewSegmentsIfNeeded(0L)).thenReturn(ImmutableMap.of(segment, 0L)).thenReturn(Collections.emptyMap());
SegmentOutputStream stream = segmentStreamFactory.createOutputStreamForSegment(segment, segmentSealedCallback, writerConfig);
ByteBuffer buffer1 = writeInt(stream, 1);
ByteBuffer buffer2 = writeInt(stream, 2);
ByteBuffer buffer3 = writeInt(stream, 3);
EventRead<byte[]> event1 = reader.readNextEvent(0);
EventRead<byte[]> event2 = reader.readNextEvent(0);
EventRead<byte[]> event3 = reader.readNextEvent(0);
assertEquals(buffer1, ByteBuffer.wrap(event1.getEvent()));
assertEquals(buffer2, ByteBuffer.wrap(event2.getEvent()));
assertEquals(buffer3, ByteBuffer.wrap(event3.getEvent()));
assertNull(reader.readNextEvent(0).getEvent());
assertEquals(buffer1, ByteBuffer.wrap(reader.fetchEvent(event1.getEventPointer())));
assertEquals(buffer3, ByteBuffer.wrap(reader.fetchEvent(event3.getEventPointer())));
assertEquals(buffer2, ByteBuffer.wrap(reader.fetchEvent(event2.getEventPointer())));
reader.close();
}
示例8: testDataTruncated
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
@Test(timeout = 10000)
public void testDataTruncated() throws SegmentSealedException, ReinitializationRequiredException {
AtomicLong clock = new AtomicLong();
MockSegmentStreamFactory segmentStreamFactory = new MockSegmentStreamFactory();
Orderer orderer = new Orderer();
ReaderGroupStateManager groupState = Mockito.mock(ReaderGroupStateManager.class);
EventStreamReaderImpl<byte[]> reader = new EventStreamReaderImpl<>(segmentStreamFactory, segmentStreamFactory,
new ByteArraySerializer(), groupState,
orderer, clock::get,
ReaderConfig.builder().build());
Segment segment = Segment.fromScopedName("Foo/Bar/0");
Mockito.when(groupState.acquireNewSegmentsIfNeeded(0L))
.thenReturn(ImmutableMap.of(segment, 0L))
.thenReturn(Collections.emptyMap());
SegmentOutputStream stream = segmentStreamFactory.createOutputStreamForSegment(segment, segmentSealedCallback,
writerConfig);
SegmentMetadataClient metadataClient = segmentStreamFactory.createSegmentMetadataClient(segment);
ByteBuffer buffer1 = writeInt(stream, 1);
ByteBuffer buffer2 = writeInt(stream, 2);
ByteBuffer buffer3 = writeInt(stream, 3);
long length = metadataClient.fetchCurrentSegmentLength();
assertEquals(0, length % 3);
EventRead<byte[]> event1 = reader.readNextEvent(0);
assertEquals(buffer1, ByteBuffer.wrap(event1.getEvent()));
metadataClient.truncateSegment(segment, length / 3);
assertEquals(buffer2, ByteBuffer.wrap(reader.readNextEvent(0).getEvent()));
metadataClient.truncateSegment(segment, length);
ByteBuffer buffer4 = writeInt(stream, 4);
AssertExtensions.assertThrows(TruncatedDataException.class, () -> reader.readNextEvent(0));
assertEquals(buffer4, ByteBuffer.wrap(reader.readNextEvent(0).getEvent()));
assertNull(reader.readNextEvent(0).getEvent());
AssertExtensions.assertThrows(NoSuchEventException.class, () -> reader.fetchEvent(event1.getEventPointer()));
reader.close();
}
示例9: readNextItem
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
@SneakyThrows
private void readNextItem(Consumer<ReadItem> eventHandler) {
EventRead<byte[]> readResult = READ_RETRY.run(() -> getReader().readNextEvent(ClientReader.this.testConfig.getTimeout().toMillis()));
if (readResult.getEvent() == null) {
// We are done.
close();
return;
}
StreamReadItem readItem = toReadItem(readResult.getEvent(), readResult.getEventPointer());
eventHandler.accept(readItem);
}
示例10: readEventsAndVerify
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
private void readEventsAndVerify(int startInclusive, int endExclusive) {
log.info("Read and Verify events between [{},{})", startInclusive, endExclusive);
final List<CompletableFuture<List<EventRead<Integer>>>> readResults = new ArrayList<>();
//start reading using configured number of readers
for (int i = 0; i < NUMBER_OF_READERS; i++) {
readResults.add(asyncReadEvents("reader-" + i));
}
//results from all readers
List<List<EventRead<Integer>>> results = Futures.allOfWithResults(readResults).join();
List<EventRead<Integer>> eventsRead = results.stream().flatMap(List::stream).collect(Collectors.toList());
verifyEvents(eventsRead, startInclusive, endExclusive);
}
示例11: asyncReadEvents
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
private CompletableFuture<List<EventRead<Integer>>> asyncReadEvents(final String readerId) {
CompletableFuture<List<EventRead<Integer>>> result = CompletableFuture.supplyAsync(
() -> readEvents(readerId), readerExecutor);
Futures.exceptionListener(result,
t -> log.error("Error observed while reading events for reader id :{}", readerId, t));
return result;
}
示例12: verifyEvents
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
private void verifyEvents(final List<EventRead<Integer>> events, int startInclusive, int endExclusive) {
Supplier<Stream<Integer>> streamSupplier = () -> events.stream().map(i -> i.getEvent()).sorted();
IntSummaryStatistics stats = streamSupplier.get().collect(Collectors.summarizingInt(value -> value));
assertTrue(String.format("Check for first event: %d, %d", stats.getMin(), startInclusive),
stats.getMin() == startInclusive);
assertTrue(String.format("Check for last event: %d, %d", stats.getMax(), endExclusive),
stats.getMax() == endExclusive - 1);
//Check for missing events
assertEquals(String.format("Check for number of events: %d, %d, %d", endExclusive, startInclusive, stats.getCount()),
endExclusive - startInclusive, stats.getCount());
assertEquals(String.format("Check for duplicate events: %d, %d, %d", endExclusive, startInclusive, streamSupplier.get().distinct().count()),
endExclusive - startInclusive, streamSupplier.get().distinct().count());
}
示例13: readEvents
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
private <T extends Serializable> List<EventRead<T>> readEvents(final String readerId) {
List<EventRead<T>> events = new ArrayList<>();
try (ClientFactory clientFactory = ClientFactory.withScope(SCOPE, controllerURI);
EventStreamReader<T> reader = clientFactory.createReader(readerId,
READER_GROUP_NAME,
new JavaSerializer<T>(),
readerConfig)) {
log.info("Reading events from {}/{} with readerId: {}", SCOPE, STREAM, readerId);
EventRead<T> event = null;
do {
try {
event = reader.readNextEvent(READ_TIMEOUT);
if (event.getEvent() != null) {
log.info("Read event {}", event.getEvent());
events.add(event);
}
if (event.isCheckpoint()) {
log.info("Read a check point event, checkpointName: {}", event.getCheckpointName());
}
} catch (ReinitializationRequiredException e) {
log.error("Exception while reading event using readerId: {}", readerId, e);
fail("Reinitialization Exception is not expected");
}
} while (event.isCheckpoint() || event.getEvent() != null);
//stop reading if event read(non-checkpoint) is null.
log.info("No more events from {}/{} for readerId: {}", SCOPE, STREAM, readerId);
} //reader.close() will automatically invoke ReaderGroup#readerOffline(String, Position)
return events;
}
示例14: run
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
@Override
public void run(SourceContext<T> ctx) throws Exception {
final String readerId = getRuntimeContext().getTaskNameWithSubtasks();
log.info("{} : Creating Pravega reader with ID '{}' for controller URI: {}",
getRuntimeContext().getTaskNameWithSubtasks(), readerId, this.controllerURI);
try (EventStreamReader<T> pravegaReader = createPravegaReader(
this.scopeName,
this.controllerURI,
readerId,
this.readerGroupName,
this.deserializationSchema,
ReaderConfig.builder().build())) {
log.info("Starting Pravega reader '{}' for controller URI {}", readerId, this.controllerURI);
// main work loop, which this task is running
while (this.running) {
final EventRead<T> eventRead = pravegaReader.readNextEvent(eventReadTimeout);
final T event = eventRead.getEvent();
// emit the event, if one was carried
if (event != null) {
if (this.deserializationSchema.isEndOfStream(event)) {
// Found stream end marker.
// TODO: Handle scenario when reading from multiple segments. This will be cleaned up as part of:
// https://github.com/pravega/pravega/issues/551.
log.info("Reached end of stream for reader: {}", readerId);
return;
}
synchronized (ctx.getCheckpointLock()) {
ctx.collect(event);
}
}
// if the read marks a checkpoint, trigger the checkpoint
if (eventRead.isCheckpoint()) {
triggerCheckpoint(eventRead.getCheckpointName());
}
}
}
}
示例15: readNextEvent
import io.pravega.client.stream.EventRead; //导入依赖的package包/类
@Override
@SneakyThrows(value = InterruptedException.class)
public EventRead<T> readNextEvent(long timeout) throws ReinitializationRequiredException {
T event = queue.poll(timeout, TimeUnit.MILLISECONDS);
return new EventReadImpl<>(null, event, null, null, null);
}