From: <jbo...@li...> - 2006-04-24 14:15:43
|
Author: wrzep Date: 2006-04-24 10:15:34 -0400 (Mon, 24 Apr 2006) New Revision: 3947 Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusConfWatcher.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresServiceRemote.java Removed: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusNodeWatcher.java Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Tools.java Log: JBLAB-599 ShotokuResourceWatcher instead of deprecated NodeWatcher Pawel Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusConfWatcher.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusConfWatcher.java 2006-04-24 14:13:06 UTC (rev 3946) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusConfWatcher.java 2006-04-24 14:15:34 UTC (rev 3947) @@ -0,0 +1,103 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.forge.status; + +import java.util.Map; +import java.util.Set; + +import org.jboss.forge.status.tools.Tools; + +import org.jboss.shotoku.cache.ChangeType; +import org.jboss.shotoku.cache.ShotokuResourceWatcher; + +public class StatusConfWatcher extends ShotokuResourceWatcher<String, StatusDescriptor> { + + private StatusDescriptor getDesc(String portalName) { + return new StatusDescriptor(portalName, getContentManager(portalName)); + } + + @Override + public StatusDescriptor init(String key) { + + String portalName = key; + + addWatchedPath(key, Tools.getXmlCmPath(portalName)); + addWatchedPath(key, Tools.getXmlStatusPluginsCmPath(portalName)); + addWatchedPath(key, Tools.getXmlServiceCmPath(portalName)); + + /* Watch projects.xml file */ + addWatchedPath(key, Tools.getProjectsXmlPath(portalName)); + + /* Watch all project.xml files. + * We assume that they contain entries used by plugins */ + Set<String> projectXmlPathsSet = Tools.getProjectXmlPathsSet(portalName); + + for (String projectXmlPath : projectXmlPathsSet) { + addWatchedPath(key, projectXmlPath); + } + + return getDesc(portalName); + } + + @Override + protected void update(String key, StatusDescriptor currentObject, Map<String, ChangeType> changes) { + put(key, getDesc(key)); + } + + /* + + StatusDescriptor desc = new StatusDescriptor(portalName, cm); + + rw = new ResourceWatcher(cm); + + /* Watch plugins confuguration files */ /* + rw.watchResource(Tools.getXmlCmPath(portalName)); + rw.watchResource(Tools.getXmlStatusPluginsCmPath(portalName)); + */ + /* Watch projects.xml file*/ /* + rw.watchResource(Tools.getProjectsXmlPath(portalName)); + */ + /* Watch all project.xml files + * We assume that they contain entries used by plugins */ /* + Set<String> projectXmlPathsSet = Tools.getProjectXmlPathsSet(portalName); + + for (String projectXmlPath : projectXmlPathsSet) { + rw.watchResource(projectXmlPath); + } + + return desc; + }*/ + + + /* + public Object nodeUpdate(String portalName, Object currentValue) { + + if ((currentValue == null) || (rw.checkResources()) || (updateCounter == 499)) { + + updateCounter = 0; + return getDesc(portalName); + } else { + ++updateCounter; + return null; + } + }*/ +} Deleted: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusNodeWatcher.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusNodeWatcher.java 2006-04-24 14:13:06 UTC (rev 3946) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusNodeWatcher.java 2006-04-24 14:15:34 UTC (rev 3947) @@ -1,83 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.jboss.forge.status; - -import java.util.Set; - -import org.jboss.forge.common.service.NodeWatcher; -import org.jboss.forge.common.service.ResourceWatcher; -import org.jboss.forge.status.tools.Tools; - -import org.jboss.shotoku.ContentManager; - -public class StatusNodeWatcher implements NodeWatcher { - - private ResourceWatcher rw; - private ContentManager cm; - - private int updateCounter; - - public StatusNodeWatcher(ContentManager cm) { - this.cm = cm; - updateCounter = 0; - } - - private StatusDescriptor getDesc(String portalName) { - - StatusDescriptor desc = new StatusDescriptor(portalName, cm); - - rw = new ResourceWatcher(cm); - - /* Watch plugins confuguration files */ - rw.watchResource(Tools.getXmlCmPath(portalName)); - rw.watchResource(Tools.getXmlStatusPluginsCmPath(portalName)); - - /* Watch projects.xml file*/ - rw.watchResource(Tools.getProjectsXmlPath(portalName)); - - /* Watch all project.xml files - * We assume that they contain entries used by plugins */ - Set<String> projectXmlPathsSet = Tools.getProjectXmlPathsSet(portalName); - - for (String projectXmlPath : projectXmlPathsSet) { - rw.watchResource(projectXmlPath); - } - - return desc; - } - - public Object init(String portalName) { - return getDesc(portalName); - } - - public Object nodeUpdate(String portalName, Object currentValue) { - - if ((currentValue == null) || (rw.checkResources()) || (updateCounter == 499)) { - - updateCounter = 0; - return getDesc(portalName); - } else { - ++updateCounter; - return null; - } - } -} Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresServiceRemote.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresServiceRemote.java 2006-04-24 14:13:06 UTC (rev 3946) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/model/ScoresServiceRemote.java 2006-04-24 14:15:34 UTC (rev 3947) @@ -0,0 +1,45 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.service.model; + +import java.util.Date; +import java.util.List; + +import org.jboss.forge.common.projects.Projects; +import org.jboss.forge.status.exceptions.GetScoresException; +import org.jboss.forge.status.exceptions.ScoresSaveException; + +/** +* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com) +*/ +public interface ScoresServiceRemote { + + public PluginsValues getPluginsValues(String portalName, + Date date) throws GetScoresException; + + public void save(Projects projects, List<PluginConf> pluginsConf, + String portalName) throws ScoresSaveException; + + public PluginValues get(String portalName, String pluginId, Date date) + throws GetScoresException; +} \ No newline at end of file Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java 2006-04-24 14:13:06 UTC (rev 3946) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java 2006-04-24 14:15:34 UTC (rev 3947) @@ -35,6 +35,7 @@ import org.jboss.forge.status.service.model.PluginConf; import org.jboss.forge.status.service.model.PluginsValues; import org.jboss.forge.status.service.model.ScoresService; +import org.jboss.forge.status.service.model.ScoresServiceRemote; import org.jboss.mx.util.MBeanProxyExt; import org.jboss.mx.util.MBeanServerLocator; @@ -58,10 +59,10 @@ MBeanServer server = MBeanServerLocator.locate(); - ScoresServiceLocal service; + ScoresServiceRemote service; try { - service = (ScoresServiceLocal) MBeanProxyExt.create( - ScoresServiceLocal.class, + service = (ScoresServiceRemote) MBeanProxyExt.create( + ScoresServiceRemote.class, Tools.STATUS_SERVICE_NAME, server); } catch (MalformedObjectNameException e) { @@ -69,7 +70,6 @@ } service.save(projects, pluginsConf, portalName); - } public static PluginsValues getScores(Date date, Date toDate) Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Tools.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Tools.java 2006-04-24 14:13:06 UTC (rev 3946) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Tools.java 2006-04-24 14:15:34 UTC (rev 3947) @@ -9,10 +9,9 @@ import org.jboss.forge.common.projects.permissions.NullPermissionsChecker; import org.jboss.forge.common.projects.permissions.PermissionsChecker; import org.jboss.forge.status.StatusDescriptor; -import org.jboss.forge.status.StatusNodeWatcher; +import org.jboss.forge.status.StatusConfWatcher; -import org.jboss.shotoku.ContentManager; -import org.jboss.shotoku.aop.Inject; +import org.jboss.shotoku.aop.CacheItem; /** * Common constants and functions. @@ -38,22 +37,11 @@ public static final String STATUS_SERVICE_NAME = "status:service=scores"; - @Inject - private static ContentManager cm; + @CacheItem + private static StatusConfWatcher conf; public static synchronized StatusDescriptor getDesc(final String portalName) { - String cacheKey = StatusDescriptor.class.getName(); - - StatusDescriptor desc = (StatusDescriptor) ForgeHelper - .getForgeManagement().getFromCache(portalName, cacheKey); - - if (desc == null) - desc = (StatusDescriptor) ForgeHelper.getForgeManagement() - .addNodeWatcher(portalName, - cacheKey, - new StatusNodeWatcher(cm)); - - return desc; + return conf.get(portalName); } /** |