io.vlingo.symbio.store.StorageException Java Examples
The following examples show how to use
io.vlingo.symbio.store.StorageException.
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: MockResultInterest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Override public <S,C> void writeResultedIn(final Outcome<StorageException, Result> outcome, final String id, final S state, final int stateVersion, final List<Source<C>> sources, final Object object) { outcome .andThen(result -> { writeTextResultedIn.incrementAndGet(); textWriteResult.set(result); textWriteAccumulatedResults.add(result); stateHolder.set(state); until.happened(); return result; }) .otherwise(cause -> { writeTextResultedIn.incrementAndGet(); textWriteResult.set(cause.result); textWriteAccumulatedResults.add(cause.result); stateHolder.set(state); errorCauses.add(cause); until.happened(); return cause.result; }); }
Example #2
Source File: StatefulEntity.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") final public <ST,C> void writeResultedIn(final Outcome<StorageException, Result> outcome, final String id, final ST state, final int stateVersion, final List<Source<C>> sources, final Object supplier) { outcome .andThen(result -> { state((S) state); currentVersion = stateVersion; afterApply(); completeUsing(supplier); disperseStowedMessages(); return result; }) .otherwise(cause -> { disperseStowedMessages(); final String message = "State not applied for: " + getClass() + "(" + id + ") because: " + cause.result + " with: " + cause.getMessage(); logger().error(message, cause); throw new IllegalStateException(message, cause); }); }
Example #3
Source File: StatefulEntity.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") final public <ST> void readResultedIn(final Outcome<StorageException, Result> outcome, final String id, final ST state, final int stateVersion, final Metadata metadata, final Object object) { outcome .andThen(result -> { state((S) state); currentVersion = stateVersion; disperseStowedMessages(); return result; }) .otherwise(cause -> { disperseStowedMessages(); final boolean ignoreNotFound = (boolean) object; if (!ignoreNotFound) { final String message = "State not restored for: " + getClass() + "(" + id + ") because: " + cause.result + " with: " + cause.getMessage(); logger().error(message, cause); throw new IllegalStateException(message, cause); } return cause.result; }); }
Example #4
Source File: ObjectEntity.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") final public void queryObjectResultedIn( final Outcome<StorageException, Result> outcome, final QuerySingleResult queryResult, final Object object) { outcome .andThen(result -> { stateObject((T) queryResult.stateObject); disperseStowedMessages(); return result; }) .otherwise(cause -> { disperseStowedMessages(); final boolean ignoreNotFound = (boolean) object; if (!ignoreNotFound) { final String message = "State not restored for: " + getClass() + "(" + this.id + ") because: " + cause.result + " with: " + cause.getMessage(); logger().error(message, cause); throw new IllegalStateException(message, cause); } return cause.result; }); }
Example #5
Source File: ObjectEntity.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public void persistResultedIn(final Outcome<StorageException, Result> outcome, final Object persistentObject, final int possible, final int actual, final Object supplier) { outcome .andThen(result -> { stateObject((T) persistentObject); afterApply(); completeUsing(supplier); disperseStowedMessages(); return result; }) .otherwise(cause -> { disperseStowedMessages(); final String message = "State not preserved for: " + getClass() + "(" + this.id + ") because: " + cause.result + " with: " + cause.getMessage(); logger().error(message, cause); throw new IllegalStateException(message, cause); }); }
Example #6
Source File: MockResultInterest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Override 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 -> { readTextResultedIn.incrementAndGet(); textReadResult.set(result); stateHolder.set(state); metadataHolder.set(metadata); until.happened(); return result; }) .otherwise(cause -> { readTextResultedIn.incrementAndGet(); textReadResult.set(cause.result); stateHolder.set(state); metadataHolder.set(metadata); errorCauses.add(cause); until.happened(); return cause.result; }); }
Example #7
Source File: Sourced.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
/** * Restore the state of my concrete extender from a possibly snaptshot * and stream of events. */ @Override protected final void restore() { stowMessages(Stoppable.class); journalInfo.journal.streamReader(getClass().getSimpleName()) .andThenTo(reader -> reader.streamFor(this.streamName)) .andThenConsume(stream -> { restoreSnapshot(stream.snapshot); restoreFrom(journalInfo.entryAdapterProvider.asSources(stream.entries), stream.streamVersion); disperseStowedMessages(); }) .otherwiseConsume(stream -> { disperseStowedMessages(); }) .recoverFrom(cause -> { disperseStowedMessages(); final String message = "Stream not recovered for: " + type() + "(" + this.streamName + ") because: " + cause.getMessage(); throw new StorageException(Result.Failure, message, cause); }); }
Example #8
Source File: StateStoreReader.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
/** * Single result collector. */ @Override 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 -> { readBundles.add(new TypedStateBundle(id, state, stateVersion, metadata)); return result; }) .otherwise(cause -> { readOutcome.set(outcome); success.set(false); return cause.result; }); }
Example #9
Source File: MockPersistResultInterest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Override public void persistResultedIn( final Outcome<StorageException, Result> outcome, final Object stateObject, final int possible, final int actual, final Object object) { if (actual == 1) { access.writeUsing("add", stateObject); } else if (actual > 1) { access.writeUsing("addAll", stateObject); } else { throw new IllegalArgumentException("Possible is:" + possible + " Actual is: " + actual); } }
Example #10
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 #11
Source File: InMemoryObjectStoreDelegate.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public QuerySingleResult queryObject(final QueryExpression expression) { final String id; if (expression.isListQueryExpression()) { id = idParameterAsString(expression.asListQueryExpression().parameters.get(0)); } else if (expression.isMapQueryExpression()) { id = idParameterAsString(expression.asMapQueryExpression().parameters.get("id")); } else { throw new StorageException(Result.Error, "Unknown query type: " + expression); } final Map<Long, State<?>> store = stores.computeIfAbsent(expression.type, (type) -> new HashMap<>()); final State<?> found = (id == null || id.equals("-1")) ? null : store.get(Long.parseLong(id)); final Object result = Optional .ofNullable(found) .map(stateAdapterProvider::fromRaw) .orElse(null); return new QuerySingleResult(result); }
Example #12
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 #13
Source File: StateStoreQueryActor.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 -> { QueryResultHandler.from(object).completeFoundWith(id, state, stateVersion, metadata); return result; }).otherwise(cause -> { if (cause.result.isNotFound()) { QueryResultHandler.from(object).completeNotFound(); } else { logger().info("Query state not read for update because: " + cause.getMessage(), cause); } return cause.result; }); }
Example #14
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 #15
Source File: InMemoryObjectStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
@Override public void queryObject(final QueryExpression expression, final QueryResultInterest interest, final Object object) { final QuerySingleResult result = this.storeDelegate.queryObject(expression); if (result.stateObject != null) { interest.queryObjectResultedIn(Success.of(Result.Success), result, object); } else { interest.queryObjectResultedIn(Failure.of(new StorageException(Result.NotFound, "No object identified by expression: " + expression)), QuerySingleResult.of(null), object); } }
Example #16
Source File: InMemoryStateStoreActor.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
private void readFor(final String id, final Class<?> type, final ReadResultInterest interest, final Object object) { if (interest != null) { if (id == null || type == null) { interest.readResultedIn(Failure.of(new StorageException(Result.Error, id == null ? "The id is null." : "The type is null.")), id, null, -1, null, object); return; } final String storeName = StateTypeStateStoreMap.storeNameFrom(type); if (storeName == null) { interest.readResultedIn(Failure.of(new StorageException(Result.NoTypeStore, "No type store for: " + type.getSimpleName())), id, null, -1, null, object); return; } final Map<String, RS> typeStore = store.get(storeName); if (typeStore == null) { interest.readResultedIn(Failure.of(new StorageException(Result.NotFound, "Store not found: " + storeName)), id, null, -1, null, object); return; } final RS raw = typeStore.get(id); if (raw != null) { final Object state = stateAdapterProvider.fromRaw(raw); interest.readResultedIn(Success.of(Result.Success), id, state, raw.dataVersion, raw.metadata, object); } else { for (final String storeId : typeStore.keySet()) { logger().debug("UNFOUND STATES\n====================="); logger().debug("STORE ID: '" + storeId + "' STATE: " + typeStore.get(storeId)); } interest.readResultedIn(Failure.of(new StorageException(Result.NotFound, "Not found.")), id, null, -1, null, object); } } else { logger().warn( getClass().getSimpleName() + " readFor() missing ReadResultInterest for: " + (id == null ? "unknown id" : id)); } }
Example #17
Source File: MockAppendResultInterest.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
@Override public <S, ST> void appendResultedIn(Outcome<StorageException, Result> outcome, String streamName, int streamVersion, Source<S> source, Optional<ST> snapshot, Object object) { outcome.andThen(result -> { access.writeUsing("appendResultedIn", new JournalData<>(streamName, streamVersion, null, result, Collections.singletonList(source), snapshot)); return result; }).otherwise(cause -> { access.writeUsing("appendResultedIn", new JournalData<>(streamName, streamVersion, cause, null, Collections.singletonList(source), snapshot)); return cause.result; }); }
Example #18
Source File: MockAppendResultInterest.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
@Override public <S, ST> void appendResultedIn(Outcome<StorageException, Result> outcome, String streamName, int streamVersion, Source<S> source, Metadata metadata, Optional<ST> snapshot, Object object) { outcome.andThen(result -> { access.writeUsing("appendResultedIn", new JournalData<>(streamName, streamVersion, null, result, Collections.singletonList(source), snapshot)); return result; }).otherwise(cause -> { access.writeUsing("appendResultedIn", new JournalData<>(streamName, streamVersion, cause, null, Collections.singletonList(source), snapshot)); return cause.result; }); }
Example #19
Source File: StateStoreReader.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
/** * Answer my {@code Outcome<StorageException, Result>}. * @return {@code Outcome<StorageException, Result>} */ public Outcome<StorageException, Result> readResultOutcome(final int expectedReads) { if (isFailure()) { if (!readBundles.isEmpty() && readBundles.size() < expectedReads) { return Failure.of(new StorageException(Result.NotAllFound, "Not all states were found.")); } } return readOutcome.get(); }
Example #20
Source File: Sourced.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
/** * FOR INTERNAL USE ONLY. */ @Override @SuppressWarnings({ "unchecked", "rawtypes" }) public final <STT, ST> void appendAllResultedIn(final Outcome<StorageException, Result> outcome, final String streamName, final int streamVersion,final List<Source<STT>> sources, final Metadata metadata, final Optional<ST> snapshot, final Object supplier) { //TODO handle metadata outcome .andThen(result -> { restoreSnapshot(snapshot, currentVersion); for (final Source<STT> source : sources) { applyResultVersioned(source); } afterApply(); completeUsing(supplier); disperseStowedMessages(); return result; }) .otherwise(cause -> { final Applicable<?> applicable = new Applicable(null, sources, metadata, (CompletionSupplier<?>) supplier); final String message = "Source (count " + sources.size() + ") not appended for: " + type() + "(" + this.streamName + ") because: " + cause.result + " with: " + cause.getMessage(); final ApplyFailedException exception = new ApplyFailedException(applicable, message, cause); final Optional<ApplyFailedException> maybeException = afterApplyFailed(exception); disperseStowedMessages(); if (maybeException.isPresent()) { logger().error(message, maybeException.get()); throw maybeException.get(); } logger().error(message, exception); return cause.result; }); }
Example #21
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, 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 #22
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 #23
Source File: MockStateStoreResultInterest.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
@Override 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 -> { access.writeUsing("readStoreData", new StoreData<>(1, result, state, Arrays.asList(), metadata, null)); return result; }) .otherwise(cause -> { access.writeUsing("readStoreData", new StoreData<>(1, cause.result, state, Arrays.asList(), metadata, cause)); return cause.result; }); }
Example #24
Source File: MockStateStoreResultInterest.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
@Override public <S,C> void writeResultedIn(final Outcome<StorageException, Result> outcome, final String id, final S state, final int stateVersion, final List<Source<C>> sources, final Object object) { outcome .andThen(result -> { access.writeUsing("writeStoreData", new StoreData<C>(1, result, state, sources, null, null)); return result; }) .otherwise(cause -> { access.writeUsing("writeStoreData", new StoreData<C>(1, cause.result, state, sources, null, cause)); return cause.result; }); }
Example #25
Source File: MockQueryResultInterest.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
@Override public void queryAllResultedIn( final Outcome<StorageException, Result> outcome, final QueryMultiResults results, final Object object) { access.writeUsing("addAll", results.stateObjects); }
Example #26
Source File: MockQueryResultInterest.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
@Override public void queryObjectResultedIn( final Outcome<StorageException, Result> outcome, final QuerySingleResult result, final Object object) { outcome .andThen(good -> good) .otherwise(bad -> { throw new IllegalStateException("Bogus outcome: " + bad.getMessage()); }); access.writeUsing("add", result.stateObject); }
Example #27
Source File: StateObjectQueryActor.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
/** * @see io.vlingo.symbio.store.object.ObjectStoreReader.QueryResultInterest#queryAllResultedIn(io.vlingo.common.Outcome, io.vlingo.symbio.store.object.ObjectStoreReader.QueryMultiResults, java.lang.Object) */ @Override final public void queryAllResultedIn( final Outcome<StorageException, Result> outcome, final QueryMultiResults queryResults, final Object attempt) { outcome .andThen(result -> { completeUsing(attempt, queryResults.stateObjects); return result; }) .otherwise(cause -> { switch (cause.result) { case NotFound: completeUsing(attempt, Collections.emptyList()); return cause.result; default: break; } final String message = "Query failed because: " + cause.result + " with: " + cause.getMessage(); final ObjectQueryFailedException exception = new ObjectQueryFailedException(QueryAttempt.from(attempt), message, cause); final Optional<ObjectQueryFailedException> maybeException = afterQueryFailed(exception); if (maybeException.isPresent()) { logger().error(message, maybeException.get()); throw maybeException.get(); } logger().error(message, exception); return cause.result; }); }
Example #28
Source File: StateObjectQueryActor.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@Override final public void queryObjectResultedIn( final Outcome<StorageException, Result> outcome, final QuerySingleResult queryResult, final Object attempt) { outcome .andThen(result -> { completeUsing(attempt, queryResult.stateObject); return result; }) .otherwise(cause -> { switch (cause.result) { case NotFound: completeUsing(attempt, queryResult.stateObject); return cause.result; default: break; } final String message = "Query failed because: " + cause.result + " with: " + cause.getMessage(); final ObjectQueryFailedException exception = new ObjectQueryFailedException(QueryAttempt.from(attempt), message, cause); final Optional<ObjectQueryFailedException> maybeException = afterQueryFailed(exception); if (maybeException.isPresent()) { logger().error(message, maybeException.get()); throw maybeException.get(); } logger().error(message, exception); return cause.result; }); }
Example #29
Source File: StateStoreProjectionActor.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
/** * FOR INTERNAL USE ONLY. */ @Override final public <S,C> void writeResultedIn(final Outcome<StorageException, Result> outcome, final String id, final S state, final int stateVersion, final List<Source<C>> sources, final Object object) { outcome.andThen(result -> { confirmProjection((Confirmer) object); return result; }).otherwise(cause -> { disperseStowedMessages(); // log but don't retry, allowing re-delivery of Projectable logger().info("Query state not written for update because: " + cause.getMessage(), cause); return cause.result; }); }
Example #30
Source File: Sourced.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
/** * FOR INTERNAL USE ONLY. */ @Override public final <S, ST> void appendResultedIn( final Outcome<StorageException, io.vlingo.symbio.store.Result> outcome, final String streamName, final int streamVersion, final Source<S> source, final Optional<ST> snapshot, final Object supplier) { this.appendResultedIn(outcome, streamName, streamVersion, source, Metadata.nullMetadata(), snapshot, supplier); }