Changeset 98da06c


Ignore:
Timestamp:
Sep 8, 2012 2:25:04 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e02d8298
Parents:
0d622660
Message:

limit queue size, make nonblocking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/client/ClientWriterRunner.java

    r0d622660 r98da06c  
    55
    66import net.i2p.data.i2cp.I2CPMessage;
     7import net.i2p.data.i2cp.I2CPMessageException;
    78import net.i2p.internal.PoisonI2CPMessage;
    89import net.i2p.router.RouterContext;
     
    1213 * Async writer class so that if a client app hangs, they wont take down the
    1314 * whole router with them (since otherwise the JobQueue would block until
    14  * the client reads from their i2cp socket, causing all sorts of bad shit to
     15 * the client reads from their i2cp socket, causing all sorts of bad things to
    1516 * happen)
    1617 *
    17  * @author zzz modded to use concurrent
    1818 */
    1919class ClientWriterRunner implements Runnable {
     
    2323    private final long _id;
    2424    private static long __id = 0;
     25
     26    private static final int QUEUE_SIZE = 256;
    2527   
    2628    public ClientWriterRunner(RouterContext context, ClientConnectionRunner runner) {
    2729        _log = context.logManager().getLog(ClientWriterRunner.class);
    28         _messagesToWrite = new LinkedBlockingQueue();
     30        _messagesToWrite = new LinkedBlockingQueue(QUEUE_SIZE);
    2931        _runner = runner;
    3032        _id = ++__id;
     
    3436     * Add this message to the writer's queue
    3537     *
     38     * Nonblocking, throws exception if queue is full
    3639     */
    37     public void addMessage(I2CPMessage msg) {
    38         try {
    39             _messagesToWrite.put(msg);
    40         } catch (InterruptedException ie) {}
    41         if (_log.shouldLog(Log.DEBUG))
    42             _log.debug("["+_id+"] addMessage completed for " + msg.getClass().getName());
     40    public void addMessage(I2CPMessage msg) throws I2CPMessageException {
     41        boolean success = _messagesToWrite.offer(msg);
     42        if (!success)
     43            throw new I2CPMessageException("I2CP write to queue failed");
     44        //if (_log.shouldLog(Log.DEBUG))
     45        //    _log.debug("["+_id+"] addMessage completed for " + msg.getClass().getName());
    4346    }
    4447
Note: See TracChangeset for help on using the changeset viewer.