From d40bb459ea9e1ed6ef4a48d7052b5db0357062b3 Mon Sep 17 00:00:00 2001 From: ragnarok <ragnarok> Date: Sun, 18 Sep 2005 22:36:10 +0000 Subject: [PATCH] * Get the PetNameDB for the PetNameNamingService from the router context. --- core/java/src/net/i2p/I2PAppContext.java | 17 +++++++++++++++++ .../i2p/client/naming/PetNameNamingService.java | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/java/src/net/i2p/I2PAppContext.java b/core/java/src/net/i2p/I2PAppContext.java index ac4996d638..0ae7279bed 100644 --- a/core/java/src/net/i2p/I2PAppContext.java +++ b/core/java/src/net/i2p/I2PAppContext.java @@ -5,6 +5,7 @@ import java.util.Properties; import java.util.Set; import net.i2p.client.naming.NamingService; +import net.i2p.client.naming.PetNameDB; import net.i2p.crypto.AESEngine; import net.i2p.crypto.CryptixAESEngine; import net.i2p.crypto.DSAEngine; @@ -60,6 +61,7 @@ public class I2PAppContext { private StatManager _statManager; private SessionKeyManager _sessionKeyManager; private NamingService _namingService; + private PetNameDB _petnameDb; private ElGamalEngine _elGamalEngine; private ElGamalAESEngine _elGamalAESEngine; private AESEngine _AESEngine; @@ -74,6 +76,7 @@ public class I2PAppContext { private volatile boolean _statManagerInitialized; private volatile boolean _sessionKeyManagerInitialized; private volatile boolean _namingServiceInitialized; + private volatile boolean _petnameDbInitialized; private volatile boolean _elGamalEngineInitialized; private volatile boolean _elGamalAESEngineInitialized; private volatile boolean _AESEngineInitialized; @@ -128,6 +131,7 @@ public class I2PAppContext { _statManager = null; _sessionKeyManager = null; _namingService = null; + _petnameDb = null; _elGamalEngine = null; _elGamalAESEngine = null; _logManager = null; @@ -237,6 +241,19 @@ public class I2PAppContext { } } + public PetNameDB petnameDb() { + if (!_petnameDbInitialized) initializePetnameDb(); + return _petnameDb; + } + private void initializePetnameDb() { + synchronized (this) { + if (_petnameDb == null) { + _petnameDb = new PetNameDB(); + } + _petnameDbInitialized = true; + } + } + /** * This is the ElGamal engine used within this context. While it doesn't * really have anything substantial that is context specific (the algorithm diff --git a/core/java/src/net/i2p/client/naming/PetNameNamingService.java b/core/java/src/net/i2p/client/naming/PetNameNamingService.java index 164498d4a7..9a2446aba3 100644 --- a/core/java/src/net/i2p/client/naming/PetNameNamingService.java +++ b/core/java/src/net/i2p/client/naming/PetNameNamingService.java @@ -17,7 +17,7 @@ public class PetNameNamingService extends NamingService { public PetNameNamingService(I2PAppContext context) { super(context); - _petnameDb = new PetNameDB(); + _petnameDb = _context.petnameDb(); String file = _context.getProperty(PROP_PETNAME_FILE, DEFAULT_PETNAME_FILE); //If the petnamedb file doesn't exist, create it, using the -- GitLab