Package org.exist.collections

Examples of org.exist.collections.CollectionCache


    @Override
    public Collection getOrCreateCollection(final Txn transaction, XmldbURI name) throws PermissionDeniedException, IOException, TriggerException {

        name = prepend(name.normalizeCollectionPath());

        final CollectionCache collectionsCache = pool.getCollectionsCache();

        synchronized(collectionsCache) {
            try {
                //TODO : resolve URIs !
                final XmldbURI[] segments = name.getPathSegments();
View Full Code Here


    public void readCollectionEntry(final SubCollectionEntry entry) {

        final XmldbURI uri = prepend(entry.getUri().toCollectionPathURI());

        Collection collection;
        final CollectionCache collectionsCache = pool.getCollectionsCache();
        synchronized(collectionsCache) {
            collection = collectionsCache.get(uri);
            if(collection == null) {
                final Lock lock = collectionsDb.getLock();
                try {
                    lock.acquire(Lock.READ_LOCK);

                    final Value key = new CollectionStore.CollectionKey(uri.toString());
                    final VariableByteInput is = collectionsDb.getAsStream(key);
                    if(is == null) {
                        LOG.warn("Could not read collection entry for: " + uri);
                        return;
                    }

                    //read the entry details
                    entry.read(is);

                } catch(final UnsupportedEncodingException e) {
                    LOG.error("Unable to encode '" + uri + "' in UTF-8");
                } catch(final LockException e) {
                    LOG.warn("Failed to acquire lock on " + collectionsDb.getFile().getName());
                } catch(final IOException e) {
                    LOG.error(e.getMessage(), e);
                } finally {
                    lock.release(Lock.READ_LOCK);
                }
            } else {

                if(!collection.getURI().equalsInternal(uri)) {
                    LOG.error("The collection received from the cache is not the requested: " + uri +
                        "; received: " + collection.getURI());
                    return;
                }

                entry.read(collection);

                collectionsCache.add(collection);
            }
        }
    }
View Full Code Here

     */
    private Collection openCollection(XmldbURI uri, final long address, final int lockMode) throws PermissionDeniedException {
        uri = prepend(uri.toCollectionPathURI());
        //We *must* declare it here (see below)
        Collection collection;
        final CollectionCache collectionsCache = pool.getCollectionsCache();
        synchronized(collectionsCache) {
            collection = collectionsCache.get(uri);
            if(collection == null) {
                final Lock lock = collectionsDb.getLock();
                try {
                    lock.acquire(Lock.READ_LOCK);
                    VariableByteInput is;
                    if(address == BFile.UNKNOWN_ADDRESS) {
                        final Value key = new CollectionStore.CollectionKey(uri.toString());
                        is = collectionsDb.getAsStream(key);
                    } else {
                        is = collectionsDb.getAsStream(address);
                    }
                    if(is == null) {
                        return null;
                    }
                    collection = new Collection(this, uri);
                    collection.read(this, is);
                    //TODO : manage this from within the cache -pb
                    if(!pool.isInitializing()) {
                        collectionsCache.add(collection);
                    }
                    //TODO : rethrow exceptions ? -pb
                } catch(final UnsupportedEncodingException e) {
                    LOG.error("Unable to encode '" + uri + "' in UTF-8");
                    return null;
                } catch(final LockException e) {
                    LOG.warn("Failed to acquire lock on " + collectionsDb.getFile().getName());
                    return null;
                } catch(final IOException e) {
                    LOG.error(e.getMessage(), e);
                    return null;
                } finally {
                    lock.release(Lock.READ_LOCK);
                }
            } else {
                if(!collection.getURI().equalsInternal(uri)) {
                    LOG.error("The collection received from the cache is not the requested: " + uri +
                        "; received: " + collection.getURI());
                }
                collectionsCache.add(collection);

                if(!collection.getPermissionsNoLock().validate(getSubject(), Permission.EXECUTE)) {
                    throw new PermissionDeniedException("Permission denied to open collection: " + collection.getURI().toString() + " by " + getSubject().getName());
                }
            }
View Full Code Here

        }
        if(collection.getId() == destination.getId()) {
            throw new PermissionDeniedException("Cannot move collection to itself '" + collection.getURI() + "'.");
        }

        final CollectionCache collectionsCache = pool.getCollectionsCache();
        synchronized(collectionsCache) {
            final Lock lock = collectionsDb.getLock();
            try {
                pool.getProcessMonitor().startJob(ProcessMonitor.ACTION_COPY_COLLECTION, collection.getURI());
                lock.acquire(Lock.WRITE_LOCK);
View Full Code Here

     *                    function.
     */
    private void moveCollectionRecursive(final Txn transaction, final CollectionTrigger trigger, final Collection collection, final Collection destination, final XmldbURI newName, final boolean fireTrigger) throws PermissionDeniedException, IOException, LockException, TriggerException {

        final XmldbURI uri = collection.getURI();
        final CollectionCache collectionsCache = pool.getCollectionsCache();
        synchronized(collectionsCache) {

            final XmldbURI srcURI = collection.getURI();
            final XmldbURI dstURI = destination.getURI().append(newName);

            if(fireTrigger) {
                trigger.beforeMoveCollection(this, transaction, collection, dstURI);
            }

            final XmldbURI parentName = collection.getParentURI();
            final Collection parent = openCollection(parentName, Lock.WRITE_LOCK);

            if(parent != null) {
                try {
                    //TODO : resolve URIs
                    parent.removeCollection(this, uri.lastSegment());
                } finally {
                    parent.release(Lock.WRITE_LOCK);
                }
            }

            final Lock lock = collectionsDb.getLock();
            try {
                lock.acquire(Lock.WRITE_LOCK);
                collectionsCache.remove(collection);
                final Value key = new CollectionStore.CollectionKey(uri.toString());
                collectionsDb.remove(transaction, key);
                //TODO : resolve URIs destination.getURI().resolve(newName)
                collection.setPath(destination.getURI().append(newName));
                collection.setCreationTime(System.currentTimeMillis());
View Full Code Here

            final CollectionTrigger colTrigger = new CollectionTriggers(this, parent);

            colTrigger.beforeDeleteCollection(this, transaction, collection);

            final long start = System.currentTimeMillis();
            final CollectionCache collectionsCache = pool.getCollectionsCache();

            synchronized(collectionsCache) {
                final XmldbURI uri = collection.getURI();
                final String collName = uri.getRawCollectionPath();

                // Notify the collection configuration manager
                final CollectionConfigurationManager manager = pool.getConfigurationManager();
                if(manager != null) {
                    manager.invalidate(uri, getBrokerPool());
                }

                if(LOG.isDebugEnabled()) {
                    LOG.debug("Removing children collections from their parent '" + collName + "'...");
                }

                for(final Iterator<XmldbURI> i = collection.collectionIterator(this); i.hasNext(); ) {
                    final XmldbURI childName = i.next();
                    //TODO : resolve from collection's base URI
                    //TODO : resolve URIs !!! (uri.resolve(childName))
                    final Collection childCollection = openCollection(uri.append(childName), Lock.WRITE_LOCK);
                    try {
                        removeCollection(transaction, childCollection);
                    } catch(NullPointerException npe) {
                        LOG.error("childCollection '" + childName + "' is corrupted. Caught NPE to be able to actually remove the parent.");
                    } finally {
                        if(childCollection != null) {
                            childCollection.getLock().release(Lock.WRITE_LOCK);
                        } else {
                            LOG.warn("childCollection is null !");
                        }
                    }
                }

                //Drop all index entries
                notifyDropIndex(collection);

                // Drop custom indexes
                indexController.removeCollection(collection, this, false);

                if(!isRoot) {
                    // remove from parent collection
                    //TODO : resolve URIs ! (uri.resolve(".."))
                    final Collection parentCollection = openCollection(collection.getParentURI(), Lock.WRITE_LOCK);
                    // keep the lock for the transaction
                    if(transaction != null) {
                        transaction.registerLock(parentCollection.getLock(), Lock.WRITE_LOCK);
                    }

                    if(parentCollection != null) {
                        try {
                            LOG.debug("Removing collection '" + collName + "' from its parent...");
                            //TODO : resolve from collection's base URI
                            parentCollection.removeCollection(this, uri.lastSegment());
                            saveCollection(transaction, parentCollection);

                        } catch(final LockException e) {
                            LOG.warn("LockException while removing collection '" + collName + "'");
                        } finally {
                            if(transaction == null) {
                                parentCollection.getLock().release(Lock.WRITE_LOCK);
                            }
                        }
                    }
                }

                //Update current state
                final Lock lock = collectionsDb.getLock();
                try {
                    lock.acquire(Lock.WRITE_LOCK);
                    // remove the metadata of all documents in the collection
                    final Value docKey = new CollectionStore.DocumentKey(collection.getId());
                    final IndexQuery query = new IndexQuery(IndexQuery.TRUNC_RIGHT, docKey);
                    collectionsDb.removeAll(transaction, query);
                    // if this is not the root collection remove it...
                    if(!isRoot) {
                        final Value key = new CollectionStore.CollectionKey(collName);
                        //... from the disk
                        collectionsDb.remove(transaction, key);
                        //... from the cache
                        collectionsCache.remove(collection);
                        //and free its id for any further use
                        collectionsDb.freeCollectionId(collection.getId());
                    } else {
                        //Simply save the collection on disk
                        //It will remain cached
View Full Code Here

                collection.getURI().toString(), System.currentTimeMillis() - start));
        }
    }

    public void reindexCollection(final Txn transaction, final Collection collection, final int mode) throws PermissionDeniedException {
        final CollectionCache collectionsCache = pool.getCollectionsCache();
        synchronized(collectionsCache) {
            if(!collection.getPermissionsNoLock().validate(getSubject(), Permission.WRITE)) {
                throw new PermissionDeniedException("Account " + getSubject().getName() + " have insufficient privileges on collection " + collection.getURI());
            }
            LOG.debug("Reindexing collection " + collection.getURI());
View Full Code Here

        if(newName == null) {
            newName = doc.getFileURI();
        }

        final CollectionCache collectionsCache = pool.getCollectionsCache();
        synchronized(collectionsCache) {
            final Lock lock = collectionsDb.getLock();
            try {
                lock.acquire(Lock.WRITE_LOCK);
                final DocumentImpl oldDoc = destination.getDocument(this, newName);
View Full Code Here

                    //REFACTOR : construct then... configure
                    int bufferSize = conf.getInteger(PROPERTY_COLLECTION_CACHE_SIZE);
                    if(bufferSize == -1) {
                        bufferSize = DEFAULT_COLLECTION_BUFFER_SIZE;
                    }
                    collectionCache = new CollectionCache(this, bufferSize, 0.0001);
                    collectionCacheMgr = new CollectionCacheManager(this, collectionCache);

                    // compute how much memory should be reserved for caches to grow
                    final Runtime rt = Runtime.getRuntime();
                    final long maxMem = rt.maxMemory();
View Full Code Here

TOP

Related Classes of org.exist.collections.CollectionCache

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.