You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2020/04/23 20:02:37 UTC
[helix] 02/20: Created Helix distributed lock interface (#703)
This is an automated email from the ASF dual-hosted git repository.
jxue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
commit 20eda99c4dd379335fa7c800474c1bcd5e1b742c
Author: mgao0 <31...@users.noreply.github.com>
AuthorDate: Thu Jan 30 13:39:16 2020 -0800
Created Helix distributed lock interface (#703)
Added LockInfo interfaces.
---
.../main/java/org/apache/helix/lock/HelixLock.java | 53 ++++++++++++++++++++++
.../main/java/org/apache/helix/lock/LockInfo.java | 46 +++++++++++++++++++
2 files changed, 99 insertions(+)
diff --git a/helix-lock/src/main/java/org/apache/helix/lock/HelixLock.java b/helix-lock/src/main/java/org/apache/helix/lock/HelixLock.java
new file mode 100644
index 0000000..01ef63b
--- /dev/null
+++ b/helix-lock/src/main/java/org/apache/helix/lock/HelixLock.java
@@ -0,0 +1,53 @@
+package org.apache.helix.lock;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Generic interface for Helix distributed lock
+ */
+public interface HelixLock<T> {
+ /**
+ * Blocking call to acquire a lock
+ * @return true if the lock was successfully acquired,
+ * false if the lock could not be acquired
+ */
+ boolean acquireLock();
+
+ /**
+ * Blocking call to release a lock
+ * @return true if the lock was successfully released,
+ * false if the locked is not locked or is not locked by the user,
+ * or the lock could not be released
+ */
+ boolean releaseLock();
+
+ /**
+ * Retrieve the lock information, e.g. lock timeout, lock message, etc.
+ * @return lock metadata information
+ */
+ LockInfo<T> getLockInfo();
+
+ /**
+ * If the user is current lock owner
+ * @return true if the user is the lock owner,
+ * false if the user is not the lock owner or the lock doesn't have a owner
+ */
+ boolean isOwner();
+}
diff --git a/helix-lock/src/main/java/org/apache/helix/lock/LockInfo.java b/helix-lock/src/main/java/org/apache/helix/lock/LockInfo.java
new file mode 100644
index 0000000..30322bb
--- /dev/null
+++ b/helix-lock/src/main/java/org/apache/helix/lock/LockInfo.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.helix.lock;
+
+import java.util.Map;
+
+
+/**
+ * Generic interface for a map contains the Helix lock information
+ * @param <T> The type of the LockInfo value
+ */
+public interface LockInfo<T> {
+
+ //TODO: add specific setter and getter for any field that is determined to be universal for all implementations of HelixLock
+
+ /**
+ * Create a single filed of LockInfo, or update the value of the field if it already exists
+ * @param infoKey the key of the LockInfo field
+ * @param infoValue the value of the LockInfo field
+ */
+ void setInfoValue(String infoKey, T infoValue);
+
+ /**
+ * Get the value of a field in LockInfo
+ * @param infoKey the key of the LockInfo field
+ * @return the value of the field or null if this key does not exist
+ */
+ T getInfoValue(String infoKey);
+}