Examples of RAFLock


Examples of freenet.support.api.LockableRandomAccessBuffer.RAFLock

        }
    }

    byte[] preadChecksummedWithLength(long fileOffset) throws IOException, ChecksumFailedException, StorageFormatException {
        byte[] checksumBuf = new byte[checksumLength];
        RAFLock lock = raf.lockOpen();
        byte[] lengthBuf = new byte[8];
        byte[] buf;
        int length;
        try {
            raf.pread(fileOffset, lengthBuf, 0, lengthBuf.length);
            long len = new DataInputStream(new ByteArrayInputStream(lengthBuf)).readLong();
            if(len + fileOffset > rafLength || len > Integer.MAX_VALUE || len < 0)
                throw new StorageFormatException("Bogus length "+len);
            length = (int)len;
            buf = new byte[length];
            raf.pread(fileOffset+lengthBuf.length, buf, 0, length);
            raf.pread(fileOffset+length+lengthBuf.length, checksumBuf, 0, checksumLength);
        } finally {
            lock.unlock();
        }
        if(!checksumChecker.checkChecksum(buf, 0, length, checksumBuf)) {
            Arrays.fill(buf, 0, length, (byte)0);
            throw new ChecksumFailedException();
        }
View Full Code Here

Examples of freenet.support.api.LockableRandomAccessBuffer.RAFLock

           
        });
    }

    private void innerEncode(MemoryLimitedChunk chunk) {
        RAFLock lock = null;
        try {
            synchronized(this) {
                if(cancelled) return;
            }
            lock = parent.lockRAF();
            if(logMINOR) Logger.minor(this, "Encoding "+this+" for "+parent);
            byte[][] dataBlocks = readDataAndCrossCheckBlocks();
            generateKeys(dataBlocks, 0);
            byte[][] checkBlocks = new byte[checkBlockCount][];
            for(int i=0;i<checkBlocks.length;i++)
                checkBlocks[i] = new byte[CHKBlock.DATA_LENGTH];
            if(dataBlocks == null || checkBlocks == null) return; // Failed with disk error.
            parent.codec.encode(dataBlocks, checkBlocks, new boolean[checkBlocks.length], CHKBlock.DATA_LENGTH);
            for(int i=0;i<checkBlocks.length;i++)
                writeCheckBlock(i, checkBlocks[i]);
            generateKeys(checkBlocks, dataBlockCount + crossCheckBlockCount);
            synchronized(this) {
                encoded = true;
            }
            if(logMINOR) Logger.minor(this, "Encoded "+this+" for "+parent);
        } catch (IOException e) {
            parent.failOnDiskError(e);
        } catch (Throwable t) {
            Logger.error(this, "Failed: "+t, t);
            parent.fail(new InsertException(InsertExceptionMode.INTERNAL_ERROR, t, null));
        } finally {
            if(lock != null) lock.unlock();
        }
    }
View Full Code Here

Examples of freenet.support.api.LockableRandomAccessBuffer.RAFLock

        }
    }

    private byte[][] readDataAndCrossCheckBlocks() throws IOException {
        byte[][] data = new byte[dataBlockCount + crossCheckBlockCount][];
        RAFLock lock = parent.lockUnderlying();
        try {
            for(int i=0;i<dataBlockCount;i++)
                data[i] = readDataBlock(i);
        } finally {
            lock.unlock();
        }
        for(int i=0;i<crossCheckBlockCount;i++)
            data[i+dataBlockCount] = readCrossCheckBlock(i);
        return data;
    }
View Full Code Here

Examples of freenet.support.api.LockableRandomAccessBuffer.RAFLock

        writeMetadataJob.run(context);
    }
   
    void preadChecksummed(long fileOffset, byte[] buf, int offset, int length) throws IOException, ChecksumFailedException {
        byte[] checksumBuf = new byte[checker.checksumLength()];
        RAFLock lock = raf.lockOpen();
        try {
            raf.pread(fileOffset, buf, offset, length);
            raf.pread(fileOffset+length, checksumBuf, 0, checker.checksumLength());
        } finally {
            lock.unlock();
        }
        if(!checker.checkChecksum(buf, offset, length, checksumBuf)) {
            Arrays.fill(buf, offset, offset+length, (byte)0);
            throw new ChecksumFailedException();
        }
View Full Code Here

Examples of freenet.support.api.LockableRandomAccessBuffer.RAFLock

        }
    }

    byte[] preadChecksummedWithLength(long fileOffset) throws IOException, ChecksumFailedException, StorageFormatException {
        byte[] checksumBuf = new byte[checker.checksumLength()];
        RAFLock lock = raf.lockOpen();
        byte[] lengthBuf = new byte[8];
        byte[] buf;
        int length;
        try {
            raf.pread(fileOffset, lengthBuf, 0, lengthBuf.length);
            long len = new DataInputStream(new ByteArrayInputStream(lengthBuf)).readLong();
            if(len + fileOffset > rafLength || len > Integer.MAX_VALUE || len < 0)
                throw new StorageFormatException("Bogus length "+len);
            length = (int)len;
            buf = new byte[length];
            raf.pread(fileOffset+lengthBuf.length, buf, 0, length);
            raf.pread(fileOffset+length+lengthBuf.length, checksumBuf, 0, checker.checksumLength());
        } finally {
            lock.unlock();
        }
        if(!checker.checkChecksum(buf, 0, length, checksumBuf)) {
            Arrays.fill(buf, 0, length, (byte)0);
            throw new ChecksumFailedException();
        }
View Full Code Here

Examples of freenet.support.api.LockableRandomAccessBuffer.RAFLock

            parent.failOnDiskError(e);
        }
    }

    private void writeCheckBlocks(byte[][] checkBlocks) throws IOException {
        RAFLock lock = parent.lockRAF();
        try {
            for(int i=0;i<checkBlocks.length;i++)
                writeCheckBlock(i, checkBlocks[i]);
        } finally {
            lock.unlock();
        }
    }
View Full Code Here

Examples of freenet.support.api.LockableRandomAccessBuffer.RAFLock

        assert(segments[slotNumberWithinCrossSegment].segNo == segmentNumber);
        return parent.readCheckBlock(segNo, slotNumberWithinCrossSegment - dataBlockCount);
    }

    private byte[][] readDataBlocks() throws IOException {
        RAFLock lock = parent.lockUnderlying();
        try {
            byte[][] data = new byte[dataBlockCount][];
            for(int i=0;i<dataBlockCount;i++) {
                data[i] = segments[i].readDataBlock(blockNumbers[i]);
                if(DEBUG_ENCODE) {
                    ClientCHK key = segments[i].encodeBlock(data[i]).getClientKey();
                    segments[i].setKey(blockNumbers[i], key);
                }
            }
            return data;
        } finally {
            lock.unlock();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.