X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibraryServer.java;h=62548d678f2b04c6e59e8bb3e455a578e9f68f8c;hb=9b558341bc348212a2b80170cdc76fa9a3b5a334;hp=72f4e83bcc19a8563102a2adccf3e2762ebce3e8;hpb=51bf906d225bd14db66c9961e01c54cdaa500c54;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java index 72f4e83..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). @@ -64,13 +69,12 @@ public class RemoteLibraryServer extends ServerObject { */ public RemoteLibraryServer(String key, int port) throws IOException { super("Fanfix remote library", port, key); - setTraceHandler(Instance.getTraceHandler()); } @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 = ""; @@ -95,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 {