All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.oliverwetterau.neo4j.websockets.client.helpers.ConcurrentSequence Maven / Gradle / Ivy

Go to download

This framework allows to connect clients with embedded Neo4j servers through websockets. Furthermore it offers high availability and load balancing to the clients when using Neo4j in a cluster.

The newest version!
package de.oliverwetterau.neo4j.websockets.client.helpers;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;

/**
 * Created by oliver on 26.08.15.
 */
public class ConcurrentSequence {
    protected final AtomicInteger value = new AtomicInteger(0);

    public int incrementAndGet(final int maximumValue) {
        for (;;) {
            int current = value.get();
            int next = current + 1;
            if (next >= maximumValue) next = 0;
            if (compareAndSet(current, next))
                return next;
        }
    }

    protected boolean compareAndSet(final int current, final int next) {
        if (value.compareAndSet(current, next)) {
            return true;
        } else {
            LockSupport.parkNanos(1);
            return false;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy