|
@@ -3,7 +3,11 @@ package uraxis;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+
|
|
|
import org.apache.xmlrpc.XmlRpcException;
|
|
|
+import org.apache.xmlrpc.XmlRpcRequest;
|
|
|
+import org.apache.xmlrpc.client.AsyncCallback;
|
|
|
import org.apache.xmlrpc.client.XmlRpcClient;
|
|
|
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
|
|
|
|
|
@@ -43,42 +47,83 @@ public class MyDaemonInterface {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
- public int getpos() {
|
|
|
+ public CompletableFuture<Integer> getpos() {
|
|
|
+ CompletableFuture<Integer> cf = new CompletableFuture();
|
|
|
try {
|
|
|
- Object res= client.execute("getpos", new Object[]{});
|
|
|
- return (int) res;
|
|
|
+ client.executeAsync("getpos", new Object[]{}, new AsyncCallback() {
|
|
|
+ @Override
|
|
|
+ public void handleResult(XmlRpcRequest xmlRpcRequest, Object o) {
|
|
|
+ cf.complete((Integer) o);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handleError(XmlRpcRequest xmlRpcRequest, Throwable throwable) {
|
|
|
+ cf.completeExceptionally(throwable);
|
|
|
+ }
|
|
|
+ });
|
|
|
} catch (XmlRpcException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return -1;
|
|
|
+ cf.completeExceptionally(e);
|
|
|
}
|
|
|
+ return cf;
|
|
|
}
|
|
|
- public String getstatus() {
|
|
|
+ public CompletableFuture<String> getstatus() {
|
|
|
+ CompletableFuture<String> cf = new CompletableFuture();
|
|
|
try {
|
|
|
- String res= (String) client.execute("status", new Object[]{});
|
|
|
- return res;
|
|
|
+ client.executeAsync("status", new Object[]{}, new AsyncCallback() {
|
|
|
+ @Override
|
|
|
+ public void handleResult(XmlRpcRequest xmlRpcRequest, Object o) {
|
|
|
+ cf.complete((String) o);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handleError(XmlRpcRequest xmlRpcRequest, Throwable throwable) {
|
|
|
+ cf.completeExceptionally(throwable);
|
|
|
+ }
|
|
|
+ });
|
|
|
} catch (XmlRpcException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return "";
|
|
|
+ cf.completeExceptionally(e);
|
|
|
}
|
|
|
+ return cf;
|
|
|
}
|
|
|
|
|
|
- public boolean rel(int pos, int speed) {
|
|
|
+ public CompletableFuture<Boolean> rel(int pos, int speed) {
|
|
|
+ CompletableFuture<Boolean> cf = new CompletableFuture();
|
|
|
try {
|
|
|
- boolean success= (boolean) client.execute("rel", new Object[]{pos, speed});
|
|
|
- return success;
|
|
|
+ client.executeAsync("rel", new Object[]{pos, speed}, new AsyncCallback() {
|
|
|
+ @Override
|
|
|
+ public void handleResult(XmlRpcRequest xmlRpcRequest, Object o) {
|
|
|
+ cf.complete((Boolean) o);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handleError(XmlRpcRequest xmlRpcRequest, Throwable throwable) {
|
|
|
+ cf.completeExceptionally(throwable);
|
|
|
+ }
|
|
|
+ });
|
|
|
} catch (XmlRpcException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
+ cf.completeExceptionally(e);
|
|
|
}
|
|
|
+ return cf;
|
|
|
}
|
|
|
|
|
|
- public boolean abs(int pos, int speed) {
|
|
|
+ public CompletableFuture<Boolean> abs(int pos, int speed) {
|
|
|
+ CompletableFuture<Boolean> cf = new CompletableFuture();
|
|
|
+
|
|
|
try {
|
|
|
- boolean success= (boolean) client.execute("abs", new Object[]{pos, speed});
|
|
|
- return success;
|
|
|
+ client.executeAsync("abs", new Object[]{pos, speed}, new AsyncCallback() {
|
|
|
+ @Override
|
|
|
+ public void handleResult(XmlRpcRequest xmlRpcRequest, Object o) {
|
|
|
+ cf.complete((Boolean) o);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handleError(XmlRpcRequest xmlRpcRequest, Throwable throwable) {
|
|
|
+ cf.completeExceptionally(throwable);
|
|
|
+ }
|
|
|
+ });
|
|
|
} catch (XmlRpcException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
+ cf.completeExceptionally(e);
|
|
|
}
|
|
|
+ return cf;
|
|
|
}
|
|
|
}
|