io.vlingo.symbio.Entry Java Examples

The following examples show how to use io.vlingo.symbio.Entry. 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: TextProjectableTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@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 #2
Source File: Journal__Proxy.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public <ET extends Entry<?>> io.vlingo.common.Completes<io.vlingo.symbio.store.journal.JournalReader<ET>> journalReader(final java.lang.String arg0) {
  if (!actor.isStopped()) {
    final SerializableConsumer<Journal> consumer = (actor) -> actor.journalReader(arg0);
    final io.vlingo.common.Completes<io.vlingo.symbio.store.journal.JournalReader<ET>> completes = new BasicCompletes<>(
            actor.scheduler());
    if (mailbox.isPreallocated()) {
      mailbox.send(actor, Journal.class, consumer, Returns.value(completes), journalReaderRepresentation5);
    } else {
      mailbox.send(new LocalMessage<>(actor, Journal.class, consumer, Returns.value(completes), journalReaderRepresentation5));
    }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, journalReaderRepresentation5));
  }
  return null;
}
 
Example #3
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 #4
Source File: DispatcherControlActor.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void dispatchUnconfirmed() {
  try {
    final LocalDateTime now = LocalDateTime.now();
    final Collection<? extends Dispatchable<? extends Entry<?>, ? extends State<?>>> dispatchables = delegate.allUnconfirmedDispatchableStates();
    for (final Dispatchable<? extends Entry<?>, ? extends State<?>> dispatchable : dispatchables) {
      final LocalDateTime then = dispatchable.createdOn();
      final Duration duration = Duration.between(then, now);
      if (Math.abs(duration.toMillis()) > confirmationExpiration) {
        dispatchers.forEach(d -> d.dispatch(dispatchable));
      }
    }
  } catch (final Exception e) {
    logger().error(getClass().getSimpleName() + " dispatchUnconfirmed() failed because: " + e.getMessage(), e);
  }
}
 
Example #5
Source File: RetryReaderActor.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@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 #6
Source File: InMemoryJournal.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@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 #7
Source File: RetryActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void readTest() {
    Entry<String> entry = readerActor.readOne().await();
    Assert.assertEquals("0", entry.id());

    Entry<String> entry2 = readerActor.readOne().await();
    Assert.assertEquals("1", entry2.id());

    List<Entry<String>> entries = readerActor.readNext(10).await();
    Assert.assertEquals(10, entries.size());

    List<Entry<String>> entries2 = readerActor.readNext(50).await();
    // 4 entries out of 50 didn't get loaded at all
    Assert.assertEquals(46, entries2.size());

    long previousId = -1;
    for (Entry<String> currentEntry : entries2) {
        long currentId = Long.parseLong(currentEntry.id());
        Assert.assertTrue(previousId < currentId);
        previousId = currentId;
    }
}
 
Example #8
Source File: InMemoryJournal.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public <S, ST> void appendAllWith(final String streamName, final int fromStreamVersion, final List<Source<S>> sources,
        final Metadata metadata, final ST snapshot, final AppendResultInterest interest, final Object object) {
  final List<Entry<T>> entries = entryAdapterProvider.asEntries(sources, fromStreamVersion, metadata);
  insert(streamName, fromStreamVersion, entries);
  final RS raw;
  final Optional<ST> snapshotResult;
  if (snapshot != null) {
    raw = stateAdapterProvider.asRaw(streamName, snapshot, fromStreamVersion);
    snapshots.put(streamName, raw);
    snapshotResult = Optional.of(snapshot);
  } else {
    raw = null;
    snapshotResult = Optional.empty();
  }

  dispatch(streamName, fromStreamVersion, entries, raw);
  interest.appendAllResultedIn(Success.of(Result.Success), streamName, fromStreamVersion, sources, snapshotResult, object);
}
 
Example #9
Source File: InMemoryObjectStoreEntryReaderActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<List<Entry<String>>> readNext(final int maximumEntries) {
  final List<Entry<String>> entries = new ArrayList<>(maximumEntries);

  for (int count = 0; count < maximumEntries; ++count) {
    if (currentIndex < entriesView.size()) {
      entries.add(entriesView.get(currentIndex++));
    } else {
      break;
    }
  }
  return completes().with(entries);
}
 
Example #10
Source File: RetryReaderActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
GapRetryReader<Entry<String>> reader() {
    if (reader == null) {
        reader = new GapRetryReader<>(stage(), scheduler());
    }

    return reader;
}
 
Example #11
Source File: InMemoryObjectStoreEntryReaderActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<Entry<String>> readNext() {
  if (currentIndex < entriesView.size()) {
    return completes().with(entriesView.get(currentIndex++));
  }
  return completes().with(null);
}
 
Example #12
Source File: ObjectStore__Proxy.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<EntryReader<? extends Entry<?>>> entryReader(final String arg0) {
  if (!actor.isStopped()) {
    final SerializableConsumer<ObjectStore> consumer = (actor) -> actor.entryReader(arg0);
    final Completes<EntryReader<? extends Entry<?>>> completes = new BasicCompletes<>(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, ObjectStore.class, consumer, Returns.value(completes), entryReaderRepresentation2); }
    else { mailbox.send(new LocalMessage<ObjectStore>(actor, ObjectStore.class, consumer, Returns.value(completes), entryReaderRepresentation2)); }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, entryReaderRepresentation2));
  }
  return null;
}
 
Example #13
Source File: InMemoryStateStoreActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
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 #14
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 #15
Source File: InMemoryJournal.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@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 #16
Source File: InMemoryStateStoreEntryReaderActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
private void to(final String id) {
  rewind();
  while (currentIndex < entriesView.size()) {
    final Entry<T> entry = entriesView.get(currentIndex);
    if (entry.id().equals(id)) {
      return;
    }
    ++currentIndex;
  }
}
 
Example #17
Source File: StateStore__Proxy.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public <ET extends Entry<?>> Completes<StateStoreEntryReader<ET>> entryReader(String arg0) {
  if (!actor.isStopped()) {
    final SerializableConsumer<StateStore> consumer = (actor) -> actor.entryReader(arg0);
    final Completes<StateStoreEntryReader<ET>> completes = new BasicCompletes<>(actor.scheduler());
    if (mailbox.isPreallocated()) { mailbox.send(actor, StateStore.class, consumer, Returns.value(completes), entryReaderRepresentation3); }
    else { mailbox.send(new LocalMessage<StateStore>(actor, StateStore.class, consumer, Returns.value(completes), entryReaderRepresentation3)); }
    return completes;
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, entryReaderRepresentation3));
  }
  return null;
}
 
Example #18
Source File: InMemoryJournal.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public <S, ST> void append(final String streamName, final int streamVersion, final Source<S> source, final Metadata metadata,
        final AppendResultInterest interest, final Object object) {
  final Entry<T> entry = entryAdapterProvider.asEntry(source, streamVersion, metadata);
  insert(streamName, streamVersion, entry);
  dispatch(streamName, streamVersion, Collections.singletonList(entry), null);
  interest.appendResultedIn(Success.of(Result.Success), streamName, streamVersion, source, Optional.empty(), object);
}
 
Example #19
Source File: InMemoryJournalReader.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Completes<List<T>> readNext(final int maximumEntries) {
  final List<Entry<T>> entries = new ArrayList<>(maximumEntries);
  for (int count = 0; count < maximumEntries; ++count) {
    if (currentIndex < journalView.size()) {
      entries.add(journalView.get(currentIndex++));
    } else {
      break;
    }
  }
  return Completes.withSuccess((List<T>) entries);
}
 
Example #20
Source File: InMemoryObjectStoreEntryReaderActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
private void to(final String id) {
  rewind();
  while (currentIndex < entriesView.size()) {
    final Entry<String> entry = entriesView.get(currentIndex);
    if (entry.id().equals(id)) {
      return;
    }
    ++currentIndex;
  }
}
 
Example #21
Source File: DispatcherControl.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
public DispatcherControlInstantiator(
        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.checkConfirmationExpirationInterval = checkConfirmationExpirationInterval;
  this.confirmationExpiration = confirmationExpiration;
}
 
Example #22
Source File: DispatcherControl.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
public DispatcherControlInstantiator(
        final Dispatcher<Dispatchable<? extends Entry<?>, ? extends State<?>>> dispatcher,
        final DispatcherControlDelegate<? extends Entry<?>, ? extends State<?>> delegate,
        final long checkConfirmationExpirationInterval,
        final long confirmationExpiration) {
  this(Arrays.asList(dispatcher), delegate, checkConfirmationExpirationInterval, confirmationExpiration);
}
 
Example #23
Source File: InMemoryObjectStoreActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Completes<EntryReader<? extends Entry<?>>> entryReader(final String name) {
  EntryReader<? extends Entry<?>> reader = entryReaders.get(name);
  if (reader == null) {
    final Definition definition = Definition.has(InMemoryObjectStoreEntryReaderActor.class, new ObjectStoreEntryReaderInstantiator(readOnlyJournal(), name));
    reader = childActorFor(ObjectStoreEntryReader.class, definition);
  }
  return completes().with(reader);
}
 
Example #24
Source File: InMemoryEventJournalActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatJournalAppendsOneEvent() {
  dispatcher.afterCompleting(1);
  interest.afterCompleting(1);

  final Test1Source source = new Test1Source();
  final String streamName = "123";
  final int streamVersion = 1;
  journal.append(streamName, streamVersion, source, interest, object);

  assertEquals(1, interest.getReceivedAppendsSize());

  final List<JournalData<String, SnapshotState>> entries = interest.getEntries();
  final JournalData<String, SnapshotState> journalData = entries.get(0);
  assertNotNull(journalData);
  Assert.assertEquals(streamName, journalData.streamName);
  Assert.assertEquals(streamVersion, journalData.streamVersion);
  Assert.assertEquals(Result.Success, journalData.result);
  Assert.assertFalse(journalData.snapshot.isPresent());

  final List<Source<String>> sourceList = journalData.sources;
  Assert.assertEquals(1, sourceList.size());
  Assert.assertEquals(source, sourceList.get(0));

  assertEquals(1, dispatcher.dispatchedCount());
  final Dispatchable<Entry<?>, ?> dispatched = dispatcher.getDispatched().get(0);

  Assert.assertNotNull(dispatched.createdOn());
  Assert.assertFalse(dispatched.state().isPresent());
  Assert.assertNotNull(dispatched.id());
  final Collection<Entry<?>> dispatchedEntries = dispatched.entries();
  Assert.assertEquals(1, dispatchedEntries.size());
}
 
Example #25
Source File: InMemoryEventJournalActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatJournalAppendsOneEventWithSnapshot() {
  dispatcher.afterCompleting(1);
  interest.afterCompleting(1);

  final Test1Source source = new Test1Source();
  final String streamName = "123";
  final int streamVersion = 1;

  journal.appendWith(streamName, streamVersion, new Test1Source(), new SnapshotState(), interest, object);

  final List<JournalData<String, SnapshotState>> entries = interest.getEntries();
  final JournalData<String, SnapshotState> journalData = entries.get(0);
  assertNotNull(journalData);
  Assert.assertEquals(streamName, journalData.streamName);
  Assert.assertEquals(streamVersion, journalData.streamVersion);
  Assert.assertEquals(Result.Success, journalData.result);
  Assert.assertTrue(journalData.snapshot.isPresent());

  final List<Source<String>> sourceList = journalData.sources;
  Assert.assertEquals(1, sourceList.size());
  Assert.assertEquals(source, sourceList.get(0));

  assertEquals(1, dispatcher.dispatchedCount());
  final Dispatchable<Entry<?>, ?> dispatched = dispatcher.getDispatched().get(0);

  Assert.assertNotNull(dispatched.createdOn());
  Assert.assertTrue(dispatched.state().isPresent());
  Assert.assertNotNull(dispatched.id());
  final Collection<Entry<?>> dispatchedEntries = dispatched.entries();
  Assert.assertEquals(1, dispatchedEntries.size());
}
 
Example #26
Source File: InMemoryObjectStoreActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatObjectPersistsQueries() {
  dispatcher.afterCompleting(1);
  final AccessSafely persistAccess = persistInterest.afterCompleting(1);
  final Person person = new Person("Tom Jones", 85);
  final Test1Source source = new Test1Source();
  objectStore.persist(StateSources.of(person, source), persistInterest);
  final int persistSize = persistAccess.readFrom("size");
  assertEquals(1, persistSize);
  assertEquals(person, persistAccess.readFrom("object", 0));

  final QueryExpression query = MapQueryExpression
          .using(Person.class, "find", MapQueryExpression.map("id", "" + person.persistenceId()));

  final AccessSafely queryAccess = queryResultInterest.afterCompleting(1);
  objectStore.queryObject(query, queryResultInterest, null);
  final int querySize = queryAccess.readFrom("size");
  assertEquals(1, querySize);
  assertEquals(person, queryAccess.readFrom("object", 0));

  assertEquals(1, dispatcher.dispatchedCount());
  final Dispatchable<Entry<?>, State<?>> dispatched = dispatcher.getDispatched().get(0);
  validateDispatchedState(person, dispatched);

  final List<Entry<?>> dispatchedEntries = dispatched.entries();
  Assert.assertEquals(1, dispatchedEntries.size());
  final Entry<?> entry = dispatchedEntries.get(0);
  Assert.assertNotNull(entry.id());
  Assert.assertEquals(source.getClass().getName(), entry.typeName());
  Assert.assertEquals(Metadata.nullMetadata(), entry.metadata());
}
 
Example #27
Source File: InMemoryObjectStoreActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatMultiPersistQueryResolves() {
  dispatcher.afterCompleting(3);
  final AccessSafely persistAllAccess = persistInterest.afterCompleting(1);

  final Person person1 = new Person("Tom Jones", 78);
  final Person person2 = new Person("Dean Martin", 78);
  final Person person3 = new Person("Sally Struthers", 71);
  objectStore.persistAll(Arrays.asList(StateSources.of(person1), StateSources.of(person2), StateSources.of(person3)), persistInterest);
  final int persistSize = persistAllAccess.readFrom("size");
  assertEquals(3, persistSize);

  final AccessSafely queryAllAccess = queryResultInterest.afterCompleting(1);
  objectStore.queryAll(QueryExpression.using(Person.class, "findAll"), queryResultInterest, null);
  final int querySize = queryAllAccess.readFrom("size");
  assertEquals(3, querySize);
  assertEquals(person1, queryAllAccess.readFrom("object", 0));
  assertEquals(person2, queryAllAccess.readFrom("object", 1));
  assertEquals(person3, queryAllAccess.readFrom("object", 2));

  assertEquals(3, dispatcher.dispatchedCount());

  Dispatchable<Entry<?>, State<?>> dispatched = dispatcher.getDispatched().get(0);
  validateDispatchedState(person1, dispatched);
  List<Entry<?>> dispatchedEntries = dispatched.entries();
  Assert.assertTrue(dispatchedEntries.isEmpty());

  dispatched = dispatcher.getDispatched().get(1);
  validateDispatchedState(person2, dispatched);
  dispatchedEntries = dispatched.entries();
  Assert.assertTrue(dispatchedEntries.isEmpty());

  dispatched = dispatcher.getDispatched().get(2);
  validateDispatchedState(person3, dispatched);
  dispatchedEntries = dispatched.entries();
  Assert.assertTrue(dispatchedEntries.isEmpty());
}
 
Example #28
Source File: StateStoreProjectionActor.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Construct my final state with the {@code StateStore}, which must
 * be provided by my concrete extenders, as well as with a
 * {@code stateAdapter} and a {@code entryAdapter}.
 * @param stateStore the StateStore from which previous state is read and merged current state is written
 * @param stateAdapter the {@code StateAdapter<Object, State<?>>} used by my extenders to adapt persistent state
 * @param entryAdapter the {@code EntryAdapter<Source<?>, Entry<?>>} used by my extenders to adapt persistent entries
 */
public StateStoreProjectionActor(
        final StateStore stateStore,
        final StateAdapter<Object, State<?>> stateAdapter,
        final EntryAdapter<Source<?>, Entry<?>> entryAdapter) {

  this.stateStore = stateStore;
  this.stateAdapter = stateAdapter;
  this.entryAdapter = entryAdapter;
  this.readInterest = selfAs(ReadResultInterest.class);
  this.writeInterest = selfAs(WriteResultInterest.class);

  this.adaptedSources = new ArrayList<>(2);
}
 
Example #29
Source File: CartSummaryProjectionActor.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected void prepareForMergeWith(final Projectable projectable) {
  events.clear();

  for (Entry <?> entry : projectable.entries()) {
    events.add(entryAdapter().anyTypeFromEntry(entry));
  }
}
 
Example #30
Source File: ExchangeDispatcher.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void dispatch(Dispatchable<Entry<String>, State<String>> dispatchable) {
    logger.debug("Going to dispatch id {}", dispatchable.id());

    for (Entry<String> entry : dispatchable.entries()) {
        try {
            this.exchange.send(JsonSerialization.deserialized(entry.entryData(), entry.typed()));
        } catch (Exception e) {
            logger.error("Entry {} of dispatch id {} will not be sent", dispatchable.id(), entry.id(), e);
        }
    }
    this.control.confirmDispatched(dispatchable.id(), this);
}