Index: main/plugin-web/plugin.xml
===================================================================
--- main/plugin-web/plugin.xml (revision 19760)
+++ main/plugin-web/plugin.xml (working copy)
@@ -1978,8 +1978,8 @@
logger="org.ametys.web.live.rebuild.timer">
-
Index: main/plugin-web/src/org/ametys/web/live/RebuildLiveWorkspaceComponent.java
===================================================================
--- main/plugin-web/src/org/ametys/web/live/RebuildLiveWorkspaceComponent.java (revision 19748)
+++ main/plugin-web/src/org/ametys/web/live/RebuildLiveWorkspaceComponent.java (working copy)
@@ -1,179 +0,0 @@
-/*
- * Copyright 2010 Anyware Services
- *
- * Licensed 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.ametys.web.live;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jcr.Repository;
-import javax.jcr.Session;
-
-import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-
-import org.ametys.plugins.repository.AmetysObjectIterable;
-import org.ametys.web.WebConstants;
-import org.ametys.web.cache.CacheHelper;
-import org.ametys.web.cache.pageelement.PageElementCache;
-import org.ametys.web.lucene.SitemapIndexer;
-import org.ametys.web.repository.site.Site;
-import org.ametys.web.repository.site.SiteManager;
-import org.ametys.web.repository.sitemap.Sitemap;
-
-/**
- * Component for rebuild the live workspace, reindex all sitemaps and reset cache.
- */
-public class RebuildLiveWorkspaceComponent extends AbstractLogEnabled implements Component, Serviceable
-{
- /** Avalon Role. */
- public static final String ROLE = RebuildLiveWorkspaceComponent.class.getName();
-
- private Repository _repository;
- private LivePopulatorExtensionPoint _livePopulatorExtensionPoint;
- private SitemapIndexer _sitemapIndexer;
- private SiteManager _siteManager;
- private PageElementCache _inputDataCache;
- private PageElementCache _zoneItemCache;
-
- @Override
- public void service(ServiceManager manager) throws ServiceException
- {
- _sitemapIndexer = (SitemapIndexer) manager.lookup(SitemapIndexer.ROLE);
- _repository = (Repository) manager.lookup(Repository.class.getName());
- _livePopulatorExtensionPoint = (LivePopulatorExtensionPoint) manager.lookup(LivePopulatorExtensionPoint.ROLE);
- _siteManager = (SiteManager) manager.lookup(SiteManager.ROLE);
- _inputDataCache = (PageElementCache) manager.lookup(PageElementCache.ROLE + "/inputData");
- _zoneItemCache = (PageElementCache) manager.lookup(PageElementCache.ROLE + "/zoneItem");
- }
-
- /**
- * Rebuild live workspace, index all sitemaps and reset cache.
- * @return true if the all rebuilt succeed
- * @throws Exception if an error occurs.
- */
- public Map rebuild() throws Exception
- {
- Map errors = new HashMap();
-
- Session session = null;
- Session liveSession = null;
-
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Rebuilding live workspace...");
- }
-
- try
- {
- session = _repository.login();
- liveSession = _repository.login(WebConstants.LIVE_WORKSPACE);
-
- // Synchronize other data
- for (String id : _livePopulatorExtensionPoint.getExtensionsIds())
- {
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Populating live workspace using LivePopulator " + id);
- }
-
- LivePopulator populator = _livePopulatorExtensionPoint.getExtension(id);
-
- populator.populate(session, liveSession);
-
- if (liveSession.hasPendingChanges())
- {
- liveSession.save();
- }
-
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("LivePopulator " + id + "ended.");
- }
- }
-
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Live workspace populated");
- }
- }
- catch (Throwable t)
- {
- errors.put(null, t.getMessage());
- getLogger().error("Failed to populate live workspace", t);
- }
- finally
- {
- if (session != null)
- {
- session.logout();
- }
-
- if (liveSession != null)
- {
- liveSession.logout();
- }
- }
-
- // Synchronize sites
- AmetysObjectIterable siteIterable = _siteManager.getSites();
-
- for (Site site : siteIterable)
- {
- try
- {
- _rebuildLiveWorkspace (site);
- }
- catch (Exception e)
- {
- errors.put(site.getName(), e.getMessage());
- getLogger().error("Failed to rebuild live workspace for site '" + site.getName() + "'", e);
- }
- }
-
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Live workspace rebuilt");
- }
-
- return errors;
- }
-
- private void _rebuildLiveWorkspace (Site site) throws Exception
- {
- for (Sitemap sitemap : site.getSitemaps())
- {
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Indexing sitemap " + sitemap.getName() + " started");
- }
-
- _sitemapIndexer.index(sitemap);
- }
-
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Clearing cache for site " + site.getName());
- }
-
- CacheHelper.invalidateCache(site, getLogger());
- _inputDataCache.clear(null, site.getName());
- _zoneItemCache.clear(null, site.getName());
- }
-}
Index: main/plugin-web/src/org/ametys/web/live/RebuildLiveWorkspaceAction.java
===================================================================
--- main/plugin-web/src/org/ametys/web/live/RebuildLiveWorkspaceAction.java (revision 19748)
+++ main/plugin-web/src/org/ametys/web/live/RebuildLiveWorkspaceAction.java (working copy)
@@ -30,22 +30,22 @@
import org.apache.commons.lang.StringUtils;
/**
- * Action calling the {@link RebuildLiveWorkspaceComponent}.
+ * Action calling the {@link RebuildLiveComponent}.
*/
public class RebuildLiveWorkspaceAction extends AbstractAction implements ThreadSafe, Serviceable
{
- private RebuildLiveWorkspaceComponent _rebuildLiveWorkspaceComponent;
+ private RebuildLiveComponent _rebuildLiveComponent;
@Override
public void service(ServiceManager manager) throws ServiceException
{
- _rebuildLiveWorkspaceComponent = (RebuildLiveWorkspaceComponent) manager.lookup(RebuildLiveWorkspaceComponent.ROLE);
+ _rebuildLiveComponent = (RebuildLiveComponent) manager.lookup(RebuildLiveComponent.ROLE);
}
@Override
public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception
{
- Map sitesError = _rebuildLiveWorkspaceComponent.rebuild();
+ Map sitesError = _rebuildLiveComponent.rebuildLiveWorkspace();
Map result = new HashMap();
if (sitesError.size() > 0)
Index: main/plugin-web/src/org/ametys/web/live/RebuildLiveWorkspaceTimerTask.java
===================================================================
--- main/plugin-web/src/org/ametys/web/live/RebuildLiveWorkspaceTimerTask.java (revision 19748)
+++ main/plugin-web/src/org/ametys/web/live/RebuildLiveWorkspaceTimerTask.java (working copy)
@@ -73,7 +73,7 @@
private Context _context;
private ServiceManager _manager;
- private RebuildLiveWorkspaceComponent _rebuildLiveWorkspaceComponent;
+ private RebuildLiveComponent _rebuildLiveComponent;
private I18nUtils _i18nUtils;
@Override
@@ -93,7 +93,7 @@
{
_repository = (Repository) manager.lookup(Repository.class.getName());
_manager = manager;
- _rebuildLiveWorkspaceComponent = (RebuildLiveWorkspaceComponent) manager.lookup(RebuildLiveWorkspaceComponent.ROLE);
+ _rebuildLiveComponent = (RebuildLiveComponent) manager.lookup(RebuildLiveComponent.ROLE);
_i18nUtils = (I18nUtils) manager.lookup(I18nUtils.ROLE);
}
@@ -166,7 +166,7 @@
try
{
- _rebuildLiveWorkspaceComponent.rebuild();
+ _rebuildLiveComponent.rebuildLiveWorkspace();
}
catch (Throwable t)
{
Index: main/plugin-web/src/org/ametys/web/live/RebuildLiveComponent.java
===================================================================
--- main/plugin-web/src/org/ametys/web/live/RebuildLiveComponent.java (revision 19748)
+++ main/plugin-web/src/org/ametys/web/live/RebuildLiveComponent.java (working copy)
@@ -36,19 +36,24 @@
import org.ametys.web.repository.site.Site;
import org.ametys.web.repository.site.SiteManager;
import org.ametys.web.repository.sitemap.Sitemap;
+import org.ametys.web.skin.Skin;
+import org.ametys.web.skin.SkinsManager;
/**
* Component for rebuild the live workspace, reindex all sitemaps and reset cache.
+ * Provide a way to rebuild the full live workspace, or only the live of a site.
*/
-public class RebuildLiveWorkspaceComponent extends AbstractLogEnabled implements Component, Serviceable
+public class RebuildLiveComponent extends AbstractLogEnabled implements Component, Serviceable
{
/** Avalon Role. */
- public static final String ROLE = RebuildLiveWorkspaceComponent.class.getName();
+ public static final String ROLE = RebuildLiveComponent.class.getName();
private Repository _repository;
private LivePopulatorExtensionPoint _livePopulatorExtensionPoint;
+ private SitePopulator _sitePopulator;
private SitemapIndexer _sitemapIndexer;
private SiteManager _siteManager;
+ private SkinsManager _skinsManager;
private PageElementCache _inputDataCache;
private PageElementCache _zoneItemCache;
@@ -58,7 +63,9 @@
_sitemapIndexer = (SitemapIndexer) manager.lookup(SitemapIndexer.ROLE);
_repository = (Repository) manager.lookup(Repository.class.getName());
_livePopulatorExtensionPoint = (LivePopulatorExtensionPoint) manager.lookup(LivePopulatorExtensionPoint.ROLE);
+ _sitePopulator = (SitePopulator) manager.lookup(SitePopulator.ROLE);
_siteManager = (SiteManager) manager.lookup(SiteManager.ROLE);
+ _skinsManager = (SkinsManager) manager.lookup(SkinsManager.ROLE);
_inputDataCache = (PageElementCache) manager.lookup(PageElementCache.ROLE + "/inputData");
_zoneItemCache = (PageElementCache) manager.lookup(PageElementCache.ROLE + "/zoneItem");
}
@@ -68,7 +75,7 @@
* @return true if the all rebuilt succeed
* @throws Exception if an error occurs.
*/
- public Map rebuild() throws Exception
+ public Map rebuildLiveWorkspace() throws Exception
{
Map errors = new HashMap();
@@ -138,7 +145,7 @@
{
try
{
- _rebuildLiveWorkspace (site);
+ _reindexAndClearCache (site);
}
catch (Exception e)
{
@@ -155,7 +162,45 @@
return errors;
}
- private void _rebuildLiveWorkspace (Site site) throws Exception
+ /**
+ * Rebuild the live of a site, index all sitemaps and reset cache.
+ * @param site The site to be rebuilt
+ * @throws Exception if an error occurs.
+ */
+ public void rebuildLive(Site site) throws Exception
+ {
+ String siteName = site.getName();
+
+ Skin skin = _skinsManager.getSkin(site.getSkinId());
+ assert skin != null;
+
+ if (getLogger().isInfoEnabled())
+ {
+ getLogger().info("Rebuilding site " + siteName + " started");
+ }
+
+ if (getLogger().isInfoEnabled())
+ {
+ getLogger().info("Populating site " + siteName + " started");
+ }
+
+ long t0 = System.currentTimeMillis();
+ _sitePopulator.populate(site, skin);
+
+ if (getLogger().isInfoEnabled())
+ {
+ getLogger().info("Populating site " + siteName + " ended in " + (System.currentTimeMillis() - t0) + " ms");
+ }
+
+ _reindexAndClearCache(site);
+
+ if (getLogger().isInfoEnabled())
+ {
+ getLogger().info("Rebuilding site " + siteName + " ended in " + (System.currentTimeMillis() - t0) + " ms");
+ }
+ }
+
+ private void _reindexAndClearCache(Site site) throws Exception
{
for (Sitemap sitemap : site.getSitemaps())
{
@@ -164,7 +209,13 @@
getLogger().info("Indexing sitemap " + sitemap.getName() + " started");
}
+ long t0 = System.currentTimeMillis();
_sitemapIndexer.index(sitemap);
+
+ if (getLogger().isInfoEnabled())
+ {
+ getLogger().info("Indexing sitemap " + sitemap.getName() + " ended in " + (System.currentTimeMillis() - t0) + " ms");
+ }
}
if (getLogger().isInfoEnabled())
Property changes on: main\plugin-web\src\org\ametys\web\live\RebuildLiveComponent.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Index: main/plugin-web/src/org/ametys/web/site/BuildLiveAction.java
===================================================================
--- main/plugin-web/src/org/ametys/web/site/BuildLiveAction.java (revision 19748)
+++ main/plugin-web/src/org/ametys/web/site/BuildLiveAction.java (working copy)
@@ -27,15 +27,9 @@
import org.apache.cocoon.environment.SourceResolver;
import org.apache.commons.lang.StringUtils;
-import org.ametys.web.cache.CacheHelper;
-import org.ametys.web.cache.pageelement.PageElementCache;
-import org.ametys.web.live.SitePopulator;
-import org.ametys.web.lucene.SitemapIndexer;
+import org.ametys.web.live.RebuildLiveComponent;
import org.ametys.web.repository.site.Site;
import org.ametys.web.repository.site.SiteManager;
-import org.ametys.web.repository.sitemap.Sitemap;
-import org.ametys.web.skin.Skin;
-import org.ametys.web.skin.SkinsManager;
/**
* This action re-build the live workspace for a site
@@ -43,11 +37,7 @@
public class BuildLiveAction extends ServiceableAction
{
private SiteManager _siteManager;
- private SkinsManager _skinsManager;
- private SitemapIndexer _sitemapIndexer;
- private SitePopulator _livePopulator;
- private PageElementCache _inputDataCache;
- private PageElementCache _zoneItemCache;
+ private RebuildLiveComponent _rebuildLiveComponent;
@Override
public void service(ServiceManager smanager) throws ServiceException
@@ -55,11 +45,7 @@
super.service(smanager);
_siteManager = (SiteManager) smanager.lookup(SiteManager.ROLE);
- _skinsManager = (SkinsManager) smanager.lookup(SkinsManager.ROLE);
- _sitemapIndexer = (SitemapIndexer) smanager.lookup(SitemapIndexer.ROLE);
- _livePopulator = (SitePopulator) smanager.lookup(SitePopulator.ROLE);
- _inputDataCache = (PageElementCache) smanager.lookup(PageElementCache.ROLE + "/inputData");
- _zoneItemCache = (PageElementCache) smanager.lookup(PageElementCache.ROLE + "/zoneItem");
+ _rebuildLiveComponent = (RebuildLiveComponent) smanager.lookup(RebuildLiveComponent.ROLE);
}
@Override
@@ -72,58 +58,9 @@
Site site = _siteManager.getSite(siteName);
assert site != null;
-
- Skin skin = _skinsManager.getSkin(site.getSkinId());
- assert skin != null;
-
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Rebuilding site " + siteName + " started");
- }
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Populating site " + siteName + " started");
- }
-
- long t0 = System.currentTimeMillis();
- _livePopulator.populate(site, skin);
-
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Populating site " + siteName + " ended in " + (System.currentTimeMillis() - t0) + " ms");
- }
-
- for (Sitemap sitemap : site.getSitemaps())
- {
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Indexing sitemap " + sitemap.getName() + " started");
- }
-
- long t1 = System.currentTimeMillis();
- _sitemapIndexer.index(sitemap);
-
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Indexing sitemap " + sitemap.getName() + " ended in " + (System.currentTimeMillis() - t1) + " ms");
- }
- }
-
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Clearing cache for site " + siteName);
- }
-
- CacheHelper.invalidateCache(site, getLogger());
- _inputDataCache.clear(null, siteName);
- _zoneItemCache.clear(null, siteName);
+ _rebuildLiveComponent.rebuildLive(site);
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Rebuilding site " + siteName + " ended in " + (System.currentTimeMillis() - t0) + " ms");
- }
-
return EMPTY_MAP;
}
}