Java Code Examples for com.indeed.util.core.io.Closeables2#closeQuietly()

The following examples show how to use com.indeed.util.core.io.Closeables2#closeQuietly() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Store.java    From lsmtree with Apache License 2.0 6 votes vote down vote up
public void checkpoint(File checkpointDir) throws IOException {
    final SharedReference<GenerationState<K, V>> localState = generationState.getCopy();
    try {
        if (localState == null) {
            throw new IOException("store is closed");
        }
        checkpointDir.mkdirs();
        localState.get().volatileGeneration.checkpoint(checkpointDir);
        for (Generation<K, V> generation : localState.get().stableGenerations) {
            generation.checkpoint(checkpointDir);
        }
        PosixFileOperations.cplr(new File(localState.get().path, "state"), checkpointDir);
    } finally {
        Closeables2.closeQuietly(localState, log);
    }
}
 
Example 2
Source File: Store.java    From lsmtree with Apache License 2.0 6 votes vote down vote up
public void compact() throws IOException {
    lock.lock();
    try {
        if (!closed) {
            final SharedReference<GenerationState<K, V>> localStateReference = generationState.getCopy();
            try {
                if (localStateReference == null) return;
                final GenerationState<K, V> localState = localStateReference.get();
                //this is double checked locking but in this case it doesn't really matter since it's just a heuristic
                if (localState.volatileGeneration.sizeInBytes() > maxVolatileGenerationSize) {
                    final GenerationState<K, V> nextState = startNewLog(localState);
                    startCompaction(nextState);
                }
            } finally {
                Closeables2.closeQuietly(localStateReference, log);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 3
Source File: FlamdexSubsetFTGSIterator.java    From imhotep with Apache License 2.0 6 votes vote down vote up
@Override
public final void close() {
    synchronized (session) {
        if (docIdStream != null) {
            Closeables2.closeQuietly(docIdStream, ImhotepLocalSession.log);
        }
        if (intTermIterator != null) {
            Closeables2.closeQuietly(intTermIterator, ImhotepLocalSession.log);
            intTermIterator = null;
        }
        if (stringTermIterator != null) {
            Closeables2.closeQuietly(stringTermIterator, ImhotepLocalSession.log);
            stringTermIterator = null;
        }
        if (flamdexReader != null) {
            Closeables2.closeQuietly(flamdexReader, ImhotepLocalSession.log);
            flamdexReader = null;
        }
    }
}
 
Example 4
Source File: CachedFlamdexReader.java    From imhotep with Apache License 2.0 6 votes vote down vote up
@Override
public void close() {
    try {
        if (readLockRef == null) {
            Closeables2.closeAll(log, metricCache, wrapped);
        } else {
            Closeables2.closeAll(log, metricCache, wrapped, readLockRef);                
        }
    } finally {
        if (memory == null) {
            return;
        }
        if (memory.usedMemory() > 0) {
            log.error("CachedFlamdexReader is leaking! memory reserved after all memory has been freed: "+memory.usedMemory());
        }
        Closeables2.closeQuietly(memory, log);
    }
}
 
Example 5
Source File: RecordLogDirectory.java    From lsmtree with Apache License 2.0 6 votes vote down vote up
@Override
public E get(long address) throws IOException {
    final int segmentNum = (int)(address>>> segmentShift);
    final Option<SharedReference<BlockCompressedRecordFile<E>>> option = fileCache.get(segmentNum);
    if (option.isNone()) {
        throw new IOException("address is invalid: "+address);
    }
    final SharedReference<BlockCompressedRecordFile<E>> reference = option.some();
    final E ret;
    try {
        ret = reference.get().get(address & segmentMask);
    } finally {
        Closeables2.closeQuietly(reference, log);
    }
    return ret;
}
 
Example 6
Source File: CachedFlamdexReaderReference.java    From imhotep with Apache License 2.0 5 votes vote down vote up
@Override
public void close() {
    if (!closed) {
        closed = true;
        Closeables2.closeQuietly(reference, log);
    }
}
 
Example 7
Source File: LocalImhotepServiceCore.java    From imhotep with Apache License 2.0 5 votes vote down vote up
private List<ShardInfo> buildShardList() throws IOException {
    final Map<String, Map<String, AtomicSharedReference<Shard>>> localShards = shards;
    final List<ShardInfo> ret = new ArrayList<ShardInfo>();
    for (final Map<String, AtomicSharedReference<Shard>> map : localShards.values()) {
        for (final String shardName : map.keySet()) {
            final SharedReference<Shard> ref = map.get(shardName).getCopy();
            try {
                if (ref != null) {
                    final Shard shard = ref.get();
                    ret.add(new ShardInfo(shard.getDataset(), shardName,
                                          shard.getLoadedMetrics(), shard.getNumDocs(),
                                          shard.getShardVersion()));
                }
            } finally {
                Closeables2.closeQuietly(ref, log);
            }
        }
    }
    Collections.sort(ret, new Comparator<ShardInfo>() {
        @Override
        public int compare(ShardInfo o1, ShardInfo o2) {
            final int c = o1.dataset.compareTo(o2.dataset);
            if (c != 0) {
                return c;
            }
            return o1.shardId.compareTo(o2.shardId);
        }
    });
    return ret;
}
 
Example 8
Source File: CachingLocalImhotepServiceCore.java    From imhotep with Apache License 2.0 5 votes vote down vote up
private List<ShardInfo> buildShardList() throws IOException {
    final Map<String, Map<String, AtomicSharedReference<Shard>>> localShards = shards;
    final List<ShardInfo> ret = new ArrayList<ShardInfo>();
    for (final Map<String, AtomicSharedReference<Shard>> map : localShards.values()) {
        for (final String shardName : map.keySet()) {
            final SharedReference<Shard> ref = map.get(shardName).get();
            try {
                if (ref != null) {
                    final Shard shard = ref.get();
                    ret.add(new ShardInfo(shard.getDataset(), shardName,
                                          shard.getLoadedMetrics(), shard.getNumDocs(),
                                          shard.getShardVersion()));
                }
            } finally {
                Closeables2.closeQuietly(ref, log);
            }
        }
    }
    Collections.sort(ret, new Comparator<ShardInfo>() {
        @Override
        public int compare(ShardInfo o1, ShardInfo o2) {
            final int c = o1.dataset.compareTo(o2.dataset);
            if (c != 0)
                return c;
            return o1.shardId.compareTo(o2.shardId);
        }
    });
    return ret;
}
 
Example 9
Source File: SafeFiles.java    From util with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void close() throws IOException {
    if (! closed) {
        Closeables2.closeQuietly(fileChannel, LOG);
        deleteIfExistsQuietly(tempFile);

        closed = true;
    }
}
 
Example 10
Source File: AbstractSessionManager.java    From imhotep with Apache License 2.0 5 votes vote down vote up
@Override
public void removeAndCloseIfExists(final String sessionId, Exception e) {
    final SharedReference<ImhotepSession> imhotepSession;
    synchronized (sessionMap) {
        final Session<E> session = sessionMap.remove(sessionId);
        if (session == null) {
            return;
        }
        imhotepSession = session.imhotepSession;
    }
    failureCauseMap.put(sessionId, e);
    Closeables2.closeQuietly(imhotepSession, log);
}
 
Example 11
Source File: MTImhotepMultiSession.java    From imhotep with Apache License 2.0 5 votes vote down vote up
@Override
protected void postClose() {
    if (memory.usedMemory() > 0) {
        log.error("MTImhotepMultiSession is leaking! usedMemory = "+memory.usedMemory());
    }
    Closeables2.closeQuietly(memory, log);
}
 
Example 12
Source File: AbstractImhotepServiceCore.java    From imhotep with Apache License 2.0 5 votes vote down vote up
public <Z> Z doWithSession(String sessionId, Function<ImhotepSession, Z> f)  {
    final SharedReference<ImhotepSession> sessionRef = getSessionManager().getSession(sessionId);
    try {
        return f.apply(sessionRef.get());
    } finally {
        Closeables2.closeQuietly(sessionRef, log);
    }
}
 
Example 13
Source File: Shard.java    From imhotep with Apache License 2.0 5 votes vote down vote up
public Set<String> getLoadedMetrics() {
    final SharedReference<CachedFlamdexReader> copy = ref.copyIfLoaded();
    if (copy != null) {
        try {
            return copy.get().getLoadedMetrics();
        } finally {
            Closeables2.closeQuietly(copy, log);
        }
    }
    return Collections.emptySet();
}
 
Example 14
Source File: Store.java    From lsmtree with Apache License 2.0 5 votes vote down vote up
private void finishClose() throws IOException {
    try {
        final SharedReference<GenerationState<K, V>> state = generationState.getAndUnset();
        try {
            if (state != null) {
                final VolatileGeneration<K, V> volatileGeneration = state.get().volatileGeneration;
                if (volatileGeneration != null) volatileGeneration.closeWriter();
            }
        } finally {
            Closeables2.closeQuietly(state, log);
        }
    } finally {
        threadPool.shutdown();
    }
}
 
Example 15
Source File: MMapSignedByteArrayIntValueLookup.java    From imhotep with Apache License 2.0 4 votes vote down vote up
@Override
public void close() {
    Closeables2.closeQuietly(buffer, LOG);
}
 
Example 16
Source File: MapCache.java    From imhotep with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized void close() throws IOException {
    for (Map.Entry<String, SharedReference<MMapBuffer>> entry : mappingCache.entrySet()) {
        Closeables2.closeQuietly(entry.getValue(), log);
    }
}
 
Example 17
Source File: AtomicSharedReference.java    From util with Apache License 2.0 4 votes vote down vote up
/**
 * Unsets the reference, closing with Closeables2.closeQuietly().
 */
public synchronized void unsetQuietly() {
    if (ref != null) Closeables2.closeQuietly(ref, log);
    ref = null;
}
 
Example 18
Source File: MMapByteArrayIntValueLookup.java    From imhotep with Apache License 2.0 4 votes vote down vote up
@Override
public void close() {
    Closeables2.closeQuietly(buffer, LOG);
}
 
Example 19
Source File: MMapIntArrayIntValueLookup.java    From imhotep with Apache License 2.0 4 votes vote down vote up
@Override
public void close() {
    Closeables2.closeQuietly(buffer, LOG);
}
 
Example 20
Source File: MMapStringValueLookup.java    From imhotep with Apache License 2.0 4 votes vote down vote up
public void close() {
    Closeables2.closeQuietly(docIdToAddressBuffer, log);
    Closeables2.closeQuietly(stringValuesBuffer, log);
}