forked from I2P_Developers/i2p.i2p
* PeerManager: Load profiles in separate thread to avoid slowing
down the context initAll()
This commit is contained in:
@ -53,9 +53,8 @@ class PeerManager {
|
|||||||
private static final long REORGANIZE_TIME_LONG = 551*1000;
|
private static final long REORGANIZE_TIME_LONG = 551*1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Warning - this loads all the profiles in the constructor.
|
* Profiles are now loaded in a separate thread,
|
||||||
* This may take a long time - 30 seconds or more.
|
* so this should return quickly.
|
||||||
* Instantiate this in a Job or Thread.
|
|
||||||
*/
|
*/
|
||||||
public PeerManager(RouterContext context) {
|
public PeerManager(RouterContext context) {
|
||||||
_context = context;
|
_context = context;
|
||||||
@ -67,10 +66,10 @@ class PeerManager {
|
|||||||
_peersByCapability = new Set[26];
|
_peersByCapability = new Set[26];
|
||||||
for (int i = 0; i < _peersByCapability.length; i++)
|
for (int i = 0; i < _peersByCapability.length; i++)
|
||||||
_peersByCapability[i] = new ConcurrentHashSet();
|
_peersByCapability[i] = new ConcurrentHashSet();
|
||||||
loadProfiles();
|
loadProfilesInBackground();
|
||||||
////_context.jobQueue().addJob(new EvaluateProfilesJob(_context));
|
////_context.jobQueue().addJob(new EvaluateProfilesJob(_context));
|
||||||
//SimpleScheduler.getInstance().addPeriodicEvent(new Reorg(), 0, REORGANIZE_TIME);
|
//SimpleScheduler.getInstance().addPeriodicEvent(new Reorg(), 0, REORGANIZE_TIME);
|
||||||
new Reorg();
|
//new Reorg();
|
||||||
//_context.jobQueue().addJob(new PersistProfilesJob(_context, this));
|
//_context.jobQueue().addJob(new PersistProfilesJob(_context, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +123,30 @@ class PeerManager {
|
|||||||
_persistenceHelper.writeProfile(prof);
|
_persistenceHelper.writeProfile(prof);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the profiles in a separate thread, so we don't spend
|
||||||
|
* forever in the constructor (slowing down the Router constructor
|
||||||
|
* via RouterContext.initAll()).
|
||||||
|
* This also instantiates Reorg, so only call this once
|
||||||
|
*
|
||||||
|
* @since 0.8.8
|
||||||
|
*/
|
||||||
|
private void loadProfilesInBackground() {
|
||||||
|
(new Thread(new ProfileLoader())).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the profiles and instantiate Reorg
|
||||||
|
*
|
||||||
|
* @since 0.8.8
|
||||||
|
*/
|
||||||
|
private class ProfileLoader implements Runnable {
|
||||||
|
public void run() {
|
||||||
|
loadProfiles();
|
||||||
|
new Reorg();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This may take a long time - 30 seconds or more
|
* This may take a long time - 30 seconds or more
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user