diff --git a/pom.xml b/pom.xml index b9d2711..7348809 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ maven-javadoc-plugin 2.9.1 - example + example;*.impl @@ -62,46 +62,3 @@ - -## - - 4.0.0 - org.apache.maven - maven - jar - Maven core - 2.0 - The maven main core project description - http://maven.apache.org - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - http://svn.apache.org/viewcvs.cgi/maven - http://svn.apache.org/viewcvs.cgi/maven - - - - ... - ... - ... - - - - - ... - ... - ... - - ... - - - \ No newline at end of file diff --git a/src/main/java/examples/Config.java b/src/main/java/examples/Config.java index 0e81b2a..aad05c7 100644 --- a/src/main/java/examples/Config.java +++ b/src/main/java/examples/Config.java @@ -7,9 +7,9 @@ package examples; public class Config { - public static final String USERNAME = "admin"; + public static final String HOST = "10.0.0.3"; + public static final String USERNAME = "admin"; public static final String PASSWORD = ""; - public static final String HOST = "10.0.1.3"; } diff --git a/src/main/java/examples/Example5.java b/src/main/java/examples/Example5.java new file mode 100644 index 0000000..8bc4903 --- /dev/null +++ b/src/main/java/examples/Example5.java @@ -0,0 +1,49 @@ +package examples; + +import java.util.Map; +import me.legrange.mikrotik.MikrotikApiException; +import me.legrange.mikrotik.ResponseListener; + +/** + * Example 5: Asynchronous results, with error and completion. Run a command and receive results, errors and completion notification for it asynchronously with a ResponseListener + * + * @author gideon + */ +public class Example5 extends Example { + + public static void main(String... args) throws Exception { + Example5 ex = new Example5(); + ex.connect(); + ex.test(); + ex.disconnect(); + } + + private void test() throws MikrotikApiException, InterruptedException { + boolean completed = false; + String id = con.execute("/interface/wireless/monitor .id=wlan1", new ResponseListener() { + private int prev = 0; + + public void receive(Map result) { + int val = Integer.parseInt(result.get("signal-strength")); + String sym = (val == prev) ? " " : ((val < prev) ? "-" : "+"); + System.out.printf("%d %s\n", val, sym); + prev = val; + } + + public void error(MikrotikApiException ex) { + System.out.printf("An error ocurred: %s\n", ex.getMessage()); + ex.printStackTrace(); + } + + public void completed() { + System.out.printf("The request has been completed\n"); + } + + + }); + // let it run for 60 seconds + Thread.sleep(10000); + con.cancel(id); + Thread.sleep(2000); + } +} diff --git a/src/main/java/me/legrange/mikrotik/ApiConnection.java b/src/main/java/me/legrange/mikrotik/ApiConnection.java index b3c49ca..9ecc75f 100644 --- a/src/main/java/me/legrange/mikrotik/ApiConnection.java +++ b/src/main/java/me/legrange/mikrotik/ApiConnection.java @@ -12,9 +12,9 @@ import me.legrange.mikrotik.impl.ApiConnectionImpl; */ public abstract class ApiConnection { + /** default TCP port used by Mikrotik API */ public static final int DEFAULT_PORT = 8728; - /** * Create a new API connection to the give device on the supplied port * @param host The host to which to connect.