Changeset ca6ce37


Ignore:
Timestamp:
Mar 21, 2017 7:26:48 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
4727706
Parents:
a00f11d
Message:

context: New ClientAppManagerImpl? in AppContext?, so registration
works there (for i2psnark-rpc in standalone)

Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/I2PAppContext.java

    ra00f11d rca6ce37  
    99
    1010import net.i2p.app.ClientAppManager;
     11import net.i2p.app.ClientAppManagerImpl;
    1112import net.i2p.client.naming.NamingService;
    1213import net.i2p.crypto.AESEngine;
     
    117118    private volatile File _tmpDir;
    118119    private final Random _tmpDirRand = new Random();
     120    private final ClientAppManager _appManager;
    119121    // split up big lock on this to avoid deadlocks
    120122    private final Object _lock1 = new Object(), _lock2 = new Object(), _lock3 = new Object(), _lock4 = new Object(),
     
    199201        _shutdownTasks = new ConcurrentHashSet<Runnable>(32);
    200202        _portMapper = new PortMapper(this);
     203        _appManager = isRouterContext() ? null : new ClientAppManagerImpl(this);
    201204   
    202205   /*
     
    10081011
    10091012    /**
    1010      *  The RouterAppManager in RouterContext, null always in I2PAppContext
    1011      *  @return null always
     1013     *  As of 0.9.30, returns non-null in I2PAppContext, null in RouterContext.
     1014     *  Prior to that, returned null always.
     1015     *  Overridden in RouterContext to return the RouterAppManager.
     1016     *
     1017     *  @return As of 0.9.30, returns non-null in I2PAppContext, null in RouterContext
    10121018     *  @since 0.9.11, in RouterContext since 0.9.4
    10131019     */
  • router/java/src/net/i2p/router/startup/RouterAppManager.java

    ra00f11d rca6ce37  
    2323 *  @since 0.9.4
    2424 */
    25 public class RouterAppManager implements ClientAppManager {
     25public class RouterAppManager extends ClientAppManagerImpl {
    2626   
    2727    private final RouterContext _context;
     
    3030    // this assumes clients do not override equals()
    3131    private final ConcurrentHashMap<ClientApp, String[]> _clients;
    32     // registered name to client
    33     private final ConcurrentHashMap<String, ClientApp> _registered;
    3432
    3533    public RouterAppManager(RouterContext ctx) {
     34        super(ctx);
    3635        _context = ctx;
    3736        _log = ctx.logManager().getLog(RouterAppManager.class);
    3837        _clients = new ConcurrentHashMap<ClientApp, String[]>(16);
    39         _registered = new ConcurrentHashMap<String, ClientApp>(8);
    4038        ctx.addShutdownTask(new Shutdown());
    4139    }
     
    9290     *  @param e may be null
    9391     */
     92    @Override
    9493    public void notify(ClientApp app, ClientAppState state, String message, Exception e) {
    9594        switch(state) {
     
    138137     *  @return true if successful, false if duplicate name
    139138     */
     139    @Override
    140140    public boolean register(ClientApp app) {
    141141        if (!_clients.containsKey(app)) {
     
    149149            _log.info("Client " + app.getDisplayName() + " REGISTERED AS " + app.getName());
    150150        // TODO if old app in there is not running and != this app, allow replacement
    151         return _registered.putIfAbsent(app.getName(), app) == null;
     151        return super.register(app);
    152152    }
    153153   
    154     /**
    155      *  Unregister with the manager. Name must be the same as that from register().
    156      *  Only required for apps used by other apps.
    157      *
    158      *  @param app non-null
    159      */
    160     public void unregister(ClientApp app) {
    161         _registered.remove(app.getName(), app);
    162     }
    163    
    164     /**
    165      *  Get a registered app.
    166      *  Only used for apps finding other apps.
    167      *  Do not hold a static reference.
    168      *  If you only need to find a port, use the PortMapper instead.
    169      *
    170      *  @param name non-null
    171      *  @return client app or null
    172      */
    173     public ClientApp getRegisteredApp(String name) {
    174         return _registered.get(name);
    175     }
    176 
    177154    /// end ClientAppManager interface
    178155
Note: See TracChangeset for help on using the changeset viewer.