MyDaemonInterface.java 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package uraxis;
  2. import java.net.MalformedURLException;
  3. import java.net.URL;
  4. import java.util.ArrayList;
  5. import org.apache.xmlrpc.XmlRpcException;
  6. import org.apache.xmlrpc.client.XmlRpcClient;
  7. import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
  8. public class MyDaemonInterface {
  9. XmlRpcClient client;
  10. public MyDaemonInterface(String host, int port) {
  11. XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
  12. config.setEnabledForExtensions(true);
  13. try {
  14. config.setServerURL(new URL("http://" + host + ":" + port + "/RPC2"));
  15. } catch (MalformedURLException e) {
  16. e.printStackTrace();
  17. }
  18. config.setConnectionTimeout(1000); //1s
  19. client = new XmlRpcClient();
  20. client.setConfig(config);
  21. }
  22. public boolean isReachable() {
  23. try {
  24. client.execute("get_title", new ArrayList<String>());
  25. return true;
  26. } catch (XmlRpcException e) {
  27. return false;
  28. }
  29. }
  30. public void setTitle(String title) {
  31. }
  32. public String getTitle() {
  33. return "";
  34. }
  35. public String getMessage(String name) {
  36. return "";
  37. }
  38. public boolean rel(int val) {
  39. try {
  40. client.execute("rel", new Object[]{String.valueOf(val)});
  41. return true;
  42. } catch (XmlRpcException e) {
  43. e.printStackTrace();
  44. return false;
  45. }
  46. }
  47. public boolean abs(int val) {
  48. try {
  49. client.execute("abs", new Object[]{String.valueOf(val)});
  50. return true;
  51. } catch (XmlRpcException e) {
  52. e.printStackTrace();
  53. return false;
  54. }
  55. }
  56. }