forked from spring-projects/spring-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spring-projectsGH-3444: Add Custom TTL support for RedisLock, and Jdb…
…cLock Fixes: spring-projects#3444 * Add `CustomTtlLock`, and `CustomTtlLockRegistry` interfaces * Modify `RedisLockRegistry` to implement the interfaces. * Modify ddl of `INT_LOCK` table, `LockRepository`, `DefaultLockRepository`, and `JdbcLockRegistry` to implement the interfaces. * Fix potential concurrency issue of `unlock` method of `JdbcLock`. * Maintain existing test cases and add new test cases.
- Loading branch information
1 parent
4108ea5
commit e82814b
Showing
22 changed files
with
413 additions
and
167 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...ation-core/src/main/java/org/springframework/integration/support/locks/CustomTtlLock.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,49 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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.springframework.integration.support.locks; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.locks.Lock; | ||
|
||
/** | ||
* A {@link Lock} implementing this interface supports the spring distributed locks with custom time-to-live value per lock | ||
* | ||
* @author Eddie Cho | ||
* | ||
* @since 6.3 | ||
*/ | ||
public interface CustomTtlLock extends Lock { | ||
|
||
/** | ||
* Attempt to acquire a lock with a specific time-to-live | ||
* @param time the maximum time to wait for the lock unit | ||
* @param unit the time unit of the time argument | ||
* @param customTtl the specific time-to-live for the lock status data | ||
* @param customTtlUnit the time unit of the customTtl argument | ||
* @return true if the lock was acquired and false if the waiting time elapsed before the lock was acquired | ||
* @throws InterruptedException - | ||
* if the current thread is interrupted while acquiring the lock (and interruption of lock acquisition is supported) | ||
*/ | ||
boolean tryLock(long time, TimeUnit unit, long customTtl, TimeUnit customTtlUnit) throws InterruptedException; | ||
|
||
/** | ||
* Attempt to acquire a lock with a specific time-to-live | ||
* @param customTtl the specific time-to-live for the lock status data | ||
* @param customTtlUnit the time unit of the customTtl argument | ||
*/ | ||
void lock(long customTtl, TimeUnit customTtlUnit); | ||
} |
29 changes: 29 additions & 0 deletions
29
...re/src/main/java/org/springframework/integration/support/locks/CustomTtlLockRegistry.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,29 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
/** | ||
* A {@link LockRegistry} implementing this interface supports the CustomTtlLock | ||
* | ||
* @author Eddie Cho | ||
* | ||
* @since 6.3 | ||
*/ | ||
package org.springframework.integration.support.locks; | ||
|
||
public interface CustomTtlLockRegistry extends LockRegistry { | ||
|
||
CustomTtlLock obtainCustomTtlLock(Object lockKey); | ||
} |
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
Oops, something went wrong.