Changeset 9d2816f4


Ignore:
Timestamp:
Jul 9, 2011 2:30:33 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
5402bd0
Parents:
b41c5834
Message:
  • Use a different lock for the executor than for shared clients so shutdown doesn't hang
  • Javadocs
Location:
apps/i2ptunnel/java/src/net/i2p/i2ptunnel
Files:
3 edited

Legend:

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

    rb41c5834 r9d2816f4  
    8686    private static volatile ThreadPoolExecutor _executor;
    8787    private static int _executorThreadCount;
    88 
     88    private static final Object _executorLock = new Object();
     89
     90    /**
     91     *  This constructor always starts the tunnel (ignoring the i2cp.delayOpen option).
     92     *  It is used to add a client to an existing socket manager.
     93     *
     94     *  @param sktMgr the existing socket manager
     95     */
    8996    public I2PTunnelClientBase(int localPort, Logging l, I2PSocketManager sktMgr,
    9097            I2PTunnel tunnel, EventDispatcher notifyThis, long clientId )
     
    105112        _log = _context.logManager().getLog(getClass());
    106113
    107         synchronized (I2PTunnelClientBase.class) {
     114        synchronized (_executorLock) {
    108115            if (_executor == null)
    109116                _executor = new CustomThreadPoolExecutor();
     
    111118
    112119        Thread t = new I2PAppThread(this, "Client " + tunnel.listenHost + ':' + localPort);
    113         listenerReady = false;
    114120        t.start();
    115121        open = true;
     
    133139    }
    134140
     141    /**
     142     * The main constructor.
     143     * This may take a LONG time if building and starting a new manager.
     144     *
     145     * @throws IllegalArgumentException if the I2CP configuration is b0rked so
     146     *                                  badly that we can't create a socketManager
     147     */
    135148    public I2PTunnelClientBase(int localPort, boolean ownDest, Logging l,
    136149                               EventDispatcher notifyThis, String handlerName,
     
    140153
    141154    /**
    142      * @param pkf null to generate a transient key
    143      *
    144      * @throws IllegalArgumentException if the I2CP configuration is b0rked so
    145      *                                  badly that we cant create a socketManager
     155     * Use this to build a client with a persistent private key.
     156     * This may take a LONG time if building and starting a new manager.
     157     *
     158     * @param pkf Path to the private key file, or null to generate a transient key
     159     *
     160     * @throws IllegalArgumentException if the I2CP configuration is b0rked so
     161     *                                  badly that we can't create a socketManager
    146162     */
    147163    public I2PTunnelClientBase(int localPort, boolean ownDest, Logging l,
     
    163179        _log = _context.logManager().getLog(getClass());
    164180
    165         synchronized (I2PTunnelClientBase.class) {
     181        synchronized (_executorLock) {
    166182            if (_executor == null)
    167183                _executor = new CustomThreadPoolExecutor();
     
    201217        Thread t = new I2PAppThread(this);
    202218        t.setName("Client " + _clientId);
    203         listenerReady = false;
    204219        t.start();
    205220        open = true;
     
    227242   
    228243    /**
    229      * Sets the this.sockMgr field if it is null, or if we want a new one
     244     * Sets the this.sockMgr field if it is null, or if we want a new one.
     245     * This may take a LONG time if building a new manager.
    230246     *
    231247     * We need a socket manager before getDefaultOptions() and most other things
     
    266282
    267283    /**
    268      * this is ONLY for shared clients
     284     * This is ONLY for shared clients.
     285     * This may take a LONG time if building a new manager.
     286     *
    269287     * @return non-null
    270288     * @throws IllegalArgumentException if the I2CP configuration is b0rked so
    271289     *                                  badly that we cant create a socketManager
    272290     */
    273     protected synchronized I2PSocketManager getSocketManager() {
     291    protected I2PSocketManager getSocketManager() {
    274292        return getSocketManager(getTunnel(), this.privKeyFile);
    275293    }
    276294
    277295    /**
    278      * this is ONLY for shared clients
     296     * This is ONLY for shared clients.
     297     * This may take a LONG time if building a new manager.
     298     *
    279299     * @return non-null
    280300     * @throws IllegalArgumentException if the I2CP configuration is b0rked so
    281301     *                                  badly that we cant create a socketManager
    282302     */
    283     protected static synchronized I2PSocketManager getSocketManager(I2PTunnel tunnel) {
     303    protected static I2PSocketManager getSocketManager(I2PTunnel tunnel) {
    284304        return getSocketManager(tunnel, null);
    285305    }
    286306
    287307    /**
    288      * this is ONLY for shared clients
     308     * This is ONLY for shared clients.
     309     * This may take a LONG time if building a new manager.
     310     *
    289311     * @return non-null
    290312     * @throws IllegalArgumentException if the I2CP configuration is b0rked so
     
    301323                if (s != null)
    302324                    tunnel.removeSession(s);
     325                // We could be here a LONG time, holding the lock
    303326                socketManager = buildSocketManager(tunnel, pkf);
    304327            } else {
     
    315338
    316339    /**
     340     * This may take a LONG time.
     341     *
    317342     * @return non-null
    318343     * @throws IllegalArgumentException if the I2CP configuration is b0rked so
     
    323348    }
    324349    /**
     350     * This may take a LONG time.
     351     *
    325352     * @return non-null
    326353     * @throws IllegalArgumentException if the I2CP configuration is b0rked so
     
    335362
    336363    /**
     364     * This may take a LONG time.
     365     *
    337366     * @param pkf absolute path or null
    338367     * @return non-null
     
    345374
    346375    /**
     376     * This may take a LONG time.
     377     *
    347378     * @param pkf absolute path or null
    348379     * @return non-null
     
    365396       
    366397        I2PSocketManager sockManager = null;
    367         // Todo: Can't stop a tunnel from the UI while it's in this loop (no session yet)
     398        // FIXME: Can't stop a tunnel from the UI while it's in this loop (no session yet)
    368399        int retries = 0;
    369400        while (sockManager == null) {
     
    571602     */
    572603    static void killClientExecutor() {
    573         synchronized (I2PTunnelClientBase.class) {
     604        synchronized (_executorLock) {
    574605            if (_executor != null) {
    575606                _executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java

    rb41c5834 r9d2816f4  
    186186        .getBytes();
    187187
     188    /**
     189     *  This constructor always starts the tunnel (ignoring the i2cp.delayOpen option).
     190     *  It is used to add a client to an existing socket manager.
     191     *
     192     *  @param sktMgr the existing socket manager
     193     */
    188194    public I2PTunnelHTTPClient(int localPort, Logging l, I2PSocketManager sockMgr, I2PTunnel tunnel, EventDispatcher notifyThis, long clientId) {
    189195        super(localPort, l, sockMgr, tunnel, notifyThis, clientId);
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientBase.java

    rb41c5834 r9d2816f4  
    6767    }
    6868
     69    /**
     70     *  This constructor always starts the tunnel (ignoring the i2cp.delayOpen option).
     71     *  It is used to add a client to an existing socket manager.
     72     *
     73     *  @param sktMgr the existing socket manager
     74     */
    6975    public I2PTunnelHTTPClientBase(int localPort, Logging l, I2PSocketManager sktMgr,
    7076            I2PTunnel tunnel, EventDispatcher notifyThis, long clientId )
Note: See TracChangeset for help on using the changeset viewer.