@Override public Long[] nextRange(int size) { Long[] result = new Long[size]; long current = idGen.getAndAdd(size); for (int i=1; i <= size; i++) { result[i] = current + 1; } return result; }
private void getAndAdd(Exchange exchange) { long delta = exchange.getIn().getBody(Long.class); exchange.getOut().setBody(this.atomicnumber.getAndAdd(delta)); }
public static int obtainNewServerId() { /* currently does not reuse the server Id value while any server is up. This can be changed if needed. However, we currently depend on the first server getting the IAtomicLong 0 to know that it is the first member to appear. By reusing numbers with the cluster alive, we either don't reuse 0 or change the algorithm that detects the first member */ IAtomicLong serverIdGenerator = getHazelcastInstance().getAtomicLong("serverId"); long longId = serverIdGenerator.getAndAdd(1L); logger.info("Got (long) serverId: {}", longId); int intId = (int) longId; if (intId != longId) { throw new Error("Failed to obtain a valid id"); } return intId; }
public static int obtainNewServerId() { /* currently does not reuse the server Id value while any server is up. This can be changed if needed. However, we currently depend on the first server getting the AtomicNumber 0 to know that it is the first member to appear. By reusing numbers with the cluster alive, we either don't reuse 0 or change the algorithm that detects the first member */ IAtomicLong serverIdGenerator = getHazelcastInstance().getAtomicLong("serverId"); long longId = serverIdGenerator.getAndAdd(1L); logger.info("Got (long) serverId: {}", longId); int intId = (int) longId; if (intId != longId) { throw new Error("Failed to obtain a valid id"); } return intId; }
@ManagedAnnotation(value = "getAndAdd", operation = true) @ManagedDescription("get the current value then add") public long getAndAdd(long delta) { return managedObject.getAndAdd(delta); }
@ManagedAnnotation(value = "getAndAdd", operation = true) @ManagedDescription("get the current value then add") public long getAndAdd(long delta) { return managedObject.getAndAdd(delta); }