Skip to content

Commit 6c0e2c1

Browse files
committed
finish extracting reusable and references
1 parent 6ee7f81 commit 6c0e2c1

121 files changed

Lines changed: 911 additions & 2009 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

rlib-common/src/main/java/javasabr/rlib/common/concurrent/GroupThreadFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package javasabr.rlib.common.concurrent;
22

33
import java.util.concurrent.ThreadFactory;
4-
import javasabr.rlib.common.concurrent.atomic.ReusableAtomicInteger;
4+
import java.util.concurrent.atomic.AtomicInteger;
55
import org.jspecify.annotations.NullMarked;
66

77
/**
@@ -18,7 +18,7 @@ public interface ThreadConstructor {
1818
Thread create(ThreadGroup group, Runnable runnable, String name);
1919
}
2020

21-
private final ReusableAtomicInteger ordinal;
21+
private final AtomicInteger ordinal;
2222
private final String name;
2323
private final ThreadGroup group;
2424
private final ThreadConstructor constructor;
@@ -43,7 +43,7 @@ public GroupThreadFactory(String name, ThreadConstructor constructor, int priori
4343
this.priority = priority;
4444
this.name = name;
4545
this.group = new ThreadGroup(name);
46-
this.ordinal = new ReusableAtomicInteger();
46+
this.ordinal = new AtomicInteger();
4747
this.daemon = daemon;
4848
}
4949

rlib-common/src/main/java/javasabr/rlib/common/concurrent/atomic/ReusableAtomicInteger.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

rlib-common/src/main/java/javasabr/rlib/common/concurrent/atomic/ReusableAtomicReference.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

rlib-common/src/main/java/javasabr/rlib/common/concurrent/lock/impl/AtomicLock.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package javasabr.rlib.common.concurrent.lock.impl;
22

33
import java.util.concurrent.TimeUnit;
4+
import java.util.concurrent.atomic.AtomicInteger;
45
import java.util.concurrent.locks.Condition;
56
import java.util.concurrent.locks.Lock;
6-
import javasabr.rlib.common.concurrent.atomic.ReusableAtomicInteger;
77
import org.jspecify.annotations.NullMarked;
88

99
/**
@@ -20,7 +20,7 @@ public class AtomicLock implements Lock {
2020
/**
2121
* The status of lock.
2222
*/
23-
protected final ReusableAtomicInteger status;
23+
protected final AtomicInteger status;
2424

2525
/**
2626
* The field for consuming CPU.
@@ -31,7 +31,7 @@ public class AtomicLock implements Lock {
3131
* Instantiates a new Atomic lock.
3232
*/
3333
public AtomicLock() {
34-
this.status = new ReusableAtomicInteger();
34+
this.status = new AtomicInteger();
3535
this.sink = 1;
3636
}
3737

rlib-common/src/main/java/javasabr/rlib/common/concurrent/lock/impl/AtomicReadWriteLock.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package javasabr.rlib.common.concurrent.lock.impl;
22

33
import java.util.concurrent.TimeUnit;
4+
import java.util.concurrent.atomic.AtomicInteger;
45
import java.util.concurrent.locks.Condition;
56
import java.util.concurrent.locks.Lock;
6-
import javasabr.rlib.common.concurrent.atomic.ReusableAtomicInteger;
77
import javasabr.rlib.common.concurrent.lock.AsyncReadSyncWriteLock;
88
import org.jspecify.annotations.NullMarked;
99

@@ -25,17 +25,17 @@ public class AtomicReadWriteLock implements AsyncReadSyncWriteLock, Lock {
2525
/**
2626
* The status of write lock.
2727
*/
28-
protected final ReusableAtomicInteger writeStatus;
28+
protected final AtomicInteger writeStatus;
2929

3030
/**
3131
* The count of writers.
3232
*/
33-
protected final ReusableAtomicInteger writeCount;
33+
protected final AtomicInteger writeCount;
3434

3535
/**
3636
* The count of readers.
3737
*/
38-
protected final ReusableAtomicInteger readCount;
38+
protected final AtomicInteger readCount;
3939

4040
/**
4141
* The field for consuming CPU.
@@ -46,9 +46,9 @@ public class AtomicReadWriteLock implements AsyncReadSyncWriteLock, Lock {
4646
* Instantiates a new Atomic read write lock.
4747
*/
4848
public AtomicReadWriteLock() {
49-
this.writeCount = new ReusableAtomicInteger(0);
50-
this.writeStatus = new ReusableAtomicInteger(0);
51-
this.readCount = new ReusableAtomicInteger(0);
49+
this.writeCount = new AtomicInteger(0);
50+
this.writeStatus = new AtomicInteger(0);
51+
this.readCount = new AtomicInteger(0);
5252
this.sink = 1;
5353
}
5454

rlib-common/src/main/java/javasabr/rlib/common/concurrent/lock/impl/ReentrantAtomicLock.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package javasabr.rlib.common.concurrent.lock.impl;
22

33
import java.util.concurrent.TimeUnit;
4+
import java.util.concurrent.atomic.AtomicInteger;
5+
import java.util.concurrent.atomic.AtomicReference;
46
import java.util.concurrent.locks.Condition;
57
import java.util.concurrent.locks.Lock;
6-
import javasabr.rlib.common.concurrent.atomic.ReusableAtomicInteger;
7-
import javasabr.rlib.common.concurrent.atomic.ReusableAtomicReference;
88
import org.jspecify.annotations.NullMarked;
99

1010
/**
@@ -18,12 +18,12 @@ public class ReentrantAtomicLock implements Lock {
1818
/**
1919
* The status of lock.
2020
*/
21-
private final ReusableAtomicReference<Thread> status;
21+
private final AtomicReference<Thread> status;
2222

2323
/**
2424
* The level of locking.
2525
*/
26-
private final ReusableAtomicInteger level;
26+
private final AtomicInteger level;
2727

2828
/**
2929
* The field for consuming CPU.
@@ -34,8 +34,8 @@ public class ReentrantAtomicLock implements Lock {
3434
* Instantiates a new Reentrant atomic lock.
3535
*/
3636
public ReentrantAtomicLock() {
37-
this.status = new ReusableAtomicReference<>();
38-
this.level = new ReusableAtomicInteger();
37+
this.status = new AtomicReference<>();
38+
this.level = new AtomicInteger();
3939
this.sink = 1;
4040
}
4141

rlib-common/src/main/java/javasabr/rlib/common/concurrent/util/ConcurrentUtils.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.function.Function;
44
import javasabr.rlib.common.concurrent.lock.Lockable;
55
import javasabr.rlib.common.function.ObjectIntFunction;
6-
import javasabr.rlib.common.function.ObjectLongFunction;
76
import javasabr.rlib.logger.api.Logger;
87
import javasabr.rlib.logger.api.LoggerManager;
98
import org.jspecify.annotations.NullMarked;
@@ -148,26 +147,6 @@ public static <T extends Lockable, R> R get(T sync, int argument, ObjectIntFunct
148147
}
149148
}
150149

151-
/**
152-
* Apply a function in locked block.
153-
*
154-
* @param <T> the type parameter
155-
* @param <R> the type parameter
156-
* @param sync the synchronizer.
157-
* @param argument the argument.
158-
* @param function the function.
159-
* @return the result from the function.
160-
*/
161-
@Nullable
162-
public static <T extends Lockable, @Nullable R> R getInL(T sync, long argument, ObjectLongFunction<T, R> function) {
163-
sync.lock();
164-
try {
165-
return function.apply(sync, argument);
166-
} finally {
167-
sync.unlock();
168-
}
169-
}
170-
171150
private ConcurrentUtils() {
172151
throw new RuntimeException();
173152
}

rlib-common/src/main/java/javasabr/rlib/common/function/ObjectLongFunction.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

rlib-common/src/main/java/javasabr/rlib/common/util/ObjectUtils.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.function.Function;
55
import java.util.function.LongFunction;
66
import java.util.function.Supplier;
7-
import javasabr.rlib.common.util.pools.Reusable;
87
import org.jspecify.annotations.NullMarked;
98
import org.jspecify.annotations.Nullable;
109

@@ -153,15 +152,4 @@ public static int hash(long value) {
153152
public static int hash(@Nullable Object object) {
154153
return object == null ? 0 : object.hashCode();
155154
}
156-
157-
/**
158-
* Call the method {@link Reusable#release()} if the object is instanceof {@link Reusable}.
159-
*
160-
* @param object the object.
161-
*/
162-
public static void release(@Nullable Object object) {
163-
if (object instanceof Reusable) {
164-
((Reusable) object).release();
165-
}
166-
}
167155
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package javasabr.rlib.common.util;
2+
3+
/**
4+
* @author JavaSaBr
5+
*/
6+
public interface Reusable extends AutoCloseable {
7+
8+
/**
9+
* Cleanup this object
10+
*/
11+
default void cleanup() {}
12+
13+
@Override
14+
default void close() {
15+
cleanup();
16+
}
17+
}

0 commit comments

Comments
 (0)