use the context to find a location for the sessionKeys.dat file (router.sessionKeys.location=filename in router.config)

This commit is contained in:
jrandom
2004-04-26 01:09:10 +00:00
committed by zzz
parent 52ece833a7
commit f80f02da73

View File

@ -18,7 +18,8 @@ public class SessionKeyPersistenceHelper implements Service {
private Log _log; private Log _log;
private RouterContext _context; private RouterContext _context;
private final static long PERSIST_DELAY = 3*60*1000; private final static long PERSIST_DELAY = 3*60*1000;
private final static String SESSION_KEY_FILE = "sessionKeys.dat"; private final static String PROP_SESSION_KEY_FILE = "router.sessionKeys.location";
private final static String DEFAULT_SESSION_KEY_FILE = "sessionKeys.dat";
public SessionKeyPersistenceHelper(RouterContext context) { public SessionKeyPersistenceHelper(RouterContext context) {
_context = context; _context = context;
@ -29,11 +30,18 @@ public class SessionKeyPersistenceHelper implements Service {
writeState(); writeState();
} }
private String getKeyFile() {
String val = _context.router().getConfigSetting(PROP_SESSION_KEY_FILE);
if (val == null)
val = DEFAULT_SESSION_KEY_FILE;
return val;
}
public void startup() { public void startup() {
SessionKeyManager mgr = _context.sessionKeyManager(); SessionKeyManager mgr = _context.sessionKeyManager();
if (mgr instanceof PersistentSessionKeyManager) { if (mgr instanceof PersistentSessionKeyManager) {
PersistentSessionKeyManager manager = (PersistentSessionKeyManager)mgr; PersistentSessionKeyManager manager = (PersistentSessionKeyManager)mgr;
File f = new File(SESSION_KEY_FILE); File f = new File(getKeyFile());
if (f.exists()) { if (f.exists()) {
FileInputStream fin = null; FileInputStream fin = null;
try { try {
@ -69,7 +77,7 @@ public class SessionKeyPersistenceHelper implements Service {
if (expired > 0) { if (expired > 0) {
_log.info("Agressive expired " + expired + " tag sets"); _log.info("Agressive expired " + expired + " tag sets");
} }
fos = new FileOutputStream(SESSION_KEY_FILE); fos = new FileOutputStream(getKeyFile());
mgr.saveState(fos); mgr.saveState(fos);
fos.flush(); fos.flush();
_log.debug("Session keys written"); _log.debug("Session keys written");