+ public Status getStatus() {
+ Instance.getTraceHandler().trace("Getting remote lib status...");
+ Status status = getStatusDo();
+ Instance.getTraceHandler().trace("Remote lib status: " + status);
+ return status;
+ }
+
+ private Status getStatusDo() {
+ final Status[] result = new Status[1];
+
+ result[0] = Status.INVALID;
+
+ try {
+ new ConnectActionClientObject(host, port, key) {
+ @Override
+ public void action(Version serverVersion) throws Exception {
+ Object rep = send(new Object[] { subkey, "PING" });
+
+ if ("r/w".equals(rep)) {
+ rw = true;
+ result[0] = Status.READY;
+ } else if ("r/o".equals(rep)) {
+ rw = false;
+ result[0] = Status.READY;
+ } else {
+ result[0] = Status.UNAUTHORIZED;
+ }
+ }
+
+ @Override
+ protected void onError(Exception e) {
+ if (e instanceof SSLException) {
+ result[0] = Status.UNAUTHORIZED;
+ } else {
+ result[0] = Status.UNAVAILABLE;
+ }
+ }
+ }.connect();
+ } catch (UnknownHostException e) {
+ result[0] = Status.INVALID;
+ } catch (IllegalArgumentException e) {
+ result[0] = Status.INVALID;
+ } catch (Exception e) {
+ result[0] = Status.UNAVAILABLE;
+ }
+
+ return result[0];
+ }
+
+ @Override
+ public Image getCover(final String luid) {
+ final Image[] result = new Image[1];
+
+ try {
+ new ConnectActionClientObject(host, port, key) {
+ @Override
+ public void action(Version serverVersion) throws Exception {
+ Object rep = send(new Object[] { subkey, "GET_COVER", luid });
+ result[0] = (Image) rep;
+ }
+
+ @Override
+ protected void onError(Exception e) {
+ if (e instanceof SSLException) {
+ Instance.getTraceHandler().error(
+ "Connection refused (bad key)");
+ } else {
+ Instance.getTraceHandler().error(e);
+ }
+ }
+ }.connect();
+ } catch (Exception e) {
+ Instance.getTraceHandler().error(e);
+ }
+
+ return result[0];
+ }
+
+ @Override
+ public Image getCustomSourceCover(final String source) {
+ return getCustomCover(source, "SOURCE");
+ }
+
+ @Override
+ public Image getCustomAuthorCover(final String author) {
+ return getCustomCover(author, "AUTHOR");
+ }
+
+ // type: "SOURCE" or "AUTHOR"
+ private Image getCustomCover(final String source, final String type) {
+ final Image[] result = new Image[1];
+
+ try {
+ new ConnectActionClientObject(host, port, key) {
+ @Override
+ public void action(Version serverVersion) throws Exception {
+ Object rep = send(new Object[] { subkey,
+ "GET_CUSTOM_COVER", type, source });
+ result[0] = (Image) rep;
+ }
+
+ @Override
+ protected void onError(Exception e) {
+ if (e instanceof SSLException) {
+ Instance.getTraceHandler().error(
+ "Connection refused (bad key)");
+ } else {
+ Instance.getTraceHandler().error(e);
+ }
+ }
+ }.connect();
+ } catch (Exception e) {
+ Instance.getTraceHandler().error(e);
+ }
+
+ return result[0];
+ }
+
+ @Override
+ public synchronized Story getStory(final String luid, Progress pg) {
+ final Progress pgF = pg;
+ final Story[] result = new Story[1];
+
+ try {
+ new ConnectActionClientObject(host, port, key) {
+ @Override
+ public void action(Version serverVersion) throws Exception {
+ Progress pg = pgF;
+ if (pg == null) {
+ pg = new Progress();
+ }
+
+ Object rep = send(new Object[] { subkey, "GET_STORY", luid });
+
+ MetaData meta = null;
+ if (rep instanceof MetaData) {
+ meta = (MetaData) rep;
+ if (meta.getWords() <= Integer.MAX_VALUE) {
+ pg.setMinMax(0, (int) meta.getWords());