From: Niki Roo Date: Tue, 30 Apr 2019 21:10:01 +0000 (+0200) Subject: update nikiroo-utils, better rec/send remote server info X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=9b558341bc348212a2b80170cdc76fa9a3b5a334;p=nikiroo-utils.git update nikiroo-utils, better rec/send remote server info --- diff --git a/libs/nikiroo-utils-4.7.2-dev-sources.jar b/libs/nikiroo-utils-4.7.2-dev-sources.jar index 1e960e9..604c761 100644 Binary files a/libs/nikiroo-utils-4.7.2-dev-sources.jar and b/libs/nikiroo-utils-4.7.2-dev-sources.jar differ diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java index 0893746..62548d6 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java @@ -4,7 +4,9 @@ import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.net.ssl.SSLException; @@ -50,6 +52,9 @@ import be.nikiroo.utils.serial.server.ServerObject; * @author niki */ public class RemoteLibraryServer extends ServerObject { + private Map commands = new HashMap(); + private Map times = new HashMap(); + /** * Create a new remote server (will not be active until * {@link RemoteLibraryServer#start()} is called). @@ -68,8 +73,8 @@ public class RemoteLibraryServer extends ServerObject { } @Override - protected Object onRequest(ConnectActionServerObject action, Object data) - throws Exception { + protected Object onRequest(ConnectActionServerObject action, Object data, + long id) throws Exception { long start = new Date().getTime(); String command = ""; @@ -94,14 +99,22 @@ public class RemoteLibraryServer extends ServerObject { Object rep = doRequest(action, command, args); - String rec = StringUtils.formatNumber(action.getBytesReceived()) + "b"; - String sent = StringUtils.formatNumber(action.getBytesSent()) + "b"; - System.out.println(String.format("[>%s]: (%s sent, %s rec) in %d ms", - command, sent, rec, (new Date().getTime() - start))); + commands.put(id, command); + times.put(id, (new Date().getTime() - start)); return rep; } + @Override + protected void onRequestDone(long id, long bytesReceived, long bytesSent) { + String rec = StringUtils.formatNumber(bytesReceived) + "b"; + String sent = StringUtils.formatNumber(bytesSent) + "b"; + System.out.println(String.format("[>%s]: (%s sent, %s rec) in %d ms", + commands.get(id), sent, rec, times.get(id))); + commands.remove(id); + times.remove(id); + } + private Object doRequest(ConnectActionServerObject action, String command, Object[] args) throws NoSuchFieldException, NoSuchMethodException, ClassNotFoundException, IOException {