Replace EvictingQueue with own implementation

For some unknown reason the EvictingQueue didn't evict or evicted only
partially. Nevertheless it caused an OutOfMemoryError.
This commit is contained in:
0xboobface 2019-03-21 14:51:52 +01:00
parent 1dd432dbd9
commit 335233f473
1 changed files with 6 additions and 2 deletions

View File

@ -10,11 +10,13 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -27,7 +29,6 @@ import org.slf4j.LoggerFactory;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.collect.EvictingQueue;
import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.Moshi; import com.squareup.moshi.Moshi;
@ -66,7 +67,7 @@ public class MyFreeCamsClient {
private static int messageId = 31415; // starting with 31415 just for fun private static int messageId = 31415; // starting with 31415 just for fun
private Map<Integer, Consumer<Message>> responseHandlers = new HashMap<>(); private Map<Integer, Consumer<Message>> responseHandlers = new HashMap<>();
private EvictingQueue<String> receivedTextHistory = EvictingQueue.create(100); private Queue<String> receivedTextHistory = new LinkedList<>();
private MyFreeCamsClient() { private MyFreeCamsClient() {
moshi = new Moshi.Builder().build(); moshi = new Moshi.Builder().build();
@ -193,6 +194,9 @@ public class MyFreeCamsClient {
super.onMessage(webSocket, text); super.onMessage(webSocket, text);
heartBeat = System.currentTimeMillis(); heartBeat = System.currentTimeMillis();
receivedTextHistory.add(text); receivedTextHistory.add(text);
while(receivedTextHistory.size() > 100) {
receivedTextHistory.poll();
}
msgBuffer.append(text); msgBuffer.append(text);
Message message; Message message;
try { try {