Browse Source

移除init value

zhouhao 8 năm trước cách đây
mục cha
commit
282e0f21d1

+ 3 - 3
hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/AbstractCounterManager.java

@@ -11,14 +11,14 @@ public abstract class AbstractCounterManager implements CounterManager {
     private final Map<String, Counter> counterStore = new HashMap<>(128);
 
     @Override
-    public Counter getCounter(String name, long initValue) {
+    public Counter getCounter(String name) {
         Counter counter = counterStore.get(name);
         if (counter != null)
             return counter;
         synchronized (counterStore) {
-            return counterStore.computeIfAbsent(name, k -> this.createCount(name, initValue));
+            return counterStore.computeIfAbsent(name, this::createCount);
         }
     }
 
-    protected abstract Counter createCount(String name, long initValue);
+    protected abstract Counter createCount(String name);
 }

+ 1 - 4
hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/CounterManager.java

@@ -24,9 +24,6 @@ package org.hswebframework.web.concurrent.counter;
  */
 public interface CounterManager {
 
-    default Counter getCounter(String name) {
-        return getCounter(name, 0);
-    }
+    Counter getCounter(String name);
 
-    Counter getCounter(String name, long initValue);
 }

+ 1 - 1
hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/SimpleCounterManager.java

@@ -7,7 +7,7 @@ package org.hswebframework.web.concurrent.counter;
  */
 public class SimpleCounterManager extends AbstractCounterManager {
     @Override
-    protected Counter createCount(String name, long initValue) {
+    protected Counter createCount(String name) {
         return new SimpleCounter();
     }
 }

+ 2 - 5
hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedissonCounterManager.java

@@ -20,10 +20,7 @@ public class RedissonCounterManager extends AbstractCounterManager {
     }
 
     @Override
-    protected Counter createCount(String name, long initValue) {
-        Counter counter = new RedissonCounter(redisson.getAtomicLong(name));
-        if (counter.get() == 0)
-            counter.set(initValue);
-        return counter;
+    protected Counter createCount(String name) {
+        return new RedissonCounter(redisson.getAtomicLong(name));
     }
 }