io.vlingo.symbio.Metadata Java Examples
The following examples show how to use
io.vlingo.symbio.Metadata.
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: 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 #2
Source File: TextProjectableTest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Test public void testStateWithEventProjectableness() { final String textState = "test-state"; final TextState state = new TextState("123", String.class, 1, textState, 1, Metadata.with("value", "op")); final Entry<String> entry = new TextEntry(); final Projectable projectable = new TextProjectable(state, Arrays.asList(entry), "p123"); assertEquals("op", projectable.becauseOf()[0]); assertEquals("java.lang.Object", projectable.becauseOf()[1]); assertEquals(textState, projectable.dataAsText()); assertEquals("123", projectable.dataId()); assertEquals(1, projectable.dataVersion()); assertEquals("value", projectable.metadata()); assertEquals("p123", projectable.projectionId()); assertEquals(String.class.getName(), projectable.type()); assertEquals(1, projectable.typeVersion()); }
Example #3
Source File: InMemoryJournal.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Override public <S, ST> void appendWith(final String streamName, final int streamVersion, final Source<S> source, final Metadata metadata, final ST snapshot, final AppendResultInterest interest, final Object object) { final Entry<T> entry = entryAdapterProvider.asEntry(source, streamVersion, metadata); insert(streamName, streamVersion, entry); final RS raw; final Optional<ST> snapshotResult; if (snapshot != null) { raw = stateAdapterProvider.asRaw(streamName, snapshot, streamVersion); snapshots.put(streamName, raw); snapshotResult = Optional.of(snapshot); } else { raw = null; snapshotResult = Optional.empty(); } dispatch(streamName, streamVersion, Collections.singletonList(entry), raw); interest.appendResultedIn(Success.of(Result.Success), streamName, streamVersion, source, snapshotResult, object); }
Example #4
Source File: ProjectableTest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatStateDoesNotFail() { final Object object = new Object(); final Projectable projectable = new TextProjectable( new TextState("ABC", String.class, 1, "state", 1, Metadata.with(object, "value", "op1")), Arrays.asList(), "123"); Assert.assertEquals(1, projectable.dataVersion()); Assert.assertEquals("ABC", projectable.dataId()); Assert.assertEquals("value", projectable.metadata()); Assert.assertTrue(projectable.hasObject()); Assert.assertNotNull(projectable.object()); Assert.assertEquals(object, projectable.object()); Assert.assertTrue(projectable.optionalObject().isPresent()); Assert.assertTrue(projectable.hasState()); Assert.assertEquals(1, projectable.typeVersion()); }
Example #5
Source File: StateProjectionDispatcherTest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@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: StateStoreProjectionActor.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
/** * FOR INTERNAL USE ONLY. */ @Override @SuppressWarnings("unchecked") final public <S> void readResultedIn(final Outcome<StorageException, Result> outcome, final String id, final S state, final int stateVersion, final Metadata metadata, final Object object) { outcome.andThen(result -> { ((BiConsumer<S,Integer>) object).accept(state, stateVersion); return result; }).otherwise(cause -> { if (cause.result.isNotFound()) { ((BiConsumer<S,Integer>) object).accept(null, -1); } else { // log but don't retry, allowing re-delivery of Projectable logger().info("Query state not read for update because: " + cause.getMessage(), cause); } return cause.result; }); }
Example #7
Source File: InMemoryStateStoreEntryReaderActorTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatEntryReaderReadsOne() { final AccessSafely access = interest.afterCompleting(3); dispatcher.afterCompleting(0); store.write(Id1, new Entity1(Id1, 10), 1, Arrays.asList(new Event1()), interest); store.write(Id2, new Entity2(Id2, "20"), 1, Arrays.asList(new Event2()), interest); store.write(Id3, new Entity1(Id3, 30), 1, Arrays.asList(new Event3()), interest); assertEquals(new Event1(), access.readFrom("sources")); assertEquals(new Event2(), access.readFrom("sources")); assertEquals(new Event3(), access.readFrom("sources")); final TextEntry entry1 = reader.readNext().await(); assertEquals(entryAdapterProvider.asEntry(new Event1(), 1, Metadata.nullMetadata()).withId("0"), entry1); final TextEntry entry2 = reader.readNext().await(); assertEquals(entryAdapterProvider.asEntry(new Event2(), 1, Metadata.nullMetadata()).withId("1"), entry2); final TextEntry entry3 = reader.readNext().await(); assertEquals(entryAdapterProvider.asEntry(new Event3(), 1, Metadata.nullMetadata()).withId("2"), entry3); reader.rewind(); assertEquals(Arrays.asList(entry1, entry2, entry3), reader.readNext(3).await()); }
Example #8
Source File: InMemoryStateStoreTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatStateStoreWritesAndReadsMetadataOperation() { final AccessSafely access1 = interest.afterCompleting(2); dispatcher.afterCompleting(2); final Entity1 entity = new Entity1("123", 5); final Metadata sourceMetadata = Metadata.with("value", "operation"); store.write(entity.id, entity, 1, sourceMetadata, interest); store.read(entity.id, Entity1.class, interest); assertEquals(1, (int) access1.readFrom("readObjectResultedIn")); assertEquals(1, (int) access1.readFrom("writeObjectResultedIn")); assertEquals(Result.Success, access1.readFrom("objectReadResult")); assertEquals(entity, access1.readFrom("objectState")); final Metadata metadata = access1.readFrom("metadataHolder"); assertNotNull(metadata); assertTrue(metadata.hasOperation()); assertEquals("operation", metadata.operation); final Entity1 readEntity = (Entity1) access1.readFrom("objectState"); assertEquals("123", readEntity.id); assertEquals(5, readEntity.value); }
Example #9
Source File: StateStore.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
public TypedStateBundle(final String id, final Class<?> type, final Object state, final int stateVersion, final Metadata metadata) { this.id = id; this.type = type; this.state = state; this.stateVersion = stateVersion; this.metadata = metadata; }
Example #10
Source File: InMemoryJournal.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
@Override public <S, ST> void appendAll(final String streamName, final int fromStreamVersion, final List<Source<S>> sources, final Metadata metadata, final AppendResultInterest interest, final Object object) { final List<Entry<T>> entries = entryAdapterProvider.asEntries(sources, fromStreamVersion, metadata); insert(streamName, fromStreamVersion, entries); dispatch(streamName, fromStreamVersion, entries, null); interest.appendAllResultedIn(Success.of(Result.Success), streamName, fromStreamVersion, sources, Optional.empty(), object); }
Example #11
Source File: MockAppendResultInterest.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
@Override public <S, ST> void appendAllResultedIn(Outcome<StorageException, Result> outcome, String streamName, int streamVersion, List<Source<S>> sources, Metadata metadata, Optional<ST> snapshot, Object object) { outcome.andThen(result -> { access.writeUsing("appendResultedIn", new JournalData<>(streamName, streamVersion, null, result, sources, snapshot)); return result; }).otherwise(cause -> { access.writeUsing("appendResultedIn", new JournalData<>(streamName, streamVersion, cause, null, sources, snapshot)); return cause.result; }); }
Example #12
Source File: Entity1.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
@Override public TextState toRawState(final Entity1 state, final int stateVersion) { return toRawState(state, stateVersion, Metadata.with("value", "op")); }
Example #13
Source File: InMemoryEventJournalActorTest.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(final Test2Source source, final int version, final String id, final Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(id, Test2Source.class, 1, serialization, version, metadata); }
Example #14
Source File: MockCounterAppendResultInterest.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Override public <S, ST> void appendResultedIn(final Outcome<StorageException, Result> outcome, final String streamName, final int streamVersion, final Source<S> source, final Metadata metadata, final Optional<ST> snapshot, final Object object) { }
Example #15
Source File: EntryAdapters.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(final PostedToDiscussion source, final Metadata metadata) { return toEntry(source, source.forumId, metadata); }
Example #16
Source File: EventAdapter.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(final T object) { final String serialization = JsonSerialization.serialized(object); return new TextEntry(type, eventVersion, serialization, Metadata.nullMetadata()); }
Example #17
Source File: Test2HappenedAdapter.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(Test2Happened source, int version, String id, Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(id, Test2Happened.class, 1, serialization, version, metadata); }
Example #18
Source File: UserIdStateAdapter.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Override public State.TextState toRawState(String id, UserId state, int stateVersion, Metadata metadata) { final String serialization = JsonSerialization.serialized(state); return new State.TextState(id, CartUserSummaryData.class, typeVersion(), serialization, stateVersion, metadata); }
Example #19
Source File: JournalProjectionDispatcherTest.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(OneHappened source, Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(OneHappened.class, 1, serialization, metadata); }
Example #20
Source File: CartStateAdapter.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Override public State.TextState toRawState(String id, CartUserSummaryData state, int stateVersion, Metadata metadata) { final String serialization = JsonSerialization.serialized(state); return new State.TextState(id, CartUserSummaryData.class, typeVersion(), serialization, stateVersion, metadata); }
Example #21
Source File: CounterIncreasedAdapter.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(final CounterIncreased source, final String id, final Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(id, CounterIncreased.class, 1, serialization, metadata); }
Example #22
Source File: EntryAdapters.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(final DoStepTwo source, final String id, final Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(id, DoStepTwo.class, 1, serialization, metadata); }
Example #23
Source File: Test3HappenedAdapter.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(Test3Happened source, int version, String id, Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(id, Test3Happened.class, 1, serialization, version, metadata); }
Example #24
Source File: ProcessMessageTextAdapter.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(final ProcessMessage source, final String id, final Metadata metadata) { final SerializableProcessMessage serializedMessage = new SerializableProcessMessage(source); final String serialization = JsonSerialization.serialized(serializedMessage); return new TextEntry(id, ProcessMessage.class, 1, serialization, metadata); }
Example #25
Source File: CounterDecreasedAdapter.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(final CounterDecreased source, final String id, final Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(id, CounterIncreased.class, 1, serialization, metadata); }
Example #26
Source File: JournalProjectionDispatcherTest.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(ThreeHappened source, String id, Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(id, ThreeHappened.class, 1, serialization, metadata); }
Example #27
Source File: EntryAdapters.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(final DoStepTwo source, final Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(DoStepTwo.class, 1, serialization, metadata); }
Example #28
Source File: DoCommand1Adapter.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(DoCommand1 source, int version, String id, Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(id, DoCommand1.class, 1, serialization, version, metadata); }
Example #29
Source File: EntryAdapters.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(final DiscussionTopicChanged source, final int version, String id, final Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(id, DiscussionTopicChanged.class, 1, serialization, version, metadata); }
Example #30
Source File: EntryAdapters.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Override public TextEntry toEntry(final DoStepFour source, final String id, final Metadata metadata) { final String serialization = JsonSerialization.serialized(source); return new TextEntry(id, DoStepFour.class, 1, serialization, metadata); }