io.vlingo.symbio.store.journal.Journal Java Examples

The following examples show how to use io.vlingo.symbio.store.journal.Journal. 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: 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 #2
Source File: SourcedRegistration.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void registerAllWith(final SourcedTypeRegistry registry, final Journal journal) {
  registry.register(new Info(journal, ForumEntity.class, ForumEntity.class.getSimpleName()))
          .register(new Info(journal, DiscussionEntity.class, DiscussionEntity.class.getSimpleName()))
          .register(new Info(journal, PostEntity.class, PostEntity.class.getSimpleName()));

  registry.info(ForumEntity.class)
          .registerEntryAdapter(ForumStarted.class, new ForumStartedAdapter())
          .registerEntryAdapter(ForumModeratorAssigned.class, new ForumModeratorAssignedAdapter())
          .registerEntryAdapter(ForumClosed.class, new ForumClosedAdapter())
          .registerEntryAdapter(ForumDescribed.class, new ForumDescribedAdapter())
          .registerEntryAdapter(ForumReopened.class, new ForumReopenedAdapter())
          .registerEntryAdapter(ForumTopicChanged.class, new ForumTopicChangedAdapter())
          .registerStateAdapter(Forum.State.class, new ForumStateAdapter());

  registry.info(DiscussionEntity.class)
          .registerEntryAdapter(DiscussionStarted.class, new DiscussionStartedAdapter())
          .registerEntryAdapter(DiscussionClosed.class, new DiscussionClosedAdapter())
          .registerEntryAdapter(DiscussionReopened.class, new DiscussionReopenedAdapter())
          .registerEntryAdapter(DiscussionTopicChanged.class, new DiscussionTopicChangedAdapter());

  registry.info(PostEntity.class)
          .registerEntryAdapter(PostedToDiscussion.class, new PostedToDiscussionAdapter())
          .registerEntryAdapter(PostModerated.class, new PostModeratedAdapter());
}
 
Example #3
Source File: CommandSourcedTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Before
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setUp() {
  world = World.startWithDefaults("test-cs");

  dispatcher = new MockJournalDispatcher();

  journal = world.actorFor(Journal.class, InMemoryJournalActor.class, dispatcher);

  registry = new SourcedTypeRegistry(world);
  registry.register(new Info(journal, TestCommandSourcedEntity.class, TestCommandSourcedEntity.class.getSimpleName()));
  registry.info(TestCommandSourcedEntity.class)
    .registerEntryAdapter(DoCommand1.class, new DoCommand1Adapter())
    .registerEntryAdapter(DoCommand2.class, new DoCommand2Adapter())
    .registerEntryAdapter(DoCommand3.class, new DoCommand3Adapter());

  result = new Result();
  entity = world.actorFor(Entity.class, TestCommandSourcedEntity.class, result);
}
 
Example #4
Source File: EventSourcedTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Before
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setUp() {
  testWorld = TestWorld.startWithDefaults("test-es");

  world = testWorld.world();

  dispatcher = new MockJournalDispatcher();

  EntryAdapterProvider entryAdapterProvider = EntryAdapterProvider.instance(world);

  entryAdapterProvider.registerAdapter(Test1Happened.class, new Test1HappenedAdapter());
  entryAdapterProvider.registerAdapter(Test2Happened.class, new Test2HappenedAdapter());
  entryAdapterProvider.registerAdapter(Test3Happened.class, new Test3HappenedAdapter());

  journal = world.actorFor(Journal.class, InMemoryJournalActor.class, dispatcher);

  registry = new SourcedTypeRegistry(world);
  registry.register(new Info(journal, TestEventSourcedEntity.class, TestEventSourcedEntity.class.getSimpleName()));
  registry.register(new Info(journal, ProductEntity.class, ProductEntity.class.getSimpleName()));
  registry.register(new Info(journal, ProductParent.class, ProductParent.class.getSimpleName()));
  registry.register(new Info(journal, ProductGrandparent.class, ProductGrandparent.class.getSimpleName()));

  result = new Result();
  entity = world.actorFor(Entity.class, TestEventSourcedEntity.class, result);
}
 
Example #5
Source File: OrganizationEntityTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Before
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setUp() throws Exception {
  grid = Grid.start("sourced-entity-test", Configuration.define(), ClusterProperties.oneNode(), "node1");
  grid.quorumAchieved();
  journal = grid.actorFor(Journal.class, InMemoryJournalActor.class, new MockDispatcher());
  registry = new SourcedTypeRegistry(grid.world());

  final Info<Organization> info = new Info(journal, io.vlingo.entity.sourced.OrganizationEntity.class, "Journal");

  registry.register(info);
}
 
Example #6
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 #7
Source File: EntityTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
  testWorld = TestWorld.startWithDefaults("entity-test");
  world = testWorld.world();
  journalDispatcher = new MockJournalDispatcher();
  journal = world.actorFor(Journal.class, InMemoryJournalActor.class, journalDispatcher);
  registry = new SourcedTypeRegistry(world);
  SourcedRegistration.registerAllWith(registry, journal);
}
 
Example #8
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 #9
Source File: CounterActorTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    streamName = UUID.randomUUID().toString();
    journal = Mockito.mock(Journal.class);
    counter = world().actorFor(
            Counter.class,
            Definition.has(CounterActor.class, Definition.parameters(streamName, journal))
    );
}
 
Example #10
Source File: EntityTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
  testWorld = TestWorld.startWithDefaults("entity-test");
  world = testWorld.world();
  journalDispatcher = new MockJournalDispatcher();
  journal = world.actorFor(Journal.class, InMemoryJournalActor.class, journalDispatcher);
  registry = new SourcedTypeRegistry(world);
  SourcedRegistration.registerAllWith(registry, journal);
}
 
Example #11
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private Bootstrap() throws Exception {
    world = World.startWithDefaults("agilepm");

    final Exchange exchange = new ExchangeBootstrap(world).initExchange();

    final ExchangeDispatcher exchangeDispatcher = new ExchangeDispatcher(exchange);

    Journal<String> journal = world.actorFor(Journal.class, InMemoryJournalActor.class, exchangeDispatcher);

    SourcedTypeRegistry registry = new SourcedTypeRegistry(world);

    final SourcedTypeRegistry.Info info = new SourcedTypeRegistry.Info(journal, ProductEntity.class, ProductEntity.class.getSimpleName());
    registry.register(info);

    final ProductResource productResource = new ProductResource(world);
    final Resources resources = Resources.are(productResource.routes());

    this.server = Server.startWith(world.stage(),
            resources,
            8080,
            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 agilepm-service.");
            System.out.println("=======================");
            pause();
        }
    }));
}
 
Example #12
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 #13
Source File: SourcedTypeRegistry.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Construct my default state.
 * @param journal the {@code Journal<T>} of the registration
 * @param sourcedType the {@code Class<Sourced<T>>} of the registration
 * @param sourcedName the String name of the sourcedType
 */
public Info(final Journal<T> journal, final Class<Sourced<T>> sourcedType, final String sourcedName) {
  this.journal = journal;
  this.sourcedType = sourcedType;
  this.sourcedName = sourcedName;
  this.entryAdapterProvider = new EntryAdapterProvider();
  this.stateAdapterProvider = new StateAdapterProvider();
}
 
Example #14
Source File: SourcedRegistration.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> void registerAllWith(final SourcedTypeRegistry registry, final Journal<T> journal) {
  registry.register(new Info(journal, ProductEntity.class, ProductEntity.class.getSimpleName()));
}
 
Example #15
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 #16
Source File: CounterActor.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
public CounterActor(final String counterName, final Journal<String> journal) {
    this.counterName = counterName;
    this.journal = journal;
    this.currentCount = 0;
    this.version = 1;
}
 
Example #17
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();
        }
    }));
}
 
Example #18
Source File: FeedTest.java    From vlingo-lattice with Mozilla Public License 2.0 3 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUp() {
  world = World.startWithDefaults("feed-test");

  dispatcher = new MockJournalDispatcher();

  journal = world.actorFor(Journal.class, InMemoryJournalActor.class, dispatcher);

  entryReader = journal.journalReader("feed-test-reader").await();

  consumer = new MockFeedConsumer();

  interest = noOpInterest();
}
 
Example #19
Source File: Sourced.java    From vlingo-lattice with Mozilla Public License 2.0 3 votes vote down vote up
/**
 * Answer {@code Completes<R>}, applying the given {@code source} to myself, which
 * includes appending it to my journal and reflecting the representative changes to my
 * state, followed by the execution of a possible {@code andThen}.
 * @param source the {@code Source<T>} to apply
 * @param metadata the Metadata to apply along with source
 * @param andThen the {@code Supplier<R>} executed following the application of sources
 * @param <R> the return type of the andThen {@code Supplier<R>}
 * @return {@code Completes<R>}
 */
final protected <R> Completes<R> apply(final Source<T> source, final Metadata metadata, final Supplier<R> andThen) {
  final List<Source<T>> toApply = wrap(source);
  beforeApply(toApply);
  final Journal<?> journal = journalInfo.journal();
  stowMessages(AppendResultInterest.class);
  journal.appendAllWith(this.streamName, nextVersion(), toApply, metadata, snapshot(), interest, CompletionSupplier.supplierOrNull(andThen, completesEventually()));
  return andThen == null ? null : completes();
}
 
Example #20
Source File: Sourced.java    From vlingo-lattice with Mozilla Public License 2.0 3 votes vote down vote up
/**
 * Answer {@code Completes<RT>}, applying all of the given {@code sources} to myself,
 * which includes appending them to my journal and reflecting the representative changes
 * to my state, followed by the execution of a possible {@code andThen}.
 * @param sources the {@code List<Source<T>>} to apply
 * @param metadata the Metadata to apply along with source
 * @param andThen the {@code Supplier<R>} executed following the application of sources
 * @param <R> the return type of the andThen {@code Supplier<R>}
 * @return {@code Completes<R>}
 */
final protected <R> Completes<R> apply(final List<Source<T>> sources, final Metadata metadata, final Supplier<R> andThen) {
  beforeApply(sources);
  final Journal<?> journal = journalInfo.journal();
  stowMessages(AppendResultInterest.class);
  journal.appendAllWith(this.streamName, nextVersion(), sources, metadata, snapshot(), interest, CompletionSupplier.supplierOrNull(andThen, completesEventually()));
  return andThen == null ? null : completes();
}
 
Example #21
Source File: SourcedTypeRegistry.java    From vlingo-lattice with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Answer my {@code Journal<T>}.
 * @return {@code Journal<T>}
 */
public Journal<T> journal() {
  return journal;
}