io.vlingo.symbio.store.dispatch.Dispatcher Java Examples

The following examples show how to use io.vlingo.symbio.store.dispatch.Dispatcher. 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: 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 #2
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 #3
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 #4
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 #5
Source File: StateProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatDescribedProjectionsRegister() {
  final ProjectToDescription description = new ProjectToDescription(DescribedProjection.class, "op1", "op2");

  final Dispatcher dispatcher =
          world.actorFor(Dispatcher.class, TextProjectionDispatcherActor.class, Collections.singletonList(description));

  final Outcome outcome = new Outcome(2);
  final AccessSafely accessOutcome = outcome.afterCompleting(2);
  dispatcher.controlWith(outcome);

  final TextState state = new TextState("123", Object.class, 1, "blah1", 1, Metadata.with("", "op1"));
  dispatcher.dispatch(new Dispatchable<>("123", LocalDateTime.now(), state, Collections.emptyList()));

  final TextState state2 = new TextState("1235", Object.class, 1, "blah2", 1, Metadata.with("", "op2"));
  dispatcher.dispatch(new Dispatchable<>("1235", LocalDateTime.now(), state2, Collections.emptyList()));

  assertEquals(2, (int) accessOutcome.readFrom("count"));
}
 
Example #6
Source File: InMemoryObjectStoreActor.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public InMemoryObjectStoreActor(
        final List<Dispatcher<Dispatchable<BaseEntry<?>,State<?>>>> dispatchers,
        final long checkConfirmationExpirationInterval,
        final long confirmationExpiration ) {

  this.entryAdapterProvider = EntryAdapterProvider.instance(stage().world());

  this.dispatchers = dispatchers;

  this.entryReaders = new HashMap<>();

  this.storeDelegate = new InMemoryObjectStoreDelegate(StateAdapterProvider.instance(stage().world()));

  this.dispatcherControl = stage().actorFor(
          DispatcherControl.class,
          Definition.has(
                  DispatcherControlActor.class,
                  new DispatcherControlInstantiator(
                          dispatchers,
                          this.storeDelegate,
                          checkConfirmationExpirationInterval,
                          confirmationExpiration)));
}
 
Example #7
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 #8
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 #9
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@NotNull
@SuppressWarnings("rawtypes")
private Dispatcher createNoOpDispatcher() {
    return new Dispatcher() {
            public void controlWith(final DispatcherControl control) { }
            public void dispatch(Dispatchable d) { }
        };
}
 
Example #10
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 #11
Source File: DispatcherControlActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
public DispatcherControlActor(
        final List<Dispatcher<Dispatchable<? extends Entry<?>, ? extends State<?>>>> dispatchers,
        final DispatcherControlDelegate<? extends Entry<?>, ? extends State<?>> delegate,
        final long checkConfirmationExpirationInterval,
        final long confirmationExpiration) {
  this.dispatchers = dispatchers;
  this.delegate = delegate;
  this.confirmationExpiration = confirmationExpiration;
  this.cancellable = scheduler().schedule(this, null, DEFAULT_REDISPATCH_DELAY, checkConfirmationExpirationInterval);
  this.dispatchers.forEach(d -> d.controlWith(this));
}
 
Example #12
Source File: InMemoryStateStoreActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public InMemoryStateStoreActor(
        final List<Dispatcher<Dispatchable<Entry<?>, RS>>> dispatchers,
        final long checkConfirmationExpirationInterval,
        final long confirmationExpiration) {

  if (dispatchers == null) {
    throw new IllegalArgumentException("Dispatcher must not be null.");
  }
  this.dispatchers = dispatchers;
  this.entryAdapterProvider = EntryAdapterProvider.instance(stage().world());
  this.stateAdapterProvider = StateAdapterProvider.instance(stage().world());
  this.entries = new CopyOnWriteArrayList<>();
  this.entryReaders = new HashMap<>();
  this.store = new HashMap<>();
  this.dispatchables = new CopyOnWriteArrayList<>();
  this.readAllResultCollector = new ReadAllResultCollector();

  final InMemoryDispatcherControlDelegate<Entry<?>, RS> dispatcherControlDelegate = new InMemoryDispatcherControlDelegate<>(dispatchables);

  this.dispatcherControl = stage().actorFor(
    DispatcherControl.class,
    Definition.has(
      DispatcherControlActor.class,
      new DispatcherControlInstantiator(
        dispatchers,
        dispatcherControlDelegate,
        checkConfirmationExpirationInterval,
        confirmationExpiration)));
}
 
Example #13
Source File: InMemoryJournal.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public InMemoryJournal(
        final List<Dispatcher<Dispatchable<Entry<T>,RS>>> dispatchers,
        final World world,
        final long checkConfirmationExpirationInterval,
        final long confirmationExpiration) {

  this.entryAdapterProvider = EntryAdapterProvider.instance(world);
  this.stateAdapterProvider = StateAdapterProvider.instance(world);
  this.journal = new ArrayList<>();
  this.journalReaders = new HashMap<>(1);
  this.streamReaders = new HashMap<>(1);
  this.streamIndexes = new HashMap<>();
  this.snapshots = new HashMap<>();

  this.dispatchers = dispatchers;
  this.dispatchables = new CopyOnWriteArrayList<>();
  final InMemoryDispatcherControlDelegate<Entry<T>, RS> dispatcherControlDelegate = new InMemoryDispatcherControlDelegate<>(dispatchables);

  this.dispatcherControl = world.stage().actorFor(
          DispatcherControl.class,
          Definition.has(
                  DispatcherControlActor.class,
                  new DispatcherControlInstantiator(
                          dispatchers,
                          dispatcherControlDelegate,
                          checkConfirmationExpirationInterval,
                          confirmationExpiration)));
}
 
Example #14
Source File: InMemoryStateStoreActor.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
public InMemoryStateStoreActor(final List<Dispatcher<Dispatchable<Entry<?>, RS>>> dispatchers) {
  this(dispatchers, 1000L, 1000L);
}
 
Example #15
Source File: StateProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected Class<? extends Dispatcher> dispatcherInterfaceClass() {
  return Dispatcher.class;
}
 
Example #16
Source File: ProjectionDispatcherProvider.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
private ProjectionDispatcherProvider(final Dispatcher storeDispatcher, final ProjectionDispatcher projectionDispatcher) {
  this.storeDispatcher = storeDispatcher;
  this.projectionDispatcher = projectionDispatcher;
}
 
Example #17
Source File: InMemoryJournal.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
public InMemoryJournal(final Dispatcher<Dispatchable<Entry<T>, RS>> dispatcher, final World world ) {
  this(Arrays.asList(dispatcher), world, 1000L, 1000L);
}
 
Example #18
Source File: InMemoryJournalActor.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
public InMemoryJournalActor(final Dispatcher<Dispatchable<Entry<T>,RS>> dispatcher) {
  this.journal = new InMemoryJournal<>(dispatcher, stage().world());
  this.entryAdapterProvider = EntryAdapterProvider.instance(stage().world());
}
 
Example #19
Source File: ProjectionDispatcherProvider.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
private ProjectionDispatcherProvider(final Dispatcher storeDispatcher, final ProjectionDispatcher projectionDispatcher) {
  this.storeDispatcher = storeDispatcher;
  this.projectionDispatcher = projectionDispatcher;
}
 
Example #20
Source File: SourcedTypeRegistry.java    From vlingo-lattice with Mozilla Public License 2.0 3 votes vote down vote up
/**
 * Answer a new {@code SourcedTypeRegistry} with registered {@code sourcedTypes}, creating
 * the {@code Journal} of type {@code journalType}, registering 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
 * @return SourcedTypeRegistry
 */
@SuppressWarnings({ "unchecked" })
public static <A extends Actor, S extends Sourced<?>> SourcedTypeRegistry register(
        final World world,
        final Class<A> journalType,
        final Dispatcher<Dispatchable<Entry<?>,State<?>>> dispatcher,
        final Class<S> ... sourcedTypes) {
  return new SourcedTypeRegistry(world, journalType, dispatcher, sourcedTypes);
}
 
Example #21
Source File: Journal.java    From vlingo-symbio with Mozilla Public License 2.0 3 votes vote down vote up
/**
 * Answer a new {@code Journal<T>}
 * @param stage the Stage within which the {@code Journal<T>} is created
 * @param implementor the {@code Class<A>} of the implementor
 * @param dispatchers the {@code List<Dispatcher<T>>}
 * @param additional the Object[] of additional parameters
 * @param <A> the concrete type of the Actor implementing the {@code Journal<T>} protocol
 * @param <T> the concrete type of {@code Entry<T>} stored and read, which maybe be String, byte[], or Object
 * @param <RS> the raw snapshot state type
 * @return {@code Journal<T>}
 */
@SuppressWarnings("unchecked")
static <A extends Actor, T, RS extends State<?>> Journal<T> using(final Stage stage, final Class<A> implementor,
        final List<Dispatcher<Dispatchable<Entry<T>,RS>>> dispatchers, final Object...additional) {
  return additional.length == 0 ?
           stage.actorFor(Journal.class, implementor, dispatchers) :
           stage.actorFor(Journal.class, implementor, dispatchers, additional);
}
 
Example #22
Source File: Journal.java    From vlingo-symbio with Mozilla Public License 2.0 3 votes vote down vote up
/**
 * Answer a new {@code Journal<T>}
 * @param stage the Stage within which the {@code Journal<T>} is created
 * @param implementor the {@code Class<A>} of the implementor
 * @param dispatcher the {@code Dispatcher<T>}
 * @param additional the Object[] of additional parameters
 * @param <A> the concrete type of the Actor implementing the {@code Journal<T>} protocol
 * @param <T> the concrete type of {@code Entry<T>} stored and read, which maybe be String, byte[], or Object
 * @param <RS> the raw snapshot state type
 * @return {@code Journal<T>}
 */
@SuppressWarnings("unchecked")
static <A extends Actor, T, RS extends State<?>> Journal<T> using(final Stage stage, final Class<A> implementor,
        final Dispatcher<Dispatchable<Entry<T>,RS>> dispatcher, final Object...additional) {
  return additional.length == 0 ?
           stage.actorFor(Journal.class, implementor, dispatcher) :
           stage.actorFor(Journal.class, implementor, dispatcher, additional);
}
 
Example #23
Source File: InMemoryObjectStoreActor.java    From vlingo-symbio with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Construct my default state.
 * @param dispatcher The dispatcher to be used
 */
public InMemoryObjectStoreActor(final Dispatcher<Dispatchable<BaseEntry<?>,State<?>>> dispatcher){
  this(Arrays.asList(dispatcher), 1000L, 1000L);
}
 
Example #24
Source File: ProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 votes vote down vote up
protected abstract Class<? extends Dispatcher> dispatcherInterfaceClass();