sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefane...@apache.org
Subject svn commit: r1710047 - in /sling/trunk/bundles/extensions/discovery: commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/ oak/src/main/java/org/apache/sling/discovery/oak/
Date Thu, 22 Oct 2015 16:05:25 GMT
Author: stefanegli
Date: Thu Oct 22 16:05:09 2015
New Revision: 1710047

URL: http://svn.apache.org/viewvc?rev=1710047&view=rev
Log:
SLING-5173 : re-added complete consistency-history after introducing splitting them and using
the ConsistencyServiceChain. Probably should be refactored into something slightly nicer though

Added:
    sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/ConsistencyHistory.java
  (with props)
Modified:
    sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/AbstractServiceWithBackgroundCheck.java
    sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/OakBacklogConsistencyService.java
    sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/SyncTokenConsistencyService.java
    sling/trunk/bundles/extensions/discovery/oak/src/main/java/org/apache/sling/discovery/oak/OakDiscoveryService.java

Modified: sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/AbstractServiceWithBackgroundCheck.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/AbstractServiceWithBackgroundCheck.java?rev=1710047&r1=1710046&r2=1710047&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/AbstractServiceWithBackgroundCheck.java
(original)
+++ sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/AbstractServiceWithBackgroundCheck.java
Thu Oct 22 16:05:09 2015
@@ -18,17 +18,6 @@
  */
 package org.apache.sling.discovery.commons.providers.spi.base;
 
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.sling.api.resource.LoginException;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ResourceResolverFactory;
-import org.apache.sling.discovery.commons.providers.BaseTopologyView;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,21 +28,10 @@ import org.slf4j.LoggerFactory;
  */
 public abstract class AbstractServiceWithBackgroundCheck {
 
-    class HistoryEntry {
-        BaseTopologyView view;
-        String msg;
-        String fullLine;
-    }
-    
-    /** the date format used in the truncated log of topology events **/
-    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
-
     protected final Logger logger = LoggerFactory.getLogger(getClass());
 
     protected String slingId;
 
-    protected List<HistoryEntry> history = new LinkedList<HistoryEntry>();
-    
     /**
      * The BackgroundCheckRunnable implements the details of
      * calling BackgroundCheck.check and looping until it 
@@ -239,45 +217,4 @@ public abstract class AbstractServiceWit
             backgroundOp.triggerCheck();
         }
     }
-    
-    public List<String> getSyncHistory() {
-        List<HistoryEntry> snapshot;
-        synchronized(history) {
-            snapshot = Collections.unmodifiableList(history);
-        }
-        List<String> result = new ArrayList<String>(snapshot.size());
-        for (HistoryEntry historyEntry : snapshot) {
-            result.add(historyEntry.fullLine);
-        }
-        return result;
-    }
-
-    protected void addHistoryEntry(BaseTopologyView view, String msg) {
-        synchronized(history) {
-            for(int i = history.size() - 1; i>=0; i--) {
-                HistoryEntry entry = history.get(i);
-                if (!entry.view.equals(view)) {
-                    // don't filter if the view starts differing,
-                    // only filter for the last few entries where
-                    // the view is equal
-                    break;
-                }
-                if (entry.msg.equals(msg)) {
-                    // if the view is equal and the msg matches
-                    // then this is a duplicate entry, so ignore
-                    return;
-                }
-            }
-            String fullLine = sdf.format(Calendar.getInstance().getTime()) + ": " + msg;
-            HistoryEntry newEntry = new HistoryEntry();
-            newEntry.view = view;
-            newEntry.fullLine = fullLine;
-            newEntry.msg = msg;
-            history.add(newEntry);
-            while (history.size() > 12) {
-                history.remove(0);
-            }
-        }
-    }
-
 }

Added: sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/ConsistencyHistory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/ConsistencyHistory.java?rev=1710047&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/ConsistencyHistory.java
(added)
+++ sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/ConsistencyHistory.java
Thu Oct 22 16:05:09 2015
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.discovery.commons.providers.spi.base;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.sling.discovery.commons.providers.BaseTopologyView;
+
+public class ConsistencyHistory {
+
+    class HistoryEntry {
+        BaseTopologyView view;
+        String msg;
+        String fullLine;
+    }
+    
+    /** the date format used in the truncated log of topology events **/
+    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
+
+    protected List<HistoryEntry> history = new LinkedList<HistoryEntry>();
+    
+    public List<String> getSyncHistory() {
+        List<HistoryEntry> snapshot;
+        synchronized(history) {
+            snapshot = Collections.unmodifiableList(history);
+        }
+        List<String> result = new ArrayList<String>(snapshot.size());
+        for (HistoryEntry historyEntry : snapshot) {
+            result.add(historyEntry.fullLine);
+        }
+        return result;
+    }
+
+    protected void addHistoryEntry(BaseTopologyView view, String msg) {
+        synchronized(history) {
+            for(int i = history.size() - 1; i>=0; i--) {
+                HistoryEntry entry = history.get(i);
+                if (!entry.view.equals(view)) {
+                    // don't filter if the view starts differing,
+                    // only filter for the last few entries where
+                    // the view is equal
+                    break;
+                }
+                if (entry.msg.equals(msg)) {
+                    // if the view is equal and the msg matches
+                    // then this is a duplicate entry, so ignore
+                    return;
+                }
+            }
+            String fullLine = sdf.format(Calendar.getInstance().getTime()) + ": " + msg;
+            HistoryEntry newEntry = new HistoryEntry();
+            newEntry.view = view;
+            newEntry.fullLine = fullLine;
+            newEntry.msg = msg;
+            history.add(newEntry);
+            while (history.size() > 12) {
+                history.remove(0);
+            }
+        }
+    }
+    
+}

Propchange: sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/ConsistencyHistory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/OakBacklogConsistencyService.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/OakBacklogConsistencyService.java?rev=1710047&r1=1710046&r2=1710047&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/OakBacklogConsistencyService.java
(original)
+++ sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/OakBacklogConsistencyService.java
Thu Oct 22 16:05:09 2015
@@ -19,6 +19,7 @@
 package org.apache.sling.discovery.commons.providers.spi.base;
 
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.felix.scr.annotations.Activate;
@@ -60,6 +61,8 @@ public class OakBacklogConsistencyServic
 
     @Reference
     protected SlingSettingsService settingsService;
+
+    private ConsistencyHistory consistencyHistory = new ConsistencyHistory();
     
     public static OakBacklogConsistencyService testConstructorAndActivate(
             final DiscoveryLiteConfig commonsConfig,
@@ -111,6 +114,14 @@ public class OakBacklogConsistencyServic
         logger.info("activate: activated with slingId="+slingId);
     }
     
+    public void setConsistencyHistory(ConsistencyHistory consistencyHistory) {
+        this.consistencyHistory = consistencyHistory;
+    }
+    
+    public ConsistencyHistory getConsistencyHistory() {
+        return consistencyHistory;
+    }
+    
     /** Get or create a ResourceResolver **/
     protected ResourceResolver getResourceResolver() throws LoginException {
         return resourceResolverFactory.getAdministrativeResourceResolver(null);
@@ -141,24 +152,24 @@ public class OakBacklogConsistencyServic
                 try {
                     if (!idMapService.isInitialized()) {
                         logger.info("waitWhileBacklog: could not initialize...");
-                        addHistoryEntry(view, "could not initialize idMapService");
+                        consistencyHistory.addHistoryEntry(view, "could not initialize idMapService");
                         return false;
                     }
                 } catch (Exception e) {
                     logger.error("waitWhileBacklog: could not initialized due to "+e, e);
-                    addHistoryEntry(view, "got Exception while initializing idMapService
("+e+")");
+                    consistencyHistory.addHistoryEntry(view, "got Exception while initializing
idMapService ("+e+")");
                     return false;
                 }
                 BacklogStatus backlogStatus = getBacklogStatus(view);
                 if (backlogStatus == BacklogStatus.NO_BACKLOG) {
                     logger.info("waitWhileBacklog: no backlog (anymore), done.");
-                    addHistoryEntry(view, "no backlog (anymore)");
+                    consistencyHistory.addHistoryEntry(view, "no backlog (anymore)");
                     return true;
                 } else {
                     logger.info("waitWhileBacklog: backlogStatus still "+backlogStatus);
                     // clear the cache to make sure to get the latest version in case something
changed
                     idMapService.clearCache();
-                    addHistoryEntry(view, "backlog status "+backlogStatus);
+                    consistencyHistory.addHistoryEntry(view, "backlog status "+backlogStatus);
                     return false;
                 }
             }
@@ -242,4 +253,8 @@ public class OakBacklogConsistencyServic
         return settingsService;
     }
 
+    public List<String> getSyncHistory() {
+        return consistencyHistory.getSyncHistory();
+    }
+
 }

Modified: sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/SyncTokenConsistencyService.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/SyncTokenConsistencyService.java?rev=1710047&r1=1710046&r2=1710047&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/SyncTokenConsistencyService.java
(original)
+++ sling/trunk/bundles/extensions/discovery/commons/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/SyncTokenConsistencyService.java
Thu Oct 22 16:05:09 2015
@@ -62,6 +62,8 @@ public class SyncTokenConsistencyService
     @Reference
     protected SlingSettingsService settingsService;
 
+    protected ConsistencyHistory consistencyHistory = new ConsistencyHistory();
+
     public static SyncTokenConsistencyService testConstructorAndActivate(
             DiscoveryLiteConfig commonsConfig,
             ResourceResolverFactory resourceResolverFactory,
@@ -97,6 +99,14 @@ public class SyncTokenConsistencyService
         logger.info("activate: activated with slingId="+slingId);
     }
     
+    public void setConsistencyHistory(ConsistencyHistory consistencyHistory) {
+        this.consistencyHistory = consistencyHistory;
+    }
+    
+    public ConsistencyHistory getConsistencyHistory() {
+        return consistencyHistory;
+    }
+    
     /** Get or create a ResourceResolver **/
     protected ResourceResolver getResourceResolver() throws LoginException {
         return resourceResolverFactory.getAdministrativeResourceResolver(null);
@@ -130,7 +140,7 @@ public class SyncTokenConsistencyService
                     // that they will have to wait until the timeout hits
                     
                     // so to try to avoid this, retry storing my sync token later:
-                    addHistoryEntry(view, "storing my syncToken ("+localClusterSyncTokenId+")");
+                    consistencyHistory.addHistoryEntry(view, "storing my syncToken ("+localClusterSyncTokenId+")");
                     return false;
                 }
                 
@@ -222,10 +232,10 @@ public class SyncTokenConsistencyService
             }
             if (!success) {
                 logger.info("seenAllSyncTokens: not yet seen all expected syncTokens (see
above for details)");
-                addHistoryEntry(view, historyEntry.toString());
+                consistencyHistory.addHistoryEntry(view, historyEntry.toString());
                 return false;
             } else {
-                addHistoryEntry(view, "seen all syncTokens");
+                consistencyHistory.addHistoryEntry(view, "seen all syncTokens");
             }
             
             resourceResolver.commit();

Modified: sling/trunk/bundles/extensions/discovery/oak/src/main/java/org/apache/sling/discovery/oak/OakDiscoveryService.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/oak/src/main/java/org/apache/sling/discovery/oak/OakDiscoveryService.java?rev=1710047&r1=1710046&r2=1710047&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/oak/src/main/java/org/apache/sling/discovery/oak/OakDiscoveryService.java
(original)
+++ sling/trunk/bundles/extensions/discovery/oak/src/main/java/org/apache/sling/discovery/oak/OakDiscoveryService.java
Thu Oct 22 16:05:09 2015
@@ -61,6 +61,7 @@ import org.apache.sling.discovery.common
 import org.apache.sling.discovery.commons.providers.ViewStateManager;
 import org.apache.sling.discovery.commons.providers.base.ViewStateManagerFactory;
 import org.apache.sling.discovery.commons.providers.spi.ConsistencyService;
+import org.apache.sling.discovery.commons.providers.spi.base.ConsistencyHistory;
 import org.apache.sling.discovery.commons.providers.spi.base.ConsistencyServiceChain;
 import org.apache.sling.discovery.commons.providers.spi.base.IdMapService;
 import org.apache.sling.discovery.commons.providers.spi.base.OakBacklogConsistencyService;
@@ -211,6 +212,10 @@ public class OakDiscoveryService extends
 
         ConsistencyService consistencyService;
         if (config.getSyncTokenEnabled()) {
+            //TODO: ConsistencyHistory is implemented a little bit hacky ..
+            ConsistencyHistory consistencyHistory = new ConsistencyHistory();
+            oakBacklogConsistencyService.setConsistencyHistory(consistencyHistory);
+            syncTokenConsistencyService.setConsistencyHistory(consistencyHistory);
             consistencyService = new ConsistencyServiceChain(oakBacklogConsistencyService,
syncTokenConsistencyService);
         } else {
             consistencyService = oakBacklogConsistencyService;



Mime
View raw message