io.vlingo.symbio.store.state.StateStore Java Examples
The following examples show how to use
io.vlingo.symbio.store.state.StateStore.
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: InMemoryStateStoreRedispatchControlTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Before public void setUp() { world = World.startWithDefaults("test-store"); interest = new MockStateStoreResultInterest(); dispatcher = new MockStateStoreDispatcher(interest); final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(world); new EntryAdapterProvider(world); stateAdapterProvider.registerAdapter(Entity1.class, new Entity1StateAdapter()); // NOTE: No adapter registered for Entity2.class because it will use the default StateTypeStateStoreMap.stateTypeToStoreName(Entity1.class, StoreName); store = world.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(dispatcher)); }
Example #2
Source File: QueryModelStoreProvider.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") public static QueryModelStoreProvider using(final Stage stage, final StatefulTypeRegistry registry) { if (instance != null) return instance; final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(stage.world()); stateAdapterProvider.registerAdapter(UserData.class, new UserDataStateAdapter()); stateAdapterProvider.registerAdapter(ProfileData.class, new ProfileDataStateAdapter()); new EntryAdapterProvider(stage.world()); // future final Dispatcher noop = new Dispatcher() { public void controlWith(final DispatcherControl control) { } public void dispatch(Dispatchable d) { } }; final StateStore store = stage.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(noop)); final Queries queries = stage.actorFor(Queries.class, QueriesActor.class, store); instance = new QueryModelStoreProvider(registry, store, queries); return instance; }
Example #3
Source File: CommandModelStoreProvider.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@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 #4
Source File: StateProjectionDispatcherTest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatTextStateDataProjects() { final StateStore store = store(); final MockResultInterest interest = new MockResultInterest(0); final MockProjection projection = new MockProjection(); final AccessSafely access = projection.afterCompleting(2); projectionDispatcher.projectTo(projection, new String[] { "op1" }); projectionDispatcher.projectTo(projection, new String[] { "op2" }); final Entity1 entity1 = new Entity1("123-1", 1); final Entity1 entity2 = new Entity1("123-2", 2); store.write(entity1.id, entity1, 1, Metadata.with("value1", "op1"), interest); store.write(entity2.id, entity2, 1, Metadata.with("value2", "op2"), interest); assertEquals(2, (int) access.readFrom("projections")); assertEquals("123-1", access.readFrom("projectionId", 0)); assertEquals("123-2", access.readFrom("projectionId", 1)); }
Example #5
Source File: InMemoryStateStoreTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Before public void setUp() { testWorld = TestWorld.startWithDefaults("test-store"); world = testWorld.world(); interest = new MockStateStoreResultInterest(); dispatcher = new MockStateStoreDispatcher(interest); dispatcher.afterCompleting(0); // avoid NPE final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(world); new EntryAdapterProvider(world); stateAdapterProvider.registerAdapter(Entity1.class, new Entity1StateAdapter()); // NOTE: No adapter registered for Entity2.class because it will use the default store = world.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(dispatcher)); StateTypeStateStoreMap.stateTypeToStoreName(Entity1.class, StoreName1); StateTypeStateStoreMap.stateTypeToStoreName(Entity2.class, StoreName2); }
Example #6
Source File: InMemoryStateStoreEntryReaderActorTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Before public void setUp() { testWorld = TestWorld.startWithDefaults("test-store"); world = testWorld.world(); interest = new MockStateStoreResultInterest(); dispatcher = new MockStateStoreDispatcher(interest); final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(world); entryAdapterProvider = new EntryAdapterProvider(world); stateAdapterProvider.registerAdapter(Entity1.class, new Entity1StateAdapter()); // NOTE: No adapter registered for Entity2.class because it will use the default store = world.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(dispatcher)); final Completes<StateStoreEntryReader<TextEntry>> completes = store.entryReader("test"); reader = completes.await(); StateTypeStateStoreMap.stateTypeToStoreName(Entity1.class, Entity1.class.getSimpleName()); StateTypeStateStoreMap.stateTypeToStoreName(Entity2.class, Entity2.class.getSimpleName()); }
Example #7
Source File: StateStoreProjectionActor.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
/** * Construct my final state with the {@code StateStore}, which must * be provided by my concrete extenders, as well as with a * {@code stateAdapter} and a {@code entryAdapter}. * @param stateStore the StateStore from which previous state is read and merged current state is written * @param stateAdapter the {@code StateAdapter<Object, State<?>>} used by my extenders to adapt persistent state * @param entryAdapter the {@code EntryAdapter<Source<?>, Entry<?>>} used by my extenders to adapt persistent entries */ public StateStoreProjectionActor( final StateStore stateStore, final StateAdapter<Object, State<?>> stateAdapter, final EntryAdapter<Source<?>, Entry<?>> entryAdapter) { this.stateStore = stateStore; this.stateAdapter = stateAdapter; this.entryAdapter = entryAdapter; this.readInterest = selfAs(ReadResultInterest.class); this.writeInterest = selfAs(WriteResultInterest.class); this.adaptedSources = new ArrayList<>(2); }
Example #8
Source File: OrganizationEntityTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Before @SuppressWarnings({ "unchecked", "rawtypes" }) public void setUp() throws Exception { grid = Grid.start("stateful-entity-test", Configuration.define(), ClusterProperties.oneNode(), "node1"); grid.quorumAchieved(); stateStore = grid.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(new MockDispatcher())); registry = new StatefulTypeRegistry(grid.world()); final Info<Organization> info = new Info(stateStore, io.vlingo.entity.stateful.State.class, "StateStore"); registry.register(info); }
Example #9
Source File: CartQueryProvider.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
public static CartQueryProvider using(final Stage stage, final StatefulTypeRegistry registry, final StateStore stateStore) { if (instance == null) { registerStateAdapter(stage); registerStatefulTypes(stateStore, registry); final CartQuery queries = stage.actorFor(CartQuery.class, CartQueryActor.class, stateStore); instance = new CartQueryProvider(stateStore, queries); } return instance; }
Example #10
Source File: QueryModelStoreProvider.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) private QueryModelStoreProvider(final StatefulTypeRegistry registry, final StateStore store, final Queries queries) { this.store = store; this.queries = queries; registry .register(new Info(store, UserData.class, UserData.class.getSimpleName())) .register(new Info(store, ProfileData.class, ProfileData.class.getSimpleName())); }
Example #11
Source File: CommandModelStoreProvider.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) private CommandModelStoreProvider(final StatefulTypeRegistry registry, final StateStore store, final DispatcherControl dispatcherControl) { this.store = store; this.dispatcherControl = dispatcherControl; registry .register(new Info(store, User.UserState.class, User.UserState.class.getSimpleName())) .register(new Info(store, Profile.ProfileState.class, Profile.ProfileState.class.getSimpleName())) .register(new Info(store, UserData.class, UserData.class.getSimpleName())) .register(new Info(store, ProfileData.class, ProfileData.class.getSimpleName())); }
Example #12
Source File: StatefulProcessTest.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@Before @SuppressWarnings({ "unchecked", "rawtypes" }) public void setUp() { world = World.startWithDefaults("five-step-process-test"); dispatcher = new MockTextDispatcher(); final MessageQueue queue = new AsyncMessageQueue(null); exchange = new LocalExchange(queue); stateStore = world.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(dispatcher)); EntryAdapterProvider.instance(world); statefulTypeRegistry = new StatefulTypeRegistry(world); final Info<StepCountState> stepCountStateInfo = new StatefulTypeRegistry.Info( stateStore, StepCountState.class, StepCountState.class.getSimpleName()); statefulTypeRegistry.register(stepCountStateInfo); exchangeReceivers = new ExchangeReceivers(); exchangeSender = new LocalExchangeSender(queue); registerExchangeCoveys(); processTypeRegistry = new ProcessTypeRegistry(world); processTypeRegistry.register(new StatefulProcessInfo(FiveStepEmittingStatefulProcess.class, FiveStepEmittingStatefulProcess.class.getSimpleName(), exchange, statefulTypeRegistry)); }
Example #13
Source File: StatefulEntityTest.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@Before public void setUp() { world = World.startWithDefaults("stateful-entity"); dispatcher = new MockTextDispatcher(); stateAdapterProvider = new StateAdapterProvider(world); stateAdapterProvider.registerAdapter(Entity1State.class, new Entity1StateAdapter()); new EntryAdapterProvider(world); registry = new StatefulTypeRegistry(world); store = world.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(dispatcher)); registry.register(new Info<>(store, Entity1State.class, Entity1State.class.getSimpleName())); }
Example #14
Source File: StatefulTypeRegistry.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
/** * Answer a new {@code StatefulTypeRegistry} after registering all {@code types} with the {@code stateStore} * using the default {@code storeName} for each of the {@code types}. * @param world the World to which the new StatefulTypeRegistry is registered * @param stateStore the StateStore * @param types the {@code Class<?>}[] native type of states to be stored * @return StatefulTypeRegistry */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static StatefulTypeRegistry registerAll(final World world, final StateStore stateStore, final Class<?>... types) { final StatefulTypeRegistry registry = new StatefulTypeRegistry(world); for (final Class<?> type : types) { registry.register(new Info(stateStore, type, type.getSimpleName())); } return registry; }
Example #15
Source File: ProjectionDispatcherTest.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@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 #16
Source File: WarbleStateStoreProjection.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
public WarbleStateStoreProjection(final StateStore stateStore, final boolean alwaysWrite) { super(stateStore); this.alwaysWrite = alwaysWrite; }
Example #17
Source File: Bootstrap.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@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: CartQueryProvider.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
private CartQueryProvider(final StateStore store, final CartQuery queries) { this.store = store; this.cartQuery = queries; }
Example #19
Source File: CartQueryProvider.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) private static void registerStatefulTypes(StateStore stateStore, StatefulTypeRegistry registry) { registry .register(new Info(stateStore, CartUserSummaryData.class, CartUserSummaryData.class.getSimpleName())) .register(new Info(stateStore, UserId.class, UserId.class.getSimpleName())); }
Example #20
Source File: CartQueryActor.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
public CartQueryActor(final StateStore store) { super(store); }
Example #21
Source File: StatefulTypeRegistry.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
public BinaryInfo(final StateStore store, final Class<S> storeType, final String storeName) { super(store, storeType, storeName); }
Example #22
Source File: StatefulTypeRegistry.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
public TextInfo(final StateStore store, final Class<S> storeType, final String storeName) { super(store, storeType, storeName); }
Example #23
Source File: QueriesActor.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
public QueriesActor(final StateStore store) { super(store); }
Example #24
Source File: StateProjectionDispatcherTest.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Override protected Class<? extends StateStore> stateStoreInterfaceClass() { return StateStore.class; }
Example #25
Source File: StateProjectionDispatcherTest.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Test public void testThatProjectionsPipeline() { final StateStore store = store(); final FilterOutcome filterOutcome = new FilterOutcome(); final AccessSafely filterOutcomeAccess = filterOutcome.afterCompleting(3); ProjectionDispatcher filter1 = FilterProjectionDispatcherActor.filterFor(world, projectionDispatcher, new String[] {"op-1"}, filterOutcome); ProjectionDispatcher filter2 = FilterProjectionDispatcherActor.filterFor(world, filter1, new String[] {"op-1"}, filterOutcome); FilterProjectionDispatcherActor.filterFor(world, filter2, new String[] {"op-1"}, filterOutcome); final Entity1 entity1 = new Entity1("123-1", 1); store.write(entity1.id, entity1, 1, Metadata.with("value1", "op-1"), new MockResultInterest(0)); assertEquals(3, (int) filterOutcomeAccess.readFrom("filterCount")); }
Example #26
Source File: WarbleStateStoreProjection.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
public WarbleStateStoreProjection(final StateStore stateStore) { this(stateStore, true); }
Example #27
Source File: StateStoreProjectionTest.java From vlingo-lattice with Mozilla Public License 2.0 | 3 votes |
@Before public void setUp() { world = World.startWithDefaults("test-state-store-projection"); store = world.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(new NoOpDispatcher())); projection = world.actorFor(Projection.class, WarbleStateStoreProjection.class, store); StatefulTypeRegistry.registerAll(world, store, Warble.class); valueToProjectionId = new HashMap<>(); }
Example #28
Source File: StatefulTypeRegistry.java From vlingo-lattice with Mozilla Public License 2.0 | 2 votes |
/** * Construct my default state. * @param store the StateStore * @param storeType the {@code Class<S>} of the State * @param storeName the String name of the store */ public Info(final StateStore store, final Class<S> storeType, final String storeName) { this.store = store; this.storeType = storeType; this.storeName = storeName; }
Example #29
Source File: StateStoreQueryActor.java From vlingo-lattice with Mozilla Public License 2.0 | 2 votes |
/** * Construct my final state with the {@code StateStore}, which must * be provided by my concrete extenders. * @param stateStore the StateStore from which states are read */ protected StateStoreQueryActor(final StateStore stateStore) { this.stateStore = stateStore; this.readInterest = selfAs(ReadResultInterest.class); }
Example #30
Source File: StateStoreProjectionActor.java From vlingo-lattice with Mozilla Public License 2.0 | 2 votes |
/** * Construct my final state with the {@code StateStore}, which must * be provided by my concrete extenders. I provide default state and * entry adapters. * @param stateStore the StateStore from which previous state is read and merged current state is written */ public StateStoreProjectionActor(final StateStore stateStore) { this(stateStore, defaultTextStateAdapter(), defaultTextEntryAdapter()); }