io.vlingo.actors.Protocols Java Examples

The following examples show how to use io.vlingo.actors.Protocols. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
Source File: LocalExchangeStreamTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
private void createProxyWith(final ExchangeStreamSource<LocalType1> source) {
    final Definition definition = Definition.has(ExchangeStreamPublisher.class, Definition.parameters(source,
            new PublisherConfiguration(5, Streams.OverflowPolicy.DropHead)));
    final Protocols protocols = world.actorFor(new Class[] { Publisher.class, ExchangeReceiver.class }, definition);
    publisher = protocols.get(0);
    receiver = protocols.get(1);
}
 
Example #7
Source File: ProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  world = World.startWithDefaults("test-store");

  final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(world);
  stateAdapterProvider.registerAdapter(Entity1State.class, new Entity1StateAdapter());
  new EntryAdapterProvider(world);

  StateTypeStateStoreMap.stateTypeToStoreName(Entity1.class, Entity1.class.getSimpleName());
  StateTypeStateStoreMap.stateTypeToStoreName(Entity2.class, Entity2.class.getSimpleName());

  final Protocols dispatcherProtocols =
          world.actorFor(
                  new Class<?>[] { dispatcherInterfaceClass(), ProjectionDispatcher.class },
                  projectionDispatcherClass());

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

  final Protocols storeProtocols =
          world.actorFor(
                  new Class<?>[] { stateStoreInterfaceClass(), DispatcherControl.class },
                  InMemoryStateStoreActor.class,
                  Arrays.asList(dispatcher));

  final Protocols.Two<StateStore, DispatcherControl> storeWithControl = Protocols.two(storeProtocols);
  store = storeWithControl._1;
  dispatcherControl = storeWithControl._2;
}
 
Example #8
Source File: JournalProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Before
@SuppressWarnings({ "rawtypes", "unchecked" })
public void setUp() {
  world = World.startWithDefaults("test-journal-projections");

  accessHolder = new AccessHolder();

  final List<ProjectToDescription> descriptions =
          Arrays.asList(
                  ProjectToDescription.with(OneHappenedProjectionActor.class, Optional.of(accessHolder), OneHappened.class),
                  ProjectToDescription.with(TwoHappenedProjectionActor.class, Optional.of(accessHolder), TwoHappened.class),
                  ProjectToDescription.with(AllHappenedProjectionActor.class, Optional.of(accessHolder), OneHappened.class.getPackage()));

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

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

  this.dispatcher = dispatchers._1;

  journal = Journal.using(world.stage(), InMemoryJournalActor.class, this.dispatcher);

  EntryAdapterProvider.instance(world).registerAdapter(OneHappened.class, new OneHappenedAdapter());
  EntryAdapterProvider.instance(world).registerAdapter(TwoHappened.class, new TwoHappenedAdapter());
  EntryAdapterProvider.instance(world).registerAdapter(ThreeHappened.class, new ThreeHappenedAdapter());

  appendInterest = world.stage().actorFor(AppendResultInterest.class, JournalAppendResultInterest.class);
}
 
Example #9
Source File: TestWorld.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
public Protocols actorFor(final Class<?>[] protocols, final Definition definition) {
  if (world.isTerminated()) {
    throw new IllegalStateException("vlingo/actors: TestWorld has stopped.");
  }

  return world.stage().testActorFor(protocols, definition);
}
 
Example #10
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.");
}