class LuceneDocumentIndexService extends StatelessService {

    void applyMemoryLimitToDocumentUpdateInfo() {
        long memThresholdBytes = this.updateMapMemoryLimit;
        final int bytesPerLinkEstimate = 64;
        int count = 0;

        if (hasOption(ServiceOption.INSTRUMENTATION)) {
            setStat(STAT_NAME_VERSION_CACHE_ENTRY_COUNT, this.updatesPerLink.size());
        }
        // Note: this code will be updated in the future. It currently calls a host
        // method, inside a lock, which is always a bad idea. The getServiceStage()
        // method is lock free, but its still brittle.
        synchronized (this.searchSync) {
            if (this.updatesPerLink.isEmpty()) {
                return;
            }
            if (memThresholdBytes > this.updatesPerLink.size() * bytesPerLinkEstimate) {
                return;
            }
            Iterator<Entry<String, DocumentUpdateInfo>> li = this.updatesPerLink.entrySet()
                    .iterator();
            while (li.hasNext()) {
                Entry<String, DocumentUpdateInfo> e = li.next();
                // remove entries for services no longer attached / started on host
                if (getHost().getServiceStage(e.getKey()) == null) {
                    count++;
                    li.remove();
                }
            }
            // update index time to force searcher update, per thread
            this.writerUpdateTimeMicros = Utils.getNowMicrosUtc();
        }

        if (count == 0) {
            return;
        }
        this.serviceRemovalDetectedTimeMicros = Utils.getNowMicrosUtc();

        logInfo("Cleared %d document update entries", count);
    }

    public  LuceneDocumentIndexService();
    public  LuceneDocumentIndexService(String indexDirectory);

}