List of usage examples for java.util.concurrent.atomic AtomicLong accumulateAndGet
public final long accumulateAndGet(long x, LongBinaryOperator accumulatorFunction)
From source file:org.codice.solr.factory.impl.SolrClientAdapter.java
@VisibleForTesting boolean wasNotRecent(AtomicLong previous, long freq) { final long now = System.currentTimeMillis(); if (now == previous.get()) { return false; }/*from w w w .ja v a 2 s. co m*/ // update if not recent (i.e. if the last occurrence was older than the specified frequency return previous.accumulateAndGet(now, (last, n) -> ((now - last) >= freq) ? now : last) == now; }
From source file:org.zanata.sync.jobs.cache.RepoCacheImpl.java
private long copyDir(Path source, Path target) throws IOException { Files.createDirectories(target); AtomicLong totalSize = new AtomicLong(0); Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override//w w w . j av a2 s . co m public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path targetdir = target.resolve(source.relativize(dir)); try { if (Files.isDirectory(targetdir) && Files.exists(targetdir)) { return CONTINUE; } Files.copy(dir, targetdir, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); } catch (FileAlreadyExistsException e) { if (!Files.isDirectory(targetdir)) { throw e; } } return CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Files.isRegularFile(file)) { totalSize.accumulateAndGet(Files.size(file), (l, r) -> l + r); } Path targetFile = target.resolve(source.relativize(file)); // only copy to target if it doesn't exist or it exist but the content is different if (!Files.exists(targetFile) || !com.google.common.io.Files.equal(file.toFile(), targetFile.toFile())) { Files.copy(file, targetFile, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); } return CONTINUE; } }); return totalSize.get(); }