Java源码示例:io.vlingo.symbio.EntryAdapterProvider
示例1
@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)));
}
示例2
@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);
}
示例3
@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));
}
示例4
@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());
}
示例5
/**
* 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()));
}
}
示例6
@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);
}
示例7
@SuppressWarnings({ "unchecked", "rawtypes" })
private <T extends Sourced<?>> void registerSourcedTypes(final Class<T> sourcedType) {
EntryAdapterProvider entryAdapterProvider = EntryAdapterProvider.instance(world);
sourcedTypeRegistry.register(new Info(journal, sourcedType, sourcedType.getSimpleName()));
sourcedTypeRegistry.info(sourcedType)
.registerEntryAdapter(ProcessMessage.class, new ProcessMessageTextAdapter(),
(type, adapter) -> entryAdapterProvider.registerAdapter(type, adapter))
.registerEntryAdapter(DoStepOne.class, new DoStepOneAdapter(),
(type, adapter) -> entryAdapterProvider.registerAdapter(type, adapter))
.registerEntryAdapter(DoStepTwo.class, new DoStepTwoAdapter(),
(type, adapter) -> entryAdapterProvider.registerAdapter(type, adapter))
.registerEntryAdapter(DoStepThree.class, new DoStepThreeAdapter(),
(type, adapter) -> entryAdapterProvider.registerAdapter(type, adapter))
.registerEntryAdapter(DoStepFour.class, new DoStepFourAdapter(),
(type, adapter) -> entryAdapterProvider.registerAdapter(type, adapter))
.registerEntryAdapter(DoStepFive.class, new DoStepFiveAdapter(),
(type, adapter) -> entryAdapterProvider.registerAdapter(type, adapter));
}
示例8
@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;
}
示例9
@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;
}
示例10
@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)));
}
示例11
/**
* Constructs my default state.
* @param entryReader the {@code EntryReader<T>} from which to read entry elements
* @param entryAdapterProvider the EntryAdapterProvider used to turn Entry instances into {@code Source<?>} instances
* @param flowElementsRate the long maximum elements to read at once
*/
@SuppressWarnings("unchecked")
public EntryReaderSource(
final EntryReader<T> entryReader,
final EntryAdapterProvider entryAdapterProvider,
final long flowElementsRate) {
this.entryReader = entryReader;
this.entryAdapterProvider = entryAdapterProvider;
this.flowElementsRate = flowElementsRate;
this.cache = new ArrayDeque<>();
this.cancellable = scheduler().schedule(selfAs(Scheduled.class), null, 0, Stream.FastProbeInterval);
}
示例12
@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)));
}
示例13
@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());
}
示例14
@Before
public void setUp() {
persistInterest = new MockPersistResultInterest();
queryResultInterest = new MockQueryResultInterest();
world = World.startWithDefaults("test-object-store");
final EntryAdapterProvider entryAdapterProvider = new EntryAdapterProvider(world);
entryAdapterProvider.registerAdapter(Test1Source.class, new Test1SourceAdapter());
this.dispatcher = new MockDispatcher<>(new MockConfirmDispatchedResultInterest());
objectStore = world.actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, this.dispatcher);
}
示例15
/**
* 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();
}
示例16
@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;
}
示例17
@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);
}
示例18
@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()));
}
示例19
@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));
}
示例20
@Before
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setUp() {
world = World.startWithDefaults("five-step-process-test");
final MessageQueue queue = new AsyncMessageQueue(null);
exchange = new LocalExchange(queue);
final ProcessMessageTextAdapter adapter = new ProcessMessageTextAdapter();
EntryAdapterProvider.instance(world).registerAdapter(ProcessMessage.class, adapter);
dispatcher = new MockTextDispatcher();
objectStore = world.actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, dispatcher);
objectTypeRegistry = new ObjectTypeRegistry(world);
final Info<StepCountObjectState> stepCountStateInfo =
new ObjectTypeRegistry.Info(
objectStore,
StepCountObjectState.class,
StepCountObjectState.class.getSimpleName(),
MapQueryExpression.using(StepCountObjectState.class, "find", MapQueryExpression.map("id", "id")),
StateObjectMapper.with(StepCountObjectState.class, new Object(), new Object()));
objectTypeRegistry.register(stepCountStateInfo);
exchangeReceivers = new ExchangeReceivers();
exchangeSender = new LocalExchangeSender(queue);
registerExchangeCoveys();
processTypeRegistry = new ProcessTypeRegistry(world);
processTypeRegistry.register(new ObjectProcessInfo(FiveStepEmittingObjectProcess.class, FiveStepEmittingObjectProcess.class.getSimpleName(), exchange, objectTypeRegistry));
}
示例21
@SuppressWarnings("unchecked")
public CounterQueryActor(JournalReader<TextEntry> streamReader, EntryAdapterProvider entryAdapterProvider) {
this.streamReader = streamReader;
this.entryAdapterProvider = entryAdapterProvider;
this.cancellable = scheduler().schedule(selfAs(Scheduled.class), null, 0, 5);
this.currentCount = Optional.empty();
intervalSignal(null, null);
}
示例22
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
journalReader = mock(JournalReader.class);
this.entryAdapterProvider = new EntryAdapterProvider();
counterIncreasedAdapter = new CounterIncreasedAdapter();
this.entryAdapterProvider.registerAdapter(CounterIncreased.class, counterIncreasedAdapter);
counterDecreasedAdapter = new CounterDecreasedAdapter();
this.entryAdapterProvider.registerAdapter(CounterDecreased.class, counterDecreasedAdapter);
}
示例23
public EntryReaderStream(final Stage stage, final EntryReader<T> entryReader, final EntryAdapterProvider entryAdapterProvider) {
this.stage = stage;
this.entryReader = entryReader;
this.entryAdapterProvider = entryAdapterProvider;
}
示例24
public InMemoryJournalReaderActor(final InMemoryJournalReader<T> reader, final EntryAdapterProvider entryAdapterProvider) {
this.reader = reader;
this.entryAdapterProvider = entryAdapterProvider;
}
示例25
public InMemoryJournalActor(final Dispatcher<Dispatchable<Entry<T>,RS>> dispatcher) {
this.journal = new InMemoryJournal<>(dispatcher, stage().world());
this.entryAdapterProvider = EntryAdapterProvider.instance(stage().world());
}
示例26
InMemoryJournalReaderInstantiator(final JournalReader<T> inmemory, final EntryAdapterProvider entryAdapterProvider) {
this.inmemory = inmemory;
this.entryAdapterProvider = entryAdapterProvider;
}
示例27
public InMemoryStateStoreEntryReaderActor(final List<Entry<T>> entriesView, final String name) {
this.entriesView = entriesView;
this.name = name;
this.entryAdapterProvider = EntryAdapterProvider.instance(stage().world());
this.currentIndex = 0;
}
示例28
public InMemoryObjectStoreEntryReaderActor(final List<Entry<String>> entriesView, final String name) {
this.entriesView = entriesView;
this.name = name;
this.entryAdapterProvider = EntryAdapterProvider.instance(stage().world());
this.currentIndex = 0;
}
示例29
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();
}
示例30
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?
}