From: Niki Roo Date: Sat, 2 Dec 2017 14:02:48 +0000 (+0100) Subject: RemoteLibrary: new isOnline() method X-Git-Tag: fanfix-1.6.3~16 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=3bbc86a58d68069c6eb95ec17b02daa4ca75ec7f;p=fanfix.git RemoteLibrary: new isOnline() method --- 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. *