|
1 | 1 | /*
|
2 |
| - * Copyright 2016-2019 the original author or authors. |
| 2 | + * Copyright 2016-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.integration.jdbc.lock;
|
18 | 18 |
|
| 19 | +import org.springframework.dao.CannotAcquireLockException; |
| 20 | +import org.springframework.dao.DataAccessResourceFailureException; |
| 21 | +import org.springframework.dao.TransientDataAccessException; |
| 22 | +import org.springframework.integration.support.locks.ExpirableLockRegistry; |
| 23 | +import org.springframework.integration.util.UUIDConverter; |
| 24 | +import org.springframework.util.Assert; |
| 25 | + |
19 | 26 | import java.time.Duration;
|
20 | 27 | import java.util.Iterator;
|
21 | 28 | import java.util.Map;
|
|
26 | 33 | import java.util.concurrent.locks.Lock;
|
27 | 34 | import java.util.concurrent.locks.ReentrantLock;
|
28 | 35 |
|
29 |
| -import org.springframework.dao.CannotAcquireLockException; |
30 |
| -import org.springframework.dao.DataAccessResourceFailureException; |
31 |
| -import org.springframework.dao.TransientDataAccessException; |
32 |
| -import org.springframework.integration.support.locks.ExpirableLockRegistry; |
33 |
| -import org.springframework.integration.util.UUIDConverter; |
34 |
| -import org.springframework.util.Assert; |
35 |
| - |
36 | 36 | /**
|
37 |
| - * |
38 | 37 | * An {@link ExpirableLockRegistry} using a shared database to co-ordinate the locks.
|
39 | 38 | * Provides the same semantics as the
|
40 | 39 | * {@link org.springframework.integration.support.locks.DefaultLockRegistry}, but the
|
|
47 | 46 | * @author Kai Zimmermann
|
48 | 47 | * @author Bartosz Rempuszewski
|
49 | 48 | * @author Gary Russell
|
50 |
| - * |
51 | 49 | * @since 4.3
|
52 | 50 | */
|
53 | 51 | public class JdbcLockRegistry implements ExpirableLockRegistry {
|
@@ -99,6 +97,20 @@ public void expireUnusedOlderThan(long age) {
|
99 | 97 | }
|
100 | 98 | }
|
101 | 99 |
|
| 100 | + public void renewLock(Lock lock) { |
| 101 | + Assert.isInstanceOf(JdbcLock.class, lock); |
| 102 | + JdbcLock jdbcLock = (JdbcLock) lock; |
| 103 | + |
| 104 | + if (!jdbcLock.isAcquiredInThisProcess()) { |
| 105 | + throw new IllegalMonitorStateException("You do not own mutex at " + jdbcLock.path); |
| 106 | + } |
| 107 | + |
| 108 | + if (!jdbcLock.mutex.acquire(jdbcLock.path)) { |
| 109 | + throw new IllegalStateException("Could not renew mutex at " + jdbcLock.path); |
| 110 | + } |
| 111 | + |
| 112 | + } |
| 113 | + |
102 | 114 | private static final class JdbcLock implements Lock {
|
103 | 115 |
|
104 | 116 | private final LockRepository mutex;
|
|
0 commit comments