This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 1487edf3d [type: refactor] refactor Rejector interface (#3903)
1487edf3d is described below
commit 1487edf3dab3c2e0429938f29c556cbe9feaa136
Author: dragon-zhang <[email protected]>
AuthorDate: Thu Sep 1 18:03:28 2022 +0800
[type: refactor] refactor Rejector interface (#3903)
---
.../main/java/org/apache/shenyu/common/concurrent/AbortPolicy.java | 4 +++-
.../java/org/apache/shenyu/common/concurrent/DiscardOldestPolicy.java | 4 +++-
.../main/java/org/apache/shenyu/common/concurrent/DiscardPolicy.java | 4 +++-
.../src/main/java/org/apache/shenyu/common/concurrent/Rejector.java | 4 +++-
4 files changed, 12 insertions(+), 4 deletions(-)
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/AbortPolicy.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/AbortPolicy.java
index 17a22e219..758cd0fb2 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/AbortPolicy.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/AbortPolicy.java
@@ -17,6 +17,8 @@
package org.apache.shenyu.common.concurrent;
+import java.util.Queue;
+
/**
* A handler for rejected element that throws a
* {@code RejectException}.
@@ -24,7 +26,7 @@ package org.apache.shenyu.common.concurrent;
public class AbortPolicy<E> implements Rejector<E> {
@Override
- public void reject(final E e, final MemorySafeLinkedBlockingQueue<E>
queue) {
+ public void reject(final E e, final Queue<E> queue) {
throw new RejectException("no more memory can be used !");
}
}
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/DiscardOldestPolicy.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/DiscardOldestPolicy.java
index 554d7f308..44a8fc0bb 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/DiscardOldestPolicy.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/DiscardOldestPolicy.java
@@ -17,13 +17,15 @@
package org.apache.shenyu.common.concurrent;
+import java.util.Queue;
+
/**
* A handler for rejected element that discards the oldest element.
*/
public class DiscardOldestPolicy<E> implements Rejector<E> {
@Override
- public void reject(final E e, final MemorySafeLinkedBlockingQueue<E>
queue) {
+ public void reject(final E e, final Queue<E> queue) {
queue.poll();
queue.offer(e);
}
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/DiscardPolicy.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/DiscardPolicy.java
index 6ac69a155..d7e14c91b 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/DiscardPolicy.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/DiscardPolicy.java
@@ -17,6 +17,8 @@
package org.apache.shenyu.common.concurrent;
+import java.util.Queue;
+
/**
* A handler for rejected element that silently discards the
* rejected element.
@@ -24,7 +26,7 @@ package org.apache.shenyu.common.concurrent;
public class DiscardPolicy<E> implements Rejector<E> {
@Override
- public void reject(final E e, final MemorySafeLinkedBlockingQueue<E>
queue) {
+ public void reject(final E e, final Queue<E> queue) {
}
}
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/Rejector.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/Rejector.java
index 0dccfa0ed..386549812 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/Rejector.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/Rejector.java
@@ -17,6 +17,8 @@
package org.apache.shenyu.common.concurrent;
+import java.util.Queue;
+
/**
* RejectHandler, it works when you need to custom reject action in
* {@link org.apache.shenyu.common.concurrent.MemorySafeLinkedBlockingQueue}.
@@ -39,5 +41,5 @@ public interface Rejector<E> {
* @param queue the queue attempting to add this element
* @throws RejectException if there is no more memory
*/
- void reject(E e, MemorySafeLinkedBlockingQueue<E> queue);
+ void reject(E e, Queue<E> queue);
}