¶Ô±ÈÐÂÎļþ |
| | |
| | | /* |
| | | * Copyright (c) 2018-2028, DreamLu All rights reserved. |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are met: |
| | | * |
| | | * Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * Redistributions in binary form must reproduce the above copyright |
| | | * notice, this list of conditions and the following disclaimer in the |
| | | * documentation and/or other materials provided with the distribution. |
| | | * Neither the name of the dreamlu.net developer nor the names of its |
| | | * contributors may be used to endorse or promote products derived from |
| | | * this software without specific prior written permission. |
| | | * Author: DreamLu 墿¥æ¢¦ (596392912@qq.com) |
| | | */ |
| | | |
| | | package org.springblade.core.redis.lock; |
| | | |
| | | import org.springblade.core.tool.function.CheckedSupplier; |
| | | |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * é客æ·ç«¯ |
| | | * |
| | | * @author L.cm |
| | | */ |
| | | public interface RedisLockClient { |
| | | |
| | | /** |
| | | * å°è¯è·åé |
| | | * |
| | | * @param lockName éå |
| | | * @param lockType éç±»å |
| | | * @param waitTime çå¾
æ¶é´ |
| | | * @param leaseTime èªå¨è§£éæ¶é´ï¼èªå¨è§£éæ¶é´ä¸å®å¾å¤§äºæ¹æ³æ§è¡æ¶é´ |
| | | * @param timeUnit æ¶é´åæ° |
| | | * @return æ¯å¦æå |
| | | * @throws InterruptedException InterruptedException |
| | | */ |
| | | boolean tryLock(String lockName, LockType lockType, long waitTime, long leaseTime, TimeUnit timeUnit) throws InterruptedException; |
| | | |
| | | /** |
| | | * è§£é |
| | | * |
| | | * @param lockName éå |
| | | * @param lockType éç±»å |
| | | */ |
| | | void unLock(String lockName, LockType lockType); |
| | | |
| | | /** |
| | | * èªå®è·åéåæ§è¡æ¹æ³ |
| | | * |
| | | * @param lockName éå |
| | | * @param lockType éç±»å |
| | | * @param waitTime çå¾
éè¶
æ¶æ¶é´ |
| | | * @param leaseTime èªå¨è§£éæ¶é´ï¼èªå¨è§£éæ¶é´ä¸å®å¾å¤§äºæ¹æ³æ§è¡æ¶é´ï¼å¦åä¼å¯¼è´éæåéæ¾ï¼é»è®¤100 |
| | | * @param timeUnit æ¶é´åä½ |
| | | * @param supplier è·åéåçåè° |
| | | * @return è¿åçæ°æ® |
| | | */ |
| | | <T> T lock(String lockName, LockType lockType, long waitTime, long leaseTime, TimeUnit timeUnit, CheckedSupplier<T> supplier); |
| | | |
| | | /** |
| | | * å
¬å¹³é |
| | | * |
| | | * @param lockName éå |
| | | * @param waitTime çå¾
éè¶
æ¶æ¶é´ |
| | | * @param leaseTime èªå¨è§£éæ¶é´ï¼èªå¨è§£éæ¶é´ä¸å®å¾å¤§äºæ¹æ³æ§è¡æ¶é´ï¼å¦åä¼å¯¼è´éæåéæ¾ï¼é»è®¤100 |
| | | * @param supplier è·åéåçåè° |
| | | * @return è¿åçæ°æ® |
| | | */ |
| | | default <T> T lockFair(String lockName, long waitTime, long leaseTime, CheckedSupplier<T> supplier) { |
| | | return lock(lockName, LockType.FAIR, waitTime, leaseTime, TimeUnit.SECONDS, supplier); |
| | | } |
| | | |
| | | /** |
| | | * å¯éå
¥é |
| | | * |
| | | * @param lockName éå |
| | | * @param waitTime çå¾
éè¶
æ¶æ¶é´ |
| | | * @param leaseTime èªå¨è§£éæ¶é´ï¼èªå¨è§£éæ¶é´ä¸å®å¾å¤§äºæ¹æ³æ§è¡æ¶é´ï¼å¦åä¼å¯¼è´éæåéæ¾ï¼é»è®¤100 |
| | | * @param supplier è·åéåçåè° |
| | | * @return è¿åçæ°æ® |
| | | */ |
| | | default <T> T lockReentrant(String lockName, long waitTime, long leaseTime, CheckedSupplier<T> supplier) { |
| | | return lock(lockName, LockType.REENTRANT, waitTime, leaseTime, TimeUnit.SECONDS, supplier); |
| | | } |
| | | |
| | | } |