Package com.alibaba.otter.shared.arbitrate.impl.zookeeper.lock

Examples of com.alibaba.otter.shared.arbitrate.impl.zookeeper.lock.DistributedLock


    protected ZkClientx              zookeeper = ZooKeeperClient.getInstance();
    protected ArbitrateManageService arbitrateManageService;
    protected NormalTerminProcess    normalTerminProcess;

    public boolean process(TerminEventData data) {
        DistributedLock lock = new DistributedLock(StagePathUtils.getLoadLock(data.getPipelineId()));
        try {
            boolean locked = lock.tryLock();// 尝试进行锁定,等待当前的load操作完成
            if (!locked) {
                return false;
            }
            processChain(data);
            return true;
        } catch (KeeperException e) {
            throw new ArbitrateException("Termin_process", e);
        } finally {
            try {
                lock.unlock();// 马上进行释放
            } catch (KeeperException e1) {
                // ignore
            }
        }
    }
View Full Code Here


        ExecutorService exeucotr = Executors.newCachedThreadPool();
        final int count = 50;
        final CountDownLatch latch = new CountDownLatch(count);
        final DistributedLock[] nodes = new DistributedLock[count];
        for (int i = 0; i < count; i++) {
            final DistributedLock node = new DistributedLock(dir);
            nodes[i] = node;
            exeucotr.submit(new Runnable() {

                public void run() {
                    try {
                        node.lock();
                        Thread.sleep(100 + RandomUtils.nextInt(100));
                        System.out.println("id: " + node.getId() + " is leader: " + node.isOwner());
                    } catch (InterruptedException e) {
                        want.fail();
                    } catch (KeeperException e) {
                        want.fail();
                    } finally {
                        latch.countDown();
                        try {
                            node.unlock();
                        } catch (KeeperException e) {
                            want.fail();
                        }
                    }
View Full Code Here

        final int count = 50;
        final CountDownLatch latch = new CountDownLatch(count);

        final DistributedLock[] nodes = new DistributedLock[count];
        for (int i = 0; i < count; i++) {
            final DistributedLock node = new DistributedLock(dir);
            nodes[i] = node;
            exeucotr.submit(new Runnable() {

                public void run() {
                    try {
                        while (node.tryLock() == false) {
                            Thread.sleep(100 + RandomUtils.nextInt(100));
                        }

                        System.out.println("id: " + node.getId() + " is leader: " + node.isOwner());
                    } catch (InterruptedException e) {
                        want.fail();
                    } catch (KeeperException e) {
                        want.fail();
                    } finally {
                        latch.countDown();
                        try {
                            node.unlock();
                        } catch (KeeperException e) {
                            want.fail();
                        }
                    }
View Full Code Here

TOP

Related Classes of com.alibaba.otter.shared.arbitrate.impl.zookeeper.lock.DistributedLock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.