Examples of DistributedLock


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

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

        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

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

        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

Examples of com.deftlabs.lock.mongo.DistributedLock

        @Override
        public void run() {
            while (_running) {
                try {
                    for (final String lockName : _locks.keySet()) {
                        final DistributedLock lock = _locks.get(lockName);

                        final ObjectId lockId = lock.getLockId();

                        if (!lock.isLocked() || lockId == null) continue;

                        LockDao.heartbeat(_mongo, lockName, lockId, lock.getOptions(), _svcOptions);
                    }

                    Thread.sleep(HEARTBEAT_FREQUENCY);
                } catch (final InterruptedException ie) { break;
                } catch (final Throwable t) {
View Full Code Here

Examples of com.deftlabs.lock.mongo.DistributedLock

        @Override
        public void run() {
            while (_running) {
                try {
                    for (final String lockName : _locks.keySet()) {
                        final DistributedLock lock = _locks.get(lockName);

                        if (lock.isLocked()) continue;

                        // Check to see if this is locked.
                        if (LockDao.isLocked(_mongo, lockName, _svcOptions)) continue;

                        // The lock is not locked, wakeup any blocking threads.
                        lock.wakeupBlocked();
                    }

                    Thread.sleep(FREQUENCY);
                } catch (final InterruptedException ie) { break;
                } catch (final Throwable t) {
View Full Code Here

Examples of com.deftlabs.lock.mongo.DistributedLock

        try {
            _lock.lock();

            // Interrupt the locks.
            for (final String lockName : _locks.keySet()) {
                final DistributedLock lock = _locks.get(lockName);
                if (lock == null) continue;

                ((LockImpl)lock).destroy();
            }
View Full Code Here

Examples of com.deftlabs.lock.mongo.DistributedLock

    static class LockHeartbeat implements Runnable {
        @Override public void run() {
            while (_running) {
                try {
                    for (final String lockName : _locks.keySet()) {
                        final DistributedLock lock = _locks.get(lockName);

                        final ObjectId lockId = lock.getLockId();

                        if (!lock.isLocked() || lockId == null) continue;

                        LockDao.heartbeat(_mongo, lockName, lockId, lock.getOptions(), _svcOptions);
                    }

                    Thread.sleep(HEARTBEAT_FREQUENCY);

                } catch (final InterruptedException ie) { break;
View Full Code Here

Examples of com.deftlabs.lock.mongo.DistributedLock

    static class LockUnlocked implements Runnable {
        @Override public void run() {
            while (_running) {
                try {
                    for (final String lockName : _locks.keySet()) {
                        final DistributedLock lock = _locks.get(lockName);

                        if (lock.isLocked()) continue;

                        // Check to see if this is locked.
                        if (LockDao.isLocked(_mongo, lockName, _svcOptions)) continue;

                        // The lock is not locked, wakeup any blocking threads.
                        lock.wakeupBlocked();
                    }

                    Thread.sleep(FREQUENCY);
                } catch (final InterruptedException ie) { break;
                } catch (final Throwable t) { LOG.log(Level.SEVERE, t.getMessage(), t); }
View Full Code Here

Examples of com.deftlabs.lock.mongo.DistributedLock

        try {
            _lock.lock();

            // Interrupt the locks.
            for (final String lockName : _locks.keySet()) {
                final DistributedLock lock = _locks.get(lockName);
                if (lock == null) continue;

                ((LockImpl)lock).destroy();
            }
View Full Code Here

Examples of com.deftlabs.lock.mongo.DistributedLock

        @Override
        public void run() {
            while (_running) {
                try {
                    for (final String lockName : _locks.keySet()) {
                        final DistributedLock lock = _locks.get(lockName);

                        final ObjectId lockId = lock.getLockId();

                        if (!lock.isLocked() || lockId == null) continue;

                        LockDao.heartbeat(_mongo, lockName, lockId, lock.getOptions(), _svcOptions);
                    }

                    Thread.sleep(HEARTBEAT_FREQUENCY);
                } catch (final InterruptedException ie) { break;
                } catch (final Throwable t) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.