Class LoadResult.Builder<E extends Exception>

java.lang.Object
esa.opensf.osfi.LoadResult.Builder<E>
Type Parameters:
E - Concrete type of exceptions to be recorded, or Exception for general handling.
Enclosing class:
LoadResult<R>

public static class LoadResult.Builder<E extends Exception> extends Object
Helper that processes events during a load operation to generate a LoadResult.
  • Field Details

    • events

      public final List<LoadResult.Event> events
      Warnings and errors recorded during processing.
  • Constructor Details

    • Builder

      public Builder(Class<E> clsToken, int logMinSev, int throwMinSev, List<LoadResult.Event> evtsFromPriorPhases)
      Create a helper that processes events and may generate a LoadResult.
      Parameters:
      clsToken - Class object for the main type of exceptions considered. Note that this does not mean that only this type of exception will be in the list
      logMinSev - Events below this level will not be logged or recorded.
      throwMinSev - Any event at or above this level will be rethrown when processed.
      evtsFromPriorPhases - Optional, if non-null it will be used as the initial value for the events of this instance. Used for chaining LoadResult-based calls.
  • Method Details

    • finishWithResult

      public <R> LoadResult<R> finishWithResult(Object source, R result)
      Complete the operation with a result object.
      Type Parameters:
      R - Type of the result
      Parameters:
      source - Stringified and passed to LoadResult.source, never null.
      result - Result of the load operation.
      Returns:
      Built LoadResult object, with a non-null result.
    • finishEmpty

      public <R> LoadResult<R> finishEmpty(Object source, Exception fatalErr)
      Complete the operation without a result object.
      Type Parameters:
      R - Type of the result, possibly explicit
      Parameters:
      source - Stringified and passed to LoadResult.source, never null.
      fatalErr - Optional final exception. If it is not null, and it has not already been processed as an event, it will be added with severity LoadResult.SEV_FATAL.
      Returns:
      Built LoadResult object, with a null result.
    • processEvent

      public void processEvent(int severity, E data) throws E
      Method called by subclasses to ingest an event. This function will:
      • Log the event to the OSFI logger and to the events member if the severity is ≥ logMinSeverity.
      • Rethrow the event data if its severity is ≥ throwMinSeverity.
      Parameters:
      severity - See the SEV_* constants in LoadResult
      data - Exception object to be processed, may be rethrown.
      Throws:
      E - if the severity is at or above the threshold set on construction
    • formatEventData

      protected String formatEventData(int severity, E e)
      Custom formatter for an event to appear in the OSFI log. This function must not throw.
      Parameters:
      severity - Event severity, as given by the constants in LoadResult
      e - Event data to format, never null.
      Returns:
      Single line of text that will be sent to the OSFI log.