[jboss-svn-commits] JBL Code SVN: r15206 - in labs/jbosslabs/trunk/stats-server/sources/metrics: common/src/java/org/jboss/labs/metrics/common and 8 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Sep 18 10:40:35 EDT 2007


Author: wrzep
Date: 2007-09-18 10:40:35 -0400 (Tue, 18 Sep 2007)
New Revision: 15206

Added:
   labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/DefaultConfiguration.java
Removed:
   labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/impl/ServiceScoresManager.java
   labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/plugins/KosmosPlugin.java
Modified:
   labs/jbosslabs/trunk/stats-server/sources/metrics/common/project.xml
   labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/Constants.java
   labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/ScoresService.java
   labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/Configuration.java
   labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/ServiceConf.java
   labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/tools/ProjectTools.java
   labs/jbosslabs/trunk/stats-server/sources/metrics/service/project.xml
   labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/impl/ScoresServiceImpl.java
Log:
JBLAB-891
bringing RMI back to work to access downloads at labs box


Modified: labs/jbosslabs/trunk/stats-server/sources/metrics/common/project.xml
===================================================================
--- labs/jbosslabs/trunk/stats-server/sources/metrics/common/project.xml	2007-09-18 14:39:58 UTC (rev 15205)
+++ labs/jbosslabs/trunk/stats-server/sources/metrics/common/project.xml	2007-09-18 14:40:35 UTC (rev 15206)
@@ -19,12 +19,6 @@
 	<dependencies>
 
 		<dependency>
-			<groupId>jboss-forge</groupId>
-			<artifactId>forge-common</artifactId>
-			<version>1.0</version>
-		</dependency>
-
-		<dependency>
 			<groupId>jboss</groupId>
 			<artifactId>jboss-jmx</artifactId>
 			<version>1.0</version>

Modified: labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/Constants.java
===================================================================
--- labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/Constants.java	2007-09-18 14:39:58 UTC (rev 15205)
+++ labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/Constants.java	2007-09-18 14:40:35 UTC (rev 15206)
@@ -27,7 +27,7 @@
 	public static final String STATUS_REMOTE_SERVICE 	= "ScoresService/remote";
 														//"java:/ScoresService/remote";
 
-	public static final String METRICS_SCORES_SERVICE = "metrics:service=MetricService";
+	public static final String METRICS_SCORES_SERVICE = "metrics:service=MetricsService";
 
 	public static final String METICS_SERVICE_ADDRESS 	  = "service:jmx:rmi://localhost";
 

Modified: labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/ScoresService.java
===================================================================
--- labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/ScoresService.java	2007-09-18 14:39:58 UTC (rev 15205)
+++ labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/ScoresService.java	2007-09-18 14:40:35 UTC (rev 15206)
@@ -23,47 +23,21 @@
 package org.jboss.labs.metrics.common.protocol;
 
 import java.io.Serializable;
-import java.util.Calendar;
 
-import org.jboss.labs.metrics.common.exceptions.GetScoresException;
-import org.jboss.labs.metrics.common.exceptions.ScoresException;
-import org.jboss.labs.metrics.common.protocol.conf.Configuration;
-import org.jboss.labs.metrics.common.protocol.conf.PluginsValuesRemote;
 
-
 /**
 * @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
 */
 
 public interface ScoresService extends Serializable {
 	
-	public void init(Configuration conf, ScoresManager scoresManager)
-												throws ScoresException;
-	
-	public void update(Configuration conf, ScoresManager scoresManager)
-												throws ScoresException;
-	
-	public void save() throws ScoresException;	
-	
-	public void fillPluginsValues(Calendar cal, PluginsValuesRemote pv)
-												throws GetScoresException;
-	
-	public boolean hasPluginsValues(Calendar cal);
-
-	public long getValue(String pluginId, String projectId, Calendar cal)
-												throws GetScoresException;
-
-	public long getValue(String pluginId, String projectId,
-						  Calendar start, Calendar end)
-												throws GetScoresException;
-	
 	public void ping();
 	
+	public void save();
+	
 	public Object invoke(org.jboss.invocation.Invocation mi) throws Exception;
 	
 	//	 Life cycle methods
 	public void start () throws Exception;
 	public void stop () throws Exception;
-
-	public PluginsValuesRemote getPluginsValuesRemote(Calendar cal) throws GetScoresException;
 }
\ No newline at end of file

Modified: labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/Configuration.java
===================================================================
--- labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/Configuration.java	2007-09-18 14:39:58 UTC (rev 15205)
+++ labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/Configuration.java	2007-09-18 14:40:35 UTC (rev 15206)
@@ -24,21 +24,16 @@
 
 import java.io.Serializable;
 import java.util.List;
+import java.util.Properties;
 
 /**
 * @author Pawel Wrzeszcz (pawel . wrzeszcz [at] jboss . com)
 */
 public interface Configuration extends Serializable {
 
-	public String getPortalName();
-	
 	public List<String> getProjectIds();
 	
-	public ServiceConf getScoresServiceConf();
+	public Properties getProjectsServiceProperties();
 	
-	public ServiceConf getProjectsServiceConf();
-	
 	public UpdatesConf getUpdateConf();
-	
-	public List<PluginConf> getPluginsConf();
 }
\ No newline at end of file

Modified: labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/ServiceConf.java
===================================================================
--- labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/ServiceConf.java	2007-09-18 14:39:58 UTC (rev 15205)
+++ labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/ServiceConf.java	2007-09-18 14:40:35 UTC (rev 15206)
@@ -31,5 +31,4 @@
 public interface ServiceConf extends Serializable {
 
 	public Properties getProperties();
-	
 }
\ No newline at end of file

Deleted: labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/impl/ServiceScoresManager.java
===================================================================
--- labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/impl/ServiceScoresManager.java	2007-09-18 14:39:58 UTC (rev 15205)
+++ labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/protocol/conf/impl/ServiceScoresManager.java	2007-09-18 14:40:35 UTC (rev 15206)
@@ -1,194 +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.labs.metrics.common.protocol.conf.impl;
-
-
-import java.util.Calendar;
-import java.util.Properties;
-import javax.naming.NamingException;
-
-import org.jboss.labs.metrics.common.Constants;
-import org.jboss.labs.metrics.common.exceptions.GetScoresException;
-import org.jboss.labs.metrics.common.exceptions.ScoresException;
-import org.jboss.labs.metrics.common.protocol.ScoresManager;
-import org.jboss.labs.metrics.common.protocol.ScoresService;
-import org.jboss.labs.metrics.common.protocol.conf.Configuration;
-import org.jboss.labs.metrics.common.protocol.conf.PluginsValues;
-import org.jboss.labs.metrics.common.protocol.conf.PluginsValuesRemote;
-import org.jboss.labs.metrics.common.tools.Tools;
-
-import org.jboss.logging.Logger;
-
-
-
-/**
-* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
-*/
-
-public class ServiceScoresManager implements ScoresManager {
-
-	private static final long serialVersionUID = -3398452363516977124L;
-
-	private Properties properties;
-	private Configuration conf;
-	private Logger log;
-	
-	public ServiceScoresManager(Configuration conf) throws ScoresException {
-		
-		properties = conf.getScoresServiceConf().getProperties();
-		this.conf = conf;
-		
-		log = Logger.getLogger(this.getClass());
-		
-		initService();
-	}
-
-	public synchronized void save() throws ScoresException {
-
-		ScoresService service = getService();
-		service.save();		
-	}
-	
-	
-	public boolean hasScores(Calendar cal) throws NamingException, ScoresException {
-		
-		ScoresService service = getService();
-		return service.hasPluginsValues(cal);
-	}
-	
-	
-	public PluginsValues getScores(Calendar cal)
-										throws ScoresException {
-
-		log.info("getScores");
-
-		PluginsValuesRemote pluginsValues;
-		try {
-			ScoresService service = getService();
-			pluginsValues = service.getPluginsValuesRemote(cal);
-		} catch (ScoresException e) {
-			throw e;			
-		} catch (Exception e) {
-			throw new GetScoresException(e);
-		}
-
-		if (pluginsValues == null) {
-			throw new GetScoresException("Null plugins values");
-		}
-
-		return pluginsValues;
-	}
-	
-	
-	public PluginsValues getLatestScores()
-									throws ScoresException {
-		
-		Calendar cal = Calendar.getInstance();
-		Tools.truncate(cal);
-		int attempts = 0;
-		
-		for(;;) {
-			
-			log.debug("Trying " + cal.getTime().toString());
-			
-			boolean hasScores;
-			
-			try {
-				hasScores = hasScores(cal);
-			} catch (NamingException e) {
-				throw new GetScoresException(e);
-			}
-			
-			if (hasScores) {
-				return getScores(cal);
-			}
-			
-			if ((++attempts) == Constants.MAX_ATTEMPTS) {
-				throw new GetScoresException(
-						"Can not find any recently saved scores. " +
-						"Gave up after " + attempts + " attempts.");
-			}
-			
-			cal.add(Calendar.DAY_OF_MONTH, -1);
-		}
-	}
-
-
-	/**
-	 * For the specified plugin returns historical project score
-	 * from the given <code>date</code> in the past.
-	 * 
-	 * Notice that only year, month and day matter in passed dates.
-	 * 
-	 * @return project score from the given date for specified plugin
-	 * @throws GetScoresException
-	 */
-	public long getValue(String pluginId, String projectId,
-											Calendar cal)
-			throws ScoresException {
-		
-		ScoresService service = getService();
-		return service.getValue(pluginId, projectId, cal);
-	}
-
-	/**
-	 * For the given plugin and project ids returns stored value.
-	 * 
-	 * @param pluginId plugin id
-	 * @param projectId project id
-	 * @return stored plugin value for specified project
-	 * @throws GetScoresException
-	 * Thrown when requested value was not found
-	 */
-	public long getValue(String pluginId, String projectId,
-			Calendar start, Calendar end) throws ScoresException {
-		
-		ScoresService service = getService();
-		return service.getValue(pluginId, projectId, start, end);
-	}
-	
-	private ScoresService getService() throws ScoresException {
-		
-		try {			
-			ScoresService service = Tools.getScoresService(properties);
-			service.update(conf, this);
-			
-			return service;
-		} catch (NamingException e) {
-			throw new ScoresException(e);
-		}
-	}
-	
-	private void initService() {
-		
-		try {			
-			ScoresService service = Tools.getScoresService(properties);
-			service.init(conf, this);
-		} catch (Exception e) {
-			log.warn("Unable to initialize ScoresService." +
-					"\nCause: " + e.getMessage());
-			log.debug("initService() failed", e);
-		}
-		
-	}
-}

Modified: labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/tools/ProjectTools.java
===================================================================
--- labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/tools/ProjectTools.java	2007-09-18 14:39:58 UTC (rev 15205)
+++ labs/jbosslabs/trunk/stats-server/sources/metrics/common/src/java/org/jboss/labs/metrics/common/tools/ProjectTools.java	2007-09-18 14:40:35 UTC (rev 15206)
@@ -1,20 +1,11 @@
 package org.jboss.labs.metrics.common.tools;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Properties;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
 
-import org.jboss.forge.common.projects.project.BuildResult;
-import org.jboss.forge.common.projects.project.BuildType;
-import org.jboss.forge.common.projects.project.Downloads;
-import org.jboss.forge.common.projects.project.IssueTracker;
-import org.jboss.forge.common.projects.project.IssueTrackerType;
-import org.jboss.forge.common.projects.project.Project;
-import org.jboss.forge.common.projects.project.RepoType;
-import org.jboss.forge.common.ejb3.ProjectsService;
+import org.jboss.forge.common.ejb3.MetricsProjectsService;
 import org.jboss.logging.Logger;
 
 /**
@@ -22,72 +13,21 @@
  */
 public class ProjectTools {
 	
-	private static ProjectsService service = null;
-	
 	private static Logger log = Logger.getLogger(ProjectTools.class);
-	
 
-	public static void init(String portalName,
-				Properties projectsServiceProperties) throws NamingException {
-		
+	public static MetricsProjectsService getProjectsService(Properties properties) {
+
 		try {
-			service = getProjectsService(projectsServiceProperties);
+			InitialContext ic = new InitialContext(properties);
+			return (MetricsProjectsService)ic.lookup("MetricsProjectsService");
 			
+			
 		} catch (NamingException e) {
 			log.warn("Unable to obtain Projects Service. " +
 					 "\nCause: " + e.getMessage());
-			log.debug("Properties: " + projectsServiceProperties +". ",e);
-			throw e;
+			log.debug("Properties: " + properties +". ",e);
 		}
-	}
-
-	private static ProjectsService getProjectsService(Properties properties)
-	  throws NamingException {
-
-		InitialContext ic = new InitialContext(properties);
-		ProjectsService service = (ProjectsService)ic.lookup("ProjectsService");
-
-		return service;
-	}
-
-	public static List<String> getProjectJems(String projectId) {
 		
-		return service.getProjectJems(projectId);
+		return null;
 	}
-	
-	/*
-	public static List<Repository> getProjectSVNRepositories(String projectId) {
-		
-		List<Repository> repoList = service.getProjectRepositories(projectId);
-		List<Repository> svnRepoList = new ArrayList<Repository>();
-		
-		for (Repository repository : repoList) {
-			
-			if (repository.getType() == RepoType.SVN) {
-				svnRepoList.add(repository);
-			}
-		}
-		
-		return svnRepoList;
-	}*/
-
-	public static Project getProject(String projectId) {
-		
-		return service.getProjectById(projectId);
-	}
-
-	public static Downloads getProjectDownloads(String projectId) {
-		
-		return service.getProjectDownloads(projectId);
-	}
-
-	public static long getOverallDownloadsForProject(String projectId, String portalName) {
-		
-		return service.getOverallDownloadsForProject(projectId);
-	}
-
-	public static boolean getPackagedForDownload(String projectId) {
-		
-		return service.getPackagedForDownload(projectId);
-	}
 }

Modified: labs/jbosslabs/trunk/stats-server/sources/metrics/service/project.xml
===================================================================
--- labs/jbosslabs/trunk/stats-server/sources/metrics/service/project.xml	2007-09-18 14:39:58 UTC (rev 15205)
+++ labs/jbosslabs/trunk/stats-server/sources/metrics/service/project.xml	2007-09-18 14:40:35 UTC (rev 15206)
@@ -21,6 +21,12 @@
 	<dependencies>
 
 		<dependency>
+					<groupId>jboss-forge</groupId>
+					<artifactId>forge-common</artifactId>
+					<version>1.0</version>
+		</dependency>
+		
+		<dependency>
 			<groupId>metrics</groupId>
 			<artifactId>metrics-common</artifactId>
 			<jar>metrics-common.jar</jar>

Added: labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/DefaultConfiguration.java
===================================================================
--- labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/DefaultConfiguration.java	                        (rev 0)
+++ labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/DefaultConfiguration.java	2007-09-18 14:40:35 UTC (rev 15206)
@@ -0,0 +1,37 @@
+package org.jboss.labs.metrics.service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.jboss.labs.metrics.common.protocol.conf.Configuration;
+import org.jboss.labs.metrics.common.protocol.conf.UpdatesConf;
+
+public class DefaultConfiguration implements Configuration {
+
+	private static final long serialVersionUID = 2438130442311842925L;
+
+	public List<String> getProjectIds() {
+		
+		List<String> list = new ArrayList<String>();
+		list.add("jbosswiki");
+		
+		return list;
+	}
+
+	public Properties getProjectsServiceProperties() {
+	
+		Properties p = new Properties();
+		p.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+		p.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
+		p.put("java.naming.provider.url", "jnp://localhost:1099");
+		p.put("jnp.disableDiscovery", true);
+		
+		return p;
+	}
+
+	public UpdatesConf getUpdateConf() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+}

Modified: labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/impl/ScoresServiceImpl.java
===================================================================
--- labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/impl/ScoresServiceImpl.java	2007-09-18 14:39:58 UTC (rev 15205)
+++ labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/impl/ScoresServiceImpl.java	2007-09-18 14:40:35 UTC (rev 15206)
@@ -22,36 +22,25 @@
 
 package org.jboss.labs.metrics.service.impl;
 
-import java.util.Calendar;
+import java.rmi.RMISecurityManager;
 import java.util.List;
 import java.util.Properties;
 
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
 import javax.naming.NamingException;
 
 import org.jboss.annotation.ejb.Management;
 import org.jboss.annotation.ejb.Service;
 
 import org.jboss.labs.metrics.common.Constants;
-import org.jboss.labs.metrics.common.exceptions.GetScoresException;
 import org.jboss.labs.metrics.common.exceptions.ScoresException;
-import org.jboss.labs.metrics.common.protocol.ScoresManager;
-import org.jboss.labs.metrics.common.protocol.ScoresRepositoryManager;
 import org.jboss.labs.metrics.common.protocol.ScoresService;
 import org.jboss.labs.metrics.common.protocol.conf.Configuration;
-import org.jboss.labs.metrics.common.protocol.conf.PluginConf;
-import org.jboss.labs.metrics.common.protocol.conf.PluginsValues;
-import org.jboss.labs.metrics.common.protocol.conf.PluginsValuesRemote;
-import org.jboss.labs.metrics.common.protocol.conf.ScoresFactory;
 import org.jboss.labs.metrics.common.protocol.conf.ScoresUpdater;
-import org.jboss.labs.metrics.common.tools.Plugins;
 import org.jboss.labs.metrics.common.tools.ProjectTools;
 import org.jboss.labs.metrics.common.tools.Tools;
+import org.jboss.labs.metrics.service.DefaultConfiguration;
 
-import org.jboss.labs.metrics.service.impl.db.DBScoresRepositoryManager;
-import org.jboss.labs.metrics.service.impl.db.protocol.DBScoresFactory;
-
+import org.jboss.forge.common.ejb3.MetricsProjectsService;
 import org.jboss.invocation.Invocation;
 
 import org.jboss.logging.Logger;
@@ -69,160 +58,38 @@
 
 	private Logger log = Logger.getLogger(this.getClass());;
 
-	private String portalName;
 	private Properties projectsServiceProperties;
-	private boolean initialized = false;
-	
-	private ScoresManager scoresManager;
-	private ScoresRepositoryManager repositoryManager;
-	private ScoresFactory scoresFactory;
-
-	private List<PluginConf> pluginsConf;
 	private List<String> projectIds;
 	
-	public void init(Configuration conf, ScoresManager scoresManager)
-													throws ScoresException {
+	protected void init(Configuration conf)	throws ScoresException {
 		
 		log.info("ScoresService initialization");
 		
-		portalName = conf.getPortalName();
-		projectsServiceProperties = conf.getProjectsServiceConf().getProperties();
 		
-		try {
-			ProjectTools.init(portalName, projectsServiceProperties);
-		} catch (NamingException e) {
-			throw new ScoresException("Initialization failed." +
-					"\nCause: " + e.getMessage());
-		}
+	log.info("Starting...");
 		
-		pluginsConf = conf.getPluginsConf();
-		projectIds = conf.getProjectIds();
-		
-		this.scoresManager = scoresManager;
-		
-		try {
-			repositoryManager = new DBScoresRepositoryManager();
-		} catch (NamingException e) {
-			throw new ScoresException("DB service initialization failed." +
-							"\nCause: " + e.getMessage());
+		//System.setProperty("java.security.policy", "client.policy");
+		if (System.getSecurityManager() == null) {
+			System.setSecurityManager(new RMISecurityManager()); 
 		}
 		
-		scoresFactory = new DBScoresFactory();
+		projectsServiceProperties = conf.getProjectsServiceProperties();
 		
-		ScoresUpdater updater = Tools.getScoresUpdater();
-		updater.init(this, conf.getUpdateConf());
+		projectIds = conf.getProjectIds();
 		
-		initialized = true;
-	}
-	
-	/* This method will be called before every get/save call
-	 * to ensure JMM sevice is initialized (it could be not in case of restart)
-	 * TODO Move service conf to service side.
-	 * */
-	public void update(Configuration conf, ScoresManager scoresManager)
-													throws ScoresException {
+		MetricsProjectsService service = ProjectTools.getProjectsService(projectsServiceProperties);
+		log.info("Service: " + service);
 		
-		if (initialized) {
-			return;
-		} else {
-			init(conf,scoresManager);
-		}
-	}
-	
-	/**
-	 * Saves current plugin values.
-	 * 
-	 * @param projectIds Projects for which plugin values will be saved
-	 * @param plugins Plugins for which values will be saved
-	 * @param portalName
-	 * @return true iff saving was successful
-	 */
-	@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
-	public void save() throws ScoresException {	
+		service.ping();
 		
-		log.info("Getting plugins...");
-		
-		// Get plugins from conf
-		Plugins plugins = new Plugins(pluginsConf, portalName, projectIds,
-															scoresManager);
-		
-		log.info("Computing scores...");
-		
-		// Ensure that labs ProjectsService is available
-		try {
-			ProjectTools.init(portalName, projectsServiceProperties);
-		} catch (NamingException e) {
-			throw new ScoresException(e);
-		}
-		
-		// Get plugins values and save them
-		PluginsValues pluginsValues =
-						scoresFactory.createPluginsValues(projectIds, plugins);
-		
-		log.info("Saving...");
-		
-		repositoryManager.save(pluginsValues);
-		
-		log.info("Scores saved successfully");
+		//ScoresUpdater updater = Tools.getScoresUpdater();
+		//updater.init(this, conf.getUpdateConf());
 	}
-	
-	
 
-	/**
-	 * Returns historical scores from the given <code>date</code> in the past.
-	 * 
-	 * Notice that only year, month and day matter in passed dates.
-	 * 
-	 * @return scores from the given date
-	 * @throws GetScoresException
-	 */
-	private PluginsValues getPluginsValues(Calendar cal)
-									throws GetScoresException {
-				
-		return repositoryManager.get(cal);
+	public void save() {
+		// TODOs
 	}
-	
-	public boolean hasPluginsValues(Calendar cal) {
 
-		PluginsValues pluginsValues = null;
-		
-		try {
-			pluginsValues = getPluginsValues(cal);
-		} catch (GetScoresException e) {
-			log.warn("hasPluginsValues", e);
-			return false;
-		}
-		
-		return (pluginsValues != null);
-	}
-
-	public long getValue(String pluginId, String projectId, Calendar cal)
-													throws GetScoresException {
-		
-		return repositoryManager.getValue(pluginId, projectId, cal);
-	}
-
-	public long getValue(String pluginId, String projectId,
-						  Calendar start, Calendar end)
-													throws GetScoresException {
-
-		return repositoryManager.getValue(pluginId, projectId, start, end);
-	}
-
-	public void start() throws Exception {
-		
-		log.info("JMM service started.");
-		
-		Tools.startJMXService(Constants.METICS_SERVICE_ADDRESS);
-		
-		log.info("Connector server for JMM started.");
-	}
-
-	public void stop() throws Exception {
-		
-		log.info("JMM service stopped");
-	}
-
 	public void ping() {
 		
 		log.debug("ping");
@@ -244,19 +111,23 @@
 		 
 		 return ret;
 	}
-
-	public void fillPluginsValues(Calendar cal, PluginsValuesRemote pv) throws GetScoresException {
+	
+	//	 Life cycle methods
+	
+	public void start() throws Exception {
 		
-		PluginsValues pluginsValues = getPluginsValues(cal);
-		pv.fill(pluginsValues);
+		log.info("Metrics service started.");
+		
+		Tools.startJMXService(Constants.METICS_SERVICE_ADDRESS);
+		
+		init(new DefaultConfiguration());
+		
+		
+		log.info("Connector server for Metrics started.");
 	}
 
-	public PluginsValuesRemote getPluginsValuesRemote(Calendar cal) throws GetScoresException{
+	public void stop() throws Exception {
 		
-		PluginsValuesRemote pvr = new PluginsValuesRemote();
-		PluginsValues pluginsValues = getPluginsValues(cal);
-		pvr.fill(pluginsValues);
-		
-		return pvr;
+		log.info("Metrics service stopped");
 	}
 }

Deleted: labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/plugins/KosmosPlugin.java
===================================================================
--- labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/plugins/KosmosPlugin.java	2007-09-18 14:39:58 UTC (rev 15205)
+++ labs/jbosslabs/trunk/stats-server/sources/metrics/service/src/java/org/jboss/labs/metrics/service/plugins/KosmosPlugin.java	2007-09-18 14:40:35 UTC (rev 15206)
@@ -1,140 +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.labs.metrics.service.plugins;
-
-import org.jboss.labs.metrics.common.exceptions.GetPluginValueException;
-import org.jboss.labs.metrics.common.exceptions.InvalidPluginPropertiesException;
-import org.jboss.labs.metrics.common.exceptions.UnableToGetPluginValueException;
-import org.jboss.labs.metrics.common.protocol.ScoresManager;
-import org.jboss.labs.metrics.common.protocol.conf.Plugin;
-import org.jboss.labs.metrics.common.tools.Plugins;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-/**
-* @author Pawel Wrzeszcz
-* Superclass for kosmos-service based plugins.
-*/
-
-public abstract class KosmosPlugin extends Plugin {
-	
-	/**
-	 * Kosmos-service xml tag.
-	 */
-	protected abstract String getKosmosServiceTag();
-
-	/**
-	 * Binds project ids with kosmos-service specyfic Maps.
-	 */
-	private Map<String,List> projectServices;
-	
-	/**
-	 * Kosmos service adress.
-	 */
-	protected String serviceURL;
-	
-	public KosmosPlugin() {
-		super();
-		projectServices = new HashMap<String,List>();
-	}
-	
-	@Override
-	public void init(String id, String portalName, List<String> projectIds,
-			Plugins plugins, Properties properties, ScoresManager scoresManager)
-									throws InvalidPluginPropertiesException {
-		super.init(id, portalName, projectIds, plugins, properties, scoresManager);
-		
-		getServiceProperty(properties);
-	}
-	
-	/**
-	 * Gets service URL from the given Node with plugin properites. 
-	 * 
-	 * @param propertiesNode Node with plugin specyfic properties 
-	 * @throws InvalidPluginPropertiesException
-	 */
-	private void getServiceProperty(Properties properties)
-		throws InvalidPluginPropertiesException {
-		
-		if ((properties == null) || (properties.isEmpty())) {
-			throw new InvalidPluginPropertiesException(
-					"Missing properties for plugin: " + getId() + ".");
-		}
-	
-		serviceURL = properties.getProperty(getKosmosServiceTag());
-		
-		if (serviceURL == null) {
-			throw new InvalidPluginPropertiesException(
-					"Missing " + getKosmosServiceTag() + 
-					" property for plugin: " + getId() + ".");
-		}
-	}
-
-	/**
-	 * For the given service specyfic Maps, computes plugin specyfic value.
-	 * 
-	 * @param projectMap service specyfic Map
-	 * @return Plugin value
-	 */
-	protected abstract int getPluginSpecyficValue(Object projectMap);
-	
-	/**
-	 * Returns service specyfic Maps for the given project.
-	 * 
-	 * @param projectId
-	 * @return service specyfic Map
-	 * @throws GetPluginValueException 
-	 */
-	protected abstract List getProjectServices(String projectId) throws GetPluginValueException;
-	
-	/* (non-Javadoc)
-	 * @see org.jboss.labs.metrics.Plugin#getValue(java.lang.String)
-	 */
-	@Override
-	protected long getPluginValue(String projectId)
-							throws UnableToGetPluginValueException,
-								   GetPluginValueException {
-		
-		if (!projectServices.containsKey(projectId)) {
-			projectServices.put(projectId, getProjectServices(projectId));
-		}
-		
-		List projectServicesList = projectServices.get(projectId);
-		
-		if (projectServicesList == null) {
-			throw new UnableToGetPluginValueException("Service not specified.");
-		}
-		
-		long value = 0;
-		
-		for (Object projectService : projectServicesList) {
-		
-			value += getPluginSpecyficValue(projectService);
-		}
-		
-		return value;
-	}
-}




More information about the jboss-svn-commits mailing list