Package org.apache.jackrabbit.oak.plugins.document

Examples of org.apache.jackrabbit.oak.plugins.document.NodeDocument$Children


                                       int maxCacheAge) {
        if (collection != Collection.NODES) {
            return findUncached(collection, key);
        }
        CacheValue cacheKey = new StringValue(key);
        NodeDocument doc;
        if (maxCacheAge > 0) {
            // first try without lock
            doc = nodesCache.getIfPresent(cacheKey);
            if (doc != null) {
                if (maxCacheAge == Integer.MAX_VALUE ||
                        System.currentTimeMillis() - doc.getCreated() < maxCacheAge) {
                    if (doc == NodeDocument.NULL) {
                        return null;
                    }
                    return (T) doc;
                }
            }
        }
        try {
            Lock lock = getAndLock(key);
            try {
                if (maxCacheAge == 0) {
                    invalidateCache(collection, key);
                }
                while (true) {
                    doc = nodesCache.get(cacheKey, new Callable<NodeDocument>() {
                        @Override
                        public NodeDocument call() throws Exception {
                            NodeDocument doc = (NodeDocument) findUncached(collection, key);
                            if (doc == null) {
                                doc = NodeDocument.NULL;
                            }
                            return doc;
                        }
                    });
                    if (maxCacheAge == 0 || maxCacheAge == Integer.MAX_VALUE) {
                        break;
                    }
                    if (System.currentTimeMillis() - doc.getCreated() < maxCacheAge) {
                        break;
                    }
                    // too old: invalidate, try again
                    invalidateCache(collection, key);
                }
View Full Code Here


                    Lock lock = getAndLock(id);
                    CacheValue cacheKey = new StringValue(id);
                    try {
                        // do not overwrite document in cache if the
                        // existing one in the cache is newer
                        NodeDocument cached = nodesCache.getIfPresent(cacheKey);
                        if (cached != null && cached != NodeDocument.NULL) {
                            // check mod count
                            Number cachedModCount = cached.getModCount();
                            Number modCount = doc.getModCount();
                            if (cachedModCount == null || modCount == null) {
                                throw new IllegalStateException(
                                        "Missing " + Document.MOD_COUNT);
                            }
View Full Code Here

    private <T extends Document> void applyToCache(@Nonnull Collection<T> collection,
                                                   @Nullable T oldDoc,
                                                   @Nonnull UpdateOp updateOp) {
        // cache the new document
        if (collection == Collection.NODES) {
            NodeDocument newDoc = (NodeDocument) collection.newDocument(this);
            if (oldDoc != null) {
                oldDoc.deepCopy(newDoc);
                oldDoc.seal();
            }
            CacheValue key = new StringValue(updateOp.getId());
            UpdateUtils.applyChanges(newDoc, updateOp, comparator);
            newDoc.seal();

            NodeDocument cached = addToCache(newDoc);
            if (cached == newDoc) {
                // successful
                return;
            }
            if (oldDoc == null) {
                // this is an insert and some other thread was quicker
                // loading it into the cache -> return now
                return;
            }
            // this is an update (oldDoc != null)
            if (Objects.equal(cached.getModCount(), oldDoc.getModCount())) {
                nodesCache.put(key, newDoc);
            } else {
                // the cache entry was modified by some other thread in
                // the meantime. the updated cache entry may or may not
                // include this update. we cannot just apply our update
View Full Code Here

        // meantime. That is, use get() with a Callable,
        // which is only used when the document isn't there
        try {
            CacheValue key = new StringValue(doc.getId());
            for (;;) {
                NodeDocument cached = nodesCache.get(key,
                        new Callable<NodeDocument>() {
                    @Override
                    public NodeDocument call() {
                        return doc;
                    }
View Full Code Here

    public String toString() {
        StringBuilder buff = new StringBuilder();
        buff.append("Nodes:\n");
        for (String p : nodes.keySet()) {
            buff.append("Path: ").append(p).append('\n');
            NodeDocument doc = nodes.get(p);
            for (String prop : doc.keySet()) {
                buff.append(prop).append('=').append(doc.get(prop)).append('\n');
            }
            buff.append("\n");
        }
        return buff.toString();
    }
View Full Code Here

        serializer = new KryoSerializer(new OakKryoPool(documentStore));
    }

    @Override
    public NodeDocument getIfPresent(Object key) {
        NodeDocument result = super.getIfPresent(key);
        if (result == null) {
            result = retrieve(key, false);
        }
        return result;
    }
View Full Code Here

        return super.get(key, new Callable<NodeDocument>() {
            @Override
            public NodeDocument call()
                    throws Exception {
                //Check in offHeap first
                NodeDocument result = retrieve(key, true);

                //Not found in L2 then load
                if (result == null) {
                    result = valueLoader.call();
                }
View Full Code Here

        //Look up value from L2
        Map<CacheValue, NodeDocument> r2 = Maps.newHashMap(result);
        for (CacheValue key : list) {
            if (!result.containsKey(key)) {
                NodeDocument val = retrieve(key, false);
                if (val != null) {
                    r2.put(key, val);
                }
            }
        }
View Full Code Here

    }

    @Nullable
    @Override
    public CachedNodeDocument getCachedDocument(String id) {
        NodeDocument doc = super.getIfPresent(id);
        if (doc != null) {
            return doc;
        }
        return offHeapCache.getIfPresent(id);
    }
View Full Code Here

        if (value == null) {
            statsCounter.recordMisses(1);
            return null;
        }

        NodeDocument result = value.getDocument();
        if (result != null) {
            statsCounter.recordLoadSuccess(watch.elapsed(TimeUnit.NANOSECONDS));
        } else {
            statsCounter.recordMisses(1);
        }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.plugins.document.NodeDocument$Children

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.