You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:17:28 UTC

[sling-org-apache-sling-settings] 09/21: SLING-5190 factor out of SlingSettingsServiceImpl a Sling ID util

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.settings-1.3.8
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-settings.git

commit bbdf3d146669a3601d63689e59deb761ec98c336
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Fri Oct 23 12:02:50 2015 +0000

    SLING-5190 factor out of SlingSettingsServiceImpl a Sling ID util
    
    * fix logging and adjust exception handling
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/settings@1710190 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/sling/settings/impl/SlingIdUtil.java  | 14 +++-----------
 .../sling/settings/impl/SlingSettingsServiceImpl.java     | 15 +++++++++++++--
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java b/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java
index 95032c2..0bcbf3b 100644
--- a/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java
+++ b/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java
@@ -31,7 +31,7 @@ public class SlingIdUtil {
     /**
      * Read the id from a file.
      */
-    static String readSlingId(final File idFile, int maxLength) {
+    static String readSlingId(final File idFile, int maxLength) throws IOException {
         if (idFile.exists() && idFile.length() >= maxLength) {
             DataInputStream dis = null;
             try {
@@ -41,13 +41,7 @@ public class SlingIdUtil {
                 final String rawString = new String(rawBytes, "ISO-8859-1");
 
                 // roundtrip to ensure correct format of UUID value
-                final String id = UUID.fromString(rawString).toString();
-                // logger.debug("Got Sling ID {} from file {}", id, idFile);
-
-                return id;
-            } catch (final Throwable t) {
-                // logger.error("Failed reading UUID from id file " + idFile
-                //        + ", creating new id", t);
+                return UUID.fromString(rawString).toString();
             } finally {
                 if (dis != null) {
                     try {
@@ -62,7 +56,7 @@ public class SlingIdUtil {
     /**
      * Write the sling id file.
      */
-    static void writeSlingId(final File idFile, final String id) {
+    static void writeSlingId(final File idFile, final String id) throws IOException {
         idFile.delete();
         idFile.getParentFile().mkdirs();
         DataOutputStream dos = null;
@@ -71,8 +65,6 @@ public class SlingIdUtil {
             dos = new DataOutputStream(new FileOutputStream(idFile));
             dos.write(rawBytes, 0, rawBytes.length);
             dos.flush();
-        } catch (final Throwable t) {
-            // logger.error("Failed writing UUID to id file " + idFile, t);
         } finally {
             if (dos != null) {
                 try {
diff --git a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
index 1899aa3..d865896 100644
--- a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
+++ b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
@@ -127,12 +127,23 @@ public class SlingSettingsServiceImpl
             // the osgi framework does not support storing something in the file system
             throw new RuntimeException("Unable to read from bundle data file.");
         }
-        this.slingId = SlingIdUtil.readSlingId(idFile, SLING_ID_LENGTH);
+
+        try {
+            slingId = SlingIdUtil.readSlingId(idFile, SLING_ID_LENGTH);
+            logger.info("Read Sling ID {} from file {}", slingId, idFile);
+        } catch (final Throwable t) {
+            logger.error("Failed reading Sling ID from file " + idFile, t);
+        }
 
         // no sling id yet or failure to read file: create an id and store
         if (slingId == null) {
             slingId = UUID.randomUUID().toString();
-            SlingIdUtil.writeSlingId(idFile, this.slingId);
+            logger.info("Created new Sling ID {}", slingId);
+            try {
+                SlingIdUtil.writeSlingId(idFile, slingId);
+            } catch (final Throwable t) {
+                logger.error("Failed writing Sling ID to file " + idFile, t);
+            }
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.