io.vlingo.common.Completes Java Examples

The following examples show how to use io.vlingo.common.Completes. 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: InMemoryStateStoreEntryReaderActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  testWorld = TestWorld.startWithDefaults("test-store");
  world = testWorld.world();

  interest = new MockStateStoreResultInterest();
  dispatcher = new MockStateStoreDispatcher(interest);

  final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(world);
  entryAdapterProvider = new EntryAdapterProvider(world);

  stateAdapterProvider.registerAdapter(Entity1.class, new Entity1StateAdapter());
  // NOTE: No adapter registered for Entity2.class because it will use the default

  store = world.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(dispatcher));

  final Completes<StateStoreEntryReader<TextEntry>> completes = store.entryReader("test");
  reader = completes.await();

  StateTypeStateStoreMap.stateTypeToStoreName(Entity1.class, Entity1.class.getSimpleName());
  StateTypeStateStoreMap.stateTypeToStoreName(Entity2.class, Entity2.class.getSimpleName());
}
 
Example #2
Source File: InMemoryObjectStoreEntryReaderActor.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public Completes<String> seekTo(final String id) {
  final String currentId;

  switch (id) {
  case Beginning:
    rewind();
    currentId = readCurrentId();
    break;
  case End:
    end();
    currentId = readCurrentId();
    break;
  case Query:
    currentId = readCurrentId();
    break;
  default:
    to(id);
    currentId = readCurrentId();
    break;
  }

  return completes().with(currentId);
}
 
Example #3
Source File: ResourceBuilderTest.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void simpleRoute() {
  final DynamicResource resource = (DynamicResource) resource("userResource",
      get("/helloWorld").handle(() -> Completes.withSuccess((Response.of(Ok, serialized("Hello World"))))),
      post("/post/{postId}")
        .param(String.class)
        .body(UserData.class)
        .handle((RequestHandler2.Handler2<String, UserData>) (postId, userData) -> Completes.withSuccess(Response.of(Ok, serialized(postId))))
    );

  assertNotNull(resource);
  assertEquals("userResource", resource.name);
  assertEquals(10, resource.handlerPoolSize);
  assertEquals(2, resource.handlers.size());
}
 
Example #4
Source File: Stock.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
static Completes<StockState> unload(final Stage stage, final Location location, final ItemId itemId, final Integer quantity) {
    return StockQueryProvider.instance()
            .queries().queryByLocation(location)
            .andThenTo(state -> {
                final Address address = stage.addressFactory().from(state.stockId().value);
                return stage.actorOf(Stock.class, address);
            })
            .andThenTo(stock -> stock.unload(itemId, quantity));
}
 
Example #5
Source File: JournalReader__Proxy.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public Completes<Stream> streamAll() {
  if (!actor.isStopped()) {
    final SerializableConsumer<JournalReader> consumer = (actor) -> actor.streamAll();
    final io.vlingo.common.Completes<Stream> completes = new BasicCompletes<>(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, JournalReader.class, consumer, Returns.value(completes), sizeRepresentation7); }
    else { mailbox.send(new LocalMessage<JournalReader>(actor, JournalReader.class, consumer, Returns.value(completes), sizeRepresentation7)); }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, sizeRepresentation7));
  }
  return null;
}
 
Example #6
Source File: Server__Proxy.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<Boolean> shutDown() {
  if (!actor.isStopped()) {
    final SerializableConsumer<Server> consumer = (actor) -> actor.shutDown();
    final Completes<Boolean> completes = new BasicCompletes<>(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, Server.class, consumer, Returns.value(completes), shutDownRepresentation1); }
    else { mailbox.send(new LocalMessage<Server>(actor, Server.class, consumer, Returns.value(completes), shutDownRepresentation1)); }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, shutDownRepresentation1));
  }
  return null;
}
 
Example #7
Source File: RetryReaderActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<Entry<String>> readOne() {
    // Simulate failed read of one entry
    final Entry<String> entry = null;
    final List<Long> gapIds = reader().detectGaps(entry, offset);
    GappedEntries<Entry<String>> gappedEntries = new GappedEntries<>(new ArrayList<>(), gapIds, completesEventually());

    reader().readGaps(gappedEntries, 3, 10L, this::readIds);
    offset++;

    return completes();
}
 
Example #8
Source File: UserResourceFluent.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
public Completes<Response> queryUsers() {
  final List<UserData> users = new ArrayList<>();
  for (final User.State userState : repository.users()) {
    users.add(UserData.from(userState));
  }
  return Completes.withSuccess(Response.of(Ok, serialized(users)));
}
 
Example #9
Source File: Router.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected <T1, T2, T3, T4, R extends Completes<?>> R dispatchQuery(final PentaFunction<P, T1, T2, T3, T4, R> query, final T1 routable1, final T2 routable2, final T3 routable3, final T4 routable4) {
  final CompletesEventually completesEventually = completesEventually();
  routingFor(routable1, routable2)
    .first() //by default, for protocols with a return value, route only to first routee
    .receiveQuery(query, routable1, routable2, routable3, routable4)
    .andFinallyConsume(completesEventually::with);
  return (R) completes(); //this is a fake out; the real completes doesn't happen until inside the lambda
}
 
Example #10
Source File: JournalReader__Proxy.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public io.vlingo.common.Completes<T> readNext() {
  if (!actor.isStopped()) {
    final SerializableConsumer<JournalReader> consumer = (actor) -> actor.readNext();
    final io.vlingo.common.Completes<T> completes = new BasicCompletes<>(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, JournalReader.class, consumer, Returns.value(completes), readNextRepresentation4); }
    else { mailbox.send(new LocalMessage<JournalReader>(actor, JournalReader.class, consumer, Returns.value(completes), readNextRepresentation4)); }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, readNextRepresentation4));
  }
  return null;
}
 
Example #11
Source File: CartActor.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<List<CartItem>> addItem(ProductId productId) {
    return apply(CartEvents
            .ProductQuantityChangeEvent
            .with(state.cartId,
                    state.userId,
                    productId,
                    1,
                    state.calcNewQuantityByProductId(productId, 1)),
            () -> state.getCartItems());
}
 
Example #12
Source File: OrganizationResource.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Answer the eventual {@code Response} of defining a new Organization.
 * @return {@code Completes<Response>}
 */
public Completes<Response> defineOrganization() {
  final String id = id();
  final String uri = "/organizations/" + id;
  
  world.defaultLogger().debug(getClass().getSimpleName() + ": startOrganization(): " + uri);
  
  return Completes.withSuccess(Response.of(Created, headers(of(Location, uri)), id));
}
 
Example #13
Source File: InMemoryJournalActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <ET extends Entry<?>> Completes<JournalReader<ET>> journalReader(final String name) {
  final JournalReader<ET> inmemory = (JournalReader<ET>) journal.journalReader(name).outcome();
  final JournalReader<ET> actor = childActorFor(JournalReader.class, Definition.has(InMemoryJournalReaderActor.class, new InMemoryJournalReaderInstantiator<>(inmemory, entryAdapterProvider)));
  return completes().with(actor);
}
 
Example #14
Source File: CompletesActorProtocolTest.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<Integer> getOne() {
  try {
    Thread.sleep(100);
  } catch (InterruptedException e) {
    // ignore
  }
  return completes().with(new Integer(1));
}
 
Example #15
Source File: ServerActor.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
@Override
    public void closeWith(final RequestResponseContext<?> requestResponseContext, final Object data) {
//    logger().debug("===================== CLOSE WITH: " + data);
      if (data != null) {
        final Request request = filters.process((Request) data);
        final Completes<Response> completes = responseCompletes.of(requestResponseContext, /*request,*/ false, request.headers.headerOf(RequestHeader.XCorrelationID), true);
        final Context context = new Context(requestResponseContext, request, world.completesFor(Returns.value(completes)));
        dispatcher.dispatchFor(context);
      }
    }
 
Example #16
Source File: Space__Proxy.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public <T>io.vlingo.common.Completes<io.vlingo.lattice.grid.spaces.KeyItem<T>> put(io.vlingo.lattice.grid.spaces.Key arg0, io.vlingo.lattice.grid.spaces.Item<T> arg1) {
  if (!actor.isStopped()) {
    ActorProxyBase<Space> self = this;
    final SerializableConsumer<Space> consumer = (actor) -> actor.put(ActorProxyBase.thunk(self, (Actor)actor, arg0), ActorProxyBase.thunk(self, (Actor)actor, arg1));
    final io.vlingo.common.Completes<io.vlingo.lattice.grid.spaces.KeyItem<T>> returnValue = Completes.using(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, Space.class, consumer, Returns.value(returnValue), putRepresentation2); }
    else { mailbox.send(new LocalMessage<Space>(actor, Space.class, consumer, Returns.value(returnValue), putRepresentation2)); }
    return returnValue;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, putRepresentation2));
  }
  return null;
}
 
Example #17
Source File: FluentTestResource.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
public Completes<Response> queryRes(final String resId) {
  final Data data = entities.get(resId);

  return Completes.withSuccess(data == null ?
          Response.of(NotFound) :
          Response.of(Ok, serialized(data)));
}
 
Example #18
Source File: StateStore__Proxy.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<Stream> streamSomeUsing(final QueryExpression query) {
  if (!actor.isStopped()) {
    final SerializableConsumer<StateStore> consumer = (actor) -> actor.streamSomeUsing(query);
    final Completes<Stream> completes = new BasicCompletes<>(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, StateStore.class, consumer, Returns.value(completes), streamSomeUsingRepresentation5); }
    else { mailbox.send(new LocalMessage<StateStore>(actor, StateStore.class, consumer, Returns.value(completes), streamSomeUsingRepresentation5)); }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, streamSomeUsingRepresentation5));
  }
  return null;
}
 
Example #19
Source File: RequestHandler0.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected Completes<Response> execute(final Request request,
                            final Action.MappedParameters mappedParameters,
                            final Logger logger) {
  final Completes<Response> response = execute(request, logger);
  return response;
}
 
Example #20
Source File: CalculatorActor.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<Double> calculate() {
  state.completes = completesEventually();
  for (int start = 0; start < state.totalMessages; ++start) {
    calculatePartition(start);
  }
  return completes();
}
 
Example #21
Source File: RequestHandler3.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
Completes<Response> execute(final Request request,
final T param1,
final R param2,
final U param3,
final MediaTypeMapper mediaTypeMapper,
final ErrorHandler errorHandler,
final Logger logger);
 
Example #22
Source File: StateStoreEntryReader__Proxy.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public io.vlingo.common.Completes<T> readNext(java.lang.String arg0) {
  if (!actor.isStopped()) {
    final SerializableConsumer<StateStoreEntryReader> consumer = (actor) -> actor.readNext(arg0);
    final io.vlingo.common.Completes<T> completes = new BasicCompletes<>(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, StateStoreEntryReader.class, consumer, Returns.value(completes), readNextRepresentation6); }
    else { mailbox.send(new LocalMessage<StateStoreEntryReader>(actor, StateStoreEntryReader.class, consumer, Returns.value(completes), readNextRepresentation6)); }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, readNextRepresentation6));
  }
  return null;
}
 
Example #23
Source File: ServerActor.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Completes<Boolean> startUp() {
  if (requestMissingContentTimeout > 0) {
    stage().scheduler().schedule(selfAs(Scheduled.class), null, 1000L, requestMissingContentTimeout);
  }

  return completes().with(true);
}
 
Example #24
Source File: StateStoreEntryReader__Proxy.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<Stream> streamAll() {
  if (!actor.isStopped()) {
    final SerializableConsumer<StateStoreEntryReader> consumer = (actor) -> actor.streamAll();
    final io.vlingo.common.Completes<Stream> completes = new BasicCompletes<>(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, StateStoreEntryReader.class, consumer, Returns.value(completes), streamAllRepresentation10); }
    else { mailbox.send(new LocalMessage<StateStoreEntryReader>(actor, StateStoreEntryReader.class, consumer, Returns.value(completes), streamAllRepresentation10)); }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, streamAllRepresentation10));
  }
  return null;
}
 
Example #25
Source File: Space__Proxy.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public <T>io.vlingo.common.Completes<T> itemFor(java.lang.Class<T> arg0, java.lang.Class<? extends io.vlingo.actors.Actor> arg1, java.lang.Object... arg2) {
  if (!actor.isStopped()) {
    ActorProxyBase<Space> self = this;
    final SerializableConsumer<Space> consumer = (actor) -> actor.itemFor(ActorProxyBase.thunk(self, (Actor)actor, arg0), ActorProxyBase.thunk(self, (Actor)actor, arg1), ActorProxyBase.thunk(self, (Actor)actor, arg2));
    final io.vlingo.common.Completes<T> returnValue = Completes.using(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, Space.class, consumer, Returns.value(returnValue), itemForRepresentation4); }
    else { mailbox.send(new LocalMessage<Space>(actor, Space.class, consumer, Returns.value(returnValue), itemForRepresentation4)); }
    return returnValue;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, itemForRepresentation4));
  }
  return null;
}
 
Example #26
Source File: OrganizationResource.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
public Completes<Response> enableOrganization(String organizationId) {
  return Completes.withSuccess(Response.of(Ok, "enabled"));
}
 
Example #27
Source File: BroadcastRouter.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected <T1, T2, R extends Completes<?>> R dispatchQuery(TriFunction<P, T1, T2, R> query, T1 routable1, T2 routable2) {
  throw new UnsupportedOperationException("query protocols are not supported by this router by default");
}
 
Example #28
Source File: OrganizationEntity.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Completes<OrganizationState> defineWith(final String name, final String description) {
  return apply(new OrganizationDefined(this.state.organizationId, name, description), () -> state);
}
 
Example #29
Source File: FileProcessorActor.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Completes<ResultType> process(String path) {
  tracking.put(path, completesEventually());
  FileStabilityChecker.bySize(stage(), recheckInterval, retries).determineStability(path, interest);
  return completes();
}
 
Example #30
Source File: UserResource.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
public Completes<Response> changeContact(final String userId, final ContactData contactData) {
  return stage.actorOf(User.class, addressFactory.from(userId))
    .andThenTo(user -> user.withContact(new Contact(contactData.emailAddress, contactData.telephoneNumber)))
    .andThenTo(userState -> Completes.withSuccess(Response.of(Ok, serialized(UserData.from(userState)))))
    .otherwise(noUser -> Response.of(NotFound, userLocation(userId)));
}