public abstract class ApiConnection extends Object implements AutoCloseable
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_COMMAND_TIMEOUT
default command timeout used for synchronous commands
|
static int |
DEFAULT_CONNECTION_TIMEOUT
default connection timeout to use when opening the connection
|
static int |
DEFAULT_PORT
default TCP port used by Mikrotik API
|
static int |
DEFAULT_TLS_PORT
default TCP TLS port used by Mikrotik API
|
| Constructor and Description |
|---|
ApiConnection() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
cancel(String tag)
cancel a command
|
abstract void |
close()
Disconnect from the remote API
|
static ApiConnection |
connect(SocketFactory fact,
String host,
int port,
int timeout)
Create a new API connection to the give device on the supplied port using
the supplied socket factory to create the socket.
|
static ApiConnection |
connect(String host)
Create a new API connection to the give device on the default API port.
|
abstract List<Map<String,String>> |
execute(String cmd)
execute a command and return a list of results.
|
abstract String |
execute(String cmd,
ResultListener lis)
execute a command and attach a result listener to receive it's results.
|
abstract boolean |
isConnected()
Check the state of connection.
|
abstract void |
login(String username,
String password)
Log in to the remote router.
|
abstract void |
setTimeout(int timeout)
set the command timeout.
|
public static final int DEFAULT_PORT
public static final int DEFAULT_TLS_PORT
public static final int DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_COMMAND_TIMEOUT
public static ApiConnection connect(SocketFactory fact, String host, int port, int timeout) throws MikrotikApiException
fact - SocketFactory to use for TCP socket creation.host - The host to which to connect.port - The TCP port to use.timeout - The connection timeout to use when opening the connection.MikrotikApiException - Thrown if there is a
problem connectingpublic static ApiConnection connect(String host) throws MikrotikApiException
host - The host to which to connect.MikrotikApiException - Thrown if there is a
problem connectingpublic abstract boolean isConnected()
public abstract void login(String username, String password) throws MikrotikApiException
username - - username of the user on the routerpassword - - password for the userMikrotikApiException - Thrown if the API encounters an error on login.public abstract List<Map<String,String>> execute(String cmd) throws MikrotikApiException
cmd - Command to executeMikrotikApiException - Thrown if the API encounters an error executing a command.public abstract String execute(String cmd, ResultListener lis) throws MikrotikApiException
cmd - Command to executelis - ResultListener that will receive the resultsMikrotikApiException - Thrown if the API encounters an error executing a command.public abstract void cancel(String tag) throws MikrotikApiException
tag - The tag of the command to cancelMikrotikApiException - Thrown if there is a
problem cancelling the commandpublic abstract void setTimeout(int timeout)
throws MikrotikApiException
timeout - The time out in milliseconds.MikrotikApiException - Thrown if the timeout specified is invalid.public abstract void close()
throws ApiConnectionException
close in interface AutoCloseableApiConnectionException - Thrown if there is a
problem closing the connection.Copyright © 2018. All rights reserved.