private void getValueFromExternalRefStream(
            final PipelineReference pipelineReference,
            final long time,
            final String mapName,
            final String keyName,
            final ReferenceDataResult result) {

        if (pipelineReference.getFeed() == null ||
            pipelineReference.getFeed().getUuid() == null ||
            pipelineReference.getFeed().getUuid().isEmpty() ||
            pipelineReference.getStreamType() == null ||
            pipelineReference.getStreamType().isEmpty()) {

            result.logSimpleTemplate(Severity.ERROR,
                    "pipelineReference is not fully formed, {}",
                    pipelineReference);
        }

        // Check that the current user has permission to read the ref stream.
        final boolean hasPermission = localDocumentPermissionCache.computeIfAbsent(pipelineReference, k ->
                documentPermissionCache == null ||
                documentPermissionCache.canUseDocument(pipelineReference.getFeed()));

        if (hasPermission) {
            // Find the latest ref stream that is before our lookup time
            final Optional<EffectiveMeta> optEffectiveStream = effectiveStreamService.determineEffectiveStream(
                    pipelineReference, time, result);

            // If we have an effective stream then use it.
            if (optEffectiveStream.isPresent()) {
                final EffectiveMeta effectiveStream = optEffectiveStream.get();

                result.logLazyTemplate(Severity.INFO,
                        "Checking effective stream: {} in feed: '{}' for presence of map '{}' " +
                        "(stream effective time: {}, lookup time: {}, pipeline feed: '{}')",
                        () -> Arrays.asList(
                                effectiveStream.getId(),
                                effectiveStream.getFeedName(),
                                mapName,
                                Instant.ofEpochMilli(effectiveStream.getEffectiveMs()).toString(),
                                Instant.ofEpochMilli(time).toString(),
                                pipelineReference.getFeed().getName()));

                final RefStreamDefinition refStreamDefinition = new RefStreamDefinition(
                        pipelineReference.getPipeline(),
                        getPipelineVersion(pipelineReference),
                        effectiveStream.getId());

                result.addEffectiveStream(pipelineReference, refStreamDefinition);

                MapAvailability mapAvailability = refDataStoreHolder.getMapAvailabilityInStream(
                        pipelineReference, refStreamDefinition, mapName);
                logMapAvailability(pipelineReference, mapName, result, refStreamDefinition, mapAvailability);

                if (mapAvailability.isLookupRequired()) {
                    // Stream is known to hold the map we are trying to hit, or we don't yet know the
                    // contents so have to do the lookup in case.
                    final RefDataStore offHeapRefDataStore = refDataStoreHolder.getOffHeapRefDataStore(
                            refStreamDefinition);

                    // load the ref stream into the store if not already there
                    final boolean isRefStreamAvailableForLookups = ensureRefStreamAvailability(
                            result,
                            pipelineReference,
                            refStreamDefinition,
                            offHeapRefDataStore);

                    if (isRefStreamAvailableForLookups) {
                        // now we should have the required data in the store (unless the max age is set far too small)
                        // Note however that the effective stream may not contain the map we are interested in. A data
                        // may have two ref loaders on it.  When a lookup is done it must try the lookup against the two
                        // effective streams as it cannot know which ref streams contain (if at all) the map name of
                        // interest.
                        if (MapAvailability.UNKNOWN.equals(mapAvailability)) {
                            // Re-check the availability now we have the facts
                            mapAvailability = refDataStoreHolder.getMapAvailabilityInStream(
                                    pipelineReference, refStreamDefinition, mapName);

                            logMapAvailability(pipelineReference,
                                    mapName,
                                    result,
                                    refStreamDefinition,
                                    mapAvailability);
                        }

                        if (mapAvailability.isLookupRequired()) {
                            setValueProxyOnResult(
                                    offHeapRefDataStore,
                                    mapName,
                                    keyName,
                                    result,
                                    refStreamDefinition);
                        }
                    }
                }
            } else {
                // No eff stream.  We have already logged the fact in the EffectiveStreamService,
                // so just move on to the next pipelineReference.
            }
        } else {
            result.logLazyTemplate(
                    Severity.ERROR,
                    "User does not have permission to use data from feed '{}'",
                    () -> List.of(
                            pipelineReference.getFeed().getName()));
        }
    }
Ensures that the effective external ref stream is loaded, doing the load if it
is not. It then mutates result to set a value proxy on it so that downstream
code can use the proxy to get the value from the store.
The effective stream is determined based on the time used in the lookup() call
and the effective time of the various reference streams, i.e. picking the last ref
stream before the lookup time.
stroom-pipeline/src/main/java/stroom/pipeline/refdata/ReferenceData.java