-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add read/write locks to client/api
Signed-off-by: Todd Baert <[email protected]>
- Loading branch information
Showing
4 changed files
with
88 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/dev/openfeature/sdk/internal/AutoCloseableLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package dev.openfeature.sdk.internal; | ||
|
||
public interface AutoCloseableLock extends AutoCloseable { | ||
|
||
/** | ||
* Override the exception in AutoClosable. | ||
*/ | ||
@Override | ||
void close(); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/dev/openfeature/sdk/internal/AutoCloseableReentrantReadWriteLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.openfeature.sdk.internal; | ||
|
||
import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
|
||
/** | ||
* A utility class that wraps a multi-read/single-write lock construct as AutoCloseable, so it can | ||
* be used in a try-with-resources. | ||
*/ | ||
public class AutoCloseableReentrantReadWriteLock extends ReentrantReadWriteLock { | ||
|
||
/** | ||
* Get the single write lock as an AutoCloseableLock. | ||
* @return unlock method ref | ||
*/ | ||
public AutoCloseableLock writeLockAutoCloseable() { | ||
this.writeLock().lock(); | ||
return this.writeLock()::unlock; | ||
} | ||
|
||
/** | ||
* Get the multi read lock as an AutoCloseableLock. | ||
* @return unlock method ref | ||
*/ | ||
public AutoCloseableLock readLockAutoCloseable() { | ||
this.readLock().lock(); | ||
return this.readLock()::unlock; | ||
} | ||
} |