Changeset 5bb90c6


Ignore:
Timestamp:
Aug 20, 2012 6:28:20 PM (7 years ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
ddc1d7c
Parents:
9452547
Message:
  • Fixed the FIXME in createInstance where the method failed to ensures that there will be only one naming service instance.
File:
1 edited

Legend:

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

    r9452547 r5bb90c6  
    3131    protected final Set<NamingServiceListener> _listeners;
    3232    protected final Set<NamingServiceUpdater> _updaters;
     33
     34    private static NamingService instance;
    3335
    3436    /** what classname should be used as the naming service impl? */
     
    452454     * property.
    453455     *
    454      * FIXME Actually, it doesn't ensure that. Only call this once!!!
    455456     */
    456457    public static final synchronized NamingService createInstance(I2PAppContext context) {
    457         NamingService instance = null;
    458         String impl = context.getProperty(PROP_IMPL, DEFAULT_IMPL);
     458        if (instance instanceof NamingService) {
     459            return instance;
     460        }
     461        String impl = context.getProperty(PROP_IMPL, DEFAULT_IMPL);
    459462        try {
    460463            Class cls = Class.forName(impl);
    461464            Constructor con = cls.getConstructor(new Class[] { I2PAppContext.class });
    462465            instance = (NamingService)con.newInstance(new Object[] { context });
    463         } catch (Exception ex) {
    464             Log log = context.logManager().getLog(NamingService.class);
    465             // Blockfile may throw RuntimeException but HostsTxt won't
    466             if (!impl.equals(BACKUP_IMPL)) {
    467                 log.error("Cannot load naming service " + impl + ", using HostsTxtNamingService", ex);
    468                 instance = new HostsTxtNamingService(context);
    469             } else {
    470                 log.error("Cannot load naming service " + impl + ", only .b32.i2p lookups will succeed", ex);
    471                 instance = new DummyNamingService(context);
    472             }
    473         }
     466        } catch (Exception ex) { 
     467            Log log = context.logManager().getLog(NamingService.class); 
     468            // Blockfile may throw RuntimeException but HostsTxt won't 
     469            if (!impl.equals(BACKUP_IMPL)) { 
     470                log.error("Cannot load naming service " + impl + ", using HostsTxtNamingService", ex); 
     471                instance = new HostsTxtNamingService(context); 
     472            } else { 
     473                log.error("Cannot load naming service " + impl + ", only .b32.i2p lookups will succeed", ex); 
     474                instance = new DummyNamingService(context); 
     475            } 
     476        } 
    474477        return instance;
    475478    }
Note: See TracChangeset for help on using the changeset viewer.