Changeset 65c61864


Ignore:
Timestamp:
Jan 13, 2011 2:21:48 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
b55bfd03, c92a885
Parents:
4c1050b
Message:

Cleanups: Collections.singleton(), COWAS - includes ticket #388

Files:
15 edited

Legend:

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

    r4c1050b r65c61864  
    4444import java.net.UnknownHostException;
    4545import java.util.ArrayList;
    46 import java.util.HashSet;
    4746import java.util.Iterator;
    4847import java.util.LinkedList;
     
    5150import java.util.Set;
    5251import java.util.StringTokenizer;
     52import java.util.concurrent.CopyOnWriteArraySet;
    5353
    5454import net.i2p.I2PAppContext;
     
    100100    private int next_task_id = 1;
    101101
    102     private final Set listeners = new HashSet();
     102    private final Set listeners = new CopyOnWriteArraySet();
    103103
    104104    public static void main(String[] args) throws IOException {
     
    16271627    public void addConnectionEventListener(ConnectionEventListener lsnr) {
    16281628        if (lsnr == null) return;
    1629         synchronized (listeners) {
    1630             listeners.add(lsnr);
    1631         }
     1629        listeners.add(lsnr);
    16321630    }
    16331631
    16341632    public void removeConnectionEventListener(ConnectionEventListener lsnr) {
    16351633        if (lsnr == null) return;
    1636         synchronized (listeners) {
    1637             listeners.remove(lsnr);
    1638         }
     1634        listeners.remove(lsnr);
    16391635    }
    16401636   
     
    16501646    void routerDisconnected() {
    16511647        _log.error(getPrefix() + "Router disconnected - firing notification events");
    1652         synchronized (listeners) {
    16531648            for (Iterator iter = listeners.iterator(); iter.hasNext();) {
    16541649                ConnectionEventListener lsnr = (ConnectionEventListener) iter.next();
    16551650                if (lsnr != null) lsnr.routerDisconnected();
    16561651            }
    1657         }
    16581652    }
    16591653
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelControllerGroup.java

    r4c1050b r65c61864  
    311311            Set<TunnelController> owners = _sessions.get(session);
    312312            if (owners == null) {
    313                 owners = new HashSet(1);
     313                owners = new HashSet(2);
    314314                _sessions.put(session, owners);
    315315            }
  • apps/streaming/java/src/net/i2p/client/streaming/MessageHandler.java

    r4c1050b r65c61864  
    33import java.util.Iterator;
    44import java.util.Set;
     5import java.util.concurrent.CopyOnWriteArraySet;
    56
    67import net.i2p.I2PAppContext;
     
    910import net.i2p.client.I2PSessionListener;
    1011import net.i2p.util.Log;
    11 import net.i2p.util.ConcurrentHashSet;
    1212
    1313/**
     
    2525        _manager = mgr;
    2626        _context = ctx;
    27         _listeners = new ConcurrentHashSet(1);
     27        _listeners = new CopyOnWriteArraySet();
    2828        _log = ctx.logManager().getLog(MessageHandler.class);
    2929        _context.statManager().createRateStat("stream.packetReceiveFailure", "When do we fail to decrypt or otherwise receive a packet sent to us?", "Stream", new long[] { 60*60*1000, 24*60*60*1000 });
  • core/java/src/net/i2p/crypto/ElGamalAESEngine.java

    r4c1050b r65c61864  
    1111
    1212import java.util.ArrayList;
     13import java.util.Collections;
    1314import java.util.HashSet;
    1415import java.util.Iterator;
     
    528529    }
    529530
    530     private final static Set EMPTY_SET = new HashSet();
    531 
    532531    /**
    533532     * For both scenarios, this method encrypts the AES area using the given key, iv
     
    553552        //_log.debug("iv for encryption: " + DataHelper.toString(iv, 16));
    554553        //_log.debug("Encrypting AES");
    555         if (tagsForDelivery == null) tagsForDelivery = EMPTY_SET;
     554        if (tagsForDelivery == null) tagsForDelivery = Collections.EMPTY_SET;
    556555        int size = 2 // sizeof(tags)
    557556                 + tagsForDelivery.size()
  • core/java/src/net/i2p/util/Clock.java

    r4c1050b r65c61864  
    11package net.i2p.util;
    22
    3 import java.util.HashSet;
    43import java.util.Iterator;
    54import java.util.Set;
     5import java.util.concurrent.CopyOnWriteArraySet;
    66
    77import net.i2p.I2PAppContext;
     
    2020 */
    2121public class Clock implements Timestamper.UpdateListener {
    22     protected I2PAppContext _context;
    23     private Timestamper _timestamper;
    24     protected long _startedOn;
     22    protected final I2PAppContext _context;
     23    private final Timestamper _timestamper;
     24    protected final long _startedOn;
    2525    protected boolean _statCreated;
     26    protected volatile long _offset;
     27    protected boolean _alreadyChanged;
     28    private final Set _listeners;
    2629   
    2730    public Clock(I2PAppContext context) {
    2831        _context = context;
    29         _offset = 0;
    30         _alreadyChanged = false;
    31         _listeners = new HashSet(1);
     32        _listeners = new CopyOnWriteArraySet();
    3233        _timestamper = new Timestamper(context, this);
    3334        _startedOn = System.currentTimeMillis();
    34         _statCreated = false;
    3535    }
    3636    public static Clock getInstance() {
     
    4242    /** we fetch it on demand to avoid circular dependencies (logging uses the clock) */
    4343    protected Log getLog() { return _context.logManager().getLog(Clock.class); }
    44    
    45     protected volatile long _offset;
    46     protected boolean _alreadyChanged;
    47     private final Set _listeners;
    4844
    4945    /** if the clock is skewed by 3+ days, fuck 'em */
     
    137133
    138134    public void addUpdateListener(ClockUpdateListener lsnr) {
    139         synchronized (_listeners) {
    140135            _listeners.add(lsnr);
    141         }
    142136    }
    143137
    144138    public void removeUpdateListener(ClockUpdateListener lsnr) {
    145         synchronized (_listeners) {
    146139            _listeners.remove(lsnr);
    147         }
    148140    }
    149141
    150142    protected void fireOffsetChanged(long delta) {
    151         synchronized (_listeners) {
    152143            for (Iterator iter = _listeners.iterator(); iter.hasNext();) {
    153144                ClockUpdateListener lsnr = (ClockUpdateListener) iter.next();
    154145                lsnr.offsetChanged(delta);
    155146            }
    156         }
    157147    }
    158148
  • core/java/src/net/i2p/util/I2PAppThread.java

    r4c1050b r65c61864  
    1111
    1212
    13 import java.util.HashSet;
    1413import java.util.Iterator;
    1514import java.util.Set;
     15import java.util.concurrent.CopyOnWriteArraySet;
    1616
    1717/**
     
    2323public class I2PAppThread extends I2PThread {
    2424
    25     private Set _threadListeners = new HashSet(0);
     25    private final Set _threadListeners = new CopyOnWriteArraySet();
    2626
    2727    public I2PAppThread() {
  • core/java/src/net/i2p/util/I2PThread.java

    r4c1050b r65c61864  
    1111
    1212
    13 import java.util.HashSet;
    1413import java.util.Iterator;
    1514import java.util.Set;
     15import java.util.concurrent.CopyOnWriteArraySet;
    1616
    1717/**
     
    2222public class I2PThread extends Thread {
    2323    private static volatile Log _log;
    24     private static Set _listeners = new HashSet(4);
     24    private static final Set _listeners = new CopyOnWriteArraySet();
    2525    private String _name;
    2626    private Exception _createdBy;
  • router/java/src/net/i2p/router/OutNetMessage.java

    r4c1050b r65c61864  
    226226    public void transportFailed(String transportStyle) {
    227227        if (_failedTransports == null)
    228             _failedTransports = new HashSet(1);
     228            _failedTransports = new HashSet(2);
    229229        _failedTransports.add(transportStyle);
    230230    }
  • router/java/src/net/i2p/router/RouterClock.java

    r4c1050b r65c61864  
    3535    private int _lastStratum;
    3636
    37     RouterContext _contextRC; // LINT field hides another field
     37    private final RouterContext _contextRC;
    3838
    3939    public RouterClock(RouterContext context) {
  • router/java/src/net/i2p/router/Shitlist.java

    r4c1050b r65c61864  
    157157        e.transports = null;
    158158        if (transport != null) {
    159             e.transports = new ConcurrentHashSet(1);
     159            e.transports = new ConcurrentHashSet(2);
    160160            e.transports.add(transport);
    161161        }
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java

    r4c1050b r65c61864  
    7575    List<Hash> selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet kbuckets, boolean preferConnected) {
    7676        if (peersToIgnore == null)
    77             peersToIgnore = new HashSet(1);
    78         peersToIgnore.add(_context.routerHash());
     77            peersToIgnore = Collections.singleton(_context.routerHash());
     78        else
     79            peersToIgnore.add(_context.routerHash());
    7980        // TODO this is very slow
    8081        FloodfillSelectionCollector matches = new FloodfillSelectionCollector(key, peersToIgnore, maxNumRouters);
     
    9596     */
    9697    List<Hash> selectFloodfillParticipants(KBucketSet kbuckets) {
    97         Set<Hash> ignore = new HashSet(1);
    98         ignore.add(_context.routerHash());
     98        Set<Hash> ignore = Collections.singleton(_context.routerHash());
    9999        return selectFloodfillParticipants(ignore, kbuckets);
    100100    }
     
    133133     */
    134134    List<Hash> selectFloodfillParticipants(Hash key, int maxNumRouters, KBucketSet kbuckets) {
    135         Set<Hash> ignore = new HashSet(1);
    136         ignore.add(_context.routerHash());
     135        Set<Hash> ignore = Collections.singleton(_context.routerHash());
    137136        return selectFloodfillParticipants(key, maxNumRouters, ignore, kbuckets);
    138137    }
     
    153152    List<Hash> selectFloodfillParticipants(Hash key, int howMany, Set<Hash> toIgnore, KBucketSet kbuckets) {
    154153        if (toIgnore == null) {
    155             toIgnore = new HashSet(1);
    156             toIgnore.add(_context.routerHash());
     154            toIgnore = Collections.singleton(_context.routerHash());
    157155        } else if (!toIgnore.contains(_context.routerHash())) {
    158156            // copy the Set so we don't confuse StoreJob
  • router/java/src/net/i2p/router/networkdb/kademlia/PeerSelector.java

    r4c1050b r65c61864  
    3232 */
    3333class PeerSelector {
    34     protected Log _log;
    35     protected RouterContext _context;
     34    protected final Log _log;
     35    protected final RouterContext _context;
    3636   
    3737    public PeerSelector(RouterContext ctx) {
  • router/java/src/net/i2p/router/networkdb/kademlia/SearchJob.java

    r4c1050b r65c61864  
    1010
    1111import java.util.ArrayList;
    12 import java.util.HashSet;
     12import java.util.Collections;
    1313import java.util.Iterator;
    1414import java.util.List;
     
    801801            if (_log.shouldLog(Log.DEBUG))
    802802                _log.debug(getJobId() + ": Queueing up for next time: " + peer);
    803             Set s = new HashSet(1);
    804             s.add(peer);
     803            Set<Hash> s = Collections.singleton(peer);
    805804            _facade.queueForExploration(s);
    806805        }
  • router/java/src/net/i2p/router/peermanager/PeerManager.java

    r4c1050b r65c61864  
    1212import java.io.Writer;
    1313import java.util.ArrayList;
     14import java.util.Collections;
    1415import java.util.HashSet;
    1516import java.util.Iterator;
     
    116117    List<Hash> selectPeers(PeerSelectionCriteria criteria) {
    117118        Set<Hash> peers = new HashSet(criteria.getMinimumRequired());
    118         Set<Hash> exclude = new HashSet(1);
    119         exclude.add(_context.routerHash());
     119        Set<Hash> exclude = Collections.singleton(_context.routerHash());
    120120        switch (criteria.getPurpose()) {
    121121            case PeerSelectionCriteria.PURPOSE_TEST:
  • router/java/src/net/i2p/router/tunnel/pool/TestJob.java

    r4c1050b r65c61864  
    11package net.i2p.router.tunnel.pool;
    22
    3 import java.util.HashSet;
     3import java.util.Collections;
    44import java.util.Set;
    55
     
    145145            return;
    146146        }
    147         Set encryptTags = new HashSet(1);
    148         encryptTags.add(encryptTag);
     147        Set<SessionTag> encryptTags = Collections.singleton(encryptTag);
    149148        // Register the single tag with the appropriate SKM
    150149        if (_cfg.isInbound() && !_pool.getSettings().isExploratory()) {
Note: See TracChangeset for help on using the changeset viewer.