List of usage examples for java.util.concurrent.atomic AtomicLong get
public final long get()
From source file:org.structr.core.graph.NodeServiceCommand.java
/** * Executes the given transaction until the stop condition evaluates to * <b>true</b>./*from www. j ava2 s . c o m*/ * * @param securityContext * @param commitCount the number of executions after which the transaction is committed * @param transaction the operation to execute * @param stopCondition * @throws FrameworkException */ public static void bulkTransaction(final SecurityContext securityContext, final long commitCount, final StructrTransaction transaction, final Predicate<Long> stopCondition) throws FrameworkException { final App app = StructrApp.getInstance(securityContext); final AtomicLong objectCount = new AtomicLong(0L); while (!stopCondition.evaluate(securityContext, objectCount.get())) { try (final Tx tx = app.tx()) { long loopCount = 0; while (loopCount++ < commitCount && !stopCondition.evaluate(securityContext, objectCount.get())) { transaction.execute(); objectCount.incrementAndGet(); } tx.success(); } } }
From source file:org.apache.eagle.alert.engine.e2e.SampleClient2.java
private static Pair<Long, String> createFailureEntity(AtomicLong base, int hostIndex) { // TODO: add randomization IfEntity ie = new IfEntity(); ie.host = "boot-vm-0-" + hostIndex + ".datacenter.corp.com"; ie.instanceUuid = nextUuid;//from w w w .ja v a2 s .c o m ie.message = "boot failure for when try start the given vm!"; ie.reqId = nextReqId; ie.timestamp = base.get(); base.addAndGet(2000);// simply some interval. return Pair.of(base.get(), JsonUtils.writeValueAsString(ie)); }
From source file:org.springframework.http.server.reactive.AbstractRequestBodyPublisher.java
/** * Concurrent substraction bound to 0 and Long.MAX_VALUE. * Any concurrent write will "happen" before this operation. * * @param sequence current atomic to update * @param toSub delta to sub//w ww . ja v a 2 s. c om * @return value before subscription, 0 or Long.MAX_VALUE */ private static long getAndSub(AtomicLong sequence, long toSub) { long r; long u; do { r = sequence.get(); if (r == 0 || r == Long.MAX_VALUE) { return r; } u = Operators.subOrZero(r, toSub); } while (!sequence.compareAndSet(r, u)); return r; }
From source file:com.icloud.framework.core.util.FBUtilities.java
public static void atomicSetMax(AtomicLong atomic, long i) { while (true) { long j = atomic.get(); if (j >= i || atomic.compareAndSet(j, i)) break; }/*from w w w .ja v a 2 s . c om*/ }
From source file:eu.eubrazilcc.lvl.service.rest.TaskResource.java
private static Runnable checkTaskProgress(final EventOutput eventOutput, final AtomicLong eventId, final CancellableTask<?> task) { return new Runnable() { @Override/*w w w. ja va 2 s. c o m*/ public void run() { try { eventOutput .write(new OutboundEvent.Builder().name(PROGRESS_EVENT).id(Long.toString(eventId.get())) .data(String.class, JSON_MAPPER.writeValueAsString(Progress.builder().done(task.isDone()) .progress(task.getProgress()).status(task.getStatus()) .hasErrors(task.hasErrors()).build())) .build()); } catch (IOException e) { throw new RuntimeException("Error when writing the event", e); } } }; }
From source file:com.alibaba.rocketmq.common.MixAll.java
public static boolean compareAndIncreaseOnly(final AtomicLong target, final long value) { long prev = target.get(); while (value > prev) { boolean updated = target.compareAndSet(prev, value); if (updated) return true; prev = target.get();//from w w w .j a va 2s. com } return false; }
From source file:com.nextdoor.bender.handler.BaseHandler.java
private static void updateOldest(AtomicLong max, long time) { while (true) { long curMax = max.get(); /*//from ww w . j a va 2 s . c o m * With time smaller value is older */ if (curMax <= time) { return; } if (max.compareAndSet(curMax, time)) { return; } } }
From source file:ubicrypt.core.Utils.java
private static void read(final AtomicLong pos, final ByteBuffer buffer, final AsynchronousFileChannel channel, final Subscriber<? super byte[]> subscriber) { channel.read(buffer, pos.get(), pos, new CompletionHandler<Integer, AtomicLong>() { @Override/*from ww w . ja va 2 s.c o m*/ public void completed(final Integer result, final AtomicLong attachment) { if (result == -1) { subscriber.onCompleted(); return; } subscriber.onNext(buffer.array()); if (result < 1 << 16) { subscriber.onCompleted(); return; } pos.addAndGet(result); read(pos, ByteBuffer.allocate(1 << 16), channel, subscriber); } @Override public void failed(final Throwable exc, final AtomicLong attachment) { subscriber.onError(exc); } }); }
From source file:org.apache.eagle.alert.engine.e2e.SampleClient2.java
private static Pair<Long, String> createLogEntity(AtomicLong base1, int hostIndex) { // TODO: add randomization LogEntity le = new LogEntity(); if (hostIndex < 3) { le.component = "NOVA"; le.host = "nova.000-" + hostIndex + ".datacenter.corp.com"; le.message = "RabbitMQ Exception - MQ not connectable!"; } else {/*from ww w . j a va 2 s .c o m*/ le.component = "NEUTRON"; le.host = "neturon.000-" + (hostIndex - 3) + ".datacenter.corp.com"; le.message = "DNS Exception - Fail to connect to DNS!"; } le.instanceUuid = nextUuid; le.logLevel = "ERROR"; le.reqId = nextReqId; le.timestamp = base1.get(); base1.addAndGet(1000);// simply some interval. return Pair.of(base1.get(), JsonUtils.writeValueAsString(le)); }
From source file:net.dv8tion.jda.core.utils.PermissionUtil.java
/** * Gets the {@code long} representation of the effective permissions allowed for this {@link net.dv8tion.jda.core.entities.Member Member} * in this {@link net.dv8tion.jda.core.entities.Channel Channel}. This can be used in conjunction with * {@link net.dv8tion.jda.core.Permission#getPermissions(long) Permission.getPermissions(long)} to easily get a list of all * {@link net.dv8tion.jda.core.Permission Permissions} that this member can use in this {@link net.dv8tion.jda.core.entities.Channel Channel}. * <br>This functions very similarly to how {@link net.dv8tion.jda.core.entities.Role#getPermissionsRaw() Role.getPermissionsRaw()}. * * @param channel/*www.j a v a 2 s . c o m*/ * The {@link net.dv8tion.jda.core.entities.Channel Channel} being checked. * @param member * The {@link net.dv8tion.jda.core.entities.Member Member} whose permissions are being checked. * * @throws IllegalArgumentException * if any of the provided parameters is {@code null} * or the provided entities are not from the same guild * * @return The {@code long} representation of the effective permissions that this {@link net.dv8tion.jda.core.entities.Member Member} * has in this {@link net.dv8tion.jda.core.entities.Channel Channel}. */ public static long getEffectivePermission(Channel channel, Member member) { Checks.notNull(channel, "Channel"); Checks.notNull(member, "Member"); Checks.check(channel.getGuild().equals(member.getGuild()), "Provided channel and provided member are not of the same guild!"); if (member.isOwner()) { // Owner effectively has all permissions return Permission.ALL_PERMISSIONS; } long permission = getEffectivePermission(member); final long admin = Permission.ADMINISTRATOR.getRawValue(); if (isApplied(permission, admin)) return Permission.ALL_PERMISSIONS; AtomicLong allow = new AtomicLong(0); AtomicLong deny = new AtomicLong(0); getExplicitOverrides(channel, member, allow, deny); permission = apply(permission, allow.get(), deny.get()); final long viewChannel = Permission.VIEW_CHANNEL.getRawValue(); //When the permission to view the channel is not applied it is not granted // This means that we have no access to this channel at all return isApplied(permission, viewChannel) ? permission : 0; /* // currently discord doesn't implicitly grant permissions that the user can grant others // so instead the user has to explicitly make an override to grant them the permission in order to be granted that permission // yes this makes no sense but what can i do, the devs don't like changing things apparently... // I've been told half a year ago this would be changed but nothing happens // so instead I'll just bend over for them so people get "correct" permission checks... // // only time will tell if something happens and I can finally re-implement this section wew final long managePerms = Permission.MANAGE_PERMISSIONS.getRawValue(); final long manageChannel = Permission.MANAGE_CHANNEL.getRawValue(); if ((permission & (managePerms | manageChannel)) != 0) { // In channels, MANAGE_CHANNEL and MANAGE_PERMISSIONS grant full text/voice permissions permission |= Permission.ALL_TEXT_PERMISSIONS | Permission.ALL_VOICE_PERMISSIONS; } */ }