Search in sources :

Example 1 with CuratorLocksClient

use of com.bonree.brfs.common.zookeeper.curator.locking.CuratorLocksClient in project BRFS by zhangnianli.

the class StorageSequenceGenetor method getIncreSequence.

public Integer getIncreSequence() {
    int sequence = 0;
    CuratorClient client = null;
    try {
        client = CuratorClient.getClientInstance(zkUrl);
        String node = basePath + SEPARATOR + STORAGE_INDEX_NODE;
        ZKIncreSequence genExecutor = new ZKIncreSequence(node);
        CuratorLocksClient<Integer> lockClient = new CuratorLocksClient<Integer>(client, basePath + SEPARATOR + LOCKS_PATH, genExecutor, "genSingleIdentification");
        sequence = lockClient.execute();
    } catch (Exception e) {
        LOG.error("getSingleIdentification error!", e);
    } finally {
        if (client != null) {
            client.close();
        }
    }
    return sequence;
}
Also used : CuratorLocksClient(com.bonree.brfs.common.zookeeper.curator.locking.CuratorLocksClient) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient)

Example 2 with CuratorLocksClient

use of com.bonree.brfs.common.zookeeper.curator.locking.CuratorLocksClient in project BRFS by zhangnianli.

the class LockTest method main.

public static void main(String[] args) throws InterruptedException {
    ExecutorService threads = Executors.newFixedThreadPool(10);
    final String lockPath = "/brfs/wz/locks";
    for (int i = 0; i < 10; i++) {
        threads.execute(new Runnable() {

            @Override
            public void run() {
                CuratorClient client = CuratorClient.getClientInstance("192.168.101.86:2181");
                CuratorLocksClient<String> lockClient = new CuratorLocksClient<String>(client, lockPath, new MyExecutor(), "testLock");
                try {
                    lockClient.execute(10, TimeUnit.SECONDS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                client.close();
            }
        });
    }
    threads.shutdown();
    threads.awaitTermination(10, TimeUnit.MINUTES);
}
Also used : CuratorLocksClient(com.bonree.brfs.common.zookeeper.curator.locking.CuratorLocksClient) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

CuratorLocksClient (com.bonree.brfs.common.zookeeper.curator.locking.CuratorLocksClient)2 CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)1 ExecutorService (java.util.concurrent.ExecutorService)1