Marcosrico commented on code in PR #2515:
URL: https://github.com/apache/helix/pull/2515#discussion_r1230309014


##########
meta-client/src/main/java/org/apache/helix/metaclient/recipes/lock/DistributedSemaphore.java:
##########
@@ -50,23 +80,51 @@ public DistributedSemaphore(MetaClientInterface<DataRecord> 
client) {
    * @param capacity capacity of the semaphore
    */
   public void createSemaphore(String path, int capacity) {
-    throw new NotImplementedException("Not implemented yet.");
+    if (capacity <= 0) {
+      throw new MetaClientException("Capacity must be positive");
+    }
+    if (path == null || path.isEmpty()) {
+      throw new MetaClientException("Invalid path to create semaphore");
+    }
+    if (_metaClient.exists(path) != null) {
+      throw new MetaClientException("Semaphore already exists");
+    }
+    _path = path;
+    if (_metaClient.exists(path) == null) {
+      DataRecord dataRecord = new DataRecord(path);
+      dataRecord.setLongField(INITIAL_CAPACITY_NAME, capacity);
+      dataRecord.setLongField(REMAINING_CAPACITY_NAME, capacity);
+      _metaClient.create(path, dataRecord);
+    }
   }
 
   /**
    * Connect to an existing distributed semaphore.
    * @param path path of the semaphore
    */
   public void connectSemaphore(String path) {
-    throw new NotImplementedException("Not implemented yet.");
+    if (path == null || path.isEmpty()) {
+      throw new MetaClientException("Invalid path to connect semaphore");
+    }
+    if (_metaClient.exists(path) == null) {
+      throw new MetaClientException("Semaphore does not exist");
+    }
+    _path = path;
   }
 
   /**
    * Acquire a permit. If no permit is available, log error and return null.
    * @return a permit
    */
   public Permit acquire() {
-    throw new NotImplementedException("Not implemented yet.");
+    int count = 1;

Review Comment:
   Okay thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to