Java Code Examples for io.vlingo.actors.World#actorFor()

The following examples show how to use io.vlingo.actors.World#actorFor() . 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: StateProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
public static ProjectionDispatcher filterFor(
        final World world,
        final ProjectionDispatcher projectionDispatcher,
        final String[] becauseOf,
        final FilterOutcome filterOutcome) {

  final Protocols projectionProtocols =
          world.actorFor(
                  new Class<?>[] { ProjectionDispatcher.class, Projection.class },
                  FilterProjectionDispatcherActor.class,
                  filterOutcome);

  final Protocols.Two<ProjectionDispatcher, Projection> projectionFilter = Protocols.two(projectionProtocols);

  projectionDispatcher.projectTo(projectionFilter._2, becauseOf);

  return projectionFilter._1;
}
 
Example 2
Source File: SourcedTypeRegistry.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Construct my default state with {@code sourcedTypes} creating the {@code Journal}
 * of type {@code journalType}, and register me with the {@code world}.
 * @param world the World to which I am registered
 * @param journalType the concrete {@code Actor} type of the Journal to create
 * @param dispatcher the {@code Dispatcher<Dispatchable<Entry<?>,State<?>>>} of the journalType
 * @param sourcedTypes all {@code Class<Sourced<?>>} types of to register
 * @param <A> the type of Actor used for the Journal implementation
 * @param <S> the {@code Sourced<?>} types to register
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public <A extends Actor, S extends Sourced<?>> SourcedTypeRegistry(
        final World world,
        final Class<A> journalType,
        final Dispatcher<Dispatchable<Entry<?>,State<?>>> dispatcher,
        final Class<S> ... sourcedTypes) {

  this(world);

  final Journal<?> journal = world.actorFor(Journal.class, journalType, dispatcher);

  EntryAdapterProvider.instance(world);

  for (Class<S> sourcedType : sourcedTypes) {
    this.register(new Info(journal, sourcedType, sourcedType.getSimpleName()));
  }
}
 
Example 3
Source File: RequestReplyTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatRequestReplyRuns() {
  System.out.println("RequestReply: is starting.");

  final World world = World.startWithDefaults("requestreply-test");

  final RequestReplyResults results = new RequestReplyResults();
  final AccessSafely access = results.afterCompleting(2);

  final Service service = world.actorFor(Service.class, Server.class);
  world.actorFor(Consumer.class, Client.class, service, results);

  Assert.assertEquals(1, (int) access.readFrom("afterReplyReceivedCount"));
  Assert.assertEquals(1, (int) access.readFrom("afterQueryPerformedCount"));

  System.out.println("RequestReply: is completed.");
}
 
Example 4
Source File: CompetingConsumerTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatConsumersCompete() {
  final World world = World.startWithDefaults("competing-consumer-test");
  final int poolSize = 4;
  final int messagesToSend = 8;
  final CompetingConsumerResults results = new CompetingConsumerResults();
  final WorkConsumer workConsumer =
          world.actorFor(WorkConsumer.class, WorkRouterActor.class, poolSize, results);
  final AccessSafely access = results.afterCompleting(messagesToSend);

  for (int i = 0; i < messagesToSend; i++) {
    workConsumer.consumeWork(new WorkItem(i));
  }

  Assert.assertEquals(8, (int) access.readFrom("afterItemConsumedCount"));
}
 
Example 5
Source File: MessageExpirationTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testMessageExpirationRuns()
{
    World world = World.startWithDefaults( WORLD_NAME );
    world.defaultLogger().debug( "MessageExpirationTest: is started" );

    final MessageExpirationResults results = new MessageExpirationResults();
    final AccessSafely access = results.afterCompleting( ORDERS );
    
    OrderProcessor purchaseAgent = world.actorFor(OrderProcessor.class, PurchaseAgent.class, results);
    OrderProcessor purchaseRouter = world.actorFor(OrderProcessor.class, PurchaseRouter.class, purchaseAgent);
    
    purchaseRouter.placeOrder( new Order( "1", "11", 50.00, 1000L ));
    purchaseRouter.placeOrder( new Order( "2", "22", 250.00, 100L ));
    purchaseRouter.placeOrder( new Order( "3", "33", 32.95, 10L ));

    final int expectedOrderPlaced = ORDERS - (int) access.readFrom("afterOrderExpiredCount");

    Assert.assertEquals(expectedOrderPlaced, (int) access.readFrom("afterOrderPlacedCount"));

    world.defaultLogger().debug( "MessageExpirationTest: is completed" );
    
    world.terminate();
}
 
Example 6
Source File: ReturnAddressTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatReturnAddressRuns() {
  System.out.println("ReturnAddress: is starting.");

  final World world = World.startWithDefaults("returnaddress-test");

  final ReturnAddressResults results = new ReturnAddressResults();
  final AccessSafely access = results.afterCompleting(2);

  final Service service = world.actorFor(Service.class, Server.class);
  world.actorFor(Consumer.class, Client.class, service, results);

  Assert.assertEquals(1, (int) access.readFrom("afterSimpleReplyCount"));
  Assert.assertEquals(1, (int) access.readFrom("afterComplexReplyCount"));

  System.out.println("ReturnAddress: is completed.");
}
 
Example 7
Source File: PingPong.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
private static PingPong game() {
  final World world = World.startWithDefaults("ping-pong");
  final TestUntil until = TestUntil.happenings(1);
  final Pinger pinger = world.actorFor(Pinger.class, PingerActor.class, until);
  final Ponger ponger = world.actorFor(Ponger.class, PongerActor.class);

  return new PingPong(world, until, pinger, ponger);
}
 
Example 8
Source File: PlaygroundTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testPlayPingPong() {
  final World world = World.startWithDefaults("playground");
  final TestUntil until = TestUntil.happenings(1);
  final Pinger pinger = world.actorFor(Pinger.class, PingerActor.class, until);
  final Ponger ponger = world.actorFor(Ponger.class, PongerActor.class);

  pinger.ping(ponger);

  until.completes();

  world.terminate();
}
 
Example 9
Source File: MessageBusTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testMessageBusRuns()
{
    World world = World.startWithDefaults( WORLD_NAME );
    
    world.defaultLogger().debug( "TradingBus: is started" );
    
    final TradingBusResults results = new TradingBusResults();
    final AccessSafely access = results.afterCompleting( EVENTS );
    
    final TradingBusProcessor tradingBus = world.actorFor(TradingBusProcessor.class, TradingBus.class, results);
    
    @SuppressWarnings("unused")
    final TradingProcessor stockTrader = world.actorFor(TradingProcessor.class, StockTrader.class, results, tradingBus);
    @SuppressWarnings("unused")
    final TradingProcessor portfolioManager = world.actorFor(TradingProcessor.class, PortfolioManager.class, results, tradingBus);
    @SuppressWarnings("unused")
    final TradingProcessor marketAnalysisTool = world.actorFor(TradingProcessor.class,  MarketAnalysisTools.class, results, tradingBus);
    
    tradingBus.trade( new TradingCommand( TradingProcessor.EXECUTE_BUY_ORDER, "p123", "MSFT", 100, 31.85 ));
    tradingBus.trade( new TradingCommand( TradingProcessor.EXECUTE_SELL_ORDER, "p456", "MSFT", 200, 31.80 ));
    tradingBus.trade( new TradingCommand( TradingProcessor.EXECUTE_BUY_ORDER, "p789", "MSFT", 100, 31.83 ));

    Assert.assertEquals(3, (int) access.readFrom("afterCommandDispatchedCount"));
    Assert.assertEquals(6, (int) access.readFrom("afterNotificationDispatchedCount"));
    Assert.assertEquals(2, (int) access.readFrom("afterHandlerRegisteredCount"));
    Assert.assertEquals(4, (int) access.readFrom("afterInterestRegisteredCount"));
    Assert.assertEquals(2, (int) access.readFrom("afterMarketAnalysisBuyOrderExecutedCount"));
    Assert.assertEquals(1, (int) access.readFrom("afterMarketAnalysisSellOrderExecutedCount"));
    Assert.assertEquals(2, (int) access.readFrom("afterPortfolioManagerBuyOrderExecutedCount"));
    Assert.assertEquals(1, (int) access.readFrom("afterPortfolioManagerSellOrderExecutedCount"));
    Assert.assertEquals(2, (int) access.readFrom("afterStockTraderBuyOrderExecutedCount"));
    Assert.assertEquals(1, (int) access.readFrom("afterStockTraderSellOrderExecutedCount"));

    world.defaultLogger().debug( "TradingBus: is completed" );
    
    world.terminate();
}
 
Example 10
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private Bootstrap() throws Exception {
  final World world = World.startWithDefaults("agile-collaboration");

  final Exchange camelExchange = new ExchangeBootstrap(world).initExchange();
  final ExchangeDispatcher dispatcher = new ExchangeDispatcher(camelExchange);
  final Journal journal = world.actorFor(Journal.class, InMemoryJournalActor.class, dispatcher);
  final SourcedTypeRegistry registry = new SourcedTypeRegistry(world);

  SourcedRegistration.registerAllWith(registry, journal);
}
 
Example 11
Source File: MessageFilterTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatMessageFilterRuns() {

    System.out.println("Message Filter: is starting.");

    final World world = World.startWithDefaults("message-filter-test");

    final MessageFilterResults results = new MessageFilterResults();

    final AccessSafely access = results.afterCompleting(3);

    final InventorySystem restrictedInventorySystemActor =
            world.actorFor(InventorySystem.class, RestrictedInventorySystemActor.class, results);

    final InventorySystem notRestrictedInventorySystemActor =
            world.actorFor(InventorySystem.class, NotRestrictedInventorySystemActor.class, results);

    final InventorySystem inventoryMessageFilter =
            world.actorFor(InventorySystem.class, InventorySystemMessageFilter.class, results, notRestrictedInventorySystemActor);

    final Order order =
            new Order("1",
                    "TypeDEF",
                    Arrays.asList(
                            new OrderItem("2", "TypeDEF", "A description", 100d),
                            new OrderItem("3", "TypeDEF", "A description", 150d))
                            .stream().collect(toMap(OrderItem::orderItemId, identity())));

    restrictedInventorySystemActor.processOrder(order);
    notRestrictedInventorySystemActor.processOrder(order);
    inventoryMessageFilter.processOrder(order);

    Assert.assertEquals(1, (int) access.readFrom("afterOrderProcessedCount"));
    Assert.assertEquals(2, (int) access.readFrom("afterOrderFilteredCount"));

    System.out.println("Message Filter: is completed.");
}
 
Example 12
Source File: InventoryOrdersTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Test lifecycle of an {@link OrderPlaced}
 */
@Test
public void testOrderPlaced() {

    OrderItem orderItem1 = new OrderItem ( "1", "TypeABC.4", "An item of type ABC.4.", 29.95 );
    OrderItem orderItem2 = new OrderItem ( "2", "TypeABC.1", "An item of type ABC.1.", 99.95 );
    OrderItem orderItem3 = new OrderItem ( "3", "TypeABC.9", "An item of type ABC.9.", 14.95 );

    Map<String, OrderItem> items = Maps.newHashMap ();
    items.put ( orderItem1.getItemType (), orderItem1 );
    items.put ( orderItem2.getItemType (), orderItem2 );
    items.put ( orderItem3.getItemType (), orderItem3 );

    OrderPlaced orderPlaced = new OrderPlaced ( new Order ( "123", "TypeABC", items ) );

    OrderItem orderItem4 = new OrderItem ( "4", "TypeXYZ.2", "An item of type XYZ.2.", 74.95 );
    OrderItem orderItem5 = new OrderItem ( "5", "TypeXYZ.1", "An item of type XYZ.1.", 59.95 );
    OrderItem orderItem6 = new OrderItem ( "6", "TypeXYZ.7", "An item of type XYZ.7.", 29.95 );
    OrderItem orderItem7 = new OrderItem ( "7", "TypeXYZ.5", "An item of type XYZ.5.", 9.95 );

    Map<String, OrderItem> items1 = Maps.newHashMap ();
    items1.put ( orderItem4.getItemType (), orderItem4 );
    items1.put ( orderItem5.getItemType (), orderItem5 );
    items1.put ( orderItem6.getItemType (), orderItem6 );
    items1.put ( orderItem7.getItemType (), orderItem7 );

    OrderPlaced orderPlaced2 = new OrderPlaced ( new Order ( "124", "TypeXYZ", items1 ) );

    final World world = World.startWithDefaults ( WORLD_NAME );
    final OrderRoutingResults results = new OrderRoutingResults();
    final AccessSafely access = results.afterCompleting(2);

    final OrderRouter orderRouter = world.actorFor (OrderRouter.class, OrderRouterActor.class, results);
    orderRouter.routeOrder ( orderPlaced );
    orderRouter.routeOrder ( orderPlaced2 );

    Assert.assertEquals(2, (int) access.readFrom("afterOrderRoutedCount"));

    world.terminate ();
}
 
Example 13
Source File: PipesAndFiltersTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatPipesAndFiltersRuns() {
  System.out.println("PipesAndFilters: is starting.");

  final World world = World.startWithDefaults("pipesandfilters-test");

  final PipeAndFilterResults results = new PipeAndFilterResults();
  final AccessSafely access = results.afterCompleting(9);

  final String orderText = "(encryption)(certificate)<order id='123'>...</order>";
  final byte[] rawOrderBytes = orderText.getBytes();

  final OrderProcessor filter5 = world.actorFor(OrderProcessor.class, OrderManagementSystem.class, results);
  final OrderProcessor filter4 = world.actorFor(OrderProcessor.class, Deduplicator.class, filter5, results);
  final OrderProcessor filter3 = world.actorFor(OrderProcessor.class, Authenticator.class, filter4, results);
  final OrderProcessor filter2 = world.actorFor(OrderProcessor.class, Decrypter.class, filter3, results);
  final OrderProcessor filter1 = world.actorFor(OrderProcessor.class, OrderAcceptanceEndpoint.class, filter2, results);

  filter1.processIncomingOrder(rawOrderBytes);
  filter1.processIncomingOrder(rawOrderBytes);

  Assert.assertEquals(2, (int) access.readFrom("afterOrderAuthenticatedCount"));
  Assert.assertEquals(2, (int) access.readFrom("afterOrderDecryptedCount"));
  Assert.assertEquals(2, (int) access.readFrom("afterOrderDeduplicatedCount"));
  Assert.assertEquals(2, (int) access.readFrom("afterOrderAcceptedCount"));
  Assert.assertEquals(1, (int) access.readFrom("afterOrderManagedCount"));

  System.out.println("PipesAndFilters: is completed.");
}
 
Example 14
Source File: PublishSubscribeTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testThatPublishSubscribeRuns() {

    System.out.println("Publish Subscribe: is starting.");

    final World world = World.startWithDefaults("publish-subscribe-test");

    final MarketQuotationResults results = new MarketQuotationResults();

    final AccessSafely access = results.afterCompleting(6);

    final Subscriber<PriceQuoted> allMarketsSubscriber =
            world.actorFor(Subscriber.class, AllMarketsSubscriber.class, results);

    final Subscriber<PriceQuoted> nasdaqSubscriber =
            world.actorFor(Subscriber.class, NASDAQSubscriber.class, results);

    final Subscriber<PriceQuoted> nyseSubscriber =
            world.actorFor(Subscriber.class, NYSESubscriber.class, results);

    final Publisher publisher = new DefaultPublisher();

    publisher.subscribe(new Market("quotes"), allMarketsSubscriber);
    publisher.subscribe(new Market("quotes/NASDAQ"), nasdaqSubscriber);
    publisher.subscribe(new Market("quotes/NYSE"), nyseSubscriber);

    publisher.publish(new Market("quotes/NYSE"), new PriceQuoted("ORCL", new Money("121.13")));
    publisher.publish(new Market("quotes/NASDAQ"), new PriceQuoted( "MSFT", new Money("1099.76")));
    publisher.publish(new Market("quotes/DAX"), new PriceQuoted("SAP:GR", new Money("885.00")));
    publisher.publish(new Market("quotes/NKY"), new PriceQuoted("6701:JP", new Money("131.12")));

    Assert.assertEquals(4, (int) access.readFrom("afterQuotationReceivedAtGeneralSubscriberCount"));
    Assert.assertEquals(1, (int) access.readFrom("afterQuotationReceivedAtNASDAQSubscriberCount"));
    Assert.assertEquals(1, (int) access.readFrom("afterQuotationReceivedAtNYSESubscriberCount"));
}
 
Example 15
Source File: MessageRouterTest.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Test
public void testAlternatingRouteProcessorRuns()
{
    
    final World world = World.startWithDefaults( WORLD_NAME );
    
    world.defaultLogger().debug( "AlternatingRouteProcessor: is starting"  );

    final MessageRouterResults results = new MessageRouterResults();

    final AccessSafely access = results.afterCompleting( ROUTES );

    final Processor messageProcessor1 = world.actorFor(Processor.class, WorkerProcessor.class, "MP One" );
    final Processor messageProcessor2 = world.actorFor(Processor.class, WorkerProcessor.class, "MP Two" );
    final Processor alternatingRouter = world.actorFor(Processor.class, AlternatingRouteProcessor.class, results, messageProcessor1, messageProcessor2 );
    
    int routeCount = 0;
    int j = 0;
    while ( true )
    {
        int remaining = ROUTES - access.totalWrites();
        if ( routeCount < ROUTES )
        {
            alternatingRouter.process( routeCount );
            routeCount++;
        }
        
        if ( j != remaining )
        {
            world.defaultLogger().debug( String.format( "Count: %d", remaining ));
            j = remaining;
        }
        
        if ( remaining == 0 ) break;
    }

    Assert.assertEquals(10, (int) access.readFrom("afterMessageProcessedByFirstProcessorCount"));
    Assert.assertEquals(10, (int) access.readFrom("afterMessageProcessedBySecondProcessorCount"));
    
    world.defaultLogger().debug( "AlternatingRouteProcessor: is completed"  );
    
    world.terminate();
    
}
 
Example 16
Source File: PointToPointChannelTest.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Test
public void testPointToPointChannelRuns()
{
    final World world = World.startWithDefaults( WORLD_NAME );
    
    world.defaultLogger().debug( "PointToPointChannel: is starting" );
    
    final PointToPointResults results = new PointToPointResults();

    final AccessSafely access = results.afterCompleting( NUMBER_MESSAGES );
    
    final PointToPointProcessor peerNodeActor = world.actorFor(PointToPointProcessor.class, PeerNodeActor.class, results);
    
    peerNodeActor.process( MSG_ID_1 );
    peerNodeActor.process( MSG_ID_2 );
    peerNodeActor.process( MSG_ID_3 );
    peerNodeActor.process( MSG_ID_4 );

    Assert.assertEquals(NUMBER_MESSAGES.intValue(), (int) access.readFrom("afterMessageProcessedCount"));
    
    world.defaultLogger().debug( "PointToPointChannel: is completed" );
    
    world.terminate();
    
}
 
Example 17
Source File: ScatterGatherTest.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Test
public void testScatterGatherRuns()
{
    World world = World.startWithDefaults( WORLD_NAME );
    world.defaultLogger().debug( "ScatterGatherTest: is started" );
    
    final ScatterGatherResults results = new ScatterGatherResults();
    final AccessSafely access = results.afterCompleting(10);
    
    AggregateProcessor priceQuoteAggregator = world.actorFor( AggregateProcessor.class, PriceQuoteAggregator.class );
    OrderProcessor mtnSuppliesOrderProcessor = world.actorFor( OrderProcessor.class, MountainSuppliesOrderProcessor.class, priceQuoteAggregator, results );
    world.actorFor( QuoteProcessor.class, BudgetHikersPriceQuotes.class, mtnSuppliesOrderProcessor );
    world.actorFor( QuoteProcessor.class, HighSierraPriceQuotes.class, mtnSuppliesOrderProcessor );
    world.actorFor( QuoteProcessor.class, MountainAscentPriceQuotes.class, mtnSuppliesOrderProcessor );
    world.actorFor( QuoteProcessor.class, PinnacleGearPriceQuotes.class, mtnSuppliesOrderProcessor );
    world.actorFor( QuoteProcessor.class, RockBottomOuterwearPriceQuotes.class, mtnSuppliesOrderProcessor );
    
    world.defaultLogger().debug("Register completes!!!");
    
    mtnSuppliesOrderProcessor
        .requestForQuote( 
            new RetailBasket( 
                "123", 
                new RetailItem( "1", 29.95 ), 
                new RetailItem( "2", 99.95 ), 
                new RetailItem( "3", 14.95 )
            )
        );
    
    mtnSuppliesOrderProcessor
        .requestForQuote( 
            new RetailBasket( 
                "125", 
                new RetailItem( "4", 39.95 ), 
                new RetailItem( "5", 199.95 ), 
                new RetailItem( "6", 149.95 ),
                new RetailItem( "7", 724.99 )
            )
        );

    mtnSuppliesOrderProcessor
        .requestForQuote( 
            new RetailBasket( 
                "129", 
                new RetailItem( "8", 119.99 ), 
                new RetailItem( "9", 499.95 ), 
                new RetailItem( "10", 519.00 ),
                new RetailItem( "11", 209.50 )
            )
        );

    mtnSuppliesOrderProcessor
        .requestForQuote( 
            new RetailBasket( 
                "135", 
                new RetailItem( "12", .97 ), 
                new RetailItem( "13", 9.50 ), 
                new RetailItem( "14", 1.99 )
            )
        );

    mtnSuppliesOrderProcessor
        .requestForQuote( 
            new RetailBasket( 
                "140", 
                new RetailItem( "15", 107.50 ), 
                new RetailItem( "16", 9.50 ), 
                new RetailItem( "17", 599.99 ),
                new RetailItem( "18", 249.95 ),
                new RetailItem( "19", 789.99 )
            )
        );

    Assert.assertEquals(5, (int) access.readFrom("afterProcessorRegisteredCount"));
    Assert.assertEquals(5, (int) access.readFrom("afterBestPriceQuotationRegisteredCount"));

    world.defaultLogger().debug( "ScatterGatherTest: is completed" );
    world.terminate();
}
 
Example 18
Source File: OrderRouterActor.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
public OrderRouterActor(final OrderRoutingResults orderRoutingResults) {
    World world = stage ().world ();
    this.orderRoutingResults = orderRoutingResults;
    inventorySystemA = world.actorFor ( Inventory.class, InventorySystemA.class );
    inventorySystemX = world.actorFor ( Inventory.class, InventorySystemX.class );
}
 
Example 19
Source File: AggregatorTest.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Test
public void testThatAggregatorRuns() {
  System.out.println("Aggregator: is starting.");

  final World world = World.startWithDefaults("aggregator-test");

  final AggregatorResults results = new AggregatorResults();

  final AccessSafely access = results.afterCompleting(5);

  final Protocols protocols =
          world.actorFor(
                  new Class[] { RequestForQuotationProcessor.class,
                      RequestForQuotationSupplier.class,
                      PriceQuotesFulfillmentWatcher.class },
                  MountaineeringSuppliesOrderProcessor.class,
                  results);

  final Protocols.Three<RequestForQuotationProcessor, RequestForQuotationSupplier, PriceQuotesFulfillmentWatcher> three = Protocols.three(protocols);
  final RequestForQuotationProcessor processor = three._1;
  final RequestForQuotationSupplier supplier = three._2;

  world.actorFor(PriceQuoteAggregator.class, PriceQuoteAggregatorActor.class, three._3);

  world.actorFor(PriceQuotes.class, BudgetHikersPriceQuotesActor.class, supplier);
  world.actorFor(PriceQuotes.class, HighSierraPriceQuotesActor.class, supplier);
  world.actorFor(PriceQuotes.class, MountainAscentPriceQuotesActor.class, supplier);
  world.actorFor(PriceQuotes.class, PinnacleGearPriceQuotesActor.class, supplier);
  world.actorFor(PriceQuotes.class, RockBottomOuterwearPriceQuotesActor.class,supplier);

  processor.requestPriceQuotationFor(
          new RequestForQuotation(
                  "123",
                  Arrays.asList(
                          new RetailItem("1", 29.95),
                          new RetailItem("2", 99.95),
                          new RetailItem("3", 14.95))));

  processor.requestPriceQuotationFor(
          new RequestForQuotation(
                  "125",
                  Arrays.asList(
                          new RetailItem("4", 39.99),
                          new RetailItem("5", 199.95),
                          new RetailItem("6", 149.95),
                          new RetailItem("7", 724.99))));

  processor.requestPriceQuotationFor(
          new RequestForQuotation(
                  "129",
                  Arrays.asList(
                          new RetailItem("8", 119.99),
                          new RetailItem("9", 499.95),
                          new RetailItem("10", 519.00),
                          new RetailItem("11", 209.50))));

  processor.requestPriceQuotationFor(
          new RequestForQuotation(
                  "135",
                  Arrays.asList(
                          new RetailItem("12", 0.97),
                          new RetailItem("13", 9.50),
                          new RetailItem("14", 1.99))));

  processor.requestPriceQuotationFor(
          new RequestForQuotation(
                  "140",
                  Arrays.asList(
                          new RetailItem("15", 107.50),
                          new RetailItem("16", 9.50),
                          new RetailItem("17", 599.99),
                          new RetailItem("18", 249.95),
                          new RetailItem("19", 789.99))));

  Assert.assertEquals(5, (int) access.readFrom("afterQuotationFulfillmentCount"));

  System.out.println("Aggregator: is completed.");
}
 
Example 20
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Flyway.configure().dataSource(DB_URL, DB_USER, DB_PWD).load().migrate();
    final Configuration configuration = new Configuration(
    		DatabaseType.Postgres,
            new NoopConfigurationInterest(),
            "org.postgresql.Driver",
            DataFormat.Text,
            DB_URL,
            DB_NAME,
            DB_USER,
            DB_PWD,
            false,
            "",
            false
    );

    final World world = World.startWithDefaults("event-journal");

    final NoopEventJournalDispatcher journalDispatcher = new NoopEventJournalDispatcher();
    Journal<String> journal = Journal.using(world.stage(), JDBCJournalActor.class, journalDispatcher, configuration);

    final Counter counter = world.actorFor(
            Counter.class,
            Definition.has(CounterActor.class, Definition.parameters(DB_NAME, journal))
    );

    final CounterQuery counterQuery = world.actorFor(
            CounterQuery.class,
            Definition.has(CounterQueryActor.class, Definition.parameters(journal.journalReader(DB_NAME).<JournalReader<Entry<?>>>await(), new EntryAdapterProvider()))
    );

    for (int i = 0; i < 5000; i++) {
        if (i % 10 == 0) {
            counter.decrease();
        } else {
            counter.increase();
        }

        pause();
        counterQuery.counter().andThenConsume(System.out::println);
    }

    world.terminate();
}