io.vlingo.symbio.store.object.StateObject Java Examples

The following examples show how to use io.vlingo.symbio.store.object.StateObject. 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 vote down vote up
@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: InMemoryObjectStoreActor.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@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 #3
Source File: InMemoryObjectStoreDelegate.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public <T extends StateObject> Collection<State<?>> persistAll(final Collection<T> stateObjects, final long updateId, final Metadata metadata) {
  final List<State<?>> states = new ArrayList<>(stateObjects.size());
  for (final T stateObject : stateObjects) {
    final State<?> raw = persist(stateObject, metadata);
    states.add(raw);
  }

  return states;
}
 
Example #4
Source File: InMemoryObjectStoreDelegate.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public <T extends StateObject> State<?> persist(final T stateObject, final long updateId, final Metadata metadata) {
  return persist(stateObject, metadata);
}