Changeset d9e6c06


Ignore:
Timestamp:
Sep 8, 2012 8:45:11 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
9bc54f2
Parents:
e02d8298
Message:
Files:
4 edited

Legend:

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

    re02d8298 rd9e6c06  
    11package net.i2p.client;
    22
     3import java.io.BufferedOutputStream;
    34import java.io.IOException;
    45import java.io.OutputStream;
     
    3031    /** starts the thread too */
    3132    public ClientWriterRunner(OutputStream out, I2PSessionImpl session) {
    32         _out = out;
     33        _out = new BufferedOutputStream(out);
    3334        _session = session;
    3435        _messagesToWrite = new LinkedBlockingQueue(MAX_QUEUE_SIZE);
  • router/java/src/net/i2p/router/client/ClientConnectionRunner.java

    re02d8298 rd9e6c06  
    1010
    1111import java.io.BufferedInputStream;
     12import java.io.BufferedOutputStream;
    1213import java.io.EOFException;
    1314import java.io.IOException;
     
    119120    }
    120121   
    121     private static volatile int __id = 0;
     122    private static final AtomicInteger __id = new AtomicInteger();
    122123
    123124    /**
     
    127128     *
    128129     */
    129     public synchronized void startRunning() {
    130         try {
     130    public synchronized void startRunning() throws IOException {
     131            if (_dead || _reader != null)
     132                throw new IllegalStateException();
    131133            _reader = new I2CPMessageReader(new BufferedInputStream(_socket.getInputStream(), BUF_SIZE),
    132134                                            new ClientMessageEventListener(_context, this, true));
    133135            _writer = new ClientWriterRunner(_context, this);
    134136            I2PThread t = new I2PThread(_writer);
    135             t.setName("I2CP Writer " + ++__id);
     137            t.setName("I2CP Writer " + __id.incrementAndGet());
    136138            t.setDaemon(true);
    137139            t.setPriority(I2PThread.MAX_PRIORITY);
    138140            t.start();
    139             _out = _socket.getOutputStream(); // FIXME OWCH! needs a better way so it can be final. FIXME
     141            _out = new BufferedOutputStream(_socket.getOutputStream());
    140142            _reader.startReading();
    141143            // TODO need a cleaner for unclaimed items in _messages, but we have no timestamps...
    142         } catch (IOException ioe) {
    143             _log.error("Error starting up the runner", ioe);
    144         }
    145     }
    146    
    147     /** die a horrible death */
     144    }
     145   
     146    /**
     147     *  Die a horrible death. Cannot be restarted.
     148     */
    148149    public synchronized void stopRunning() {
    149150        if (_dead) return;
     
    157158        if (_socket != null) try { _socket.close(); } catch (IOException ioe) { }
    158159        _messages.clear();
     160        _acceptedPending.clear();
    159161        if (_sessionKeyManager != null)
    160162            _sessionKeyManager.shutdown();
     
    500502    boolean getIsDead() { return _dead; }
    501503
     504    /**
     505     *  Not thread-safe. Blocking. Only used for external sockets.
     506     *  ClientWriterRunner thread is the only caller.
     507     *  Others must use doSend().
     508     */
    502509    void writeMessage(I2CPMessage msg) {
    503         long before = _context.clock().now();
     510        //long before = _context.clock().now();
    504511        try {
    505             // We don't still need synchronization here? isn't ClientWriterRunner the only writer?
    506             synchronized (_out) {
     512            // We don't need synchronization here, ClientWriterRunner is the only writer.
     513            //synchronized (_out) {
    507514                msg.writeMessage(_out);
    508515                _out.flush();
    509             }
    510             if (_log.shouldLog(Log.DEBUG))
    511                 _log.debug("after writeMessage("+ msg.getClass().getName() + "): "
    512                            + (_context.clock().now()-before) + "ms");
     516            //}
     517            //if (_log.shouldLog(Log.DEBUG))
     518            //    _log.debug("after writeMessage("+ msg.getClass().getName() + "): "
     519            //               + (_context.clock().now()-before) + "ms");
    513520        } catch (I2CPMessageException ime) {
    514521            _log.error("Error sending I2CP message to client", ime);
     
    526533            _log.log(Log.CRIT, "Unhandled exception sending I2CP message to client", t);
    527534            stopRunning();
    528         } finally {
    529             long after = _context.clock().now();
    530             long lag = after - before;
    531             if (lag > 300) {
    532                 if (_log.shouldLog(Log.WARN))
    533                     _log.warn("synchronization on the i2cp message send took too long (" + lag
    534                               + "ms): " + msg);
    535             }
     535        //} finally {
     536        //    long after = _context.clock().now();
     537        //    long lag = after - before;
     538        //    if (lag > 300) {
     539        //        if (_log.shouldLog(Log.WARN))
     540        //            _log.warn("synchronization on the i2cp message send took too long (" + lag
     541        //                      + "ms): " + msg);
     542        //    }
    536543        }
    537544    }
     
    544551        if (_out == null) throw new I2CPMessageException("Output stream is not initialized");
    545552        if (msg == null) throw new I2CPMessageException("Null message?!");
    546         if (_log.shouldLog(Log.DEBUG)) {
    547             if ( (_config == null) || (_config.getDestination() == null) )
    548                 _log.debug("before doSend of a "+ msg.getClass().getName()
    549                            + " message on for establishing i2cp con");
    550             else
    551                 _log.debug("before doSend of a "+ msg.getClass().getName()
    552                            + " message on for "
    553                            + _config.getDestination().calculateHash().toBase64());
    554         }
     553        //if (_log.shouldLog(Log.DEBUG)) {
     554        //    if ( (_config == null) || (_config.getDestination() == null) )
     555        //        _log.debug("before doSend of a "+ msg.getClass().getName()
     556        //                   + " message on for establishing i2cp con");
     557        //    else
     558        //        _log.debug("before doSend of a "+ msg.getClass().getName()
     559        //                   + " message on for "
     560        //                   + _config.getDestination().calculateHash().toBase64());
     561        //}
    555562        _writer.addMessage(msg);
    556         if (_log.shouldLog(Log.DEBUG)) {
    557             if ( (_config == null) || (_config.getDestination() == null) )
    558                 _log.debug("after doSend of a "+ msg.getClass().getName()
    559                            + " message on for establishing i2cp con");
    560             else
    561                 _log.debug("after doSend of a "+ msg.getClass().getName()
    562                            + " message on for "
    563                            + _config.getDestination().calculateHash().toBase64());
    564         }
     563        //if (_log.shouldLog(Log.DEBUG)) {
     564        //    if ( (_config == null) || (_config.getDestination() == null) )
     565        //        _log.debug("after doSend of a "+ msg.getClass().getName()
     566        //                   + " message on for establishing i2cp con");
     567        //    else
     568        //        _log.debug("after doSend of a "+ msg.getClass().getName()
     569        //                   + " message on for "
     570        //                   + _config.getDestination().calculateHash().toBase64());
     571        //}
    565572    }
    566573   
  • router/java/src/net/i2p/router/client/ClientManager.java

    re02d8298 rd9e6c06  
    142142
    143143    public void registerConnection(ClientConnectionRunner runner) {
    144         synchronized (_pendingRunners) {
    145             _pendingRunners.add(runner);
    146         }
    147         runner.startRunning();
     144        try {
     145            runner.startRunning();
     146            synchronized (_pendingRunners) {
     147                _pendingRunners.add(runner);
     148            }
     149        } catch (IOException ioe) {
     150            _log.error("Error starting up the runner", ioe);
     151            runner.stopRunning();
     152        }
    148153    }
    149154   
  • router/java/src/net/i2p/router/client/ClientWriterRunner.java

    re02d8298 rd9e6c06  
    1616 * happen)
    1717 *
     18 * For external I2CP connections only.
    1819 */
    1920class ClientWriterRunner implements Runnable {
    2021    private final BlockingQueue<I2CPMessage> _messagesToWrite;
    2122    private final ClientConnectionRunner _runner;
    22     private final Log _log;
    23     private final long _id;
    24     private static long __id = 0;
     23    //private final Log _log;
     24    //private final long _id;
     25    //private static long __id = 0;
    2526
    2627    private static final int QUEUE_SIZE = 256;
    2728   
    2829    public ClientWriterRunner(RouterContext context, ClientConnectionRunner runner) {
    29         _log = context.logManager().getLog(ClientWriterRunner.class);
     30        //_log = context.logManager().getLog(ClientWriterRunner.class);
    3031        _messagesToWrite = new LinkedBlockingQueue(QUEUE_SIZE);
    3132        _runner = runner;
    32         _id = ++__id;
     33        //_id = ++__id;
    3334    }
    3435
Note: See TracChangeset for help on using the changeset viewer.