From 3bbc86a58d68069c6eb95ec17b02daa4ca75ec7f Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sat, 2 Dec 2017 15:02:48 +0100 Subject: [PATCH] RemoteLibrary: new isOnline() method --- .../nikiroo/fanfix/library/RemoteLibrary.java | 30 +++++++++++++++++++ .../fanfix/library/RemoteLibraryServer.java | 5 +++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java index ea155eb..e51de45 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java @@ -224,6 +224,36 @@ public class RemoteLibrary extends BasicLibrary { "Operation not supportorted on remote Libraries"); } + /** + * Check if this {@link RemoteLibraryServer} is able to connect and identify + * to the remote server. + * + * @return TRUE if it is online + */ + public boolean isOnline() { + final Boolean[] result = new Boolean[1]; + + result[0] = false; + try { + new ConnectActionClientObject(host, port, true) { + @Override + public void action(Version serverVersion) throws Exception { + Object rep = send(new Object[] { key, "PING" }); + result[0] = "PONG".equals(rep); + } + + @Override + protected void onError(Exception e) { + Instance.getTraceHandler().error(e); + } + }.connect(); + } catch (Exception e) { + Instance.getTraceHandler().error(e); + } + + return result[0]; + } + @Override protected List getMetas(Progress pg) { final Progress pgF = pg; diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java index 40386ec..b95c50f 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java @@ -25,6 +25,7 @@ import be.nikiroo.utils.serial.server.ServerObject; * The key is always a String, the commands are also Strings; the parameters * vary depending upon the command. *