From: Niki Roo Date: Wed, 17 Apr 2019 16:12:19 +0000 (+0200) Subject: remote: display the rec/sent bytes in the server traces X-Git-Tag: fanfix-3.0.0~92 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=37abe20c2f39a8e9e4fef5dfe5e14cb732d25b02;p=fanfix.git remote: display the rec/sent bytes in the server traces --- diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java index d62b41b..b1aebb3 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java @@ -37,14 +37,13 @@ import be.nikiroo.utils.serial.server.ServerObject; *
  • PING: will return PONG if the key is accepted
  • *
  • GET_METADATA *: will return the metadata of all the stories in the * library (array)
  • * - *
  • GET_METADATA [luid]: will return the metadata of the story of LUID - * luid
  • + *
  • GET_METADATA [luid]: will return the metadata of the story of LUID luid
  • *
  • GET_STORY [luid]: will return the given story if it exists (or NULL if * not)
  • *
  • SAVE_STORY [luid]: save the story (that must be sent just after the * command) with the given LUID, then return the LUID
  • - *
  • IMPORT [url]: save the story found at the given URL, then return the - * LUID
  • + *
  • IMPORT [url]: save the story found at the given URL, then return the LUID + *
  • *
  • DELETE_STORY [luid]: delete the story of LUID luid
  • *
  • GET_COVER [luid]: return the cover of the story
  • *
  • GET_CUSTOM_COVER ["SOURCE"|"AUTHOR"] [source]: return the cover for this @@ -124,8 +123,11 @@ public class RemoteLibraryServer extends ServerObject { Object rep = doRequest(action, command, args); - getTraceHandler().trace(String.format("[>%s]: %d ms", command, - (new Date().getTime() - start))); + String rec = StringUtils.formatNumber(action.getBytesReceived()) + "b"; + String sent = StringUtils.formatNumber(action.getBytesSent()) + "b"; + getTraceHandler().trace( + String.format("[>%s]: (%s sent, %s rec) in %d ms", command, + sent, rec, (new Date().getTime() - start))); return rep; } @@ -157,8 +159,8 @@ public class RemoteLibraryServer extends ServerObject { return metas.toArray(new MetaData[] {}); } - return new MetaData[] { - Instance.getLibrary().getInfo((String) args[0]) }; + return new MetaData[] { Instance.getLibrary().getInfo( + (String) args[0]) }; } else if ("GET_STORY".equals(command)) { MetaData meta = Instance.getLibrary().getInfo((String) args[0]); meta = meta.clone(); @@ -167,8 +169,8 @@ public class RemoteLibraryServer extends ServerObject { action.send(meta); action.rec(); - Story story = Instance.getLibrary().getStory((String) args[0], - null); + Story story = Instance.getLibrary() + .getStory((String) args[0], null); for (Object obj : breakStory(story)) { action.send(obj); action.rec(); @@ -189,8 +191,8 @@ public class RemoteLibraryServer extends ServerObject { return story.getMeta().getLuid(); } else if ("IMPORT".equals(command)) { Progress pg = createPgForwarder(action); - Story story = Instance.getLibrary().imprt(new URL((String) args[0]), - pg); + Story story = Instance.getLibrary().imprt( + new URL((String) args[0]), pg); forcePgDoneSent(pg); return story.getMeta().getLuid(); } else if ("DELETE_STORY".equals(command)) { @@ -199,11 +201,11 @@ public class RemoteLibraryServer extends ServerObject { return Instance.getLibrary().getCover((String) args[0]); } else if ("GET_CUSTOM_COVER".equals(command)) { if ("SOURCE".equals(args[0])) { - return Instance.getLibrary() - .getCustomSourceCover((String) args[1]); + return Instance.getLibrary().getCustomSourceCover( + (String) args[1]); } else if ("AUTHOR".equals(args[0])) { - return Instance.getLibrary() - .getCustomAuthorCover((String) args[1]); + return Instance.getLibrary().getCustomAuthorCover( + (String) args[1]); } else { return null; } @@ -341,8 +343,9 @@ public class RemoteLibraryServer extends ServerObject { public void progress(Progress progress, String name) { int min = pg.getMin(); int max = pg.getMax(); - int relativeProgress = min + (int) Math - .round(pg.getRelativeProgress() * (max - min)); + int relativeProgress = min + + (int) Math.round(pg.getRelativeProgress() + * (max - min)); // Do not re-send the same value twice over the wire, // unless more than 2 seconds have elapsed (to maintain the @@ -354,8 +357,7 @@ public class RemoteLibraryServer extends ServerObject { p[2] = relativeProgress; try { - action.send( - new Integer[] { min, max, relativeProgress }); + action.send(new Integer[] { min, max, relativeProgress }); action.rec(); } catch (Exception e) { Instance.getTraceHandler().error(e);