Search in sources :

Example 1 with FileSize

use of com.ctrip.xpipe.api.utils.FileSize in project x-pipe by ctripcorp.

the class DefaultRdbStore method createControllableFile.

private ControllableFile createControllableFile() throws IOException {
    if (eofType instanceof LenEofType) {
        return new DefaultControllableFile(file);
    } else if (eofType instanceof EofMarkType) {
        return new SizeControllableFile(file, new FileSize() {

            @Override
            public long getSize(LongSupplier realSizeProvider) {
                long realSize = 0;
                synchronized (truncateLock) {
                    // truncate may make size wrong
                    realSize = realSizeProvider.getAsLong();
                }
                if (status.get() == Status.Writing) {
                    long ret = realSize - ((EofMarkType) eofType).getTag().length();
                    logger.debug("[getSize][writing]{}, {}", DefaultRdbStore.this, ret);
                    return ret < 0 ? 0 : ret;
                }
                return realSize;
            }
        });
    } else {
        throw new IllegalStateException("unknown eoftype:" + eofType.getClass() + "," + eofType);
    }
}
Also used : DefaultControllableFile(com.ctrip.xpipe.utils.DefaultControllableFile) SizeControllableFile(com.ctrip.xpipe.utils.SizeControllableFile) EofMarkType(com.ctrip.xpipe.redis.core.protocal.protocal.EofMarkType) LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) LongSupplier(java.util.function.LongSupplier) FileSize(com.ctrip.xpipe.api.utils.FileSize)

Aggregations

FileSize (com.ctrip.xpipe.api.utils.FileSize)1 EofMarkType (com.ctrip.xpipe.redis.core.protocal.protocal.EofMarkType)1 LenEofType (com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType)1 DefaultControllableFile (com.ctrip.xpipe.utils.DefaultControllableFile)1 SizeControllableFile (com.ctrip.xpipe.utils.SizeControllableFile)1 LongSupplier (java.util.function.LongSupplier)1