Renamed examples

This commit is contained in:
Gideon le Grange 2015-12-31 18:30:02 +02:00
parent 5d081c8c88
commit 0b80064e46
11 changed files with 22 additions and 48 deletions

View File

@ -7,10 +7,10 @@ import me.legrange.mikrotik.MikrotikApiException;
* *
* @author gideon * @author gideon
*/ */
public class Example6 extends Example { public class AddAndModify extends Example {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
Example6 ex = new Example6(); AddAndModify ex = new AddAndModify();
ex.connect(); ex.connect();
ex.test(); ex.test();
ex.disconnect(); ex.disconnect();

View File

@ -9,10 +9,10 @@ import me.legrange.mikrotik.ResultListener;
* *
* @author gideon * @author gideon
*/ */
public class Example4 extends Example { public class AsyncCommand extends Example {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
Example4 ex = new Example4(); AsyncCommand ex = new AsyncCommand();
ex.connect(); ex.connect();
ex.test(); ex.test();
ex.disconnect(); ex.disconnect();

View File

@ -9,10 +9,10 @@ import me.legrange.mikrotik.ResultListener;
* *
* @author gideon * @author gideon
*/ */
public class Example5 extends Example { public class AsyncWithErrorHandling extends Example {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
Example5 ex = new Example5(); AsyncWithErrorHandling ex = new AsyncWithErrorHandling();
ex.connect(); ex.connect();
ex.test(); ex.test();
ex.disconnect(); ex.disconnect();
@ -23,6 +23,7 @@ public class Example5 extends Example {
String id = con.execute("/interface/wireless/monitor .id=wlan1", new ResultListener() { String id = con.execute("/interface/wireless/monitor .id=wlan1", new ResultListener() {
private int prev = 0; private int prev = 0;
@Override
public void receive(Map<String, String> result) { public void receive(Map<String, String> result) {
int val = Integer.parseInt(result.get("signal-strength")); int val = Integer.parseInt(result.get("signal-strength"));
String sym = (val == prev) ? " " : ((val < prev) ? "-" : "+"); String sym = (val == prev) ? " " : ((val < prev) ? "-" : "+");
@ -30,11 +31,13 @@ public class Example5 extends Example {
prev = val; prev = val;
} }
@Override
public void error(MikrotikApiException ex) { public void error(MikrotikApiException ex) {
System.out.printf("An error ocurred: %s\n", ex.getMessage()); System.out.printf("An error ocurred: %s\n", ex.getMessage());
ex.printStackTrace(); ex.printStackTrace();
} }
@Override
public void completed() { public void completed() {
System.out.printf("The request has been completed\n"); System.out.printf("The request has been completed\n");
} }

View File

@ -9,10 +9,10 @@ import me.legrange.mikrotik.MikrotikApiException;
* *
* @author gideon * @author gideon
*/ */
public class Example3 extends Example { public class CommandWithWhere extends Example {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
Example3 ex = new Example3(); CommandWithWhere ex = new CommandWithWhere();
ex.connect(); ex.connect();
ex.test(); ex.test();
ex.disconnect(); ex.disconnect();

View File

@ -8,8 +8,8 @@ public class Config {
public static final String HOST = "192.168.1.34"; public static final String HOST = "192.168.1.34";
public static final String USERNAME = "admin"; public static final String USERNAME = "gideon";
public static final String PASSWORD = ""; public static final String PASSWORD = "minapp";
} }

View File

@ -9,10 +9,10 @@ import me.legrange.mikrotik.MikrotikApiException;
* *
* @author gideon * @author gideon
*/ */
public class Example7 extends Example { public class DownloadConfig extends Example {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
Example7 ex = new Example7(); DownloadConfig ex = new DownloadConfig();
ex.connect(); ex.connect();
ex.test(); ex.test();
ex.disconnect(); ex.disconnect();

View File

@ -1,28 +0,0 @@
package examples;
import java.util.List;
import java.util.Map;
import me.legrange.mikrotik.MikrotikApiException;
/**
* Example 7: Dump your complete config
*
* @author gideon
*/
public class Example8 extends Example {
public static void main(String... args) throws Exception {
Example8 ex = new Example8();
ex.connect();
ex.test();
ex.disconnect();
}
private void test() throws MikrotikApiException, InterruptedException {
List<Map<String, String>> res = con.execute("/ip/hotspot/user/print where uptime!=1");
for (Map<String, String> r : res) {
System.out.println(r);
}
// con.execute("/ip/firewall/filter/add chain=forward hotspot=!auth protocol=tcp src-port=8000-8084");
}
}

View File

@ -6,10 +6,10 @@ import me.legrange.mikrotik.MikrotikApiException;
* Example 1: A very simple command: Reboot the remote router * Example 1: A very simple command: Reboot the remote router
* @author gideon * @author gideon
*/ */
public class Example1 extends Example { public class SimpleCommand extends Example {
public static void main(String...args) throws Exception { public static void main(String...args) throws Exception {
Example1 ex = new Example1(); SimpleCommand ex = new SimpleCommand();
ex.connect(); ex.connect();
ex.test(); ex.test();
ex.disconnect(); ex.disconnect();

View File

@ -9,10 +9,10 @@ import me.legrange.mikrotik.MikrotikApiException;
* *
* @author gideon * @author gideon
*/ */
public class Example2 extends Example { public class SimpleCommandWithResults extends Example {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
Example2 ex = new Example2(); SimpleCommandWithResults ex = new SimpleCommandWithResults();
ex.connect(); ex.connect();
ex.test(); ex.test();
ex.disconnect(); ex.disconnect();

View File

@ -1,7 +1,5 @@
package examples; package examples;
import java.util.List;
import java.util.Map;
import me.legrange.mikrotik.ApiConnection; import me.legrange.mikrotik.ApiConnection;
import me.legrange.mikrotik.MikrotikApiException; import me.legrange.mikrotik.MikrotikApiException;
@ -10,10 +8,10 @@ import me.legrange.mikrotik.MikrotikApiException;
* *
* @author gideon * @author gideon
*/ */
public class Example9 { public class TryWithResources {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
Example9 ex = new Example9(); TryWithResources ex = new TryWithResources();
ex.test(); ex.test();
} }

View File

@ -242,6 +242,7 @@ public final class ApiConnectionImpl extends ApiConnection {
} catch (InterruptedException ex2) { } catch (InterruptedException ex2) {
} }
} catch (ApiConnectionException | InterruptedException ex) { } catch (ApiConnectionException | InterruptedException ex) {
ex.printStackTrace();
} }
} }
} }