Search in sources :

Example 6 with TimeoutTask

use of org.codelibs.core.timer.TimeoutTask in project fess by codelibs.

the class PythonJob method execute.

@Override
public String execute() {
    final StringBuilder resultBuf = new StringBuilder();
    if (sessionId == null) {
        // create session id
        sessionId = RandomStringUtils.randomAlphabetic(15);
    }
    resultBuf.append("Session Id: ").append(sessionId).append("\n");
    if (jobExecutor != null) {
        jobExecutor.addShutdownListener(() -> ComponentUtil.getProcessHelper().destroyProcess(sessionId));
    }
    final TimeoutTask timeoutTask = createTimeoutTask();
    try {
        executePython();
    } catch (final Exception e) {
        logger.warn("Failed to run python command.", e);
        resultBuf.append(e.getMessage()).append("\n");
    } finally {
        if (timeoutTask != null && !timeoutTask.isCanceled()) {
            timeoutTask.cancel();
        }
    }
    return resultBuf.toString();
}
Also used : JobProcessingException(org.codelibs.fess.exception.JobProcessingException) TimeoutTask(org.codelibs.core.timer.TimeoutTask)

Example 7 with TimeoutTask

use of org.codelibs.core.timer.TimeoutTask in project fess-crawler by codelibs.

the class FileSystemClient method processRequest.

protected ResponseData processRequest(final String uri, final boolean includeContent) {
    if (!isInit.get()) {
        synchronized (isInit) {
            if (!isInit.get()) {
                init();
                isInit.set(true);
            }
        }
    }
    // start
    AccessTimeoutTarget accessTimeoutTarget = null;
    TimeoutTask accessTimeoutTask = null;
    if (accessTimeout != null) {
        accessTimeoutTarget = new AccessTimeoutTarget(Thread.currentThread());
        accessTimeoutTask = TimeoutManager.getInstance().addTimeoutTarget(accessTimeoutTarget, accessTimeout.intValue(), false);
    }
    try {
        return getResponseData(uri, includeContent);
    } finally {
        if (accessTimeout != null) {
            accessTimeoutTarget.stop();
            if (!accessTimeoutTask.isCanceled()) {
                accessTimeoutTask.cancel();
            }
        }
    }
}
Also used : AccessTimeoutTarget(org.codelibs.fess.crawler.client.AccessTimeoutTarget) TimeoutTask(org.codelibs.core.timer.TimeoutTask)

Example 8 with TimeoutTask

use of org.codelibs.core.timer.TimeoutTask in project fess-crawler by codelibs.

the class HcHttpClient method doHttpMethod.

public ResponseData doHttpMethod(final String url, final HttpUriRequest httpRequest) {
    if (httpClient == null) {
        init();
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Accessing " + url);
    }
    // start
    AccessTimeoutTarget accessTimeoutTarget = null;
    TimeoutTask accessTimeoutTask = null;
    if (accessTimeout != null) {
        accessTimeoutTarget = new AccessTimeoutTarget(Thread.currentThread());
        accessTimeoutTask = TimeoutManager.getInstance().addTimeoutTarget(accessTimeoutTarget, accessTimeout.intValue(), false);
    }
    try {
        return processHttpMethod(url, httpRequest);
    } finally {
        if (accessTimeout != null) {
            accessTimeoutTarget.stop();
            if (!accessTimeoutTask.isCanceled()) {
                accessTimeoutTask.cancel();
            }
        }
    }
}
Also used : AccessTimeoutTarget(org.codelibs.fess.crawler.client.AccessTimeoutTarget) TimeoutTask(org.codelibs.core.timer.TimeoutTask)

Example 9 with TimeoutTask

use of org.codelibs.core.timer.TimeoutTask in project fess-crawler by codelibs.

the class SmbClient method processRequest.

protected ResponseData processRequest(final String uri, final boolean includeContent) {
    if (smbAuthenticationHolder == null) {
        init();
    }
    // start
    AccessTimeoutTarget accessTimeoutTarget = null;
    TimeoutTask accessTimeoutTask = null;
    if (accessTimeout != null) {
        accessTimeoutTarget = new AccessTimeoutTarget(Thread.currentThread());
        accessTimeoutTask = TimeoutManager.getInstance().addTimeoutTarget(accessTimeoutTarget, accessTimeout.intValue(), false);
    }
    try {
        return getResponseData(uri, includeContent);
    } finally {
        if (accessTimeout != null) {
            accessTimeoutTarget.stop();
            if (!accessTimeoutTask.isCanceled()) {
                accessTimeoutTask.cancel();
            }
        }
    }
}
Also used : AccessTimeoutTarget(org.codelibs.fess.crawler.client.AccessTimeoutTarget) TimeoutTask(org.codelibs.core.timer.TimeoutTask)

Example 10 with TimeoutTask

use of org.codelibs.core.timer.TimeoutTask in project fess by codelibs.

the class CrawlJob method execute.

@Override
public String execute() {
    // check # of crawler processes
    final int maxCrawlerProcesses = ComponentUtil.getFessConfig().getJobMaxCrawlerProcessesAsInteger();
    if (maxCrawlerProcesses > 0) {
        final int runningJobCount = getRunningJobCount();
        if (runningJobCount > maxCrawlerProcesses) {
            throw new JobProcessingException(runningJobCount + " crawler processes are running. Max processes are " + maxCrawlerProcesses + ".");
        }
    }
    final StringBuilder resultBuf = new StringBuilder(100);
    final boolean runAll = webConfigIds == null && fileConfigIds == null && dataConfigIds == null;
    if (sessionId == null) {
        // create session id
        final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        sessionId = sdf.format(new Date());
    }
    resultBuf.append("Session Id: ").append(sessionId).append("\n");
    resultBuf.append("Web  Config Id:");
    if (webConfigIds == null) {
        if (runAll) {
            resultBuf.append(" ALL\n");
        } else {
            resultBuf.append(" NONE\n");
        }
    } else {
        for (final String id : webConfigIds) {
            resultBuf.append(' ').append(id);
        }
        resultBuf.append('\n');
    }
    resultBuf.append("File Config Id:");
    if (fileConfigIds == null) {
        if (runAll) {
            resultBuf.append(" ALL\n");
        } else {
            resultBuf.append(" NONE\n");
        }
    } else {
        for (final String id : fileConfigIds) {
            resultBuf.append(' ').append(id);
        }
        resultBuf.append('\n');
    }
    resultBuf.append("Data Config Id:");
    if (dataConfigIds == null) {
        if (runAll) {
            resultBuf.append(" ALL\n");
        } else {
            resultBuf.append(" NONE\n");
        }
    } else {
        for (final String id : dataConfigIds) {
            resultBuf.append(' ').append(id);
        }
        resultBuf.append('\n');
    }
    if (jobExecutor != null) {
        jobExecutor.addShutdownListener(() -> ComponentUtil.getProcessHelper().destroyProcess(sessionId));
    }
    final TimeoutTask timeoutTask = createTimeoutTask();
    try {
        executeCrawler();
        ComponentUtil.getKeyMatchHelper().update();
    } catch (final JobProcessingException e) {
        throw e;
    } catch (final Exception e) {
        throw new JobProcessingException("Failed to execute a crawl job.", e);
    } finally {
        if (timeoutTask != null && !timeoutTask.isCanceled()) {
            timeoutTask.cancel();
        }
    }
    return resultBuf.toString();
}
Also used : JobProcessingException(org.codelibs.fess.exception.JobProcessingException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) TimeoutTask(org.codelibs.core.timer.TimeoutTask)

Aggregations

TimeoutTask (org.codelibs.core.timer.TimeoutTask)13 AccessTimeoutTarget (org.codelibs.fess.crawler.client.AccessTimeoutTarget)5 JobProcessingException (org.codelibs.fess.exception.JobProcessingException)4 ContainerNotAvailableException (org.codelibs.fess.exception.ContainerNotAvailableException)3 SystemMonitorTarget (org.codelibs.fess.timer.SystemMonitorTarget)3 CmdLineException (org.kohsuke.args4j.CmdLineException)3 CmdLineParser (org.kohsuke.args4j.CmdLineParser)3 GenericExternalContext (org.lastaflute.di.core.external.GenericExternalContext)3 GenericExternalContextComponentDefRegister (org.lastaflute.di.core.external.GenericExternalContextComponentDefRegister)3 IOException (java.io.IOException)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Header (org.apache.http.Header)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 BasicHeader (org.apache.http.message.BasicHeader)1 InterruptedRuntimeException (org.codelibs.core.exception.InterruptedRuntimeException)1