-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provides extra hooks to ensure we capture all discarded elements
Signed-off-by: Oleh Dokuka <shadowgun@i.ua>
- Loading branch information
1 parent
c2475c2
commit 626dd81
Showing
3 changed files
with
136 additions
and
10 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
rsocket-core/src/main/java/io/rsocket/core/CleanOnClearQueueDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package io.rsocket.core; | ||
|
||
import io.netty.util.ReferenceCountUtil; | ||
import io.rsocket.Payload; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.Queue; | ||
|
||
final class CleanOnClearQueueDecorator implements Queue<Payload> { | ||
final Queue<Payload> delegate; | ||
|
||
CleanOnClearQueueDecorator(Queue<Payload> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
Payload p; | ||
while ((p = delegate.poll()) != null) { | ||
ReferenceCountUtil.safeRelease(p); | ||
} | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return delegate.size(); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return delegate.isEmpty(); | ||
} | ||
|
||
@Override | ||
public boolean contains(Object o) { | ||
return delegate.contains(o); | ||
} | ||
|
||
@Override | ||
public Iterator<Payload> iterator() { | ||
return delegate.iterator(); | ||
} | ||
|
||
@Override | ||
public Object[] toArray() { | ||
return delegate.toArray(); | ||
} | ||
|
||
@Override | ||
public <T> T[] toArray(T[] a) { | ||
return delegate.toArray(a); | ||
} | ||
|
||
@Override | ||
public boolean add(Payload payload) { | ||
return delegate.add(payload); | ||
} | ||
|
||
@Override | ||
public boolean remove(Object o) { | ||
return delegate.remove(o); | ||
} | ||
|
||
@Override | ||
public boolean containsAll(Collection<?> c) { | ||
return delegate.containsAll(c); | ||
} | ||
|
||
@Override | ||
public boolean addAll(Collection<? extends Payload> c) { | ||
return delegate.addAll(c); | ||
} | ||
|
||
@Override | ||
public boolean removeAll(Collection<?> c) { | ||
return delegate.retainAll(c); | ||
} | ||
|
||
@Override | ||
public boolean retainAll(Collection<?> c) { | ||
return delegate.retainAll(c); | ||
} | ||
|
||
@Override | ||
public boolean offer(Payload payload) { | ||
return delegate.offer(payload); | ||
} | ||
|
||
@Override | ||
public Payload remove() { | ||
return delegate.remove(); | ||
} | ||
|
||
@Override | ||
public Payload poll() { | ||
return delegate.poll(); | ||
} | ||
|
||
@Override | ||
public Payload element() { | ||
return delegate.element(); | ||
} | ||
|
||
@Override | ||
public Payload peek() { | ||
return delegate.peek(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters