X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibrary.java;h=63d2d7d345952820ff42a5ef3c9c8b395492c55b;hb=e6249b0f26fd3a7ec4cf5e49ba9f9939018c43d3;hp=e51de45daf1d17aaf5ee294073b7e58ff3de726a;hpb=5083ef84efb7e001c0b5de235d3424e1b59c62f4;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java index e51de45..63d2d7d 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java @@ -3,6 +3,7 @@ package be.nikiroo.fanfix.library; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; @@ -47,6 +48,50 @@ public class RemoteLibrary extends BasicLibrary { return host + ":" + port; } + @Override + public Status getStatus() { + final Status[] result = new Status[1]; + + result[0] = Status.INVALID; + + ConnectActionClientObject action = null; + try { + action = new ConnectActionClientObject(host, port, true) { + @Override + public void action(Version serverVersion) throws Exception { + Object rep = send(new Object[] { key, "PING" }); + if ("PONG".equals(rep)) { + result[0] = Status.READY; + } else { + result[0] = Status.UNAUTORIZED; + } + } + + @Override + protected void onError(Exception e) { + result[0] = Status.UNAVAILABLE; + } + }; + + } catch (UnknownHostException e) { + result[0] = Status.INVALID; + } catch (IllegalArgumentException e) { + result[0] = Status.INVALID; + } catch (Exception e) { + result[0] = Status.UNAVAILABLE; + } + + if (action != null) { + try { + action.connect(); + } catch (Exception e) { + result[0] = Status.UNAVAILABLE; + } + } + + return result[0]; + } + @Override public BufferedImage getCover(final String luid) { final BufferedImage[] result = new BufferedImage[1]; @@ -224,36 +269,6 @@ 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;