
com.jaeksoft.searchlib.script.commands.ExecutionCommands Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensearchserver Show documentation
Show all versions of opensearchserver Show documentation
OpenSearchServer is a powerful, enterprise-class, search engine program. Using the web user interface,
the crawlers (web, file, database, ...) and the REST/RESTFul API you will be able to integrate quickly and
easily advanced full-text search capabilities in your application. OpenSearchServer runs on Windows and
Linux/Unix/BSD.
The newest version!
/**
* License Agreement for OpenSearchServer
*
* Copyright (C) 2013 Emmanuel Keller / Jaeksoft
*
* http://www.open-search-server.com
*
* This file is part of OpenSearchServer.
*
* OpenSearchServer is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenSearchServer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenSearchServer.
* If not, see .
**/
package com.jaeksoft.searchlib.script.commands;
import java.util.ArrayList;
import java.util.List;
import com.jaeksoft.searchlib.script.CommandAbstract;
import com.jaeksoft.searchlib.script.CommandEnum;
import com.jaeksoft.searchlib.script.ScriptCommandContext;
import com.jaeksoft.searchlib.script.ScriptCommandContext.OnError;
import com.jaeksoft.searchlib.script.ScriptException;
import com.jaeksoft.searchlib.util.ThreadUtils;
import com.jaeksoft.searchlib.util.ThreadUtils.WaitInterface;
public class ExecutionCommands {
public static class SleepCommand extends CommandAbstract {
public SleepCommand() {
super(CommandEnum.SLEEP);
}
@Override
public void run(ScriptCommandContext context, String id,
String... parameters) throws ScriptException {
checkParameters(1, parameters);
int sec = Integer.parseInt(parameters[0].toString());
if (context.callback instanceof WaitInterface)
ThreadUtils.waitUntil(sec, (WaitInterface) context.callback);
else
ThreadUtils.sleepMs(sec * 1000);
}
}
public static class ScriptCommand extends CommandAbstract {
public ScriptCommand() {
super(CommandEnum.SCRIPT);
}
@Override
public void run(ScriptCommandContext context, String id,
String... parameters) throws ScriptException {
checkParameters(1, parameters);
String scriptName = getParameterString(0);
context.subscript(scriptName, null);
}
}
public static class OnErrorCommand extends CommandAbstract {
public OnErrorCommand() {
super(CommandEnum.ON_ERROR);
}
@Override
public void run(ScriptCommandContext context, String id,
String... parameters) throws ScriptException {
checkParameters(1, parameters);
OnError onError = OnError.valueOf(getParameterString(0));
switch (onError) {
case FAILURE:
case RESUME:
context.setOnError(onError, null);
break;
case NEXT_COMMAND:
checkParameters(2, parameters);
List commands = new ArrayList(0);
for (int i = 1; i < parameters.length; i++) {
String p = parameters[i];
if (p == null)
continue;
p = p.trim();
if (p.length() == 0)
continue;
commands.add(CommandEnum.find(p));
}
context.setOnError(onError, commands);
break;
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy