Package org.exist.storage.lock

Examples of org.exist.storage.lock.Lock


    }

    public void lock(DBBroker broker, boolean exclusive, boolean checkExisting) throws LockException {
        sort();
        DocumentImpl d;
        Lock dlock;
        for (int idx = 0; idx < documentCount; idx++) {
            d = nodes[documentOffsets[idx]].getDocument();
            dlock = d.getUpdateLock();
            if (exclusive)
                {dlock.acquire(Lock.WRITE_LOCK);}
            else
                {dlock.acquire(Lock.READ_LOCK);}
        }
    }
View Full Code Here


    }

    public void unlock(boolean exclusive) {
        sort();
        DocumentImpl d;
        Lock dlock;
        final Thread thread = Thread.currentThread();
        for(int idx = 0; idx < documentCount; idx++) {
            d = nodes[documentOffsets[idx]].getDocument();
            dlock = d.getUpdateLock();
            if(exclusive)
                {dlock.release(Lock.WRITE_LOCK);}
            else if (dlock.isLockedForRead(thread))
                {dlock.release(Lock.READ_LOCK);}
        }
    }
View Full Code Here

    }

    @Override
    public void lock(DBBroker broker, boolean exclusive, boolean checkExisting) throws LockException {
        DocumentImpl d;
        Lock dlock;
        //final Thread thread = Thread.currentThread();
        for(int idx = 0; idx < tabSize; idx++) {
            if(values[idx] == null || values[idx] == REMOVED)
                {continue;}
            d = (DocumentImpl)values[idx];
            dlock = d.getUpdateLock();
            //if (checkExisting && dlock.hasLock(thread))
                //continue;
            if(exclusive)
                {dlock.acquire(Lock.WRITE_LOCK);}
            else
                {dlock.acquire(Lock.READ_LOCK);}
        }
    }
View Full Code Here

    }

    @Override
    public void unlock(boolean exclusive) {
        DocumentImpl d;
        Lock dlock;
        final Thread thread = Thread.currentThread();
        for(int idx = 0; idx < tabSize; idx++) {
            if(values[idx] == null || values[idx] == REMOVED)
                {continue;}
            d = (DocumentImpl)values[idx];
            dlock = d.getUpdateLock();
            if(exclusive)
                {dlock.release(Lock.WRITE_LOCK);}
            else if (dlock.isLockedForRead(thread))
                {dlock.release(Lock.READ_LOCK);}
        }
    }
View Full Code Here

    public NodeSet docsToNodeSet() {
        return new NodeProxy(doc, NodeId.DOCUMENT_NODE);
    }

    public void lock(DBBroker broker, boolean exclusive, boolean checkExisting) throws LockException {
        final Lock dlock = doc.getUpdateLock();
        if (exclusive)
            {dlock.acquire(Lock.WRITE_LOCK);}
        else
            {dlock.acquire(Lock.READ_LOCK);}
    }
View Full Code Here

        else
            {dlock.acquire(Lock.READ_LOCK);}
    }

    public void unlock(boolean exclusive) {
        final Lock dlock = doc.getUpdateLock();
        if(exclusive)
            {dlock.release(Lock.WRITE_LOCK);}
        else if (dlock.isLockedForRead(Thread.currentThread()))
            {dlock.release(Lock.READ_LOCK);}
    }
View Full Code Here

    @Override
    public void sync() throws DBException {
        if (btree == null)
            {return;}
        final Lock lock = btree.getLock();
        try {
            lock.acquire(Lock.WRITE_LOCK);
            btree.flush();
        } catch (final LockException e) {
            LOG.warn("Failed to acquire lock for '" + btree.getFile().getName() + "'", e);
            //TODO : throw an exception ? -pb
        } catch (final DBException e) {
            LOG.error(e.getMessage(), e);
            //TODO : throw an exception ? -pb
        } finally {
            lock.release(Lock.WRITE_LOCK);
        }
    }
View Full Code Here

     * The method <code>run</code>
     *
     * @return an <code>Object</code> value
     */
    public Object run() {
        final Lock lock = file.getLock();
        try {
            // try to acquire a lock on the file
            try {
                lock.acquire( mode );
            } catch( final LockException e ) {
                System.out.println("Failed to acquire read lock on " + file.getFile().getName());
                return null;
            }
            file.setOwnerObject(ownerObject);
            file.setCurrentDocument(document);
            return start();
        } catch(final ReadOnlyException e) {
            LOG.error(e.getMessage(), e);
        } finally {
            lock.release(mode);
        }
        return null;
    }
View Full Code Here

        private void flushWord(int currentSection, int collectionId, Object token, ByteArray data) {
            //return early
            //TODO : is this ever called ? -pb
            if (data.size() == 0)
                {return;}
            final Lock lock = dbTokens.getLock();
            try {
                lock.acquire(Lock.WRITE_LOCK);
                Value key;
                if (currentSection == QNAME_SECTION) {
                    final QNameTerm term = (QNameTerm) token;
                    key = new QNameWordRef(collectionId, term.qname, term.term,
                        broker.getBrokerPool().getSymbols());
                } else {
                    key = new WordRef(collectionId, token.toString());
                }
                dbTokens.append(key, data);
            } catch (final LockException e) {
                LOG.warn("Failed to acquire lock for '" +
                    dbTokens.getFile().getName() + "' (inverted index)", e);
                //TODO : throw exception ? -pb
            } catch (final ReadOnlyException e) {
                LOG.warn("Read-only error on '" + dbTokens.getFile().getName() +
                    "' (inverted index)", e);
                //TODO : throw exception ?
            } catch (final IOException e) {
                LOG.error(e.getMessage() + "' in '" + dbTokens.getFile().getName() +
                    "' (inverted index)", e);
                //TODO : throw exception ? -pb
            } finally {
                lock.release(Lock.WRITE_LOCK);
                os.clear();
            }
        }
View Full Code Here

        public void dropIndex(DocumentImpl document) {
            //Return early
            if (document == null)
                {return;}
            final int collectionId = document.getCollection().getId();
            final Lock lock = dbTokens.getLock();
            for (byte currentSection = 0; currentSection <= QNAME_SECTION; currentSection++) {
                //Not very necessary, but anyway...
                switch (currentSection) {
                    case TEXT_SECTION :
                    case ATTRIBUTE_SECTION :
                    case QNAME_SECTION :
                        break;
                    default :
                        throw new IllegalArgumentException("Invalid section type in '" +
                            dbTokens.getFile().getName() + "' (inverted index)");
                }
                LOG.debug("Removing " + words[currentSection].size() + " tokens");
                for (final Iterator i = words[currentSection].entrySet().iterator(); i.hasNext();) {
                    //Compute a key for the token
                    final Map.Entry entry = (Map.Entry) i.next();
                    final Object token = entry.getKey();
                    Value key;
                    if (currentSection == QNAME_SECTION) {
                        final QNameTerm term = (QNameTerm) token;
                        key = new QNameWordRef(collectionId, term.qname,
                            term.term, broker.getBrokerPool().getSymbols());
                    } else {
                        key = new WordRef(collectionId, token.toString());
                    }
                    os.clear();
                    try {
                        lock.acquire(Lock.WRITE_LOCK);
                        boolean changed = false;
                        os.clear();
                        final VariableByteInput is = dbTokens.getAsStream(key);
                        //Does the token already has data in the index ?
                        if (is == null)
                            {continue;}
                        //try {
                        while (is.available() > 0) {
                            final int storedDocId = is.readInt();
                            final byte section = is.readByte();
                            final int gidsCount = is.readInt();
                            //Read (variable) length of node IDs + frequency + offsets
                            final int length = is.readFixedInt();
                            if (storedDocId != document.getDocId()) {
                                // data are related to another document:
                                // copy them to any existing data
                                os.writeInt(storedDocId);
                                os.writeByte(section);
                                os.writeInt(gidsCount);
                                os.writeFixedInt(length);
                                is.copyRaw(os, length);
                            } else {
                                // data are related to our document:
                                // skip them
                                changed = true;
                                is.skipBytes(length);
                            }
                        }
                        //Store new data, if relevant
                        if (changed) {
                            //Well, nothing to store : remove the existing data
                            if (os.data().size() == 0) {
                                dbTokens.remove(key);
                            } else {
                                if (dbTokens.put(key, os.data()) == BFile.UNKNOWN_ADDRESS) {
                                    LOG.error("Could not put index data for token '" +
                                        token + "' in '" + dbTokens.getFile().getName() + "'");
                                    //TODO : throw an exception ?
                                }
                            }
                        }
                    } catch (final LockException e) {
                        LOG.warn("Failed to acquire lock for '" +
                            dbTokens.getFile().getName() + "'", e);
                        //TODO : throw exception ? -pb
                    } catch (final IOException e) {
                        LOG.error(e.getMessage() + " in '" +
                            dbTokens.getFile().getName() + "'", e);
                        //TODO : throw exception ? -pb
                    } catch (final ReadOnlyException e) {
                        LOG.error(e.getMessage() + " in '" +
                            dbTokens.getFile().getName() + "'", e);
                        //TODO : throw exception ? -pb
                    } finally {
                        lock.release(Lock.WRITE_LOCK);
                        os.clear();
                    }
                }
                words[currentSection].clear();
            }
View Full Code Here

TOP

Related Classes of org.exist.storage.lock.Lock

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.