io.vlingo.symbio.BaseEntry Java Examples
The following examples show how to use
io.vlingo.symbio.BaseEntry.
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: InMemoryStreamReader.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Override public Completes<EntityStream<T>> streamFor(final String streamName, final int fromStreamVersion) { int version = fromStreamVersion; State<T> snapshot = snapshotsView.get(streamName); if (snapshot != null) { if (snapshot.dataVersion > version) { version = snapshot.dataVersion; } else { snapshot = null; // reading from beyond snapshot } } final List<BaseEntry<T>> entries = new ArrayList<>(); final Map<Integer,Integer> versionIndexes = streamIndexesView.get(streamName); if (versionIndexes != null) { Integer journalIndex = versionIndexes.get(version); while (journalIndex != null) { final BaseEntry<T> entry = journalView.get(journalIndex); entries.add(entry); journalIndex = versionIndexes.get(++version); } } return Completes.withSuccess(new EntityStream<>(streamName, version - 1, entries, snapshot)); }
Example #2
Source File: EventSourcedTest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatCtorEmits() { final AccessSafely resultAccess = result.afterCompleting(2); final AccessSafely dispatcherAccess = dispatcher.afterCompleting(1); entity.doTest1(); assertTrue(resultAccess.readFrom("tested1")); assertEquals(1, (int) resultAccess.readFrom("appliedCount")); assertEquals(1, (int) dispatcherAccess.readFrom("entriesCount")); Object appliedAt0 = resultAccess.readFrom("appliedAt", 0); assertNotNull(appliedAt0); assertEquals(Test1Happened.class, appliedAt0.getClass()); BaseEntry<String> appendeAt0 = dispatcherAccess.readFrom("appendedAt", 0); assertNotNull(appendeAt0); assertEquals(Test1Happened.class.getName(), appendeAt0.typeName()); assertFalse(resultAccess.readFrom("tested2")); }
Example #3
Source File: RetryReaderActor.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Override public Completes<List<Entry<String>>> readNext(int count) { List<Entry<String>> entries = new ArrayList<>(); for (int i = 0; i < count; i++) { // every 3rd entry is loaded successfully if (i % 3 == 0) { BaseEntry.TextEntry entry = new BaseEntry.TextEntry(Long.toString(offset + i), Object.class, 1, "Entry_" + offset + i); entries.add(entry); } } final List<Long> gapIds = reader().detectGaps(entries, offset, count); GappedEntries<Entry<String>> gappedEntries = new GappedEntries<>(entries, gapIds, completesEventually()); offset += count; reader().readGaps(gappedEntries, 3, 10L, this::readIds); return completes(); }
Example #4
Source File: InMemoryObjectStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Override public <T extends StateObject, E> void persistAll(Collection<StateSources<T, E>> allStateSources, Metadata metadata, long updateId, PersistResultInterest interest, Object object) { final Collection<T> allPersistentObjects = new ArrayList<>(); try { for (StateSources<T, E> stateSources : allStateSources) { final T stateObject = stateSources.stateObject(); final State<?> state = storeDelegate.persist(stateObject, updateId, metadata); allPersistentObjects.add(stateObject); final int entryVersion = (int) stateSources.stateObject().version(); final List<BaseEntry<?>> entries = entryAdapterProvider.asEntries(stateSources.sources(), entryVersion, metadata); this.storeDelegate.persistEntries(entries); final Dispatchable<BaseEntry<?>, State<?>> dispatchable = buildDispatchable(state, entries); this.storeDelegate.persistDispatchable(dispatchable); dispatch(buildDispatchable(state, entries)); } interest.persistResultedIn(Success.of(Result.Success), allPersistentObjects, allPersistentObjects.size(), allPersistentObjects.size(), object); } catch (final StorageException e){ logger().error("Failed to persist all objects", e); interest.persistResultedIn(Failure.of(e), null, 0, 0, object); } }
Example #5
Source File: InMemoryObjectStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Override public <T extends StateObject, E> void persist(StateSources<T, E> stateSources, Metadata metadata, long updateId, PersistResultInterest interest, Object object) { try { final T stateObject = stateSources.stateObject(); final List<Source<E>> sources = stateSources.sources(); final State<?> raw = storeDelegate.persist(stateObject, updateId, metadata); final int entryVersion = (int) stateSources.stateObject().version(); final List<BaseEntry<?>> entries = entryAdapterProvider.asEntries(sources, entryVersion, metadata); final Dispatchable<BaseEntry<?>, State<?>> dispatchable = buildDispatchable(raw, entries); this.storeDelegate.persistEntries(entries); this.storeDelegate.persistDispatchable(dispatchable); dispatch(dispatchable); interest.persistResultedIn(Success.of(Result.Success), stateObject, 1, 1, object); } catch (StorageException e){ logger().error("Failed to persist all objects", e); interest.persistResultedIn(Failure.of(e), null, 0, 0, object); } }
Example #6
Source File: InMemoryObjectStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@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: CounterQueryActor.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Override @SuppressWarnings("rawtypes") public void intervalSignal(Scheduled<Object> scheduled, Object data) { streamReader.readNext() .andThen(event -> ((BaseEntry) event).asTextEntry()) .andThenConsume(entry -> { counted = (Event) entryAdapterProvider.asSource(entry); currentCount = Optional.of(counted.currentCounter); }); }
Example #8
Source File: EventSourcedTest.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatOutcomeCompletes() { final AccessSafely resultAccess = result.afterCompleting(2); final AccessSafely dispatcherAccess = dispatcher.afterCompleting(1); entity.doTest1(); assertTrue(resultAccess.readFrom("tested1")); assertFalse(resultAccess.readFrom("tested3")); assertEquals(1, (int) resultAccess.readFrom("appliedCount")); assertEquals(1, (int) dispatcherAccess.readFrom("entriesCount")); Object appliedAt0 = resultAccess.readFrom("appliedAt", 0); assertNotNull(appliedAt0); assertEquals(Test1Happened.class, appliedAt0.getClass()); BaseEntry<String> appendeAt0 = dispatcherAccess.readFrom("appendedAt", 0); assertNotNull(appendeAt0); assertEquals(Test1Happened.class.getName(), appendeAt0.typeName()); final AccessSafely resultAccess2 = result.afterCompleting(2); final AccessSafely dispatcherAccess2 = dispatcher.afterCompleting(1); entity.doTest3().andThenConsume(greeting -> { assertEquals("hello", greeting); }); assertEquals(2, (int) resultAccess2.readFrom("appliedCount")); assertEquals(2, (int) dispatcherAccess2.readFrom("entriesCount")); Object appliedAt1 = resultAccess2.readFrom("appliedAt", 1); assertNotNull(appliedAt1); assertEquals(Test3Happened.class, appliedAt1.getClass()); BaseEntry<String> appendeAt1 = dispatcherAccess.readFrom("appendedAt", 1); assertNotNull(appendeAt1); assertEquals(Test3Happened.class.getName(), appendeAt1.typeName()); }
Example #9
Source File: EventSourcedTest.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatCommandEmits() { final AccessSafely resultAccess = result.afterCompleting(2); final AccessSafely dispatcherAccess = dispatcher.afterCompleting(1); entity.doTest1(); assertTrue(resultAccess.readFrom("tested1")); assertFalse(resultAccess.readFrom("tested2")); assertEquals(1, (int) resultAccess.readFrom("appliedCount")); assertEquals(1, (int) dispatcherAccess.readFrom("entriesCount")); Object appliedAt0 = resultAccess.readFrom("appliedAt", 0); assertNotNull(appliedAt0); assertEquals(Test1Happened.class, appliedAt0.getClass()); BaseEntry<String> appendeAt0 = dispatcherAccess.readFrom("appendedAt", 0); assertNotNull(appendeAt0); assertEquals(Test1Happened.class.getName(), appendeAt0.typeName()); final AccessSafely resultAccess2 = result.afterCompleting(2); final AccessSafely dispatcherAccess2 = dispatcher.afterCompleting(1); entity.doTest2(); assertEquals(2, (int) resultAccess2.readFrom("appliedCount")); assertEquals(2, (int) dispatcherAccess.readFrom("entriesCount")); Object appliedAt1 = resultAccess2.readFrom("appliedAt", 1); assertNotNull(appliedAt1); assertEquals(Test2Happened.class, appliedAt1.getClass()); BaseEntry<String> appendeAt1 = dispatcherAccess2.readFrom("appendedAt", 1); assertNotNull(appendeAt1); assertEquals(Test2Happened.class.getName(), appendeAt1.typeName()); }
Example #10
Source File: InMemoryEventJournalActorTest.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
public AccessSafely afterCompleting(final int times) { access = AccessSafely.afterCompleting(times) .writingWith("addAll", (values) -> this.entries.addAll((Collection<BaseEntry<String>>) values)) .readingWith("entry", (index) -> this.entries.get((int) index)) .readingWith("entryId", (index) -> this.entries.get((int) index).id()) .readingWith("size", () -> this.entries.size()); return access; }
Example #11
Source File: InMemoryObjectStoreDelegate.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void persistEntries(final Collection<BaseEntry<?>> entries) { entries.forEach(baseEntry -> { baseEntry.__internal__setId(identityGenerator.generate().toString()); }); this.entries.addAll(entries); }
Example #12
Source File: InMemoryStateStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
private <C> List<Entry<?>> appendEntries(final List<Source<C>> sources, final int stateVersion, final Metadata metadata) { final List<Entry<?>> adapted = entryAdapterProvider.asEntries(sources, stateVersion, metadata); for (final Entry<?> each : adapted) { ((BaseEntry<?>) each).__internal__setId(String.valueOf(entries.size())); entries.add(each); } return adapted; }
Example #13
Source File: InMemoryJournal.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
private void insert(final String streamName, final int streamVersion, final Entry<T> entry) { final int entryIndex = journal.size(); final String id = "" + (entryIndex + 1); ((BaseEntry<T>) entry).__internal__setId(id); //questionable cast journal.add(entry); final Map<Integer, Integer> versionIndexes = streamIndexes.computeIfAbsent(streamName, k -> new HashMap<>()); versionIndexes.put(streamVersion, entryIndex); }
Example #14
Source File: InMemoryStreamReader.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
public InMemoryStreamReader( final List<BaseEntry<T>> journalView, final Map<String, Map<Integer,Integer>> streamIndexesView, final Map<String, State<T>> snapshotsView, final String name) { this.journalView = journalView; this.streamIndexesView = streamIndexesView; this.snapshotsView = snapshotsView; this.name = name; }
Example #15
Source File: InMemoryObjectStoreDelegate.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
List<BaseEntry<?>> readOnlyJournal() { return entries; }
Example #16
Source File: InMemoryObjectStoreDelegate.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public Collection<Dispatchable<BaseEntry<?>, State<?>>> allUnconfirmedDispatchableStates() { return new ArrayList<>(dispatchables); }
Example #17
Source File: InMemoryObjectStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
private void dispatch(final Dispatchable<BaseEntry<?>, State<?>> dispatchable){ this.dispatchers.forEach(d -> d.dispatch(dispatchable)); }
Example #18
Source File: InMemoryObjectStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
private static Dispatchable<BaseEntry<?>, State<?>> buildDispatchable(final State<?> state, final List<BaseEntry<?>> entries) { final String id = getDispatchId(state, entries); return new Dispatchable<>(id, LocalDateTime.now(), state, entries); }
Example #19
Source File: InMemoryObjectStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
private static String getDispatchId(final State<?> raw, final List<BaseEntry<?>> entries) { return raw.id + ":" + entries.stream().map(Entry::id).collect(Collectors.joining(":")); }
Example #20
Source File: InMemoryObjectStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
private List<BaseEntry<?>> readOnlyJournal() { return ((InMemoryObjectStoreDelegate) storeDelegate).readOnlyJournal(); }
Example #21
Source File: InMemoryObjectStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
ObjectStoreEntryReaderInstantiator(final List<BaseEntry<?>> readOnlyJournal, final String name) { this.readOnlyJournal = readOnlyJournal; this.name = name; }
Example #22
Source File: InMemoryObjectStoreDelegate.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void persistDispatchable(final Dispatchable<BaseEntry<?>, State<?>> dispatchable) { this.dispatchables.add(dispatchable); }
Example #23
Source File: EntityStream.java From vlingo-symbio with Mozilla Public License 2.0 | 3 votes |
/** * Construct a new Stream. * * @param streamName the {@code String} name of this stream, which is generally a global unique identity * of an associated entity/aggregate * @param streamVersion the {@code int} version of the stream * @param entries the {@code List<Entry<T>>} of all entries in the named stream or some sub-stream * @param snapshot the {@code State<T>} of a persisted state, or an empty {@code State<T>} if none */ public EntityStream(final String streamName, final int streamVersion, final List<BaseEntry<T>> entries, final State<T> snapshot) { this.streamName = streamName; this.streamVersion = streamVersion; this.entries = entries; this.snapshot = snapshot; }
Example #24
Source File: InMemoryObjectStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 2 votes |
/** * 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); }