curator-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sznajder ForMailingList <bs4mailingl...@gmail.com>
Subject Error thrown using the InterprocessSemaphoreV2#getParticipantsNodes()
Date Thu, 09 Jan 2014 16:06:00 GMT
Hi

When calling the method getParticipantsNodes() from
InterprocessSemaphoreV2, we systematically get a
org.apache.zookeeper.KeeperException$NoNodeException

I created a simple test for showing that..

Benjamin






package counter.semaphore;

import java.util.Collection;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.locks.InterProcessSemaphoreV2;
import org.apache.curator.framework.recipes.locks.Lease;
import org.apache.curator.test.TestingServer;

import com.ibm.hrl.crawler.Utils;

public class SemaphoreErrorTest {
    private static final String PATH = "/semaphore_test_path";

    public static void main(String[] args) {
        TestingServer server;
        try {
            server = new TestingServer();
            String connectString = server.getConnectString();

            final CuratorFramework framework =
Utils.newFramework(connectString);
            framework.start();

            // We create a semaphore:
            InterProcessSemaphoreV2 semaphore = new
InterProcessSemaphoreV2(framework, PATH, 2);

            // We acquire the semaphore
            Lease lease = null;
            try {
                lease = semaphore.acquire();

                try {
                    Collection<String> participantNodes =
semaphore.getParticipantNodes();
                    System.out.println("There are " + participantNodes ==
null ? 0 : participantNodes.size() + " participant nodes");
                } catch (Exception e) {
                    System.err.println("!! - Error! I got the following
exception " + e);
                }

            } finally {
                if (lease != null) {
                    semaphore.returnLease(lease);
                }
            }


            framework.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Mime
View raw message