io.vlingo.actors.Definition Java Examples

The following examples show how to use io.vlingo.actors.Definition. 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: ProjectionDispatcherProvider.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
public static ProjectionDispatcherProvider using(final Stage stage) {
  if (instance != null) return instance;

  final List<ProjectToDescription> descriptions =
          Arrays.asList(
                  new ProjectToDescription(UserProjectionActor.class, "User:new", "User:contact", "User:name"),
                  new ProjectToDescription(PrivateTokenSynchronizerActor.class, "User:new"),
                  new ProjectToDescription(ProfileProjectionActor.class, "Profile:new", "Profile:twitter", "Profile:linkedIn", "Profile:website"));

  final Protocols dispatcherProtocols =
          stage.actorFor(
                  new Class<?>[] { Dispatcher.class, ProjectionDispatcher.class },
                  Definition.has(TextProjectionDispatcherActor.class, Definition.parameters(descriptions)));

  final Protocols.Two<Dispatcher, ProjectionDispatcher> dispatchers = Protocols.two(dispatcherProtocols);

  instance = new ProjectionDispatcherProvider(dispatchers._1, dispatchers._2);

  return instance;
}
 
Example #2
Source File: SupervisionStrategyTest.java    From vlingo-actors with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testEscalate() {
  final EscalateSupervisorTestResults escalateSupervisorTestResults = new EscalateSupervisorTestResults();
  
  final TestActor<Supervisor> supervisor =
          testWorld.actorFor(
                  Supervisor.class,
                  Definition.has(EscalateSupervisorActor.class, Definition.parameters(escalateSupervisorTestResults), "escalate"));
  
  final FailureControlTestResults failureControlTestResults = new FailureControlTestResults();
  
  final TestActor<FailureControl> failure =
          testWorld.actorFor(
                  FailureControl.class,
                  Definition.has(FailureControlActor.class, Definition.parameters(failureControlTestResults), supervisor.actorInside(), "failure"));
  
  AccessSafely escalateAccess = escalateSupervisorTestResults.afterCompleting(1);
  AccessSafely failureAccess = failureControlTestResults.afterCompleting(1);
  
  failure.actor().failNow();
  
  assertEquals(1, (int) escalateAccess.readFrom("informedCount"));
  assertEquals(1, (int) failureAccess.readFrom("stoppedCount"));
}
 
Example #3
Source File: RingBufferMailboxActorTest.java    From vlingo-actors with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testBasicDispatch() throws Exception {
  init(MailboxSize);

  final TestResults testResults = new TestResults(MaxCount);

  final CountTaker countTaker =
          world.actorFor(
                  CountTaker.class,
                  Definition.has(CountTakerActor.class, Definition.parameters(testResults), "testRingMailbox", "countTaker-1"));

  testResults.setMaximum(MaxCount);

  for (int count = 1; count <= MaxCount; ++count) {
    countTaker.take(count);
  }

  assertEquals(MaxCount, testResults.getHighest());
}
 
Example #4
Source File: ManyToOneConcurrentArrayQueueMailboxActorTest.java    From vlingo-actors with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testBasicDispatch() {
  final TestResults testResults = new TestResults(MaxCount);

  final CountTaker countTaker =
          world.actorFor(
                  CountTaker.class,
                  Definition.has(CountTakerActor.class, Definition.parameters(testResults), "testRingMailbox", "countTaker-1"));

  final int totalCount = MailboxSize / 2;

  for (int count = 1; count <= totalCount; ++count) {
    countTaker.take(count);
  }

  assertEquals(MaxCount, testResults.getHighest());
}
 
Example #5
Source File: Deliver.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Function<io.vlingo.actors.Message, Deliver<?>> from(BiConsumer<UUID, Returns<?>> correlation) {
  return (message) -> {
    final LocalMessage<?> __message = (LocalMessage<?>) message;
    final Optional<Returns<?>> returns = Optional.ofNullable(__message.returns());

    final UUID answerCorrelationId = returns.map(_return -> {
      final UUID correlationId = UUID.randomUUID();
      correlation.accept(correlationId, _return);
      return correlationId;
    }).orElse(null);

    return new Deliver(
        __message.protocol(),
        __message.actor().address(),
        Definition.SerializationProxy.from(__message.actor().definition()),
        __message.consumer(),
        answerCorrelationId,
        __message.representation());
  };
}
 
Example #6
Source File: InMemoryObjectStoreActor.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public InMemoryObjectStoreActor(
        final List<Dispatcher<Dispatchable<BaseEntry<?>,State<?>>>> dispatchers,
        final long checkConfirmationExpirationInterval,
        final long confirmationExpiration ) {

  this.entryAdapterProvider = EntryAdapterProvider.instance(stage().world());

  this.dispatchers = dispatchers;

  this.entryReaders = new HashMap<>();

  this.storeDelegate = new InMemoryObjectStoreDelegate(StateAdapterProvider.instance(stage().world()));

  this.dispatcherControl = stage().actorFor(
          DispatcherControl.class,
          Definition.has(
                  DispatcherControlActor.class,
                  new DispatcherControlInstantiator(
                          dispatchers,
                          this.storeDelegate,
                          checkConfirmationExpirationInterval,
                          confirmationExpiration)));
}
 
Example #7
Source File: BasicSupervisionTest.java    From vlingo-actors with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testStoppingSupervisor() {
  final TestActor<Supervisor> supervisor =
          testWorld.actorFor(
                  Supervisor.class,
                  Definition.has(StoppingSupervisorActor.class, Definition.NoParameters, "stopping-supervisor"));

  final FailureControlTestResults failureControlTestResults = new FailureControlTestResults();

  final TestActor<FailureControl> failure =
          testWorld.actorFor(
                  FailureControl.class,
                  Definition.has(FailureControlActor.class, Definition.parameters(failureControlTestResults), supervisor.actorInside(), "failure-for-stop"));

  AccessSafely access = failureControlTestResults.afterCompleting(2);

  failure.actor().failNow();
  assertEquals(1, (int) access.readFrom("failNowCount"));

  failure.actor().afterFailure();
  assertEquals(1, (int) access.readFrom("stoppedCount"));
  assertEquals(0, (int) access.readFrom("afterFailureCount"));
}
 
Example #8
Source File: Accessor.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
public synchronized Space spaceFor(final String name, final int totalPartitions, final Duration defaultScanInterval) {
  if (defaultScanInterval.isNegative() || defaultScanInterval.isZero()) {
    throw new IllegalArgumentException("The defaultScanInterval must be greater than zero.");
  }

  if (!isDefined()) {
    throw new IllegalStateException("Accessor is invalid.");
  }

  Space space = spaces.get(name);

  if (space == null) {
    final Definition definition = Definition.has(PartitioningSpaceRouter.class, new PartitioningSpaceRouterInstantiator(totalPartitions, defaultScanInterval), name);
    final Space internalSpace = grid.actorFor(Space.class, definition);
    space = new SpaceItemFactoryRelay(grid, internalSpace);
    spaces.put(name, space);
  }

  return space;
}
 
Example #9
Source File: ManyToOneConcurrentArrayQueueMailboxActorTest.java    From vlingo-actors with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testOverflowDispatch() {
  final TestResults testResults = new TestResults(MaxCount);

  final CountTaker countTaker =
          world.actorFor(
                  CountTaker.class,
                  Definition.has(CountTakerActor.class, Definition.parameters(testResults), "testArrayQueueMailbox", "countTaker-2"));

  final int totalCount = MailboxSize * 2;

  for (int count = 1; count <= totalCount; ++count) {
    countTaker.take(count);
  }


  assertEquals(MaxCount, testResults.getHighest());
}
 
Example #10
Source File: OutboundGridActorControl.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void relocate(
        final Id receiver,
        final Id sender,
        final Definition.SerializationProxy definitionProxy,
        final Address address,
        final Object snapshot, List<? extends io.vlingo.actors.Message> pending) {

  final List<Deliver<?>> messages =
          pending
            .stream()
            .map(Deliver.from(correlation))
            .collect(Collectors.toList());

  send(receiver, new Relocate(address, definitionProxy, snapshot, messages));
}
 
Example #11
Source File: ProjectionDispatcherActor.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
protected ProjectionDispatcherActor(final Collection<ProjectToDescription> projectToDescriptions, final long multiConfirmationsExpiration) {
  super(projectToDescriptions);

  this.interest = selfAs(ConfirmDispatchedResultInterest.class);
  this.projectionControl = new ProjectionControl() {
    @Override
    public void confirmProjected(String projectionId) {
      if (control != null) {
        control.confirmDispatched(projectionId, interest);
      } else if (requiresDispatchedConfirmation()) {
        logger().error("WARNING: ProjectionDispatcher control is not set; unconfirmed: " + projectionId);
      }
    }
  };

  final Protocols protocols =
          childActorFor(
                  new Class[] { MultiConfirming.class, ProjectionControl.class },
                  Definition.has(MultiConfirmingProjectionControlActor.class,
                                 Definition.parameters(projectionControl, multiConfirmationsExpiration)));

  this.multiConfirming = protocols.get(0);
  this.multiConfirmingProjectionControl = protocols.get(1);
}
 
Example #12
Source File: TestkitTest.java    From vlingo-actors with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testTesterPingPong() throws Exception {
  final TestActor<PongCounter> pongCounter =
          testWorld.actorFor(
                  PongCounter.class,
                  Definition.has(PongCounterActor.class, Definition.NoParameters));
  
  final TestActor<PingCounter> pingCounter =
          testWorld.actorFor(
                  PingCounter.class,
                  Definition.has(PingPongCounterActor.class, Definition.parameters(pongCounter.actor())));
  
  pingCounter.actor().ping();
  pingCounter.actor().ping();
  pingCounter.actor().ping();
  
  assertEquals(3, TestWorld.Instance.get().allMessagesFor(pingCounter.address()).size());
  
  assertEquals(3, (int) pingCounter.viewTestState().valueOf("count"));
  
  assertEquals(3, (int) pongCounter.viewTestState().valueOf("count"));
}
 
Example #13
Source File: Order.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
static Completes<OrderState> register(final ApplicationRegistry registry,
                                      final ProductId productId,
                                      final Integer quantity,
                                      final Site site) {

    final Stage stage = registry.retrieveStage();

    final MessagingClient messagingClient = registry.retrieveMessagingClient();

    final Address address = stage.addressFactory().uniqueWith(generateName());

    final OrderId orderId = OrderId.from(address.idString());

    final Order order =
            stage.actorFor(Order.class,
                    Definition.has(OrderEntity.class, Definition.parameters(orderId)), address);

    final DomainEventNotifier notifier =
            stage.actorFor(DomainEventNotifier.class,
                    Definition.has(DomainEventNotifierActor.class, Definition.parameters(messagingClient)));

    return order.register(productId, quantity, site).andThen(newOrder -> {
        notifier.notify(new OrderWasRegistered(productId, quantity, site));
        return newOrder;
    });
}
 
Example #14
Source File: ProjectionDispatcherProvider.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
public static ProjectionDispatcherProvider using(final Stage stage) {

    if (instance == null) {
      final List<ProjectToDescription> descriptions =
              Arrays.asList(
            		  new ProjectToDescription(
            				  CartSummaryProjectionActor.class,
            				  CreatedForUser.class.getName(),
            				  ProductQuantityChangeEvent.class.getName(),
            				  AllItemsRemovedEvent.class.getName()));

      final Protocols dispatcherProtocols =
              stage.actorFor(
                      new Class<?>[]{Dispatcher.class, ProjectionDispatcher.class},
                      Definition.has(TextProjectionDispatcherActor.class, Definition.parameters(descriptions)));

      final Protocols.Two<Dispatcher, ProjectionDispatcher> dispatchers = Protocols.two(dispatcherProtocols);
      final Dispatcher storeDispatcher = dispatchers._1;
      final ProjectionDispatcher projectionDispatcher = dispatchers._2;

      instance = new ProjectionDispatcherProvider(storeDispatcher, projectionDispatcher);
    }
    return instance;
  }
 
Example #15
Source File: Server.java    From vlingo-http with Mozilla Public License 2.0 6 votes vote down vote up
public static Server startWithAgent(
        final Stage stage,
        final Resources resources,
        final Filters filters,
        final int port,
        final int dispatcherPoolSize,
        final String severMailboxTypeName) {

  final Server server = stage.actorFor(
          Server.class,
          Definition.has(
                  ServerActor.class,
                  new ServerWithAgentInstantiator(resources, filters, port, dispatcherPoolSize),
                  severMailboxTypeName,
                  ServerActor.ServerName),
          stage.world().addressFactory().withHighId(),
          stage.world().defaultLogger());

  server.startUp();

  return server;
}
 
Example #16
Source File: OrderResource.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
private Completes<ObjectResponse<String>> create(final OrderCreateRequest request) {
    final Address orderAddress = addressFactory.uniquePrefixedWith("order-");
    Map<ProductId, Integer> quantityByProductId = new HashMap<>();
    request.quantityByIdOfProduct.forEach((key, value) -> quantityByProductId.put(new ProductId(key), value));


    Order orderActor = stage.actorFor(
            Order.class,
            Definition.has(OrderActor.class,
                    Definition.parameters(orderAddress.idString())),
            orderAddress);

    orderActor.initOrderForUserProducts(request.userId, quantityByProductId);
    return Completes.withSuccess(
            ObjectResponse.of(Created,
                    headers(of(Location, urlLocation(orderAddress.idString()))),
                    ""));
}
 
Example #17
Source File: SseStreamResource.java    From vlingo-http with Mozilla Public License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public SsePublisherActor(final String streamName, final Class<? extends Actor> feedClass, final int feedPayload, final int feedInterval, final String feedDefaultId) {
  this.streamName = streamName;
  this.subscribers = new HashMap<>();

  final ActorInstantiator<?> instantiator = ActorInstantiatorRegistry.instantiatorFor(feedClass);
  if(instantiator==null)throw new IllegalArgumentException("No ActorInstantiator registred for feedClass="+feedClass.toString());
  instantiator.set("feedClass", feedClass);
  instantiator.set("streamName", streamName);
  instantiator.set("feedPayload", feedPayload);
  instantiator.set("feedDefaultId", feedDefaultId);

  this.feed = stage().actorFor(SseFeed.class, Definition.has(feedClass, instantiator));

  this.cancellable = stage().scheduler().schedule(selfAs(Scheduled.class), null, 10, feedInterval);

  logger().info("SsePublisher started for: " + this.streamName);
}
 
Example #18
Source File: Specification.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
public Specification(
        final Class<?> protocol,
        final Class<? extends Actor> type,
        final Window parent,
        final String title,
        final Rectangle rectangle,
        final boolean enabled,
        String tag,
        final Object...parameters) {

  this.protocol = protocol;
  this.rectangle = rectangle;
  this.windowInfo = new WindowInfo(parent, Id.unique(), tag, title);
  this.enabled = enabled;
  this.parameters = Arrays.asList(parameters);
  this.definition = Definition.has(type, Definition.NoParameters);
}
 
Example #19
Source File: ServerTest.java    From vlingo-http with Mozilla Public License 2.0 6 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
  super.setUp();

  User.resetId();

  skipTests = false;
  serverPort = baseServerPort.getAndIncrement();
  server = startServer();
  assertTrue(server.startUp().await(500L));

  progress = new Progress();

  consumer = world.actorFor(ResponseChannelConsumer.class, Definition.has(TestResponseChannelConsumer.class, Definition.parameters(progress)));

  client = new NettyClientRequestResponseChannel(Address.from(Host.of("localhost"), serverPort, AddressType.NONE), consumer, 100, 10240);
}
 
Example #20
Source File: CommandModelStoreProvider.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public static CommandModelStoreProvider using(final Stage stage, final StatefulTypeRegistry registry, final Dispatcher dispatcher) {
  if (instance != null) return instance;
  
  final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(stage.world());
  stateAdapterProvider.registerAdapter(UserState.class, new UserStateAdapter());
  stateAdapterProvider.registerAdapter(ProfileState.class, new ProfileStateAdapter());
  stateAdapterProvider.registerAdapter(UserData.class, new UserDataStateAdapter());
  stateAdapterProvider.registerAdapter(ProfileData.class, new ProfileDataStateAdapter());
  new EntryAdapterProvider(stage.world()); // future

  final Protocols storeProtocols =
          stage.actorFor(
                  new Class<?>[] { StateStore.class, DispatcherControl.class },
                  Definition.has(InMemoryStateStoreActor.class, Definition.parameters(Arrays.asList(dispatcher))));

  final Protocols.Two<StateStore, DispatcherControl> storeWithControl = Protocols.two(storeProtocols);

  instance = new CommandModelStoreProvider(registry, storeWithControl._1, storeWithControl._2);

  return instance;
}
 
Example #21
Source File: OrganizationResourceTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  world = World.startWithDefaults("OrganizationsResourceTest");
  
  resource = new OrganizationResource(world);
  
  serverPort = baseServerPort.getAndIncrement();
  
  server =
          Server.startWith(
                  world.stage(),
                  Resources.are(resource.routes()),
                  Filters.none(),
                  serverPort,
                  Sizing.defineWith(4, 10, 10, 1024),
                  Timing.defineWith(3, 1, 100));

  progress = new Progress();

  consumer = world.actorFor(ResponseChannelConsumer.class, Definition.has(TestResponseChannelConsumer.class, Definition.parameters(progress)));

  client = new BasicClientRequestResponseChannel(Address.from(Host.of("localhost"), serverPort, AddressType.NONE), consumer, 100, 10240, world.defaultLogger());
}
 
Example #22
Source File: Product.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
static Tuple2<ProductId, Product> defineWith(
        final Stage stage,
        final Tenant tenant,
        final ProductOwner productOwner,
        final String name,
        final String description,
        final boolean hasDiscussion) {

    assert (tenant != null && tenant.id != null);
    assert (productOwner != null && productOwner.id != null);
    assert (name != null);
    assert (description != null);

    Address address = stage.addressFactory().unique();
    final ProductId productId = ProductId.fromExisting(address.idString());
    final Definition definition = Definition.has(ProductEntity.class, Definition.parameters(tenant, productId), productId.id);
    final Product product = stage.actorFor(Product.class, definition);
    product.define(productOwner, name, description, hasDiscussion);
    return Tuple2.from(productId, product);
}
 
Example #23
Source File: Calculation.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
static Completes<CalculationState> calculate(final Stage stage,
                                             final Operation operation,
                                             final Integer anOperand,
                                             final Integer anotherOperand) {

    final Completes<Set<CalculationState>> calculations =
            CalculationQueryProvider.instance().queries().allCalculations();

    return calculations.andThenTo(existingCalculations -> {
        final Address address =
                stage.addressFactory().uniqueWith(generateName());

        final Definition definition =
                Definition.has(CalculationEntity.class, Definition.parameters(CalculationId.from(address.idString())));

        final Calculation calculation = stage.actorFor(Calculation.class, definition, address);

        return calculation.calculate(operation, anOperand, anotherOperand, existingCalculations);
    });
}
 
Example #24
Source File: SupervisionStrategyTest.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testStopAll() {
  StopAllSupervisorResult stopResults = new StopAllSupervisorResult();

  world.actorFor(
          Supervisor.class,
          Definition.has(StopAllSupervisorActor.class, Definition.parameters(stopResults), "stop-all"));
  
  final PingTestResults pingTestResults = new PingTestResults();
  
  final Ping ping = world.actorFor(
          Ping.class,
          Definition.has(PingActor.class, Definition.parameters(pingTestResults), StopAllSupervisorActor.instance, "ping"));

  final PongTestResults pongTestResults = new PongTestResults();
  
  world.actorFor(
          Pong.class,
          Definition.has(PongActor.class, Definition.parameters(pongTestResults), StopAllSupervisorActor.instance, "pong"));

  AccessSafely pingAccess = pingTestResults.afterCompleting(1);
  AccessSafely pongAccess = pongTestResults.afterCompleting(1);
  AccessSafely stopAccess = stopResults.afterCompleting(1);

  ping.ping();

  assertEquals(1, (int) stopAccess.readFrom("informedCount"));
  assertEquals(1, (int) pingAccess.readFrom("stopCount"));
  assertEquals(1, (int) pongAccess.readFrom("stopCount"));
}
 
Example #25
Source File: CounterQueryActorTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
private void buildWithEvent(TextEntry event) {
    when(journalReader.readNext()).thenReturn(withSuccess(event));

    query = world().actorFor(
            CounterQuery.class,
            Definition.has(CounterQueryActor.class, Definition.parameters(journalReader, entryAdapterProvider))
    );
}
 
Example #26
Source File: SupervisionStrategyTest.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void test5Intensity1PeriodRestartStrategy() {
  final RestartFiveInOneSupervisorTestResults restartFiveInOneSupervisorTestResults = new RestartFiveInOneSupervisorTestResults();
  
  final TestActor<Supervisor> supervisor =
          testWorld.actorFor(
                  Supervisor.class,
                  Definition.has(RestartFiveInOneSupervisorActor.class, Definition.parameters(restartFiveInOneSupervisorTestResults), "resuming-5-1-supervisor"));
  
  final FailureControlTestResults failureControlTestResults = new FailureControlTestResults();
  
  final TestActor<FailureControl> failure =
          testWorld.actorFor(
                  FailureControl.class,
                  Definition.has(FailureControlActor.class, Definition.parameters(failureControlTestResults), supervisor.actorInside(), "failure-for-stop"));
  
  AccessSafely failureAccess = failureControlTestResults.afterCompleting(0);
  AccessSafely restartAccess = restartFiveInOneSupervisorTestResults.afterCompleting(5);

  for (int idx = 1; idx <= 5; ++idx) {
    failureAccess = failureControlTestResults.afterCompleting(1);
    failure.actor().failNow();
    failure.actor().afterFailure();
  }

  assertEquals(5, (int) failureAccess.readFrom("failNowCount"));
  assertEquals(5, (int) failureAccess.readFrom("afterFailureCount"));
  
  failureAccess = failureControlTestResults.afterCompleting(1);
  
  restartAccess = restartFiveInOneSupervisorTestResults.afterCompleting(1);

  failure.actor().failNow();  // should stop
  failure.actor().afterFailure();
  
  assertTrue(failure.actorInside().isStopped());
  assertEquals(6, (int) failureAccess.readFrom("failNowCount"));
  assertEquals(5, (int) failureAccess.readFrom("afterFailureCount"));
  assertEquals(6, (int) restartAccess.readFrom("informedCount"));
}
 
Example #27
Source File: OrderRouter.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected void beforeStart()
{
    orderItemTypeAProcessor = childActorFor( OrderItemProcessor.class, Definition.has( OrderItemTypeAProcessor.class, Definition.parameters( results )) );
    orderItemTypeBProcessor = childActorFor( OrderItemProcessor.class, Definition.has( OrderItemTypeBProcessor.class, Definition.parameters( results )) );
    orderItemTypeCProcessor = childActorFor( OrderItemProcessor.class, Definition.has( OrderItemTypeCProcessor.class, Definition.parameters( results )) );
}
 
Example #28
Source File: CartResource.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
public Completes<ObjectResponse<String>> create(final UserId userId) {
    final Address cartAddress = addressFactory.uniquePrefixedWith("cart-");
    final Cart cartActor = stage.actorFor(
            Cart.class,
            Definition.has(CartActor.class, Definition.parameters(cartAddress.idString())),
            cartAddress);

    cartActor.createEmptyCartFor(userId);

    final Headers<ResponseHeader> headers = headers(of(Location, urlLocation(cartAddress.idString())));
    return Completes.withSuccess(ObjectResponse.of(Created, headers, ""));
}
 
Example #29
Source File: PropertiesFileConfigRingBufferMailboxActorTest.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatRingBufferIsUsed() {
  final TestResults results = new TestResults(1);

  final OneBehavior one =
          world.actorFor(
                  OneBehavior.class,
                  Definition.has(OneBehaviorActor.class, Definition.parameters(results), "ringMailbox", "one-behavior"));

  one.doSomething();

  assertEquals(1, ((int) results.accessSafely.readFrom("times")));
}
 
Example #30
Source File: WorkRouterActor.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
public WorkRouterActor(final int poolSize, final CompetingConsumerResults results) {
  super(
          new RouterSpecification<WorkConsumer>(
            poolSize,
            Definition.has(WorkConsumerActor.class, Definition.parameters(results)),
            WorkConsumer.class
          )
        );
}