Skip to content

Commit

Permalink
add generic parameter for RowLock
Browse files Browse the repository at this point in the history
Change-Id: I309b89846ca15d58ea39095d406a0b0b5de510e7
  • Loading branch information
javeme committed Dec 21, 2019
1 parent 49bff5e commit f424dc9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/baidu/hugegraph/concurrent/LockGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ public KeyLock keyLock(String lockName, int size) {
return (KeyLock) this.locksMap.get(lockName);
}

public RowLock rowLock(String lockName) {
public <K extends Comparable<K>> RowLock<K> rowLock(String lockName) {
if (!this.locksMap.containsKey(lockName)) {
this.locksMap.putIfAbsent(lockName, new RowLock());
this.locksMap.putIfAbsent(lockName, new RowLock<>());
}
return (RowLock) this.locksMap.get(lockName);
Object value = this.locksMap.get(lockName);
@SuppressWarnings("unchecked")
RowLock<K> lock = (RowLock<K>) value;
return lock;
}

public String name() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

import com.baidu.hugegraph.concurrent.AtomicLock;
import com.baidu.hugegraph.concurrent.KeyLock;
import com.baidu.hugegraph.concurrent.RowLock;
import com.baidu.hugegraph.concurrent.LockGroup;
import com.baidu.hugegraph.concurrent.RowLock;
import com.baidu.hugegraph.testutil.Assert;

public class LockGroupTest {
Expand Down Expand Up @@ -80,9 +80,9 @@ public void testKeyLockWithSize() {

@Test
public void testRowLock() {
RowLock lock = this.group.rowLock("lock");
RowLock<?> lock = this.group.rowLock("lock");
Assert.assertNotNull(lock);
RowLock lock1 = this.group.rowLock("lock");
RowLock<?> lock1 = this.group.rowLock("lock");
Assert.assertSame(lock, lock1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testRowLockMultiRows() {
@SuppressWarnings("unchecked")
@Test
public void testRowLockWithMultiThreads() {
RowLock lock = new RowLock();
RowLock<Integer> lock = new RowLock<>();
Set<String> names = new HashSet<>(THREADS_NUM);
List<Integer> keys = new ArrayList<>(5);
Random random = new Random();
Expand Down

0 comments on commit f424dc9

Please sign in to comment.