Removed Result from plublic API, it was just a Map anyway. Fixed small synchronization bug

This commit is contained in:
GideonLeGrange 2013-08-09 10:19:26 +02:00
parent e9555febbf
commit 9b4d15fc84
4 changed files with 15 additions and 15 deletions

View File

@ -1,8 +1,8 @@
package examples; package examples;
import java.util.List; import java.util.List;
import java.util.Map;
import me.legrange.mikrotik.MikrotikApiException; import me.legrange.mikrotik.MikrotikApiException;
import me.legrange.mikrotik.Result;
/** /**
* Example 2: A command that returns results. Print all interfaces * Example 2: A command that returns results. Print all interfaces
@ -19,8 +19,8 @@ public class Example2 extends Example {
} }
private void test() throws MikrotikApiException { private void test() throws MikrotikApiException {
List<Result> results = con.execute("/interface/print"); List<Map<String, String>> results = con.execute("/interface/print");
for (Result result : results) { for (Map<String, String> result : results) {
System.out.println(result); System.out.println(result);
} }
} }

View File

@ -1,8 +1,8 @@
package examples; package examples;
import java.util.List; import java.util.List;
import java.util.Map;
import me.legrange.mikrotik.MikrotikApiException; import me.legrange.mikrotik.MikrotikApiException;
import me.legrange.mikrotik.Result;
/** /**
* Example 3: Queries. Print all interfaces of a certain type. * Example 3: Queries. Print all interfaces of a certain type.
@ -19,8 +19,8 @@ public class Example3 extends Example {
} }
private void test() throws MikrotikApiException { private void test() throws MikrotikApiException {
List<Result> results = con.execute("/interface/print where type=ether"); List<Map<String, String>> results = con.execute("/interface/print where type=ether");
for (Result result : results) { for (Map<String, String> result : results) {
System.out.println(result); System.out.println(result);
} }
} }

View File

@ -75,8 +75,8 @@ public class ApiConnection {
* @param password - password for the user * @param password - password for the user
*/ */
public void login(String username, String password) throws MikrotikApiException, ApiCommandException, InterruptedException { public void login(String username, String password) throws MikrotikApiException, ApiCommandException, InterruptedException {
List<Result> list = execute("/login"); List<Map<String, String>> list = execute("/login");
Result res = list.get(0); Map<String, String> res = list.get(0);
String hash = res.get("ret"); String hash = res.get("ret");
String chal = Util.hexStrToStr("00") + new String(makePass(password)) + Util.hexStrToStr(hash); String chal = Util.hexStrToStr("00") + new String(makePass(password)) + Util.hexStrToStr(hash);
chal = Util.hashMD5(chal); chal = Util.hashMD5(chal);
@ -87,7 +87,7 @@ public class ApiConnection {
* @param cmd Command to execute * @param cmd Command to execute
* @return The list of results * @return The list of results
*/ */
public List<Result> execute(String cmd) throws MikrotikApiException { public List<Map<String, String>> execute(String cmd) throws MikrotikApiException {
return execute(Parser.parse(cmd)); return execute(Parser.parse(cmd));
} }
@ -104,10 +104,10 @@ public class ApiConnection {
/** cancel a command */ /** cancel a command */
public void cancel(String tag) throws MikrotikApiException { public void cancel(String tag) throws MikrotikApiException {
execute(String.format("/cancel tag=%s", tag)); execute(String.format("/cancel tag=%s", tag)) ;
} }
private List<Result> execute(Command cmd) throws MikrotikApiException { private List<Map<String, String>> execute(Command cmd) throws MikrotikApiException {
SyncListener l = new SyncListener(); SyncListener l = new SyncListener();
execute(cmd, l); execute(cmd, l);
return l.getResults(); return l.getResults();
@ -417,7 +417,7 @@ public class ApiConnection {
notify(); notify();
} }
public void completed() { public synchronized void completed() {
notify(); notify();
} }
@ -434,7 +434,7 @@ public class ApiConnection {
results.add(result); results.add(result);
} }
private List<Result> getResults() throws MikrotikApiException { private List<Map<String, String>> getResults() throws MikrotikApiException {
try { try {
synchronized (this) { // don't wait if we already have a result. synchronized (this) { // don't wait if we already have a result.
if ((err == null) && results.isEmpty()) { if ((err == null) && results.isEmpty()) {
@ -450,7 +450,7 @@ public class ApiConnection {
return results; return results;
} }
private List<Result> results = new LinkedList<Result>(); private List<Map<String, String>> results = new LinkedList<Map<String, String>>();
private MikrotikApiException err; private MikrotikApiException err;
} }
} }

View File

@ -9,7 +9,7 @@ import java.util.Set;
* A result from an API command. * A result from an API command.
* @author GideonLeGrange * @author GideonLeGrange
*/ */
public class Result extends Response implements Map<String, String> { class Result extends Response implements Map<String, String> {
public String get(String key) { public String get(String key) {
return map.get(key); return map.get(key);