Added new execute function that takes a timeout as parameter in order to set the timeout for the connection when executing the command

This commit is contained in:
matgr 2017-05-11 12:53:16 +02:00
parent 1f9eef7d02
commit fac39aff0d
2 changed files with 15 additions and 0 deletions

View File

@ -85,6 +85,16 @@ public abstract class ApiConnection implements AutoCloseable {
*/ */
public abstract List<Map<String, String>> execute(String cmd) throws MikrotikApiException; public abstract List<Map<String, String>> execute(String cmd) throws MikrotikApiException;
/**
* execute a command and return a list of results.
*
* @param cmd Command to execute
* @param timeout The connection timeout to use when executing the command.
* @return The list of results
* @throws me.legrange.mikrotik.MikrotikApiException Thrown if the API encounters an error executing a command.
*/
public abstract List<Map<String, String>> execute(String cmd, int timeout) throws MikrotikApiException;
/** /**
* execute a command and attach a result listener to receive it's results. * execute a command and attach a result listener to receive it's results.
* *

View File

@ -67,6 +67,11 @@ public final class ApiConnectionImpl extends ApiConnection {
return execute(Parser.parse(cmd), timeout); return execute(Parser.parse(cmd), timeout);
} }
@Override
public List<Map<String, String>> execute(String cmd, int timeout) throws MikrotikApiException {
return execute(Parser.parse(cmd), timeout);
}
@Override @Override
public String execute(String cmd, ResultListener lis) throws MikrotikApiException { public String execute(String cmd, ResultListener lis) throws MikrotikApiException {
return execute(Parser.parse(cmd), lis); return execute(Parser.parse(cmd), lis);