private void close(final long indexShardId,
                       final Executor executor) {
        securityContext.asProcessingUser(() -> {
            try {
                // Close the shard.
                final Runnable supplier = taskContextFactory.context(
                        "Closing writer",
                        TerminateHandlerFactory.NOOP_FACTORY,
                        taskContext -> {
                            taskContext.info(() -> "Closing writer for index shard " +
                                                   indexShardId);
                            openShards.compute(indexShardId, (k, v) -> {
                                if (v != null) {
                                    closeWriter(v);
                                }
                                return null;
                            });
                        });
                CompletableFuture
                        .runAsync(
                                supplier,
                                executor)
                        .whenComplete((r, t) -> {
                            if (t != null) {
                                LOGGER.error(t::getMessage, t);
                            }
                        });
            } catch (final Exception e) {
                LOGGER.error(e::getMessage, e);
            }
        });
    }
This is called by the lifecycle service and remove writers that are past their TTL, TTI or LRU
items that exceed the capacity.
stroom-index/stroom-index-impl/src/main/java/stroom/index/impl/IndexShardWriterCacheImpl.java