Added thread names for easier debug

This commit is contained in:
Gideon le Grange 2017-01-05 15:07:48 +02:00
parent b52c80b600
commit ee8d1ba609
5 changed files with 275 additions and 178 deletions

363
pom.xml
View File

@ -1,173 +1,194 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <?xml version="1.0" encoding="UTF-8"?>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>9</version>
</parent>
<modelVersion>4.0.0</modelVersion> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>me.legrange</groupId> <groupId>org.sonatype.oss</groupId>
<artifactId>mikrotik</artifactId> <artifactId>oss-parent</artifactId>
<version>3.0.3</version> <version>9</version>
<packaging>jar</packaging> </parent>
<modelVersion>4.0.0</modelVersion>
<name>Mikrotik API Java Client Library</name> <groupId>me.legrange</groupId>
<url>https://github.com/GideonLeGrange/mikrotik-java</url> <artifactId>mikrotik</artifactId>
<licenses> <version>3.0.3</version>
<license> <packaging>jar</packaging>
<name>The Apache Software License, Version 2.0</name> <name>Mikrotik API Java Client Library</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <url>https://github.com/GideonLeGrange/mikrotik-java</url>
<distribution>repo</distribution> <licenses>
</license> <license>
</licenses> <name>The Apache Software License, Version 2.0</name>
<scm> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<url>git@github.com:GideonLeGrange/mikrotik-java.git</url> <distribution>repo</distribution>
<connection>scm:git:git@github.com:GideonLeGrange/mikrotik-java.git</connection> </license>
<developerConnection>scm:git:git@github.com:GideonLeGrange/mikrotik-java.git</developerConnection> </licenses>
</scm> <scm>
<build> <url>git@github.com:GideonLeGrange/mikrotik-java.git</url>
<plugins> <connection>scm:git:git@github.com:GideonLeGrange/mikrotik-java.git</connection>
<plugin> <developerConnection>scm:git:git@github.com:GideonLeGrange/mikrotik-java.git</developerConnection>
<groupId>org.apache.maven.plugins</groupId> </scm>
<artifactId>maven-compiler-plugin</artifactId> <build>
<version>2.3.2</version> <plugins>
<configuration> <plugin>
<showDeprecation>true</showDeprecation> <groupId>org.apache.maven.plugins</groupId>
<source>1.7</source> <artifactId>maven-compiler-plugin</artifactId>
<target>1.7</target> <version>2.3.2</version>
</configuration> <configuration>
</plugin> <showDeprecation>true</showDeprecation>
<source>1.7</source>
<plugin> <target>1.7</target>
<groupId>org.apache.maven.plugins</groupId> </configuration>
<artifactId>maven-jar-plugin</artifactId> </plugin>
<version>2.3.2</version> <plugin>
<executions> <groupId>org.apache.maven.plugins</groupId>
<execution> <artifactId>maven-jar-plugin</artifactId>
<id>default-jar</id> <version>2.3.2</version>
<phase>package</phase> <executions>
<goals> <execution>
<goal>jar</goal> <id>default-jar</id>
</goals> <phase>package</phase>
<configuration> <goals>
<excludes> <goal>jar</goal>
<exclude>**/examples</exclude> </goals>
<exclude>**/examples/*</exclude> <configuration>
</excludes> <excludes>
</configuration> <exclude>**/examples</exclude>
</execution> <exclude>**/examples/*</exclude>
</executions> </excludes>
</plugin> </configuration>
<plugin> </execution>
<groupId>org.apache.maven.plugins</groupId> </executions>
<artifactId>maven-source-plugin</artifactId> </plugin>
<version>2.2.1</version> <plugin>
<executions> <groupId>org.apache.maven.plugins</groupId>
<execution> <artifactId>maven-source-plugin</artifactId>
<id>attach-sources</id> <version>2.2.1</version>
<goals> <executions>
<goal>jar</goal> <execution>
</goals> <id>attach-sources</id>
</execution> <goals>
</executions> <goal>jar</goal>
</plugin> </goals>
<plugin> </execution>
<groupId>org.apache.maven.plugins</groupId> </executions>
<artifactId>maven-javadoc-plugin</artifactId> </plugin>
<version>2.9.1</version> <plugin>
<configuration> <groupId>org.apache.maven.plugins</groupId>
<excludePackageNames>example;*.impl</excludePackageNames> <artifactId>maven-javadoc-plugin</artifactId>
</configuration> <version>2.9.1</version>
<executions> <configuration>
<execution> <excludePackageNames>example;*.impl</excludePackageNames>
<id>attach-javadocs</id> </configuration>
<goals> <executions>
<goal>jar</goal> <execution>
</goals> <id>attach-javadocs</id>
</execution> <goals>
</executions> <goal>jar</goal>
</plugin> </goals>
</execution>
</plugins> </executions>
</build> </plugin>
<profiles> <plugin>
<profile> <groupId>org.jetbrains.kotlin</groupId>
<id>release</id> <artifactId>kotlin-maven-plugin</artifactId>
<build> <version>1.0.4</version>
<plugins> <executions>
<plugin> <execution>
<groupId>org.apache.maven.plugins</groupId> <id>compile</id>
<artifactId>maven-source-plugin</artifactId> <phase>process-sources</phase>
<version>2.4</version> <goals>
<executions> <goal>compile</goal>
<execution> </goals>
<id>attach-sources</id> </execution>
<goals> <execution>
<goal>jar</goal> <id>test-compile</id>
</goals> <phase>process-test-sources</phase>
</execution> <goals>
</executions> <goal>test-compile</goal>
</plugin> </goals>
<plugin> </execution>
<groupId>org.apache.maven.plugins</groupId> </executions>
<artifactId>maven-javadoc-plugin</artifactId> </plugin>
<version>2.10.1</version> </plugins>
<executions> </build>
<execution> <profiles>
<id>attach-javadocs</id> <profile>
<goals> <id>release</id>
<goal>jar</goal> <build>
</goals> <plugins>
</execution> <plugin>
</executions> <groupId>org.apache.maven.plugins</groupId>
</plugin> <artifactId>maven-source-plugin</artifactId>
<plugin> <version>2.4</version>
<groupId>org.apache.maven.plugins</groupId> <executions>
<artifactId>maven-gpg-plugin</artifactId> <execution>
<version>1.6</version> <id>attach-sources</id>
<executions> <goals>
<execution> <goal>jar</goal>
<id>sign-artifacts</id> </goals>
<phase>verify</phase> </execution>
<goals> </executions>
<goal>sign</goal> </plugin>
</goals> <plugin>
</execution> <groupId>org.apache.maven.plugins</groupId>
</executions> <artifactId>maven-javadoc-plugin</artifactId>
</plugin> <version>2.10.1</version>
<plugin> <executions>
<groupId>org.sonatype.plugins</groupId> <execution>
<artifactId>nexus-staging-maven-plugin</artifactId> <id>attach-javadocs</id>
<version>1.6.5</version> <goals>
<extensions>true</extensions> <goal>jar</goal>
<configuration> </goals>
<serverId>ossrh</serverId> </execution>
<nexusUrl>https://oss.sonatype.org/</nexusUrl> </executions>
<autoReleaseAfterClose>true</autoReleaseAfterClose> </plugin>
</configuration> <plugin>
</plugin> <groupId>org.apache.maven.plugins</groupId>
</plugins> <artifactId>maven-gpg-plugin</artifactId>
</build> <version>1.6</version>
<distributionManagement> <executions>
<snapshotRepository> <execution>
<id>ossrh</id> <id>sign-artifacts</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url> <phase>verify</phase>
</snapshotRepository> <goals>
</distributionManagement> <goal>sign</goal>
</profile> </goals>
</profiles> </execution>
<properties> </executions>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </plugin>
</properties> <plugin>
<groupId>org.sonatype.plugins</groupId>
<dependencies> <artifactId>nexus-staging-maven-plugin</artifactId>
<dependency> <version>1.6.5</version>
<groupId>junit</groupId> <extensions>true</extensions>
<artifactId>junit</artifactId> <configuration>
<version>3.8.1</version> <serverId>ossrh</serverId>
<scope>test</scope> <nexusUrl>https://oss.sonatype.org/</nexusUrl>
</dependency> <autoReleaseAfterClose>true</autoReleaseAfterClose>
</dependencies> </configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</profile>
</profiles>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
</project> </project>

View File

@ -7,8 +7,8 @@ package examples;
*/ */
public class Config { public class Config {
public static final String HOST = "192.168.1.34"; public static final String HOST = "wifimanager.adept.za.net";
public static final String USERNAME = "admin"; public static final String USERNAME = "adept";
public static final String PASSWORD = ""; public static final String PASSWORD = "tzrx21j";
} }

View File

@ -21,9 +21,9 @@ public class DownloadConfig extends Example {
private void test() throws MikrotikApiException, InterruptedException { private void test() throws MikrotikApiException, InterruptedException {
con.execute("/export file=conf"); con.execute("/export file=conf");
List<Map<String, String>> res = con.execute("/file/print detail where name=conf.rsc"); List<Map<String, String>> 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"); String text = res.get(0).get("contents");
for (String line : text.split("\r")) { for (String line : text.split("\r")) {
System.out.println(line); System.out.println(line);
} }
} }

View File

@ -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<String, String> 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<String, String> result) {
System.out.println(result);
}
@Override
public void error(MikrotikApiException ex) {
System.out.println(ex);
}
@Override
public void completed() {
}
});
tags.add(tag);
}
List<String> tags = new ArrayList<>();
}

View File

@ -33,7 +33,6 @@ public final class ApiConnectionImpl extends ApiConnection {
* *
* @param host The host to which to connect. * @param host The host to which to connect.
* @param port The TCP port to use. * @param port The TCP port to use.
* @param secure Is TLS required
* @param timeOut The connection timeout * @param timeOut The connection timeout
* @return The ApiConnection * @return The ApiConnection
* @throws me.legrange.mikrotik.ApiConnectionException Thrown if there is a * @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 class Reader extends Thread {
private Reader() {
super("Mikrotik API Reader");
}
private String take() throws ApiConnectionException, ApiDataException { private String take() throws ApiConnectionException, ApiDataException {
Object val = null; Object val = null;
try { try {
@ -192,7 +195,7 @@ public final class ApiConnectionImpl extends ApiConnection {
private boolean isEmpty() { private boolean isEmpty() {
return queue.isEmpty(); return queue.isEmpty();
} }
@Override @Override
public void run() { public void run() {
while (connected) { while (connected) {
@ -226,6 +229,10 @@ public final class ApiConnectionImpl extends ApiConnection {
*/ */
private class Processor extends Thread { private class Processor extends Thread {
private Processor() {
super("Mikrotik API Result Processor");
}
@Override @Override
public void run() { public void run() {
while (connected) { while (connected) {