Changeset a8976d2 for router


Ignore:
Timestamp:
Nov 12, 2016 11:10:55 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
0108c1c
Parents:
6a72c29
Message:

Profiles: Delete old ones after saving (ticket #1328)

Location:
router/java/src/net/i2p/router/peermanager
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/peermanager/PeerManager.java

    r6a72c29 ra8976d2  
    5858    private static final long REORGANIZE_TIME_LONG = 351*1000;
    5959    private static final long STORE_TIME = 19*60*60*1000;
     60    private static final long EXPIRE_AGE = 3*24*60*60*1000;
    6061   
    6162    public static final String TRACKED_CAPS = "" +
     
    103104
    104105    /**
    105      *  Reorganize the profiles. Also periodically store them.
     106     *  Reorganize the profiles. Also periodically store them,
     107     *  and delete very old ones.
    106108     *
    107109     *  This takes too long to run on the SimpleTimer2 queue
     
    132134                    _log.debug("Periodic profile store start");
    133135                    storeProfiles();
     136                    _persistenceHelper.deleteOldProfiles(EXPIRE_AGE);
    134137                    _log.debug("Periodic profile store end");
    135138                } catch (Throwable t) {
  • router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java

    r6a72c29 ra8976d2  
    230230    }
    231231   
     232    /**
     233     *  Delete profile files with timestamps older than 'age' ago
     234     *  @since 0.9.28
     235     */
     236    public void deleteOldProfiles(long age) {
     237        long cutoff = System.currentTimeMillis() - age;
     238        List<File> files = selectFiles();
     239        int i = 0;
     240        for (File f :  files) {
     241            if (!f.isFile())
     242                continue;
     243            if (f.lastModified() < cutoff) {
     244                i++;
     245                f.delete();
     246            }
     247        }
     248        if (_log.shouldWarn())
     249            _log.warn("Deleted " + i + " old profiles");
     250    }
     251
    232252    private boolean isExpired(long lastSentToSuccessfully) {
    233253        long timeSince = _context.clock().now() - lastSentToSuccessfully;
Note: See TracChangeset for help on using the changeset viewer.