You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by ji...@apache.org on 2023/05/16 05:36:33 UTC
[rocketmq] branch develop updated: [ISSUE #6765] org.apache.rocketmq.util.cache doesn't look like it's being used
This is an automated email from the ASF dual-hosted git repository.
jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new 92ea901d7 [ISSUE #6765] org.apache.rocketmq.util.cache doesn't look like it's being used
92ea901d7 is described below
commit 92ea901d7bfffdbc743ce693df3d85d9ccd60642
Author: Lobo Xu <31...@qq.com>
AuthorDate: Tue May 16 13:36:11 2023 +0800
[ISSUE #6765] org.apache.rocketmq.util.cache doesn't look like it's being used
Co-authored-by: loboxu <lo...@tencent.com>
---
.../rocketmq/util/cache/CacheEvictHandler.java | 23 ------
.../apache/rocketmq/util/cache/CacheObject.java | 36 ----------
.../rocketmq/util/cache/ExpiredLocalCache.java | 84 ----------------------
.../org/apache/rocketmq/util/cache/LocalCache.java | 58 ---------------
.../apache/rocketmq/util/cache/LockManager.java | 53 --------------
5 files changed, 254 deletions(-)
diff --git a/srvutil/src/main/java/org/apache/rocketmq/util/cache/CacheEvictHandler.java b/srvutil/src/main/java/org/apache/rocketmq/util/cache/CacheEvictHandler.java
deleted file mode 100644
index 13dcd9ef4..000000000
--- a/srvutil/src/main/java/org/apache/rocketmq/util/cache/CacheEvictHandler.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.rocketmq.util.cache;
-
-import java.util.Map;
-
-public interface CacheEvictHandler<K, V> {
- void onEvict(Map.Entry<K, V> eldest);
-}
diff --git a/srvutil/src/main/java/org/apache/rocketmq/util/cache/CacheObject.java b/srvutil/src/main/java/org/apache/rocketmq/util/cache/CacheObject.java
deleted file mode 100644
index 39c64ceb1..000000000
--- a/srvutil/src/main/java/org/apache/rocketmq/util/cache/CacheObject.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.rocketmq.util.cache;
-
-
-public class CacheObject<T> {
- private T target;
- private long bornTime = System.currentTimeMillis();
- private long exp;
-
- public CacheObject(long exp, T target) {
- this.exp = exp;
- this.target = target;
- }
-
- public T getTarget() {
- if (System.currentTimeMillis() - bornTime > exp) {
- return null;
- }
- return target;
- }
-}
diff --git a/srvutil/src/main/java/org/apache/rocketmq/util/cache/ExpiredLocalCache.java b/srvutil/src/main/java/org/apache/rocketmq/util/cache/ExpiredLocalCache.java
deleted file mode 100644
index bfece5bbf..000000000
--- a/srvutil/src/main/java/org/apache/rocketmq/util/cache/ExpiredLocalCache.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.rocketmq.util.cache;
-
-import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
-import com.googlecode.concurrentlinkedhashmap.EvictionListener;
-
-public class ExpiredLocalCache<K, T> {
- private ConcurrentLinkedHashMap<K, CacheObject<T>> cache;
- private EvictionListener<K, CacheObject<T>> listener;
-
- public ExpiredLocalCache(int size) {
- cache = new ConcurrentLinkedHashMap.Builder<K, CacheObject<T>>().maximumWeightedCapacity(size).build();
- }
-
- public ExpiredLocalCache(int size, String name) {
- cache = new ConcurrentLinkedHashMap.Builder<K, CacheObject<T>>().maximumWeightedCapacity(size).build();
- }
-
- public ExpiredLocalCache(int size, boolean memoryMeter, EvictionListener<K, CacheObject<T>> listener) {
- this.listener = listener;
- cache = new ConcurrentLinkedHashMap.Builder<K, CacheObject<T>>().listener(listener).maximumWeightedCapacity(size).build();
- }
-
- public T get(K key) {
- CacheObject<T> object = cache.get(key);
- if (object == null) {
- return null;
- }
- T ret = object.getTarget();
- if (ret == null) {
- this.delete(key);
- }
- return ret;
- }
-
- public T put(K key, T v, long exp) {
- CacheObject<T> value = new CacheObject<>(exp, v);
- CacheObject<T> old = cache.put(key, value);
- if (old == null) {
- return null;
- } else {
- return old.getTarget();
- }
- }
-
- public T putIfAbsent(K key, T v, long exp) {
- CacheObject<T> value = new CacheObject<>(exp, v);
- CacheObject<T> old = cache.putIfAbsent(key, value);
- if (old == null) {
- return null;
- } else {
- return old.getTarget();
- }
- }
-
- public T delete(K key) {
- CacheObject<T> object = cache.remove(key);
- if (object == null) {
- return null;
- }
- T ret = object.getTarget();
- return ret;
- }
-
- public ConcurrentLinkedHashMap<K, CacheObject<T>> getCache() {
- return cache;
- }
-
-}
diff --git a/srvutil/src/main/java/org/apache/rocketmq/util/cache/LocalCache.java b/srvutil/src/main/java/org/apache/rocketmq/util/cache/LocalCache.java
deleted file mode 100644
index 7dbb6e247..000000000
--- a/srvutil/src/main/java/org/apache/rocketmq/util/cache/LocalCache.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.rocketmq.util.cache;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public class LocalCache<K, V> extends LinkedHashMap<K, V> {
-
- private static final long serialVersionUID = 1606231700062718297L;
-
- private static final int DEFAULT_CACHE_SIZE = 1000;
-
- private int cacheSize = DEFAULT_CACHE_SIZE;
- private CacheEvictHandler<K, V> handler;
-
- /**
- * The default initial capacity - MUST be a power of two.
- */
- static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16
-
-
- /**
- * The load factor used when none specified in constructor.
- */
- static final float DEFAULT_LOAD_FACTOR = 0.75f;
-
- public LocalCache(int cacheSize, boolean isLru, CacheEvictHandler<K, V> handler) {
- super(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, isLru);
- this.cacheSize = cacheSize;
- this.handler = handler;
- }
-
-
- @Override
- protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
- boolean result = this.size() > cacheSize;
- if (result && handler != null) {
- handler.onEvict(eldest);
- }
- return result;
- }
-
-}
diff --git a/srvutil/src/main/java/org/apache/rocketmq/util/cache/LockManager.java b/srvutil/src/main/java/org/apache/rocketmq/util/cache/LockManager.java
deleted file mode 100644
index 510f2cb56..000000000
--- a/srvutil/src/main/java/org/apache/rocketmq/util/cache/LockManager.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.rocketmq.util.cache;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.rocketmq.common.PopAckConstants;
-import org.apache.rocketmq.remoting.protocol.header.PopMessageRequestHeader;
-
-public class LockManager {
- private static ExpiredLocalCache<String, AtomicBoolean> expiredLocalCache = new ExpiredLocalCache<>(100000);
-
- public static boolean tryLock(String key, long lockTime) {
- AtomicBoolean v = expiredLocalCache.get(key);
- if (v == null) {
- return expiredLocalCache.putIfAbsent(key, new AtomicBoolean(false), lockTime) == null;
- } else {
- return v.compareAndSet(true, false);
- }
- }
-
- public static void unLock(String key) {
- AtomicBoolean v = expiredLocalCache.get(key);
- if (v != null) {
- v.set(true);
- }
- }
-
- public static String buildKey(PopMessageRequestHeader requestHeader, int queueId) {
- return requestHeader.getConsumerGroup() + PopAckConstants.SPLIT + requestHeader.getTopic() + PopAckConstants.SPLIT + queueId;
- }
-
- public static String buildKey(String topic, String cid, int queueId) {
- return topic + PopAckConstants.SPLIT + cid + PopAckConstants.SPLIT + queueId;
- }
-
- public static String buildKey(String prefix, int queueId) {
- return prefix + PopAckConstants.SPLIT + queueId;
- }
-}