io.vlingo.actors.CompletesEventually Java Examples

The following examples show how to use io.vlingo.actors.CompletesEventually. 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: GapRetryReader.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void intervalSignal(Scheduled<RetryGappedEntries<T>> scheduled, RetryGappedEntries<T> data) {
    Function<List<Long>, List<T>> gappedReader = data.gappedReader;
    List<T> fillups = gappedReader.apply(data.gappedEntries.getGapIds());
    GappedEntries<T> nextGappedEntries = data.gappedEntries.fillupWith(fillups);

    if (!nextGappedEntries.containGaps() || !data.moreRetries()) {
        CompletesEventually eventually = data.gappedEntries.getEventually();
        if (nextGappedEntries.size() == 1) {
            // Only one entry has to be returned.
            // {@link EntryReader<T>} - read one Entry<T> method.
            eventually.with(nextGappedEntries.getFirst().orElse(null));
        } else {
            // {@link EntryReader<T>} - read a list of Entry<T>
            eventually.with(nextGappedEntries.getSortedLoadedEntries());
        }
    } else {
        RetryGappedEntries<T> nextData = data.nextRetry(nextGappedEntries);
        scheduler().scheduleOnce(scheduled, nextData, 0L, data.retryInterval);
    }
}
 
Example #2
Source File: PooledCompletesProviderTest.java    From vlingo-actors with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testCompletesAddressMatches() {
  ConfigureWorldWithPooledCompletes();

  final MockCompletes<Object> clientCompletes1 = new MockCompletes<>(1);
  final MockCompletes<Object> clientCompletes2 = new MockCompletes<>(1);

  final CompletesEventually completes1 = world.completesFor(Returns.value(clientCompletes1));
  completes1.with(5);

  final CompletesEventually completes2 = world.completesFor(completes1.address(), Returns.value(clientCompletes2));
  completes2.with(10);

  assertEquals(1, clientCompletes1.getWithCount());
  assertEquals(5, clientCompletes1.outcome());
  assertEquals(1, clientCompletes2.getWithCount());
  assertEquals(10, clientCompletes2.outcome());
  assertEquals(completes1, completes2);
}
 
Example #3
Source File: StateStoreQueryActor.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private <T, R> Completes<Collection<R>> queryAllOf(final Class<T> type, final Collection<R> all) {
  final Consumer<StateBundle> populator = (StateBundle state) -> {
    all.add((R) state.object);
  };

  final CompletesEventually completes = completesEventually();
  final Consumer<Collection<R>> collector = (Collection<R> collected) -> {
    completes.with(collected);
  };

  final TerminalOperationConsumerSink sink =
          new TerminalOperationConsumerSink(populator, all, collector);

  stateStore.streamAllOf(type).andFinallyConsume(stream -> stream.flowInto(sink));

  return completes();
}
 
Example #4
Source File: PooledCompletesProviderTest.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testFuture() throws ExecutionException, InterruptedException {
  ConfigureWorldWithPooledCompletes();

  final CompletableFuture<Integer> completableFuture = new CompletableFuture<>();

  final CompletesEventually completes1 = world.completesFor(Returns.value(completableFuture));
  completes1.with(5);

  assertEquals(5, completableFuture.get().intValue());
}
 
Example #5
Source File: PooledCompletesProviderTest.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testCompletableFuture() throws ExecutionException, InterruptedException {
  ConfigureWorldWithPooledCompletes();

  final CompletableFuture<Integer> completableFuture = new CompletableFuture<>();

  final CompletesEventually completes1 = world.completesFor(Returns.value(completableFuture));
  completes1.with(5);

  assertEquals(5, completableFuture.get().intValue());
}
 
Example #6
Source File: PooledCompletesProviderTest.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testActuallyCompletes() {
  ConfigureWorldWithPooledCompletes();

  final MockCompletes<Object> clientCompletes = new MockCompletes<>(1);

  final CompletesEventually asyncCompletes = world.completesFor(Returns.value(clientCompletes));
  asyncCompletes.with(5);

  assertEquals(1, clientCompletes.getWithCount());
  assertEquals(5, clientCompletes.outcome());
}
 
Example #7
Source File: ExpirableQuery.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
ExpirableQuery(final Key key, final boolean retainItem, final Instant expiresOn, final Period period, final CompletesEventually completes) {
  this.key = key;
  this.retainItem = retainItem;
  this.expiresOn = expiresOn;
  this.period = period;
  this.completes = completes;
}
 
Example #8
Source File: ClientCorrelatingRequesterConsumerActor.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * @see io.vlingo.wire.channel.ResponseChannelConsumer#consume(io.vlingo.wire.message.ConsumerByteBuffer)
 */
@Override
public void consume(final ConsumerByteBuffer buffer) {
  try {
    if (state.parser == null) {
      state.parser = ResponseParser.parserFor(buffer.asByteBuffer());
    } else {
      state.parser.parseNext(buffer.asByteBuffer());
    }

    while (state.parser.hasFullResponse()) {
      final Response response = state.parser.fullResponse();
      final ResponseHeader correlationId = response.headers.headerOfOrDefault(ResponseHeader.XCorrelationID, state.correlationId);
      if (correlationId == null) {
        logger().warn("Client Consumer: Cannot complete response because no correlation id.");
        state.configuration.consumerOfUnknownResponses.consume(response);
      } else {
        if (state.parser.isKeepAliveConnection() && state.parser.isStreamContentType()) {
          state.correlationId = correlationId;
        }
        final CompletesEventually completes = state.configuration.keepAlive ?
                completables.get(correlationId.value) :
                completables.remove(correlationId.value);
        if (completes == null) {
          state.configuration.stage.world().defaultLogger().warn(
                  "Client Consumer: Cannot complete response because mismatched correlation id: " +
                   correlationId.value);
          state.configuration.consumerOfUnknownResponses.consume(response);
        } else {
          completes.with(response);
        }
      }
    }
  } finally {
    buffer.release();
  }
}
 
Example #9
Source File: GappedEntries.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
public GappedEntries(List<T> loadedEntries, List<Long> gapIds, CompletesEventually eventually) {
    this.loadedEntries = loadedEntries;
    this.gapIds = gapIds;
    this.eventually = eventually;
}
 
Example #10
Source File: MockCompletesEventuallyProvider.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public CompletesEventually provideCompletesFor(final Address address, final Returns<?> clientReturns) {
  ++provideCompletesForCount;
  return completesEventually;
}
 
Example #11
Source File: MockCompletesEventuallyProvider.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public CompletesEventually provideCompletesFor(final Returns<?> clientReturns) {
  ++provideCompletesForCount;
  return completesEventually;
}
 
Example #12
Source File: MockCompletesEventuallyProvider.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public CompletesEventually completesEventually() {
  return completesEventually;
}
 
Example #13
Source File: MockSseStreamResource.java    From vlingo-http with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected CompletesEventually completes() {
  return completes;
}
 
Example #14
Source File: StateStoreQueryActor.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
private <T> Completes<T> queryFor(final String id, final Class<T> type, final QueryResultHandler.ResultType resultType, final T notFoundState) {
  final CompletesEventually completes = completesEventually();
  final Consumer<T> answer = (maybeFoundState) -> completes.with(maybeFoundState);
  stateStore.read(id, type, readInterest, new QueryResultHandler<>(answer, resultType, notFoundState));
  return completes();
}
 
Example #15
Source File: PartitioningSpaceRouter.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public <T> Completes<Optional<KeyItem<T>>> take(final Key key, final Period until) {
  final CompletesEventually completes = completesEventually();
  spaceOf(key).take(key, until).andFinallyConsume(keyItem -> completes.with(keyItem));
  return completes();
}
 
Example #16
Source File: PartitioningSpaceRouter.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public <T> Completes<Optional<KeyItem<T>>> get(final Key key, final Period until) {
  final CompletesEventually completes = completesEventually();
  spaceOf(key).get(key, until).andFinallyConsume(keyItem -> completes.with(keyItem));
  return completes();
}
 
Example #17
Source File: PartitioningSpaceRouter.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public <T> Completes<KeyItem<T>> put(final Key key, final Item<T> item) {
  final CompletesEventually completes = completesEventually();
  spaceOf(key).put(key, item).andFinallyConsume(keyItem -> completes.with(keyItem));
  return completes();
}
 
Example #18
Source File: GappedEntries.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
public CompletesEventually getEventually() {
    return eventually;
}
 
Example #19
Source File: FileProcessorActor.java    From vlingo-examples with Mozilla Public License 2.0 3 votes vote down vote up
private void completeWith(final String path, final String message, final ResultType result) {
  final CompletesEventually completesEventually = tracking.remove(path);

  completesEventually.with(result);

  logger().info(message);
}
 
Example #20
Source File: Context.java    From vlingo-http with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Construct my state.
 * @param completes the CompletesEventually through which the Response is eventually provided
 */
public Context(final CompletesEventually completes) {
  this(null, completes);
}
 
Example #21
Source File: Context.java    From vlingo-http with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Construct my state.
 * @param request the Request from the client
 * @param completes the CompletesEventually through which the Response is eventually provided
 */
public Context(final Request request, final CompletesEventually completes) {
  this(null, request, completes);
}
 
Example #22
Source File: Context.java    From vlingo-http with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Construct my state.
 * @param requestResponseContext the {@code RequestResponseContext<?>} providing channel communication
 * @param request the Request from the client
 * @param completes the CompletesEventually through which the Response is eventually provided
 */
public Context(final RequestResponseContext<?> requestResponseContext, final Request request, final CompletesEventually completes) {
  this.requestResponseContext = requestResponseContext;
  this.request = request;
  this.completes = completes;
}
 
Example #23
Source File: ResourceHandler.java    From vlingo-http with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Answer my {@code completes}.
 * @return CompletesEventually
 */
protected CompletesEventually completes() {
  return context.completes;
}