package uraxis; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Map; 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; public class MyDaemonInterface { XmlRpcClient client; public MyDaemonInterface(String host, int port) { XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); config.setEnabledForExtensions(true); try { config.setServerURL(new URL("http://" + host + ":" + port + "/RPC2")); } catch (MalformedURLException e) { e.printStackTrace(); } config.setConnectionTimeout(1000); //1s client = new XmlRpcClient(); client.setConfig(config); } public boolean isReachable() { try { client.execute("get_title", new ArrayList()); return true; } catch (XmlRpcException e) { return false; } } public void setTitle(String title) { } public String getTitle() { return ""; } public String getMessage(String name) { return ""; } public CompletableFuture getpos() { CompletableFuture cf = new CompletableFuture(); try { 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) { cf.completeExceptionally(e); } return cf; } public CompletableFuture> getstatus() { CompletableFuture> cf = new CompletableFuture(); try { client.executeAsync("status", new Object[]{}, new AsyncCallback() { @Override public void handleResult(XmlRpcRequest xmlRpcRequest, Object o) { cf.complete((Map) o); } @Override public void handleError(XmlRpcRequest xmlRpcRequest, Throwable throwable) { cf.completeExceptionally(throwable); } }); } catch (XmlRpcException e) { cf.completeExceptionally(e); } return cf; } public CompletableFuture rel(int pos, int speed) { CompletableFuture cf = new CompletableFuture(); try { client.executeAsync("rel", new Object[]{pos, speed}, 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) { cf.completeExceptionally(e); } return cf; } public CompletableFuture abs(int pos, int speed) { CompletableFuture cf = new CompletableFuture(); try { client.executeAsync("abs", new Object[]{pos, speed}, 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) { cf.completeExceptionally(e); } return cf; } }