Java Code Examples for io.vlingo.common.Completes#using()

The following examples show how to use io.vlingo.common.Completes#using() . 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: 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<java.util.Optional<io.vlingo.lattice.grid.spaces.KeyItem<T>>> get(io.vlingo.lattice.grid.spaces.Key arg0, io.vlingo.lattice.grid.spaces.Period arg1) {
  if (!actor.isStopped()) {
    ActorProxyBase<Space> self = this;
    final SerializableConsumer<Space> consumer = (actor) -> actor.get(ActorProxyBase.thunk(self, (Actor)actor, arg0), ActorProxyBase.thunk(self, (Actor)actor, arg1));
    final io.vlingo.common.Completes<java.util.Optional<io.vlingo.lattice.grid.spaces.KeyItem<T>>> returnValue = Completes.using(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, Space.class, consumer, Returns.value(returnValue), getRepresentation1); }
    else { mailbox.send(new LocalMessage<Space>(actor, Space.class, consumer, Returns.value(returnValue), getRepresentation1)); }
    return returnValue;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, getRepresentation1));
  }
  return null;
}
 
Example 2
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 3
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<java.util.Optional<io.vlingo.lattice.grid.spaces.KeyItem<T>>> take(io.vlingo.lattice.grid.spaces.Key arg0, io.vlingo.lattice.grid.spaces.Period arg1) {
  if (!actor.isStopped()) {
    ActorProxyBase<Space> self = this;
    final SerializableConsumer<Space> consumer = (actor) -> actor.take(ActorProxyBase.thunk(self, (Actor)actor, arg0), ActorProxyBase.thunk(self, (Actor)actor, arg1));
    final io.vlingo.common.Completes<java.util.Optional<io.vlingo.lattice.grid.spaces.KeyItem<T>>> returnValue = Completes.using(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, Space.class, consumer, Returns.value(returnValue), takeRepresentation3); }
    else { mailbox.send(new LocalMessage<Space>(actor, Space.class, consumer, Returns.value(returnValue), takeRepresentation3)); }
    return returnValue;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, takeRepresentation3));
  }
  return null;
}
 
Example 4
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 5
Source File: MultiConfirming__Proxy.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<List<Projectable>> managedConfirmations() {
  if (!actor.isStopped()) {
    final SerializableConsumer<MultiConfirming> consumer = (actor) -> actor.managedConfirmations();
    final Completes<List<Projectable>> returnValue = Completes.using(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, MultiConfirming.class, consumer, Returns.value(returnValue), managedConfirmationsRepresentation2); }
    else { mailbox.send(new LocalMessage<MultiConfirming>(actor, MultiConfirming.class, consumer, Returns.value(returnValue), managedConfirmationsRepresentation2)); }
    return returnValue;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, managedConfirmationsRepresentation2));
  }
  return null;
}
 
Example 6
Source File: CommandRouterTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  world = World.startWithDefaults("test-command-router");
  address = world.addressFactory().unique();
  world.stage().actorFor(Solver.class, Definition.has(SolverActor.class, Definition.NoParameters), address);
  completes = Completes.using(world.stage().scheduler());
}
 
Example 7
Source File: Client.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Answer a {@code Completes<Respose>} as the eventual outcomes of the {@code request}.
 * @param request the Request to the server
 * @return {@code Completes<Respose>}
 */
public Completes<Response> requestWith(final Request request) {
  final Completes<Response> completes =
          configuration.keepAlive ?
                  Completes.repeatableUsing(configuration.stage.scheduler()) :
                  Completes.using(configuration.stage.scheduler());
  request.headers.and(RequestHeader.Connection, (configuration.keepAlive ? Header.ValueKeepAlive : Header.ValueClose));
  consumer.requestWith(request, completes);
  return completes;
}
 
Example 8
Source File: DirectoryScanner__Proxy.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public <T> Completes<T> actorOf(final java.lang.Class<T> arg0, final io.vlingo.actors.Address arg1) {
  if (!actor.isStopped()) {
    final SerializableConsumer<DirectoryScanner> consumer = (actor) -> actor.actorOf(arg0, arg1);
    final Completes<T> completes = Completes.using(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, DirectoryScanner.class, consumer, Returns.value(completes), actorOfRepresentation1); }
    else { mailbox.send(new LocalMessage<DirectoryScanner>(actor, DirectoryScanner.class, consumer, Returns.value(completes), actorOfRepresentation1)); }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, actorOfRepresentation1));
  }
  return null;
}
 
Example 9
Source File: DirectoryScanner__Proxy.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public <T> Completes<T> actorOf(final java.lang.Class<T> arg0, final io.vlingo.actors.Address arg1, final io.vlingo.actors.Definition arg2) {
  if (!actor.isStopped()) {
    final SerializableConsumer<DirectoryScanner> consumer = (actor) -> actor.actorOf(arg0, arg1, arg2);
    final Completes<T> completes = Completes.using(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, DirectoryScanner.class, consumer, Returns.value(completes), actorOfRepresentation2); }
    else { mailbox.send(new LocalMessage<DirectoryScanner>(actor, DirectoryScanner.class, consumer, Returns.value(completes), actorOfRepresentation2)); }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, actorOfRepresentation2));
  }
  return null;
}
 
Example 10
Source File: DirectoryScanner__Proxy.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public <T> Completes<Optional<T>> maybeActorOf(final Class<T> arg0, final Address arg1) {
  if (!actor.isStopped()) {
    final SerializableConsumer<DirectoryScanner> consumer = (actor) -> actor.maybeActorOf(arg0, arg1);
    final Completes<Optional<T>> completes = Completes.using(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, DirectoryScanner.class, consumer, Returns.value(completes), maybeActorOfRepresentation3); }
    else { mailbox.send(new LocalMessage<DirectoryScanner>(actor, DirectoryScanner.class, consumer, Returns.value(completes), maybeActorOfRepresentation3)); }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, maybeActorOfRepresentation3));
  }
  return null;
}
 
Example 11
Source File: CommandRouterTest.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testThatPartitioningRouterPartitions() {
  final int totalPartitions = 5;
  final int totalTimes = totalPartitions * 2;

  final Completes<Stuff>[] completes = new Completes[totalTimes];

  final CommandRouter router = CommandRouter.of(world.stage(), Type.Partitioning, totalPartitions);

  final Result result = new Result();

  final SolverHandler[] solverHandlers = new SolverHandler[totalPartitions];

  for (int idx = 0; idx < totalPartitions; ++idx) {
    solverHandlers[idx] = SolverHandler.newInstance(result);
  }

  for (int idx = 0; idx < totalTimes; ++idx) {
    completes[idx] = Completes.using(world.stage().scheduler());

    final SolverHandler partitionSolverHandler = solverHandlers[idx % totalPartitions];

    final RoutableCommand<Solver,SolveStuff,Completes<Stuff>> command =
            RoutableCommand
              .speaks(Solver.class)
              .to(SolverActor.class)
              .at(address.idString())
              .delivers(SolveStuff.with("" + idx, 21))
              .answers(completes[idx])
              .handledBy(partitionSolverHandler);

    router.route(command);
  }

  for (int idx = 0; idx < totalTimes; ++idx) {
    final Stuff stuff = completes[idx].await();

    assertEquals(42, stuff.value);
  }

  for (int handlerId = 0; handlerId < totalPartitions; ++handlerId) {
    assertEquals(2, result.countOf(handlerId));
  }
}
 
Example 12
Source File: CommandRouterTest.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testThatRoundRobinRouterRoutesToAll() {
  final int totalRoutees = 5;
  final int totalTimes = totalRoutees * 3;

  final Completes<Stuff>[] completes = new Completes[totalTimes];

  final CommandRouter router = CommandRouter.of(world.stage(), Type.RoundRobin, totalRoutees);

  final Result result = new Result();

  final SolverHandler[] solverHandlers = new SolverHandler[totalRoutees];

  for (int idx = 0; idx < totalRoutees; ++idx) {
    solverHandlers[idx] = SolverHandler.newInstance(result);
  }

  for (int idx = 0; idx < totalTimes; ++idx) {
    completes[idx] = Completes.using(world.stage().scheduler());

    final SolverHandler roundRobinSolverHandler = solverHandlers[idx % totalRoutees];

    final RoutableCommand<Solver,SolveStuff,Completes<Stuff>> command =
            RoutableCommand
              .speaks(Solver.class)
              .to(SolverActor.class)
              .at(address.idString())
              .delivers(SolveStuff.with("" + idx, 21))
              .answers(completes[idx])
              .handledBy(roundRobinSolverHandler);

    router.route(command);
  }

  for (int idx = 0; idx < totalTimes; ++idx) {
    final Stuff stuff = completes[idx].await();

    assertEquals(42, stuff.value);
  }

  for (int handlerId = 0; handlerId < totalRoutees; ++handlerId) {
    assertEquals(3, result.countOf(handlerId));
  }
}
 
Example 13
Source File: CommandRouterTest.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testThatLoadBalancingRouterRoutesEvenly() {
  final int totalRoutees = 2;
  final int totalTimes = totalRoutees * 10;

  final Completes<Stuff>[] completes = new Completes[totalTimes];

  final CommandRouter router = CommandRouter.of(world.stage(), Type.LoadBalancing, totalRoutees);

  final Result result = new Result();

  final SolverHandler[] solverHandlers = new SolverHandler[totalRoutees];

  for (int idx = 0; idx < totalRoutees; ++idx) {
    solverHandlers[idx] = SolverHandler.newInstance(result);
  }

  for (int idx = 0; idx < totalTimes; ++idx) {
    completes[idx] = Completes.using(world.stage().scheduler());

    final SolverHandler loadBalancingSolverHandler = solverHandlers[idx % totalRoutees];

    final RoutableCommand<Solver,SolveStuff,Completes<Stuff>> command =
            RoutableCommand
              .speaks(Solver.class)
              .to(SolverActor.class)
              .at(address.idString())
              .delivers(SolveStuff.with("" + idx, 21))
              .answers(completes[idx])
              .handledBy(loadBalancingSolverHandler);

    router.route(command);
  }

  for (int idx = 0; idx < totalTimes; ++idx) {
    final Stuff stuff = completes[idx].await();

    assertEquals(42, stuff.value);
  }

  // NOTE: It is difficult to impossible to predict which of the
  // routees will have routed equal or more commands. Rather than
  // attempt that ensure that all commands have been handled.
  int totalCounts = 0;
  for (int handlerId = 0; handlerId < totalRoutees; ++handlerId) {
    totalCounts += result.countOf(handlerId);
  }
  assertEquals(totalTimes, totalCounts);
}