Changeset 61749aa


Ignore:
Timestamp:
Sep 27, 2008 10:59:22 PM (12 years ago)
Author:
sponge <sponge@…>
Branches:
master
Children:
5913d9e
Parents:
b0313bd6
Message:

Added Simple true/false storage class to the utilities
Added socketSoTimeout
CHANGED RetransmissionTimer? is now public
FIXED SimpleTimer? has a way to be stopped, and reap it's children
CLEANUP A few javadoc additions, where I could figgure out bits
CLEANUP all code that needed to catch the timeout exception for socketSoTimeout

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java

    rb0313bd6 r61749aa  
    1313import java.net.Socket;
    1414import java.net.SocketException;
     15import java.net.SocketTimeoutException;
    1516import java.util.Iterator;
    1617import java.util.Properties;
     
    220221                        _log.error("Error accepting", ce);
    221222                    // not killing the server..
     223                } catch(SocketTimeoutException ste) {
     224                    // ignored, we never set the timeout
    222225                }
    223226            }
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PServerSocket.java

    rb0313bd6 r61749aa  
    33import java.net.ConnectException;
    44
     5import java.net.SocketTimeoutException;
    56import net.i2p.I2PException;
    67
     
    2526     *         from the data available (aka the I2PSession closed, etc)
    2627     * @throws ConnectException if the I2PServerSocket is closed
     28     * @throws SocketTimeoutException
    2729     */
    28     public I2PSocket accept() throws I2PException, ConnectException;
     30    public I2PSocket accept() throws I2PException, ConnectException, SocketTimeoutException;
     31
     32    /**
     33     * Set Sock Option accept timeout
     34     * @param x
     35     */
     36    public void setSoTimeout(long x);
     37
     38    /**
     39     * Get Sock Option accept timeout
     40     * @return timeout
     41     */
     42    public long getSoTimeout();
    2943
    3044    /**
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PServerSocketImpl.java

    rb0313bd6 r61749aa  
    3131    private Object socketAddedLock = new Object();
    3232   
     33    /**
     34     * Set Sock Option accept timeout stub, does nothing
     35     * @param x
     36     */
     37    public void setSoTimeout(long x) {
     38    }
     39
     40    /**
     41     * Get Sock Option accept timeout stub, does nothing
     42     * @return timeout
     43     */
     44    public long getSoTimeout() {
     45        return -1;
     46    }
     47
    3348    public I2PServerSocketImpl(I2PSocketManager mgr) {
    3449        this.mgr = mgr;
  • apps/ministreaming/java/src/net/i2p/client/streaming/StreamSinkServer.java

    rb0313bd6 r61749aa  
    66import java.io.InputStream;
    77import java.net.ConnectException;
     8import java.net.SocketTimeoutException;
    89import java.util.Properties;
    910
     
    108109                    _log.error("Connection already dropped", ce);
    109110                    return;
     111                } catch(SocketTimeoutException ste) {
     112                    // ignored
    110113                }       
    111114            }
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionManager.java

    rb0313bd6 r61749aa  
    4040    private volatile int _numWaiting;
    4141    private Object _connectionLock;
     42    private long SoTimeout;
    4243   
    4344    public ConnectionManager(I2PAppContext context, I2PSession session, int maxConcurrent, ConnectionOptions defaultOptions) {
     
    5960        _defaultOptions = defaultOptions;
    6061        _numWaiting = 0;
     62        /** Socket timeout for accept() */
     63        SoTimeout = -1;
     64
    6165        _context.statManager().createRateStat("stream.con.lifetimeMessagesSent", "How many messages do we send on a stream?", "Stream", new long[] { 60*60*1000, 24*60*60*1000 });
    6266        _context.statManager().createRateStat("stream.con.lifetimeMessagesReceived", "How many messages do we receive on a stream?", "Stream", new long[] { 60*60*1000, 24*60*60*1000 });
     
    9195    }
    9296   
     97    /**
     98     * Set the socket accept() timeout.
     99     * @param x
     100     */
     101    public void MsetSoTimeout(long x) {
     102        SoTimeout = x;
     103    }
     104
     105    /**
     106     * Get the socket accept() timeout.
     107     * @return
     108     */
     109    public long MgetSoTimeout() {
     110        return SoTimeout;
     111    }
     112
    93113    public void setAllowIncomingConnections(boolean allow) {
    94114        _connectionHandler.setActive(allow);
  • apps/streaming/java/src/net/i2p/client/streaming/I2PServerSocketFull.java

    rb0313bd6 r61749aa  
    11package net.i2p.client.streaming;
    22
     3import java.net.SocketTimeoutException;
     4import java.util.logging.Level;
     5import java.util.logging.Logger;
    36import net.i2p.I2PException;
    47
     
    1417    }
    1518   
    16     public I2PSocket accept() throws I2PException {
     19    /**
     20     *
     21     * @return
     22     * @throws net.i2p.I2PException
     23     * @throws SocketTimeoutException
     24     */
     25    public I2PSocket accept() throws I2PException, SocketTimeoutException {
    1726        return _socketManager.receiveSocket();
    1827    }
    1928   
    20     public void close() { _socketManager.getConnectionManager().setAllowIncomingConnections(false); }
     29    public long getSoTimeout() {
     30        return _socketManager.getConnectionManager().MgetSoTimeout();
     31    }
    2132   
    22     public I2PSocketManager getManager() { return _socketManager; }
     33    public void setSoTimeout(long x) {
     34        _socketManager.getConnectionManager().MsetSoTimeout(x);
     35    }
     36    /**
     37     * Close the connection.
     38     */
     39    public void close() {
     40        _socketManager.getConnectionManager().setAllowIncomingConnections(false);
     41    }
     42
     43    /**
     44     *
     45     * @return _socketManager
     46     */
     47    public I2PSocketManager getManager() {
     48        return _socketManager;
     49    }
    2350}
  • apps/streaming/java/src/net/i2p/client/streaming/I2PSocketManagerFull.java

    rb0313bd6 r61749aa  
    22
    33import java.net.NoRouteToHostException;
     4import java.net.SocketTimeoutException;
    45import java.util.HashSet;
    56import java.util.Iterator;
     
    4546        _session = null;
    4647    }
     48
     49    /**
     50     *
     51     * @param context
     52     * @param session
     53     * @param opts
     54     * @param name
     55     */
    4756    public I2PSocketManagerFull(I2PAppContext context, I2PSession session, Properties opts, String name) {
    4857        this();
     
    5564    /**
    5665     *
     66     *
     67     * @param context
     68     * @param session
     69     * @param opts
     70     * @param name
    5771     */
    5872    public void init(I2PAppContext context, I2PSession session, Properties opts, String name) {
     
    97111    }
    98112
    99     public I2PSocket receiveSocket() throws I2PException {
     113    /**
     114     *
     115     * @return
     116     * @throws net.i2p.I2PException
     117     * @throws java.net.SocketTimeoutException
     118     */
     119    public I2PSocket receiveSocket() throws I2PException, SocketTimeoutException {
    100120        verifySession();
    101         Connection con = _connectionManager.getConnectionHandler().accept(-1);
    102         if (_log.shouldLog(Log.DEBUG))
     121        Connection con = _connectionManager.getConnectionHandler().accept(_connectionManager.MgetSoTimeout());
     122        if(_log.shouldLog(Log.DEBUG)) {
    103123            _log.debug("receiveSocket() called: " + con);
     124        }
    104125        if (con != null) {
    105126            I2PSocketFull sock = new I2PSocketFull(con);
     
    107128            return sock;
    108129        } else {
     130            if(_connectionManager.MgetSoTimeout() == -1) {
    109131            return null;
     132        }
     133            throw new SocketTimeoutException("I2PSocket timed out");
    110134        }
    111135    }
     
    115139     * the timeout specified, false otherwise.  This call blocks.
    116140     *
     141     *
     142     * @param peer
     143     * @param timeoutMs
     144     * @return
    117145     */
    118146    public boolean ping(Destination peer, long timeoutMs) {
  • apps/streaming/java/src/net/i2p/client/streaming/RetransmissionTimer.java

    rb0313bd6 r61749aa  
    66 *
    77 */
    8 class RetransmissionTimer extends SimpleTimer {
     8public class RetransmissionTimer extends SimpleTimer {
    99    private static final RetransmissionTimer _instance = new RetransmissionTimer();
    1010    public static final SimpleTimer getInstance() { return _instance; }
  • core/java/src/net/i2p/util/Executor.java

    rb0313bd6 r61749aa  
    99    private Log _log;
    1010    private List _readyEvents;
    11     public Executor(I2PAppContext ctx, Log log, List events) {
     11    private SimpleStore runn;
     12
     13    public Executor(I2PAppContext ctx, Log log, List events, SimpleStore x) {
    1214        _context = ctx;
    1315        _readyEvents = events;
     16        runn = x;
    1417    }
     18
    1519    public void run() {
    16         while (true) {
     20        while(runn.getAnswer()) {
    1721            SimpleTimer.TimedEvent evt = null;
    1822            synchronized (_readyEvents) {
  • core/java/src/net/i2p/util/SimpleTimer.java

    rb0313bd6 r61749aa  
    2626    private Map _eventTimes;
    2727    private List _readyEvents;
    28    
     28    private SimpleStore runn;
     29
    2930    protected SimpleTimer() { this("SimpleTimer"); }
    3031    protected SimpleTimer(String name) {
     32        runn = new SimpleStore(true);
    3133        _context = I2PAppContext.getGlobalContext();
    3234        _log = _context.logManager().getLog(SimpleTimer.class);
     
    3941        runner.start();
    4042        for (int i = 0; i < 3; i++) {
    41             I2PThread executor = new I2PThread(new Executor(_context, _log, _readyEvents));
     43            I2PThread executor = new I2PThread(new Executor(_context, _log, _readyEvents, runn));
    4244            executor.setName(name + "Executor " + i);
    4345            executor.setDaemon(true);
     
    4648    }
    4749   
     50    /**
     51     * Removes the SimpleTimer.
     52     */
     53    public void removeSimpleTimer() {
     54        synchronized(_events) {
     55            runn.setAnswer(false);
     56            _events.notifyAll();
     57        }
     58    }
     59
     60    /**
     61     *
     62     * @param event
     63     * @param timeoutMs
     64     */
    4865    public void reschedule(TimedEvent event, long timeoutMs) {
    4966        addEvent(event, timeoutMs, false);
     
    5673     * timeout.  If this is not the desired behavior, call removeEvent first.
    5774     *
     75     * @param event
     76     * @param timeoutMs
    5877     */
    5978    public void addEvent(TimedEvent event, long timeoutMs) { addEvent(event, timeoutMs, true); }
    6079    /**
     80     * @param event
     81     * @param timeoutMs
    6182     * @param useEarliestTime if its already scheduled, use the earlier of the
    6283     *                        two timeouts, else use the later
     
    144165    private long _occurredTime;
    145166    private long _occurredEventCount;
    146     private TimedEvent _recentEvents[] = new TimedEvent[5];
    147    
     167    // not used
     168    //  private TimedEvent _recentEvents[] = new TimedEvent[5];
    148169    private class SimpleTimerRunner implements Runnable {
    149170        public void run() {
    150171            List eventsToFire = new ArrayList(1);
    151             while (true) {
     172            while(runn.getAnswer()) {
    152173                try {
    153174                    synchronized (_events) {
     
    159180                        long nextEventDelay = -1;
    160181                        Object nextEvent = null;
    161                         while (true) {
    162                             if (_events.size() <= 0) break;
     182                        while(runn.getAnswer()) {
     183                            if(_events.size() <= 0) {
     184                                break;
     185                            }
    163186                            Long when = (Long)_events.firstKey();
    164187                            if (when.longValue() <= now) {
Note: See TracChangeset for help on using the changeset viewer.