List of usage examples for java.util.concurrent.atomic AtomicLong get
public final long get()
From source file:net.dv8tion.jda.core.utils.PermissionUtil.java
/** * Retrieves the explicit permissions of the specified {@link net.dv8tion.jda.core.entities.Member Member} * in its hosting {@link net.dv8tion.jda.core.entities.Guild Guild} and specific {@link net.dv8tion.jda.core.entities.Channel Channel}. * <br>This method does not calculate the owner in. * <b>Allowed permissions override denied permissions of {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverrides}!</b> * * <p>All permissions returned are explicitly granted to this Member via its {@link net.dv8tion.jda.core.entities.Role Roles}. * <br>Permissions like {@link net.dv8tion.jda.core.Permission#ADMINISTRATOR Permission.ADMINISTRATOR} do not * grant other permissions in this value. * <p>This factor in all {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverrides} that affect this member * and only grants the ones that are explicitly given. * * @param channel/* w ww . j av a2s.c om*/ * The target channel of which to check {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverrides} * @param member * The non-null {@link net.dv8tion.jda.core.entities.Member Member} for which to get implicit permissions * * @throws IllegalArgumentException * If any of the arguments is {@code null} * or the specified entities are not from the same {@link net.dv8tion.jda.core.entities.Guild Guild} * * @return Primitive (unsigned) long value with the implicit permissions of the specified member in the specified channel * * @since 3.1 */ public static long getExplicitPermission(Channel channel, Member member) { Checks.notNull(channel, "Channel"); Checks.notNull(member, "Member"); final Guild guild = member.getGuild(); checkGuild(channel.getGuild(), guild, "Member"); long permission = getExplicitPermission(member); AtomicLong allow = new AtomicLong(0); AtomicLong deny = new AtomicLong(0); // populates allow/deny getExplicitOverrides(channel, member, allow, deny); return apply(permission, allow.get(), deny.get()); }
From source file:ubicrypt.core.Utils.java
public static InputStream readIs(final Path path) { final PipedInputStream pis = new PipedInputStream(); final AtomicLong pos = new AtomicLong(0); try {/*from w w w .j a v a 2s . com*/ final PipedOutputStream ostream = new PipedOutputStream(pis); final AsynchronousFileChannel channel = AsynchronousFileChannel.open(path, StandardOpenOption.READ); final ByteBuffer buffer = ByteBuffer.allocate(1 << 16); channel.read(buffer, pos.get(), buffer, new CompletionHandler<Integer, ByteBuffer>() { @Override public void completed(final Integer result, final ByteBuffer buf) { try { if (result == -1) { ostream.close(); return; } final byte[] bytes = new byte[result]; System.arraycopy(buf.array(), 0, bytes, 0, result); ostream.write(bytes); ostream.flush(); if (result < 1 << 16) { ostream.close(); return; } pos.addAndGet(result); final ByteBuffer buffer = ByteBuffer.allocate(1 << 16); channel.read(buffer, pos.get(), buffer, this); } catch (final IOException e) { Throwables.propagate(e); } } @Override public void failed(final Throwable exc, final ByteBuffer attachment) { log.error(exc.getMessage(), exc); } }); } catch (final IOException e) { if (e instanceof NoSuchFileException) { throw new NotFoundException(path); } Throwables.propagate(e); } return pis; }
From source file:org.roda.core.common.RodaUtils.java
/** * @deprecated 20160907 hsilva: not seeing any method using it, so it will be * removed soon/*from ww w .ja v a 2s .co m*/ */ @Deprecated public static long getPathSize(Path startPath) throws IOException { final AtomicLong size = new AtomicLong(0); Files.walkFileTree(startPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { size.addAndGet(attrs.size()); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { // Skip folders that can't be traversed return FileVisitResult.CONTINUE; } }); return size.get(); }
From source file:com.jivesoftware.os.amza.service.storage.WALStorage.java
private static void minimize(AtomicLong existing, long value) { long existingValue = existing.get(); if (existingValue == -1 || value < existingValue) { existing.set(value);/*from w w w. j a v a 2s.co m*/ } }
From source file:io.galeb.router.services.JmxReporterService.java
private long extractDelta(final AtomicLong last, final ToLongFunction<Undertow.ListenerInfo> longFunction) { long start = System.nanoTime(); double localLast = last.get() * 1.0; double current = undertow.getListenerInfo().stream().mapToLong(longFunction).sum() * 1.0; long end = System.nanoTime(); last.set((long) current); return Math.round((current * ((double) end / (double) start)) - localLast); }
From source file:io.druid.client.cache.CacheDistributionTest.java
@Test public void testDistribution() throws Exception { KetamaNodeLocator locator = new KetamaNodeLocator(ImmutableList.of(dummyNode("druid-cache.0001", 11211), dummyNode("druid-cache.0002", 11211), dummyNode("druid-cache.0003", 11211), dummyNode("druid-cache.0004", 11211), dummyNode("druid-cache.0005", 11211)), hash, new DefaultKetamaNodeLocatorConfiguration() { @Override/*from w w w.ja va2s . c o m*/ public int getNodeRepetitions() { return reps; } }); Map<MemcachedNode, AtomicLong> counter = Maps.newHashMap(); long t = 0; for (int i = 0; i < KEY_COUNT; ++i) { final String k = DigestUtils.sha1Hex("abc" + i) + ":" + DigestUtils.sha1Hex("xyz" + i); long t0 = System.nanoTime(); MemcachedNode node = locator.getPrimary(k); t += System.nanoTime() - t0; if (counter.containsKey(node)) { counter.get(node).incrementAndGet(); } else { counter.put(node, new AtomicLong(1)); } } long min = Long.MAX_VALUE; long max = 0; System.out.printf("%25s\t%5d\t", hash, reps); for (AtomicLong count : counter.values()) { System.out.printf("%10d\t", count.get()); min = Math.min(min, count.get()); max = Math.max(max, count.get()); } System.out.printf("%7.2f\t%5.0f\n", (double) min / (double) max, (double) t / KEY_COUNT); }
From source file:uk.ac.susx.tag.method51.twitter.IdentityAnonymizer.java
public long getId(String screenName) { String hash = getHash(screenName); Long id = (Long) hashCache.get(hash); if (id == null) { AtomicLong tmp = new AtomicLong(); hashCache.set(hash, tmp, screenName); id = tmp.get(); }//from w w w.ja va 2s .c o m return id; }
From source file:org.apache.druid.client.cache.CacheDistributionTest.java
@Ignore @Test/*from ww w. j a v a 2 s. c o m*/ public void testDistribution() { KetamaNodeLocator locator = new KetamaNodeLocator(ImmutableList.of(dummyNode("druid-cache.0001", 11211), dummyNode("druid-cache.0002", 11211), dummyNode("druid-cache.0003", 11211), dummyNode("druid-cache.0004", 11211), dummyNode("druid-cache.0005", 11211)), hash, new DefaultKetamaNodeLocatorConfiguration() { @Override public int getNodeRepetitions() { return reps; } }); Map<MemcachedNode, AtomicLong> counter = Maps.newHashMap(); long t = 0; for (int i = 0; i < KEY_COUNT; ++i) { final String k = DigestUtils.sha1Hex("abc" + i) + ":" + DigestUtils.sha1Hex("xyz" + i); long t0 = System.nanoTime(); MemcachedNode node = locator.getPrimary(k); t += System.nanoTime() - t0; if (counter.containsKey(node)) { counter.get(node).incrementAndGet(); } else { counter.put(node, new AtomicLong(1)); } } long min = Long.MAX_VALUE; long max = 0; System.out.printf(Locale.ENGLISH, "%25s\t%5d\t", hash, reps); for (AtomicLong count : counter.values()) { System.out.printf(Locale.ENGLISH, "%10d\t", count.get()); min = Math.min(min, count.get()); max = Math.max(max, count.get()); } System.out.printf(Locale.ENGLISH, "%7.2f\t%5.0f%n", (double) min / (double) max, (double) t / KEY_COUNT); }
From source file:com.nesscomputing.service.discovery.job.ZookeeperProcessingTask.java
protected long determineCurrentGeneration(final AtomicLong generation, final long tick) { return generation.get(); }
From source file:org.mule.module.pgp.EncryptStreamTransformer.java
/** * {@inheritDoc}/* w w w . j av a2s.co m*/ */ @Override public boolean write(OutputStream out, AtomicLong bytesRequested) throws Exception { int len = 0; byte[] buf = new byte[1 << 16]; boolean wroteSomething = false; while (bytesRequested.get() + offset > bytesWrote && (len = this.toBeEncrypted.read(buf)) > 0) { pgpOutputStream.write(buf, 0, len); bytesWrote = bytesWrote + len; wroteSomething = true; } if (wroteSomething && len <= 0) { pgpOutputStream.close(); compressedEncryptedOutputStream.close(); encryptedOutputStream.close(); armoredOut.close(); toBeEncrypted.close(); return true; } return false; }