From 9b4d15fc8411f34168ed35493b625363d24e8ad8 Mon Sep 17 00:00:00 2001 From: GideonLeGrange Date: Fri, 9 Aug 2013 10:19:26 +0200 Subject: [PATCH] Removed Result from plublic API, it was just a Map anyway. Fixed small synchronization bug --- src/main/java/examples/Example2.java | 6 +++--- src/main/java/examples/Example3.java | 6 +++--- .../java/me/legrange/mikrotik/ApiConnection.java | 16 ++++++++-------- src/main/java/me/legrange/mikrotik/Result.java | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/examples/Example2.java b/src/main/java/examples/Example2.java index 3587d81..5391d56 100644 --- a/src/main/java/examples/Example2.java +++ b/src/main/java/examples/Example2.java @@ -1,8 +1,8 @@ package examples; import java.util.List; +import java.util.Map; import me.legrange.mikrotik.MikrotikApiException; -import me.legrange.mikrotik.Result; /** * Example 2: A command that returns results. Print all interfaces @@ -19,8 +19,8 @@ public class Example2 extends Example { } private void test() throws MikrotikApiException { - List results = con.execute("/interface/print"); - for (Result result : results) { + List> results = con.execute("/interface/print"); + for (Map result : results) { System.out.println(result); } } diff --git a/src/main/java/examples/Example3.java b/src/main/java/examples/Example3.java index 172eae9..f1380bd 100644 --- a/src/main/java/examples/Example3.java +++ b/src/main/java/examples/Example3.java @@ -1,8 +1,8 @@ package examples; import java.util.List; +import java.util.Map; import me.legrange.mikrotik.MikrotikApiException; -import me.legrange.mikrotik.Result; /** * Example 3: Queries. Print all interfaces of a certain type. @@ -19,8 +19,8 @@ public class Example3 extends Example { } private void test() throws MikrotikApiException { - List results = con.execute("/interface/print where type=ether"); - for (Result result : results) { + List> results = con.execute("/interface/print where type=ether"); + for (Map result : results) { System.out.println(result); } } diff --git a/src/main/java/me/legrange/mikrotik/ApiConnection.java b/src/main/java/me/legrange/mikrotik/ApiConnection.java index f7bf942..e044646 100644 --- a/src/main/java/me/legrange/mikrotik/ApiConnection.java +++ b/src/main/java/me/legrange/mikrotik/ApiConnection.java @@ -75,8 +75,8 @@ public class ApiConnection { * @param password - password for the user */ public void login(String username, String password) throws MikrotikApiException, ApiCommandException, InterruptedException { - List list = execute("/login"); - Result res = list.get(0); + List> list = execute("/login"); + Map res = list.get(0); String hash = res.get("ret"); String chal = Util.hexStrToStr("00") + new String(makePass(password)) + Util.hexStrToStr(hash); chal = Util.hashMD5(chal); @@ -87,7 +87,7 @@ public class ApiConnection { * @param cmd Command to execute * @return The list of results */ - public List execute(String cmd) throws MikrotikApiException { + public List> execute(String cmd) throws MikrotikApiException { return execute(Parser.parse(cmd)); } @@ -104,10 +104,10 @@ public class ApiConnection { /** cancel a command */ public void cancel(String tag) throws MikrotikApiException { - execute(String.format("/cancel tag=%s", tag)); + execute(String.format("/cancel tag=%s", tag)) ; } - private List execute(Command cmd) throws MikrotikApiException { + private List> execute(Command cmd) throws MikrotikApiException { SyncListener l = new SyncListener(); execute(cmd, l); return l.getResults(); @@ -417,7 +417,7 @@ public class ApiConnection { notify(); } - public void completed() { + public synchronized void completed() { notify(); } @@ -434,7 +434,7 @@ public class ApiConnection { results.add(result); } - private List getResults() throws MikrotikApiException { + private List> getResults() throws MikrotikApiException { try { synchronized (this) { // don't wait if we already have a result. if ((err == null) && results.isEmpty()) { @@ -450,7 +450,7 @@ public class ApiConnection { return results; } - private List results = new LinkedList(); + private List> results = new LinkedList>(); private MikrotikApiException err; } } \ No newline at end of file diff --git a/src/main/java/me/legrange/mikrotik/Result.java b/src/main/java/me/legrange/mikrotik/Result.java index 9fc9c70..1b6a741 100644 --- a/src/main/java/me/legrange/mikrotik/Result.java +++ b/src/main/java/me/legrange/mikrotik/Result.java @@ -9,7 +9,7 @@ import java.util.Set; * A result from an API command. * @author GideonLeGrange */ -public class Result extends Response implements Map { +class Result extends Response implements Map { public String get(String key) { return map.get(key);