@Override
    public boolean doWithLoaderUnlessComplete(final RefStreamDefinition refStreamDefinition,
                                              final long effectiveTimeMs,
                                              final Consumer<RefDataLoader> work) {

        final boolean result;
        try (RefDataLoader refDataLoader = createLoader(refStreamDefinition, effectiveTimeMs)) {
            // we now hold the lock for this RefStreamDefinition so re-test the completion state

            final Optional<ProcessingState> optLoadState = getLoadState(refStreamDefinition);

            final boolean isRefLoadRequired = optLoadState
                    .filter(loadState ->
                            loadState.equals(ProcessingState.COMPLETE))
                    .isEmpty();
            LOGGER.debug("optLoadState {}, isRefLoadRequired {}", optLoadState, isRefLoadRequired);

            if (optLoadState.isPresent() && optLoadState.get().equals(ProcessingState.FAILED)) {
                // A previous load of this ref stream failed so no point trying again.
                LOGGER.error("Existing reference data load is in a failed state. No point trying again. " +
                                "If the cause is environmental then purge the ref stream from the store and " +
                                "perform another lookup. {}",
                        refStreamDefinition.asUiFriendlyString());
                throw new RuntimeException(LogUtil.message(
                        "Reference Data is in a failed state from a previous load, aborting this load. {}",
                        refStreamDefinition.asUiFriendlyString()));
            } else if (optLoadState.isPresent() && optLoadState.get().equals(ProcessingState.COMPLETE)) {
                // If we get here then the data was not loaded when we checked before getting the lock,
                // so we waited for the lock and in the meantime another stream did the load.
                // Thus, we can drop out.
                LOGGER.info("Reference Data is already successfully loaded for {}, so doing nothing",
                        refStreamDefinition);
                result = false;
            } else {
                // Ref stream not in the store or a previous load was terminated part way through so
                // do the load (again)

                optLoadState.ifPresent(processingState -> {
                    if (ProcessingState.LOAD_IN_PROGRESS.equals(processingState)
                            || ProcessingState.PURGE_IN_PROGRESS.equals(processingState)) {
                        LOGGER.error("Unexpected processing state {}. This should not happen. " +
                                        "We hold the lock though, so will load anyway. {}",
                                processingState,
                                refStreamDefinition.asUiFriendlyString());
                    }
                });

                LOGGER.debug("Performing work with loader for {}", refStreamDefinition);
                work.accept(refDataLoader);

                result = true;
            }
        } catch (TaskTerminatedException e) {
            LAMBDA_LOGGER.debug(() -> "Task terminated: " + e.getMessage());
            throw e;
        } catch (UncheckedInterruptedException e) {
            LAMBDA_LOGGER.debug(() -> "Interrupted: " + e.getMessage());
            throw new TaskTerminatedException();
        } catch (Exception e) {
            String msg = e.getMessage();
            // May get suppressed exceptions from the try-with-resources
            if (e.getSuppressed() != null && e.getSuppressed().length > 0) {
                msg += " " + Arrays.stream(e.getSuppressed())
                        .map(Throwable::getMessage)
                        .collect(Collectors.joining(" "));
            }
            throw new RuntimeException(LogUtil.message(
                    "Error using reference loader for {}: {}",
                    refStreamDefinition.asUiFriendlyString(), msg), e);
        }
        return result;
    }
Get an instance of a {@link RefDataLoader} for bulk loading multiple entries for a given
{@link RefStreamDefinition} and its associated effectiveTimeMs. The {@link RefDataLoader}
should be used in a try with resources block to ensure any transactions are closed, e.g.
<pre>try (RefDataLoader refDataLoader = refDataOffHeapStore.getLoader(...)) { ... }</pre>
stroom-pipeline/src/main/java/stroom/pipeline/refdata/store/AbstractRefDataStore.java