Java Code Examples for io.vlingo.symbio.StateAdapterProvider#registerAdapter()

The following examples show how to use io.vlingo.symbio.StateAdapterProvider#registerAdapter() . 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: InMemoryStateStoreTest.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@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 2
Source File: InMemoryStateStoreRedispatchControlTest.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@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 3
Source File: InMemoryStateStoreEntryReaderActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@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 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: QueryModelStoreProvider.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@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 6
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 7
Source File: StatefulEntityTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@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 8
Source File: CartQueryProvider.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
private static void registerStateAdapter(Stage stage) {
  final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(stage.world());
  stateAdapterProvider.registerAdapter(CartUserSummaryData.class, new CartStateAdapter());
  stateAdapterProvider.registerAdapter(UserId.class, new UserIdStateAdapter() );
  new EntryAdapterProvider(stage.world()); // future?
}