You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@curator.apache.org by Sznajder ForMailingList <bs...@gmail.com> on 2014/01/09 15:50:22 UTC

Usage of semaphore

Hi

I need to allow the access to a shared resource only MAX_CON times.

It sounds natural to use the semaphore for that.

However, something is not clear to me in the API.

What is the difference between the two constructors:

public InterProcessSemaphoreV2(CuratorFramework
<http://curator.apache.org/apidocs/org/apache/curator/framework/CuratorFramework.html>
client,
                       String
<http://docs.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true>
path,
                       int maxLeases)

public InterProcessSemaphoreV2(CuratorFramework
<http://curator.apache.org/apidocs/org/apache/curator/framework/CuratorFramework.html>
client,
                       String
<http://docs.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true>
path,
                       SharedCountReader
<http://curator.apache.org/apidocs/org/apache/curator/framework/recipes/shared/SharedCountReader.html>
count)



And especially, with the second constructor signature, how do I define
the maxLeases value? How can I limit the access to be only MAX_CONN?

Many thanks

Benjamin

Re: Usage of semaphore

Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
Here’s a portion of the JavaDoc for the class:

There are two modes for determining the max leases for the semaphore. In the first mode the max leases is a convention maintained by the users of a given path. In the second mode a SharedCountReader is used as the method for semaphores of a given path to determine the max leases.

If a SharedCountReader is not used, no internal checks are done to prevent Process A acting as if there are 10 leases and Process B acting as if there are 20. Therefore, make sure that all instances in all processes use the same numberOfLeases value.

-JZ

From: Sznajder ForMailingList Sznajder ForMailingList
Reply: user@curator.apache.org user@curator.apache.org
Date: January 9, 2014 at 9:51:36 AM
To: user@curator.incubator.apache.org user@curator.incubator.apache.org
Subject:  Usage of semaphore  
Hi

I need to allow the access to a shared resource only MAX_CON times.

It sounds natural to use the semaphore for that.

However, something is not clear to me in the API.

What is the difference between the two constructors:

public InterProcessSemaphoreV2(CuratorFramework client,
                       String path,
                       int maxLeases)

public InterProcessSemaphoreV2(CuratorFramework client,
                       String path,
                       SharedCountReader count)





And especially, with the second constructor signature, how do I define the maxLeases value? How can I limit the access to be only MAX_CONN?

Many thanks

Benjamin