Version 3.1.6: fix Bridge, Serialiser, Progress:
authorNiki Roo <niki@nikiroo.be>
Sat, 2 Dec 2017 19:18:29 +0000 (20:18 +0100)
committerNiki Roo <niki@nikiroo.be>
Sat, 2 Dec 2017 19:18:29 +0000 (20:18 +0100)
- Serialiser bug with custom objects and string inside another custom object fixed
- Bridge default maxPrintSize parameter fixed
- Progress/ProgressBar synchronisation issues fixed

16 files changed:
VERSION
changelog.md
src/be/nikiroo/utils/Progress.java
src/be/nikiroo/utils/serial/CustomSerializer.java
src/be/nikiroo/utils/serial/Importer.java
src/be/nikiroo/utils/serial/SerialUtils.java
src/be/nikiroo/utils/serial/server/ConnectActionClient.java
src/be/nikiroo/utils/serial/server/ConnectActionClientObject.java
src/be/nikiroo/utils/serial/server/ConnectActionClientString.java
src/be/nikiroo/utils/serial/server/Server.java
src/be/nikiroo/utils/serial/server/ServerBridge.java
src/be/nikiroo/utils/serial/server/ServerObject.java
src/be/nikiroo/utils/serial/server/ServerString.java
src/be/nikiroo/utils/test/SerialServerTest.java
src/be/nikiroo/utils/test/SerialTest.java
src/be/nikiroo/utils/ui/ProgressBar.java

diff --git a/VERSION b/VERSION
index 3ad0595adcc26a4d1811520b2bc474ca92c11bb2..9cec7165ab0a01ccc4c9b089abd747bd12432329 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.1.5
+3.1.6
index e4354b80316a6ce5b64000203da939d6d9715bae..65521454b1c8e5f8f89ac9823910eb57c5782e6d 100644 (file)
@@ -1,5 +1,11 @@
 # nikiroo-utils
 
+## Version 3.1.6
+
+- Fix Serialiser issue with custom objects and String in a custom object
+- Fix Progress/ProgressBar synchronisation issues
+- Fix Bridge default maxPrintSize parameter
+
 ## Version 3.1.5
 
 - Fix Cache with no-parent file
index 38ce29f9c8b49e6c4a27dd939fbf4d89d330817f..6f05110e8715305b438258b45cf1674b992a4451 100644 (file)
@@ -6,7 +6,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Set;
 
 /**
  * Progress reporting system, possibly nested.
@@ -318,8 +317,10 @@ public class Progress {
         * 
         * @return the children (Who will think of the children??)
         */
-       public Set<Progress> getChildren() {
-               return children.keySet();
+       public List<Progress> getChildren() {
+               synchronized (getLock()) {
+                       return new ArrayList<Progress>(children.keySet());
+               }
        }
 
        /**
@@ -359,7 +360,9 @@ public class Progress {
         *            the listener
         */
        public void addProgressListener(ProgressListener l) {
-               this.listeners.add(l);
+               synchronized (getLock()) {
+                       this.listeners.add(l);
+               }
        }
 
        /**
@@ -371,7 +374,9 @@ public class Progress {
         * @return TRUE if it was found (and removed)
         */
        public boolean removeProgressListener(ProgressListener l) {
-               return this.listeners.remove(l);
+               synchronized (getLock()) {
+                       return this.listeners.remove(l);
+               }
        }
 
        /**
@@ -408,9 +413,12 @@ public class Progress {
                        public void progress(Progress pg, String name) {
                                synchronized (getLock()) {
                                        double total = relativeLocalProgress;
-                                       for (Entry<Progress, Double> entry : children.entrySet()) {
-                                               total += (entry.getValue() / (max - min))
-                                                               * entry.getKey().getRelativeProgress();
+                                       synchronized (getLock()) {
+                                               for (Entry<Progress, Double> entry : children
+                                                               .entrySet()) {
+                                                       total += (entry.getValue() / (max - min))
+                                                                       * entry.getKey().getRelativeProgress();
+                                               }
                                        }
 
                                        setRelativeProgress(pg, name, total);
@@ -418,7 +426,9 @@ public class Progress {
                        }
                });
 
-               this.children.put(progress, weight);
+               synchronized (getLock()) {
+                       this.children.put(progress, weight);
+               }
        }
 
        /**
index 0bafb86f65152755ca7684614622af34e7aec449..be89316eae07b74f6a67ccaeb589641ba81f8cea 100644 (file)
@@ -23,7 +23,7 @@ public abstract class CustomSerializer {
        public boolean encode(StringBuilder builder, Object value) {
                int prev = builder.length();
                String customString = toString(value);
-               builder.append("custom:").append(getType()).append(":");
+               builder.append("custom^").append(getType()).append("^");
                if (!SerialUtils.encode(builder, customString)) {
                        builder.delete(prev, builder.length());
                        return false;
@@ -37,23 +37,23 @@ public abstract class CustomSerializer {
        }
 
        public static boolean isCustom(String encodedValue) {
-               int pos1 = encodedValue.indexOf(':');
-               int pos2 = encodedValue.indexOf(':', pos1 + 1);
+               int pos1 = encodedValue.indexOf('^');
+               int pos2 = encodedValue.indexOf('^', pos1 + 1);
 
-               return pos1 >= 0 && pos2 >= 0 && encodedValue.startsWith("custom:");
+               return pos1 >= 0 && pos2 >= 0 && encodedValue.startsWith("custom^");
        }
 
        public static String typeOf(String encodedValue) {
-               int pos1 = encodedValue.indexOf(':');
-               int pos2 = encodedValue.indexOf(':', pos1 + 1);
+               int pos1 = encodedValue.indexOf('^');
+               int pos2 = encodedValue.indexOf('^', pos1 + 1);
                String type = encodedValue.substring(pos1 + 1, pos2);
 
                return type;
        }
 
        public static String contentOf(String encodedValue) {
-               int pos1 = encodedValue.indexOf(':');
-               int pos2 = encodedValue.indexOf(':', pos1 + 1);
+               int pos1 = encodedValue.indexOf('^');
+               int pos2 = encodedValue.indexOf('^', pos1 + 1);
                String encodedContent = encodedValue.substring(pos2 + 1);
 
                return encodedContent;
index 8fba42d7e78e112ddc85b017904ec21510abfe5a..e7285c42ca329c7a6e84c73fba0189c228493781 100644 (file)
@@ -154,7 +154,8 @@ public class Importer {
                        if (line.endsWith(":")) {
                                // field value is compound
                                currentFieldName = line.substring(0, line.length() - 1);
-                       } else if (line.startsWith(":") || !line.contains(":")) {
+                       } else if (line.startsWith(":") || !line.contains(":")
+                                       || line.startsWith("\"") || CustomSerializer.isCustom(line)) {
                                // not a field value but a direct value
                                me = SerialUtils.decode(line);
                        } else {
index decf57525fb30336ab00dee5be5bb2952d5f8196..a1105a90d441352d71fa51faf5d56f8294f35318 100644 (file)
@@ -7,6 +7,7 @@ import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UnknownFormatConversionException;
@@ -37,6 +38,7 @@ import be.nikiroo.utils.ImageUtils;
  * <li>Enum (any enum whose name and value is known by the caller)</li>
  * <li>java.awt.image.BufferedImage (as a {@link CustomSerializer})</li>
  * <li>An array of the above (as a {@link CustomSerializer})</li>
+ * <li>URL</li>
  * </ul>
  * 
  * @author niki
@@ -106,6 +108,30 @@ public class SerialUtils {
                        }
                });
 
+               // URL:
+               customTypes.put("java.net.URL", new CustomSerializer() {
+                       @Override
+                       protected String toString(Object value) {
+                               if (value != null) {
+                                       return ((URL) value).toString();
+                               }
+                               return null;
+                       }
+
+                       @Override
+                       protected Object fromString(String content) throws IOException {
+                               if (content != null) {
+                                       return new URL(content);
+                               }
+                               return null;
+                       }
+
+                       @Override
+                       protected String getType() {
+                               return "java.net.URL";
+                       }
+               });
+
                // Images (this is currently the only supported image type by default)
                customTypes.put("java.awt.image.BufferedImage", new CustomSerializer() {
                        @Override
index 626b62f78494ab4fdb818220629a281bc3507f14..db06a9f247544cef1d210531d7db45429af1a78b 100644 (file)
@@ -2,6 +2,7 @@ package be.nikiroo.utils.serial.server;
 
 import java.io.IOException;
 import java.net.Socket;
+import java.net.UnknownHostException;
 
 import be.nikiroo.utils.Version;
 
@@ -44,7 +45,12 @@ abstract class ConnectActionClient {
         *            TRUE for an SSL connection, FALSE for plain text
         * 
         * @throws IOException
-        *             in case of I/O error when creating the socket
+        *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the host is not known
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ConnectActionClient(String host, int port, boolean ssl)
                        throws IOException {
@@ -64,7 +70,12 @@ abstract class ConnectActionClient {
         *            the client version
         * 
         * @throws IOException
-        *             in case of I/O error when creating the socket
+        *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the host is not known
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ConnectActionClient(String host, int port, boolean ssl,
                        Version version) throws IOException {
index e9673ac299730c521aa9c1c7d0fff0165f1c7063..dd6f917ee03cf373ffe025a26fe83518e364f457 100644 (file)
@@ -2,6 +2,7 @@ package be.nikiroo.utils.serial.server;
 
 import java.io.IOException;
 import java.net.Socket;
+import java.net.UnknownHostException;
 
 import be.nikiroo.utils.Version;
 
@@ -39,7 +40,12 @@ public class ConnectActionClientObject extends ConnectActionClient {
         *            TRUE for an SSL connection, FALSE for plain text
         * 
         * @throws IOException
-        *             in case of I/O error when creating the socket
+        *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ConnectActionClientObject(String host, int port, boolean ssl)
                        throws IOException {
@@ -59,7 +65,12 @@ public class ConnectActionClientObject extends ConnectActionClient {
         *            the client version
         * 
         * @throws IOException
-        *             in case of I/O error when creating the socket
+        *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ConnectActionClientObject(String host, int port, boolean ssl,
                        Version version) throws IOException {
index f9402cbeb9a0d5a14cf4e6083c3bdefb2f725248..8b5ec2af1bb56da102c9c80c5d431bef558f1049 100644 (file)
@@ -2,6 +2,7 @@ package be.nikiroo.utils.serial.server;
 
 import java.io.IOException;
 import java.net.Socket;
+import java.net.UnknownHostException;
 
 import be.nikiroo.utils.Version;
 
@@ -39,7 +40,12 @@ public class ConnectActionClientString extends ConnectActionClient {
         *            TRUE for an SSL connection, FALSE for plain text
         * 
         * @throws IOException
-        *             in case of I/O error when creating the socket
+        *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ConnectActionClientString(String host, int port, boolean ssl)
                        throws IOException {
@@ -59,7 +65,12 @@ public class ConnectActionClientString extends ConnectActionClient {
         *            the client version
         * 
         * @throws IOException
-        *             in case of I/O error when creating the socket
+        *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ConnectActionClientString(String host, int port, boolean ssl,
                        Version version) throws IOException {
index be847d02884ec3112affd0d730d0d364b158e458..2022469a0296387f90bc5aca40005d4b2981849c 100644 (file)
@@ -3,6 +3,7 @@ package be.nikiroo.utils.serial.server;
 import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -62,6 +63,11 @@ abstract class Server implements Runnable {
         * 
         * @throws IOException
         *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public Server(int port, boolean ssl) throws IOException {
                this((String) null, port, ssl);
@@ -80,6 +86,11 @@ abstract class Server implements Runnable {
         * 
         * @throws IOException
         *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public Server(String name, int port, boolean ssl) throws IOException {
                this.name = name;
@@ -180,7 +191,8 @@ abstract class Server implements Runnable {
                }
 
                try {
-                       tracer.trace(name + ": server starting on port " + port);
+                       tracer.trace(name + ": server starting on port " + port + " ("
+                                       + (ssl ? "SSL" : "plain text") + ")");
 
                        while (started && !exiting) {
                                count(1);
@@ -334,6 +346,11 @@ abstract class Server implements Runnable {
         * 
         * @throws IOException
         *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the host is not known
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        static Socket createSocket(String host, int port, boolean ssl)
                        throws IOException {
@@ -360,6 +377,11 @@ abstract class Server implements Runnable {
         * 
         * @throws IOException
         *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        static ServerSocket createSocketServer(int port, boolean ssl)
                        throws IOException {
index 4aa9c41fab5b7cbf9bd934008b4002f5fc366f75..9ccae1c498cd04611ccb4d6016da4255efdae68f 100644 (file)
@@ -3,6 +3,7 @@ package be.nikiroo.utils.serial.server;
 import java.io.IOException;
 import java.lang.reflect.Array;
 import java.net.Socket;
+import java.net.UnknownHostException;
 
 import be.nikiroo.utils.StringUtils;
 import be.nikiroo.utils.TraceHandler;
@@ -45,6 +46,11 @@ public class ServerBridge extends Server {
         * 
         * @throws IOException
         *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ServerBridge(int port, boolean ssl, String forwardToHost,
                        int forwardToPort, boolean forwardToSsl) throws IOException {
@@ -73,6 +79,11 @@ public class ServerBridge extends Server {
         * 
         * @throws IOException
         *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ServerBridge(String name, int port, boolean ssl,
                        String forwardToHost, int forwardToPort, boolean forwardToSsl)
@@ -113,30 +124,34 @@ public class ServerBridge extends Server {
                                onClientContact(clientVersion);
                                final ConnectActionServerString bridge = this;
 
-                               new ConnectActionClientString(forwardToHost, forwardToPort,
-                                               forwardToSsl, clientVersion) {
-                                       @Override
-                                       public void action(final Version serverVersion)
-                                                       throws Exception {
-                                               onServerContact(serverVersion);
+                               try {
+                                       new ConnectActionClientString(forwardToHost, forwardToPort,
+                                                       forwardToSsl, clientVersion) {
+                                               @Override
+                                               public void action(final Version serverVersion)
+                                                               throws Exception {
+                                                       onServerContact(serverVersion);
 
-                                               for (String fromClient = bridge.rec(); fromClient != null; fromClient = bridge
-                                                               .rec()) {
-                                                       onRec(clientVersion, fromClient);
-                                                       String fromServer = send(fromClient);
-                                                       onSend(serverVersion, fromServer);
-                                                       bridge.send(fromServer);
-                                               }
+                                                       for (String fromClient = bridge.rec(); fromClient != null; fromClient = bridge
+                                                                       .rec()) {
+                                                               onRec(clientVersion, fromClient);
+                                                               String fromServer = send(fromClient);
+                                                               onSend(serverVersion, fromServer);
+                                                               bridge.send(fromServer);
+                                                       }
 
-                                               getTraceHandler().trace("=== DONE", 1);
-                                               getTraceHandler().trace("", 1);
-                                       }
+                                                       getTraceHandler().trace("=== DONE", 1);
+                                                       getTraceHandler().trace("", 1);
+                                               }
 
-                                       @Override
-                                       protected void onError(Exception e) {
-                                               ServerBridge.this.onError(e);
-                                       }
-                               }.connect();
+                                               @Override
+                                               protected void onError(Exception e) {
+                                                       ServerBridge.this.onError(e);
+                                               }
+                                       }.connect();
+                               } catch (Exception e) {
+                                       ServerBridge.this.onError(e);
+                               }
                        }
                };
        }
@@ -187,6 +202,15 @@ public class ServerBridge extends Server {
                trace("<<< SERVER (" + serverVersion + ")", data);
        }
 
+       @Override
+       public void run() {
+               getTraceHandler().trace(
+                               getName() + ": will forward to " + forwardToHost + ":"
+                                               + forwardToPort + " ("
+                                               + (forwardToSsl ? "SSL" : "plain text") + ")");
+               super.run();
+       }
+
        /**
         * Trace the data with the given prefix.
         * 
@@ -305,7 +329,7 @@ public class ServerBridge extends Server {
                        if (args.length > 6) {
                                traceLevel = Integer.parseInt(args[i++]);
                        }
-                       int maxPrintSize = 1;
+                       int maxPrintSize = 0;
                        if (args.length > 7) {
                                maxPrintSize = Integer.parseInt(args[i++]);
                        }
index dec84738865f480d64ae9a11dbd0ea5cd01b1058..53606ed420a671ce34826fe0d1380dac9501d05d 100644 (file)
@@ -2,6 +2,7 @@ package be.nikiroo.utils.serial.server;
 
 import java.io.IOException;
 import java.net.Socket;
+import java.net.UnknownHostException;
 
 import be.nikiroo.utils.Version;
 
@@ -28,6 +29,11 @@ abstract public class ServerObject extends Server {
         * 
         * @throws IOException
         *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ServerObject(int port, boolean ssl) throws IOException {
                super(port, ssl);
@@ -46,6 +52,11 @@ abstract public class ServerObject extends Server {
         * 
         * @throws IOException
         *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ServerObject(String name, int port, boolean ssl) throws IOException {
                super(name, port, ssl);
index c19e0ae68077a73841f6581999fa89e88967bd8c..3185c6f450f0cda09c4b66d7b1924d917c027417 100644 (file)
@@ -2,6 +2,7 @@ package be.nikiroo.utils.serial.server;
 
 import java.io.IOException;
 import java.net.Socket;
+import java.net.UnknownHostException;
 
 import be.nikiroo.utils.Version;
 
@@ -28,6 +29,11 @@ abstract public class ServerString extends Server {
         * 
         * @throws IOException
         *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ServerString(int port, boolean ssl) throws IOException {
                super(port, ssl);
@@ -46,6 +52,11 @@ abstract public class ServerString extends Server {
         * 
         * @throws IOException
         *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
         */
        public ServerString(String name, int port, boolean ssl) throws IOException {
                super(name, port, ssl);
index 67ba1610ef7725c4d8939174bfe24f5daa5aa584..a34d30e4fa7a83dfca08ba1cad6a9edac522c26c 100644 (file)
@@ -1,5 +1,7 @@
 package be.nikiroo.utils.test;
 
+import java.net.URL;
+
 import be.nikiroo.utils.Version;
 import be.nikiroo.utils.serial.server.ConnectActionClientObject;
 import be.nikiroo.utils.serial.server.ConnectActionClientString;
@@ -44,6 +46,7 @@ class SerialServerTest extends TestLauncher {
                                ServerBridge br = null;
                                if (bridge) {
                                        br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br.setTraceHandler(null);
 
                                        port = br.getPort();
                                        assertEquals(
@@ -95,7 +98,6 @@ class SerialServerTest extends TestLauncher {
 
                                        @Override
                                        protected void onError(Exception e) {
-                                               super.onError(e);
                                                err[0] = e;
                                        }
                                };
@@ -107,6 +109,7 @@ class SerialServerTest extends TestLauncher {
                                ServerBridge br = null;
                                if (bridge) {
                                        br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
                                }
@@ -159,7 +162,6 @@ class SerialServerTest extends TestLauncher {
 
                                        @Override
                                        protected void onError(Exception e) {
-                                               super.onError(e);
                                                err[0] = e;
                                        }
                                };
@@ -171,6 +173,7 @@ class SerialServerTest extends TestLauncher {
                                ServerBridge br = null;
                                if (bridge) {
                                        br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
                                }
@@ -224,7 +227,6 @@ class SerialServerTest extends TestLauncher {
 
                                        @Override
                                        protected void onError(Exception e) {
-                                               super.onError(e);
                                                err[0] = e;
                                        }
                                };
@@ -236,6 +238,7 @@ class SerialServerTest extends TestLauncher {
                                ServerBridge br = null;
                                if (bridge) {
                                        br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
                                }
@@ -309,11 +312,8 @@ class SerialServerTest extends TestLauncher {
 
                                ServerBridge br = null;
                                if (bridge) {
-                                       br = new ServerBridge(0, ssl, "", port, ssl) {
-                                               @Override
-                                               protected void onError(Exception e) {
-                                               }
-                                       };
+                                       br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
                                }
@@ -364,7 +364,6 @@ class SerialServerTest extends TestLauncher {
 
                                        @Override
                                        protected void onError(Exception e) {
-                                               super.onError(e);
                                                err[0] = e;
                                        }
                                };
@@ -376,6 +375,7 @@ class SerialServerTest extends TestLauncher {
                                ServerBridge br = null;
                                if (bridge) {
                                        br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
                                }
@@ -428,7 +428,6 @@ class SerialServerTest extends TestLauncher {
 
                                        @Override
                                        protected void onError(Exception e) {
-                                               super.onError(e);
                                                err[0] = e;
                                        }
                                };
@@ -440,6 +439,7 @@ class SerialServerTest extends TestLauncher {
                                ServerBridge br = null;
                                if (bridge) {
                                        br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
                                }
@@ -474,6 +474,78 @@ class SerialServerTest extends TestLauncher {
                        }
                });
 
+               series.addTest(new TestCase("Object array of URLs " + ssls) {
+                       final Object[] sent = new Object[1];
+                       final Object[] recd = new Object[1];
+                       final Exception[] err = new Exception[1];
+
+                       @Override
+                       public void test() throws Exception {
+                               ServerObject server = new ServerObject(this.getName(), 0, ssl) {
+                                       @Override
+                                       protected Object onRequest(
+                                                       ConnectActionServerObject action,
+                                                       Version clientVersion, Object data)
+                                                       throws Exception {
+                                               sent[0] = data;
+                                               return new Object[] { "ACK" };
+                                       }
+
+                                       @Override
+                                       protected void onError(Exception e) {
+                                               err[0] = e;
+                                       }
+                               };
+
+                               int port = server.getPort();
+
+                               server.start();
+
+                               ServerBridge br = null;
+                               if (bridge) {
+                                       br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br.setTraceHandler(null);
+                                       port = br.getPort();
+                                       br.start();
+                               }
+
+                               try {
+                                       try {
+                                               new ConnectActionClientObject(null, port, ssl) {
+                                                       @Override
+                                                       public void action(Version serverVersion)
+                                                                       throws Exception {
+                                                               recd[0] = send(new Object[] {
+                                                                               "key",
+                                                                               new URL(
+                                                                                               "https://example.com/from_client"),
+                                                                               "https://example.com/from_client" });
+                                                       }
+                                               }.connect();
+                                       } finally {
+                                               server.stop();
+                                       }
+                               } finally {
+                                       if (br != null) {
+                                               br.stop();
+                                       }
+                               }
+
+                               if (err[0] != null) {
+                                       fail("An exception was thrown: " + err[0].getMessage());
+                               }
+
+                               Object[] sento = (Object[]) (sent[0]);
+                               Object[] recdo = (Object[]) (recd[0]);
+
+                               assertEquals("key", sento[0]);
+                               assertEquals("https://example.com/from_client",
+                                               ((URL) sento[1]).toString());
+                               assertEquals("https://example.com/from_client", sento[2]);
+                               assertEquals("ACK", recdo[0]);
+                       }
+               });
+
                series.addTest(new TestCase("Multiple call from client " + ssls) {
                        final Object[] sent = new Object[3];
                        final Object[] recd = new Object[3];
@@ -493,7 +565,6 @@ class SerialServerTest extends TestLauncher {
 
                                        @Override
                                        protected void onError(Exception e) {
-                                               super.onError(e);
                                                err[0] = e;
                                        }
                                };
@@ -505,6 +576,7 @@ class SerialServerTest extends TestLauncher {
                                ServerBridge br = null;
                                if (bridge) {
                                        br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
                                }
index b203c2a73f96ed3a1d52fba784bb428f47632778..b27280420eb4aaf1552554d92dbe544bf7e4cd28 100644 (file)
@@ -1,5 +1,7 @@
 package be.nikiroo.utils.test;
 
+import java.net.URL;
+
 import be.nikiroo.utils.serial.Exporter;
 import be.nikiroo.utils.serial.Importer;
 
@@ -28,6 +30,53 @@ class SerialTest extends TestLauncher {
                        }
                });
 
+               addTest(new TestCase("URL Import/Export") {
+                       @Override
+                       public void test() throws Exception {
+                               URL data = new URL("https://fanfan.be/");
+                               String encoded = new Exporter().append(data).toString(false);
+                               Object redata = new Importer().read(encoded).getValue();
+                               String reencoded = new Exporter().append(redata)
+                                               .toString(false);
+
+                               assertEquals(encoded.replaceAll("@[0-9]*", "@REF"),
+                                               reencoded.replaceAll("@[0-9]*", "@REF"));
+                       }
+               });
+
+               addTest(new TestCase("URL-String Import/Export") {
+                       @Override
+                       public void test() throws Exception {
+                               String data = new URL("https://fanfan.be/").toString();
+                               String encoded = new Exporter().append(data).toString(false);
+                               Object redata = new Importer().read(encoded).getValue();
+                               String reencoded = new Exporter().append(redata)
+                                               .toString(false);
+
+                               assertEquals(encoded.replaceAll("@[0-9]*", "@REF"),
+                                               reencoded.replaceAll("@[0-9]*", "@REF"));
+                               assertEquals(data, redata);
+                       }
+               });
+
+               addTest(new TestCase("URL/URL-String arrays Import/Export") {
+                       @Override
+                       public void test() throws Exception {
+                               final String url = "https://fanfan.be/";
+
+                               Object[] data = new Object[] { new URL(url), url };
+                               String encoded = new Exporter().append(data).toString(false);
+                               Object redata = new Importer().read(encoded).getValue();
+                               String reencoded = new Exporter().append(redata)
+                                               .toString(false);
+
+                               assertEquals(encoded.replaceAll("@[0-9]*", "@REF"),
+                                               reencoded.replaceAll("@[0-9]*", "@REF"));
+                               assertEquals(data[0], ((Object[]) redata)[0]);
+                               assertEquals(data[1], ((Object[]) redata)[1]);
+                       }
+               });
+
                addTest(new TestCase("Import/Export with nested objects") {
                        @Override
                        public void test() throws Exception {
index 2c91c70dcd5db543285816353841fe9fee7e8337..219cde9a2d2f5fc2555aa8cd7519b573e73e232d 100644 (file)
@@ -28,6 +28,7 @@ public class ProgressBar extends JPanel {
        private List<ActionListener> actionListeners;
        private List<ActionListener> updateListeners;
        private Progress pg;
+       private Object lock = new Object();
 
        public ProgressBar() {
                bars = new HashMap<Progress, JProgressBar>();
@@ -68,6 +69,7 @@ public class ProgressBar extends JPanel {
                                                                        bar.setValue(pg.getProgress());
                                                                        bar.setString(pg.getName());
 
+                                                                       synchronized (lock) {
                                                                        for (Progress pgChild : getChildrenAsOrderedList(pg)) {
                                                                                JProgressBar barChild = bars
                                                                                                .get(pgChild);
@@ -83,12 +85,15 @@ public class ProgressBar extends JPanel {
                                                                                barChild.setValue(pgChild.getProgress());
                                                                                barChild.setString(pgChild.getName());
                                                                        }
-
+                                                                       
                                                                        if (ProgressBar.this.pg == null) {
                                                                                bars.clear();
                                                                        } else {
                                                                                bars = newBars;
-
+                                                                       }
+                                                                       }
+                                                                       
+                                                                       if (ProgressBar.this.pg != null) {
                                                                                if (pg.isDone()) {
                                                                                        pg.removeProgressListener(l);
                                                                                        for (ActionListener listener : actionListeners) {
@@ -138,33 +143,38 @@ public class ProgressBar extends JPanel {
        // only named ones
        private List<Progress> getChildrenAsOrderedList(Progress pg) {
                List<Progress> children = new ArrayList<Progress>();
-               for (Progress child : pg.getChildren()) {
+               
+               synchronized (lock) {
+                       for (Progress child : pg.getChildren()) {
                        if (child.getName() != null && !child.getName().isEmpty()) {
                                children.add(child);
                        }
                        children.addAll(getChildrenAsOrderedList(child));
                }
-
+               }
+               
                return children;
        }
 
        private void update() {
-               invalidate();
-               removeAll();
-
-               if (pg != null) {
-                       setLayout(new GridLayout(bars.size(), 1));
-                       add(bars.get(pg), 0);
-                       for (Progress child : getChildrenAsOrderedList(pg)) {
-                               JProgressBar jbar = bars.get(child);
-                               if (jbar != null) {
-                                       add(jbar);
+               synchronized (lock) {
+                       invalidate();
+                       removeAll();
+
+                       if (pg != null) {
+                               setLayout(new GridLayout(bars.size(), 1));
+                               add(bars.get(pg), 0);
+                               for (Progress child : getChildrenAsOrderedList(pg)) {
+                                       JProgressBar jbar = bars.get(child);
+                                       if (jbar != null) {
+                                               add(jbar);
+                                       }
                                }
                        }
-               }
 
-               validate();
-               repaint();
+                       validate();
+                       repaint();
+               }
 
                for (ActionListener listener : updateListeners) {
                        listener.actionPerformed(new ActionEvent(this, 0, "update"));