From ee8d1ba60902b90e0fcf8a60b84a95ea7d2a019b Mon Sep 17 00:00:00 2001 From: Gideon le Grange Date: Thu, 5 Jan 2017 15:07:48 +0200 Subject: [PATCH] Added thread names for easier debug --- pom.xml | 363 +++++++++--------- src/main/java/examples/Config.java | 6 +- src/main/java/examples/DownloadConfig.java | 4 +- src/main/java/examples/Issue27.java | 69 ++++ .../mikrotik/impl/ApiConnectionImpl.java | 11 +- 5 files changed, 275 insertions(+), 178 deletions(-) create mode 100644 src/main/java/examples/Issue27.java diff --git a/pom.xml b/pom.xml index 3a90ed7..ff515f9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,173 +1,194 @@ - - - org.sonatype.oss - oss-parent - 9 - + - 4.0.0 - - me.legrange - mikrotik - 3.0.3 - jar - - Mikrotik API Java Client Library - https://github.com/GideonLeGrange/mikrotik-java - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - git@github.com:GideonLeGrange/mikrotik-java.git - scm:git:git@github.com:GideonLeGrange/mikrotik-java.git - scm:git:git@github.com:GideonLeGrange/mikrotik-java.git - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - true - 1.7 - 1.7 - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.3.2 - - - default-jar - package - - jar - - - - **/examples - **/examples/* - - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - example;*.impl - - - - attach-javadocs - - jar - - - - - - - - - - release - - - - org.apache.maven.plugins - maven-source-plugin - 2.4 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.1 - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.5 - true - - ossrh - https://oss.sonatype.org/ - true - - - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - - - - UTF-8 - - - - - junit - junit - 3.8.1 - test - - + + + org.sonatype.oss + oss-parent + 9 + + 4.0.0 + me.legrange + mikrotik + 3.0.3 + jar + Mikrotik API Java Client Library + https://github.com/GideonLeGrange/mikrotik-java + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + git@github.com:GideonLeGrange/mikrotik-java.git + scm:git:git@github.com:GideonLeGrange/mikrotik-java.git + scm:git:git@github.com:GideonLeGrange/mikrotik-java.git + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + true + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.2 + + + default-jar + package + + jar + + + + **/examples + **/examples/* + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + example;*.impl + + + + attach-javadocs + + jar + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + 1.0.4 + + + compile + process-sources + + compile + + + + test-compile + process-test-sources + + test-compile + + + + + + + + + release + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.5 + true + + ossrh + https://oss.sonatype.org/ + true + + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + + + + UTF-8 + + + + junit + junit + 3.8.1 + test + + + org.jetbrains.kotlin + kotlin-stdlib + 1.0.4 + + - diff --git a/src/main/java/examples/Config.java b/src/main/java/examples/Config.java index 1af2167..9bc085f 100644 --- a/src/main/java/examples/Config.java +++ b/src/main/java/examples/Config.java @@ -7,8 +7,8 @@ package examples; */ public class Config { - public static final String HOST = "192.168.1.34"; - public static final String USERNAME = "admin"; - public static final String PASSWORD = ""; + public static final String HOST = "wifimanager.adept.za.net"; + public static final String USERNAME = "adept"; + public static final String PASSWORD = "tzrx21j"; } diff --git a/src/main/java/examples/DownloadConfig.java b/src/main/java/examples/DownloadConfig.java index b041bb1..0851e14 100644 --- a/src/main/java/examples/DownloadConfig.java +++ b/src/main/java/examples/DownloadConfig.java @@ -21,9 +21,9 @@ public class DownloadConfig extends Example { private void test() throws MikrotikApiException, InterruptedException { con.execute("/export file=conf"); List> res = con.execute("/file/print detail where name=conf.rsc"); - con.execute("/file/remove .id=conf.rsc"); + con.execute("/file/remove .id=conf.rsc"); String text = res.get(0).get("contents"); - for (String line : text.split("\r")) { + for (String line : text.split("\r")) { System.out.println(line); } } diff --git a/src/main/java/examples/Issue27.java b/src/main/java/examples/Issue27.java new file mode 100644 index 0000000..9999351 --- /dev/null +++ b/src/main/java/examples/Issue27.java @@ -0,0 +1,69 @@ +package examples; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import me.legrange.mikrotik.MikrotikApiException; +import me.legrange.mikrotik.ResultListener; + +/** + * Example to show that different character sets may work some times. + * + * @author gideon + */ +public class Issue27 extends Example { + + public static void main(String... args) throws Exception { + Issue27 ex = new Issue27(); + ex.connect(); + ex.con.setTimeout(2000); + ex.test2(); + ex.test1(); + Thread.sleep(60000); + for (String tag : ex.tags) { + ex.con.cancel(tag); + } + ex.disconnect(); + } + + private void test1() throws MikrotikApiException { + String tag = con.execute("/interface/pppoe-server/server/listen return .id,.dead,disabled,service-name,interface,max-mtu,max-mru,mrru,default-profile,authentication", new ResultListener() { + @Override + public void receive(Map result) { + System.out.println(result); + } + + @Override + public void error(MikrotikApiException ex) { + System.out.println(ex); + } + + @Override + public void completed() { + } + }); + tags.add(tag); + } + + private void test2() throws MikrotikApiException { + String tag = con.execute("/interface/listen where type=l2tp-in or type=l2tp-out or type=ovpn-in or type=ovpn-out or type=ppp-in or type=ppp-out or type=pppoe-in or type=pppoe-out or type=pptp-in or type=pptp-out or type=sstp-in or type=sstp-out return .id,.dead,.nextid,disabled,dynamic,running,slave,name,type,comment", new ResultListener() { + @Override + public void receive(Map result) { + System.out.println(result); + } + + @Override + public void error(MikrotikApiException ex) { + System.out.println(ex); + } + + @Override + public void completed() { + } + }); + tags.add(tag); + } + + List tags = new ArrayList<>(); + +} diff --git a/src/main/java/me/legrange/mikrotik/impl/ApiConnectionImpl.java b/src/main/java/me/legrange/mikrotik/impl/ApiConnectionImpl.java index 4ae2cc6..903391c 100644 --- a/src/main/java/me/legrange/mikrotik/impl/ApiConnectionImpl.java +++ b/src/main/java/me/legrange/mikrotik/impl/ApiConnectionImpl.java @@ -33,7 +33,6 @@ public final class ApiConnectionImpl extends ApiConnection { * * @param host The host to which to connect. * @param port The TCP port to use. - * @param secure Is TLS required * @param timeOut The connection timeout * @return The ApiConnection * @throws me.legrange.mikrotik.ApiConnectionException Thrown if there is a @@ -174,6 +173,10 @@ public final class ApiConnectionImpl extends ApiConnection { */ private class Reader extends Thread { + private Reader() { + super("Mikrotik API Reader"); + } + private String take() throws ApiConnectionException, ApiDataException { Object val = null; try { @@ -192,7 +195,7 @@ public final class ApiConnectionImpl extends ApiConnection { private boolean isEmpty() { return queue.isEmpty(); } - + @Override public void run() { while (connected) { @@ -226,6 +229,10 @@ public final class ApiConnectionImpl extends ApiConnection { */ private class Processor extends Thread { + private Processor() { + super("Mikrotik API Result Processor"); + } + @Override public void run() { while (connected) {