put crawler_*.properties in temp dir and add session id prefix

This commit is contained in:
Shinsuke Sugaya 2016-01-05 23:08:59 +09:00
parent 2ccddc8381
commit 32d92e9397
3 changed files with 16 additions and 10 deletions

View file

@ -364,4 +364,8 @@ public class Constants extends CoreLibConstants {
public static final String LDAP_INITIAL_CONTEXT_FACTORY = "ldap.initial.context.factory";
public static final String LDAP_ACCOUNT_FILTER = "ldap.account.filter";
public static final String CRAWLER_SESSION_ID_PREFIX = "C";
public static final String SUGGEST_SESSION_ID_PREFIX = "S";
}

View file

@ -166,7 +166,7 @@ public class CrawlJob {
if (sessionId == null) { // create session id
final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
sessionId = sdf.format(new Date());
sessionId = Constants.CRAWLER_SESSION_ID_PREFIX + sdf.format(new Date());
}
resultBuf.append("Session Id: ").append(sessionId).append("\n");
resultBuf.append("Web Config Id:");
@ -344,11 +344,10 @@ public class CrawlJob {
cmdList.add(Integer.toString(documentExpires));
}
File propFile = null;
try {
cmdList.add("-p");
File propFile =
new File(ownTmpDir != null ? ownTmpDir.getAbsolutePath() : tmpDir, "crawler_" + systemHelper.getCurrentTimeAsLong()
+ ".properties");
propFile = File.createTempFile("crawler_", ".properties");
cmdList.add(propFile.getAbsolutePath());
try (FileOutputStream out = new FileOutputStream(propFile)) {
Properties prop = new Properties();
@ -392,6 +391,9 @@ public class CrawlJob {
try {
jobHelper.destroyProcess(sessionId);
} finally {
if (propFile != null && !propFile.delete()) {
logger.warn("Failed to delete {}.", propFile.getAbsolutePath());
}
deleteTempDir(ownTmpDir);
}
}

View file

@ -32,7 +32,6 @@ import org.codelibs.fess.Constants;
import org.codelibs.fess.exception.FessSystemException;
import org.codelibs.fess.exec.SuggestCreator;
import org.codelibs.fess.helper.JobHelper;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.codelibs.fess.util.ComponentUtil;
import org.codelibs.fess.util.InputStreamThread;
@ -100,7 +99,7 @@ public class SuggestJob {
if (sessionId == null) { // create session id
final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
sessionId = sdf.format(new Date());
sessionId = Constants.SUGGEST_SESSION_ID_PREFIX + sdf.format(new Date());
}
resultBuf.append("Session Id: ").append(sessionId).append("\n");
if (jobExecutor != null) {
@ -123,7 +122,6 @@ public class SuggestJob {
final List<String> cmdList = new ArrayList<>();
final String cpSeparator = SystemUtils.IS_OS_WINDOWS ? ";" : ":";
final ServletContext servletContext = SingletonLaContainer.getComponent(ServletContext.class);
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final JobHelper jobHelper = ComponentUtil.getJobHelper();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
@ -218,11 +216,10 @@ public class SuggestJob {
cmdList.add("--sessionId");
cmdList.add(sessionId);
File propFile = null;
try {
cmdList.add("-p");
File propFile =
new File(ownTmpDir != null ? ownTmpDir.getAbsolutePath() : tmpDir, "crawler_" + systemHelper.getCurrentTimeAsLong()
+ ".properties");
propFile = File.createTempFile("crawler_", ".properties");
cmdList.add(propFile.getAbsolutePath());
try (FileOutputStream out = new FileOutputStream(propFile)) {
Properties prop = new Properties();
@ -266,6 +263,9 @@ public class SuggestJob {
try {
jobHelper.destroyProcess(sessionId);
} finally {
if (propFile != null && !propFile.delete()) {
logger.warn("Failed to delete {}.", propFile.getAbsolutePath());
}
deleteTempDir(ownTmpDir);
}
}