io.vlingo.common.Outcome Java Examples

The following examples show how to use io.vlingo.common.Outcome. 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: StatefulEntity.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@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 #2
Source File: MockPersistResultInterest.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@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 #3
Source File: ObjectEntity.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@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 #4
Source File: ObjectEntity.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@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 #5
Source File: MockResultInterest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@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 #6
Source File: StateStoreReader.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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 #7
Source File: MockResultInterest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@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 #8
Source File: StateStoreQueryActor.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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 #9
Source File: StateStoreProjectionActor.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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 #10
Source File: StatefulEntity.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@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 #11
Source File: StateObjectQueryActor.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@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 #12
Source File: StateStoreProjectionActor.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 #13
Source File: Sourced.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #14
Source File: StateObjectQueryActor.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * @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 #15
Source File: MockQueryResultInterest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@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 #16
Source File: Sourced.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * FOR INTERNAL USE ONLY.
 */
@Override
public final <S, STT> void appendResultedIn(
        final Outcome<StorageException, Result> outcome, final String streamName, final int streamVersion,
        final Source<S> source, final Metadata metadata, final Optional<STT> snapshot, final Object supplier) {
  //TODO handle metadata
  outcome
    .andThen(result -> {
      restoreSnapshot(snapshot, currentVersion);
      applyResultVersioned(source);
      afterApply();
      completeUsing(supplier);
      disperseStowedMessages();
      return result;
    })
    .otherwise(cause -> {
      final Applicable<?> applicable = new Applicable<>(null, Arrays.asList(source), metadata, (CompletionSupplier<?>) supplier);
      final String message = "Source (count 1) 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 #17
Source File: Sourced.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 #18
Source File: MockQueryResultInterest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void queryAllResultedIn(
        final Outcome<StorageException, Result> outcome,
        final QueryMultiResults results,
        final Object object) {

  access.writeUsing("addAll", results.stateObjects);
}
 
Example #19
Source File: MockAppendResultInterest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@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 #20
Source File: MockStateStoreResultInterest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@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 #21
Source File: MockStateStoreResultInterest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@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 #22
Source File: MockAppendResultInterest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@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 #23
Source File: MockAppendResultInterest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@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 #24
Source File: MockAppendResultInterest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@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 #25
Source File: ObjectStorePersistResultInterest__Proxy.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void persistResultedIn(Outcome<StorageException, Result> arg0, java.lang.Object arg1, int arg2, int arg3, Object arg4) {
  if (!actor.isStopped()) {
    final SerializableConsumer<PersistResultInterest> consumer = (actor) -> actor.persistResultedIn(arg0, arg1, arg2, arg3, arg4);
    if (mailbox.isPreallocated()) { mailbox.send(actor, PersistResultInterest.class, consumer, null, persistResultedInRepresentation1); }
    else { mailbox.send(new LocalMessage<PersistResultInterest>(actor, PersistResultInterest.class, consumer, persistResultedInRepresentation1)); }
  } else {
    actor.deadLetters().failedDelivery(new DeadLetter(actor, persistResultedInRepresentation1));
  }
}
 
Example #26
Source File: InMemoryStateStoreActor.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void readAll(final Collection<TypedStateBundle> bundles, final ReadResultInterest interest, final Object object) {
  readAllResultCollector.prepare();

  for (final TypedStateBundle bundle : bundles) {
    readFor(bundle.id, bundle.type, readAllResultCollector, null);
  }

  final Outcome<StorageException, Result> outcome = readAllResultCollector.readResultOutcome(bundles.size());

  interest.readResultedIn(outcome, readAllResultCollector.readResultBundles(), object);
}
 
Example #27
Source File: StateStoreReader.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 #28
Source File: StateStoreProjectionTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@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) {

  access.writeUsing("warble", (Warble) state);
}
 
Example #29
Source File: JournalAppendResultInterest__Proxy.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
public <S,ST>void appendResultedIn(final io.vlingo.common.Outcome<io.vlingo.symbio.store.StorageException, io.vlingo.symbio.store.Result> arg0, final java.lang.String arg1, final int arg2, io.vlingo.symbio.Source<S> arg3, final java.util.Optional<ST> arg4, final java.lang.Object arg5) {
  final SerializableConsumer<AppendResultInterest> consumer = (actor) -> actor.appendResultedIn(arg0, arg1, arg2, arg3, arg4, arg5);
  send(JournalAppendResultInterest__Proxy.appendResultedInRepresentation1, consumer);
}
 
Example #30
Source File: MockCounterAppendResultInterest.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public <S,ST> void appendAllResultedIn(Outcome<StorageException, Result> outcome, String streamName, int streamVersion,
        List<Source<S>> sources, Optional<ST> snapshot, Object object) {
  
}