Clean up Argeo Init
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / CmsUuidFactory.java
index de0be36618558f4fa49c2a3cf09bfb222472d3fa..b61e35dbc67371426c9040c6482ccc61ee35dcee 100644 (file)
@@ -11,14 +11,15 @@ import java.util.Enumeration;
 
 import org.argeo.api.cms.CmsLog;
 import org.argeo.api.uuid.ConcurrentUuidFactory;
+import org.argeo.api.uuid.NodeIdSupplier;
 import org.argeo.api.uuid.UuidBinaryUtils;
 
 public class CmsUuidFactory extends ConcurrentUuidFactory {
        private final static CmsLog log = CmsLog.getLog(CmsUuidFactory.class);
 
        public CmsUuidFactory(byte[] nodeId) {
-               super(nodeId);
-               assert newTimeUUID().node() == BitSet.valueOf(toNodeIdBytes(nodeId, 0)).toLongArray()[0];
+               super(0, nodeId);
+               assert createTimeUUID().node() == BitSet.valueOf(toNodeIdBytes(nodeId, 0)).toLongArray()[0];
        }
 
        public CmsUuidFactory() {
@@ -73,10 +74,12 @@ public class CmsUuidFactory extends ConcurrentUuidFactory {
                        }
                }
                InetAddress selectedIp = selectedIpv6 != null ? selectedIpv6 : selectedIpv4;
-               if (selectedIp == null)
-                       throw new IllegalStateException("No IP address found");
+               if (selectedIp == null) {
+                       log.warn("No IP address found, using a random node id for UUID generation");
+                       return NodeIdSupplier.randomNodeId();
+               }
                byte[] digest = sha1(selectedIp.getAddress());
-               log.info("Use IP " + selectedIp + " hashed as " + UuidBinaryUtils.toHexString(digest) + " as node id");
+               log.debug("Use IP " + selectedIp + " hashed as " + UuidBinaryUtils.toHexString(digest) + " as node id");
                byte[] nodeId = toNodeIdBytes(digest, 0);
                // marks that this is not based on MAC address
                forceToNoMacAddress(nodeId, 0);