Java Code Examples for io.vlingo.symbio.store.journal.Journal#using()

The following examples show how to use io.vlingo.symbio.store.journal.Journal#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: InMemoryEventJournalActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  world = World.startWithDefaults("test-journal");
  this.dispatcher = new MockDispatcher<>(new MockConfirmDispatchedResultInterest());

  journal = Journal.using(world.stage(), InMemoryJournalActor.class, this.dispatcher);
  EntryAdapterProvider.instance(world).registerAdapter(Test1Source.class, new Test1SourceAdapter());
  EntryAdapterProvider.instance(world).registerAdapter(Test2Source.class, new Test2SourceAdapter());
  StateAdapterProvider.instance(world).registerAdapter(SnapshotState.class, new SnapshotStateAdapter());
}
 
Example 2
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 3
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();
}
 
Example 4
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private Bootstrap(final int portNumber) {
    world = World.startWithDefaults("cartservice");

    final StatefulTypeRegistry statefulTypeRegistry = new StatefulTypeRegistry(world);


    final StateStore keyValueStateStore = world.stage().actorFor(StateStore.class,
            InMemoryStateStoreActor.class,
            Arrays.asList(createNoOpDispatcher()));

    CartQueryProvider.using(world.stage(), statefulTypeRegistry, keyValueStateStore);
    ProjectionDispatcherProvider.using(world.stage());

    final Journal<String> journal = Journal.using(world.stage(),
                                            InMemoryJournalActor.class,
                                            ProjectionDispatcherProvider.instance().storeDispatcher);

    final SourcedTypeRegistry registry = new SourcedTypeRegistry(world);
    registry.register(new Info(journal, CartActor.class, CartActor.class.getSimpleName()));
    registry.register(new Info(journal, OrderActor.class, OrderActor.class.getSimpleName()));

    registry.info(OrderActor.class)
            .registerEntryAdapter(OrderEvents.Created.class, new EventAdapter<>(OrderEvents.Created.class))
            .registerEntryAdapter(OrderEvents.PaymentReceived.class, new EventAdapter<>(OrderEvents.PaymentReceived.class))
            .registerEntryAdapter(OrderEvents.OrderShipped.class, new EventAdapter<>(OrderEvents.OrderShipped.class));

    registry.info(CartActor.class)
            .registerEntryAdapter(CreatedForUser.class, new EventAdapter<>(CreatedForUser.class))
            .registerEntryAdapter(ProductQuantityChangeEvent.class, new EventAdapter<>(ProductQuantityChangeEvent.class))
            .registerEntryAdapter(AllItemsRemovedEvent.class, new EventAdapter<>(AllItemsRemovedEvent.class));

    final CartResource cartResource = new CartResource(world.stage(),
                                                       world.addressFactory(),
                                                       CartQueryProvider.instance().cartQuery);

    final OrderResource orderResource = new OrderResource(world);
    final UserResource userResource = new UserResource(CartQueryProvider.instance().cartQuery);
    final Resources resources = Resources.are(
            cartResource.routes(),
            orderResource.routes(),
            userResource.routes());

    this.server = Server.startWith(world.stage(),
            resources,
            portNumber,
            Configuration.Sizing.define(),
            Configuration.Timing.define());

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        if (instance != null) {
            instance.server.stop();

            System.out.println("\n");
            System.out.println("=======================");
            System.out.println("Stopping ecommerce-service.");
            System.out.println("=======================");
            pause();
        }
    }));
}