Package com.hazelcast.core

Examples of com.hazelcast.core.ILock


    public void memberRemoved(MembershipEvent event) {
        try {
            String memberAddr = event.getMember().getInetSocketAddress().toString();
            if (endpointOwners.containsKey(memberAddr)) {
                synchronized (shutdownMutex) {
                    ILock lock = hazelcastInstance.getLock("EndpointOwners/" + memberAddr);
                    lock.lock();
                    try {
                        if (endpointOwners.containsKey(memberAddr)) {
                            Collection<String> keys = endpointOwners.remove(memberAddr);
                            for (Object k : keys) {
                                Endpoint endpoint = (Endpoint)endpointMap.remove(k);
                                runningComponentContributions.remove(endpoint.getComponent().getName());
                            }
                        }
                        if (runningCompositeOwners.containsKey(memberAddr)) {
                            Map<String, List<String>> cs = runningCompositeOwners.remove(memberAddr);
                            for (String curi : cs.keySet()) {
                                Map<String, String> rcs = runningComposites.get(curi);
                                for (String uri : cs.get(curi)) {
                                    rcs.remove(uri);
                                }
                            }
                        }
                    } finally {
                        lock.unlock();
                    }
                }
            }
        } catch (Exception e) {
            if (e.getCause() != null && e.getCause().getCause() != null) {
View Full Code Here


    public void memberRemoved(MembershipEvent event) {
        try {
            String memberAddr = event.getMember().getInetSocketAddress().toString();
            if (endpointOwners.containsKey(memberAddr)) {
                synchronized (shutdownMutex) {
                    ILock lock = hazelcastInstance.getLock("EndpointOwners/" + memberAddr);
                    lock.lock();
                    try {
                        if (endpointOwners.containsKey(memberAddr)) {
                            Collection<String> keys = endpointOwners.remove(memberAddr);
                            for (Object k : keys) {
                                endpointMap.remove(k);
                            }
                        }
                    } finally {
                        lock.unlock();
                    }
                }
            }
        } catch (Exception e) {
            if (e.getCause() != null && e.getCause().getCause() != null) {
View Full Code Here

    public void memberRemoved(MembershipEvent event) {
        try {
            String memberAddr = event.getMember().getInetSocketAddress().toString();
            if (endpointOwners.containsKey(memberAddr)) {
                synchronized (shutdownMutex) {
                    ILock lock = hazelcastInstance.getLock("EndpointOwners/" + memberAddr);
                    lock.lock();
                    try {
                        if (endpointOwners.containsKey(memberAddr)) {
                            Collection<String> keys = endpointOwners.remove(memberAddr);
                            for (Object k : keys) {
                                Endpoint endpoint = (Endpoint)endpointMap.remove(k);
                                runningComponentContributions.remove(endpoint.getComponent().getName());
                            }
                        }
                        if (runningCompositeOwners.containsKey(memberAddr)) {
                            Map<String, List<String>> cs = runningCompositeOwners.remove(memberAddr);
                            for (String curi : cs.keySet()) {
                                Map<String, String> rcs = runningComposites.get(curi);
                                for (String uri : cs.get(curi)) {
                                    rcs.remove(uri);
                                }
                            }
                        }
                    } finally {
                        lock.unlock();
                    }
                }
            }
        } catch (Exception e) {
            if (e.getCause() != null && e.getCause().getCause() != null) {
View Full Code Here

    @Override
    public void run()
    {
      logger.info(threadName+"   ---   Acquiring lock ...");
      ILock lock = Hazelcast.getLock(lockName);
      lock.unlock();
      lock.lock();
      lock.lock();
      logger.info(threadName+"   ---   Acquired lock.");
      logger.info(threadName+"   ---   Waiting: "+waitTime);
      try
      {
        Thread.sleep(waitTime);
      }
      catch (InterruptedException ex)
      {
        Logger.getLogger(TestHazelcastLocks.class.getName()).log(Level.SEVERE, null, ex);
      }
      logger.info(threadName+"   ---   Wait done.");
      logger.info(threadName+"   ---   Releasing lock ...");
      ILock lock2 = Hazelcast.getLock(lockName);
      lock2.unlock();
      lock.unlock();
      logger.info(threadName+"   ---   Unlocked");
    }
View Full Code Here

    public void memberRemoved(MembershipEvent event) {
        try {
            String memberAddr = event.getMember().getInetSocketAddress().toString();
            if (endpointOwners.containsKey(memberAddr)) {
                synchronized (shutdownMutex) {
                    ILock lock = hazelcastInstance.getLock("EndpointOwners/" + memberAddr);
                    lock.lock();
                    try {
                        if (endpointOwners.containsKey(memberAddr)) {
                            Collection<String> keys = endpointOwners.remove(memberAddr);
                            for (Object k : keys) {
                                endpointMap.remove(k);
                            }
                        }
                    } finally {
                        lock.unlock();
                    }
                }
            }
        } catch (Exception e) {
            if (e.getCause() != null && e.getCause().getCause() != null) {
View Full Code Here

    public void memberRemoved(MembershipEvent event) {
        try {
            String memberAddr = event.getMember().getInetSocketAddress().toString();
            if (endpointOwners.containsKey(memberAddr)) {
                synchronized (shutdownMutex) {
                    ILock lock = hazelcastInstance.getLock("EndpointOwners/" + memberAddr);
                    lock.lock();
                    try {
                        if (endpointOwners.containsKey(memberAddr)) {
                            Collection<String> keys = endpointOwners.remove(memberAddr);
                            for (Object k : keys) {
                                endpointMap.remove(k);
                            }
                        }
                    } finally {
                        lock.unlock();
                    }
                }
            }
        } catch (Exception e) {
            if (e.getCause() != null && e.getCause().getCause() != null) {
View Full Code Here

    // ========================= lease time ==============================================

    @Test(expected = NullPointerException.class, timeout = 60000)
    public void testLockLeaseTime_whenNullTimeout() {
        final HazelcastInstance instance = createHazelcastInstance();
        final ILock lock = instance.getLock(randomString());

        lock.lock(1000, null);
    }
View Full Code Here

    }

    @Test(timeout = 60000)
    public void testLockLeaseTime_whenLockFree() {
        final HazelcastInstance instance = createHazelcastInstance();
        final ILock lock = instance.getLock(randomString());

        lock.lock(1000, TimeUnit.MILLISECONDS);
    }
View Full Code Here

    }

    @Test(timeout = 60000)
    public void testLockLeaseTime_whenLockAcquiredByOther() throws InterruptedException {
        final HazelcastInstance instance = createHazelcastInstance();
        final ILock lock = instance.getLock(randomString());

        final CountDownLatch latch0 = new CountDownLatch(1);
        final CountDownLatch latch = new CountDownLatch(1);

        new Thread() {
            public void run() {
                lock.lock();
                latch0.countDown();
                sleepMillis(500);
                lock.unlock();
            }
        }.start();

        latch0.await();

        lock.lock(1000, TimeUnit.MILLISECONDS);

        assertTrue(lock.isLocked());
        sleepSeconds(2);
        assertFalse(lock.isLocked());
    }
View Full Code Here

    }

    @Test(timeout = 60000)
    public void testLockLeaseTime_lockIsReleasedEventually() throws InterruptedException {
        HazelcastInstance instance = createHazelcastInstance();
        final ILock lock = instance.getLock(randomString());

        lock.lock(1000, TimeUnit.MILLISECONDS);
        assertTrue(lock.isLocked());

        lock.lock();
        assertTrue(lock.isLocked());
    }
View Full Code Here

TOP

Related Classes of com.hazelcast.core.ILock

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.