update nikiroo-utils, better rec/send remote server info
authorNiki Roo <niki@nikiroo.be>
Tue, 30 Apr 2019 21:10:01 +0000 (23:10 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 30 Apr 2019 21:10:01 +0000 (23:10 +0200)
libs/nikiroo-utils-4.7.2-dev-sources.jar
src/be/nikiroo/fanfix/library/RemoteLibraryServer.java

index 1e960e954c8d031ad642643fbb52d1058330cb0a..604c7611fbf7593d2b6a9e9c246fb48e8ca33fd4 100644 (file)
Binary files a/libs/nikiroo-utils-4.7.2-dev-sources.jar and b/libs/nikiroo-utils-4.7.2-dev-sources.jar differ
index 0893746239292297aeb1091aa51780351288b749..62548d678f2b04c6e59e8bb3e455a578e9f68f8c 100644 (file)
@@ -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<Long, String> commands = new HashMap<Long, String>();
+       private Map<Long, Long> times = new HashMap<Long, Long>();
+
        /**
         * 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 {