1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-23 06:42:05 +01:00

Adding max queue size to throttle traffic (avoids OOM). (SMACK-208).

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7419 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2007-03-09 02:02:27 +00:00 committed by matt
parent 44c5f274ea
commit e9f049adc9

View file

@ -25,10 +25,10 @@ import org.jivesoftware.smack.packet.Packet;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.util.Queue;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
/** /**
* Writes packets to a XMPP server. Packets are sent using a dedicated thread. Packet * Writes packets to a XMPP server. Packets are sent using a dedicated thread. Packet
@ -43,7 +43,7 @@ class PacketWriter {
private Thread keepAliveThread; private Thread keepAliveThread;
private Writer writer; private Writer writer;
private XMPPConnection connection; private XMPPConnection connection;
private final Queue<Packet> queue; private final BlockingQueue<Packet> queue;
private boolean done; private boolean done;
private final Map<PacketListener, ListenerWrapper> listeners = private final Map<PacketListener, ListenerWrapper> listeners =
@ -69,7 +69,7 @@ class PacketWriter {
* @param connection the connection. * @param connection the connection.
*/ */
protected PacketWriter(XMPPConnection connection) { protected PacketWriter(XMPPConnection connection) {
this.queue = new ConcurrentLinkedQueue<Packet>(); this.queue = new ArrayBlockingQueue<Packet>(500, true);
this.connection = connection; this.connection = connection;
init(); init();
} }
@ -102,7 +102,13 @@ class PacketWriter {
// may modify the content of the packet. // may modify the content of the packet.
processInterceptors(packet); processInterceptors(packet);
queue.add(packet); try {
queue.put(packet);
}
catch (InterruptedException ie) {
ie.printStackTrace();
return;
}
synchronized (queue) { synchronized (queue) {
queue.notifyAll(); queue.notifyAll();
} }