Author: unibrew Date: 2006-05-12 20:27:10 -0400 (Fri, 12 May 2006) New Revision: 4212 Added: labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersService.java labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/CountersServiceInterface.java Removed: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/CountersService.java Modified: labs/jbosslabs/trunk/portal-extensions/counters-ejb3/project.xml labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersEntity.java labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersMDB.java labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersServiceBean.java labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Counter.java labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDB.java labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersWatcher.java labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Sorting.java Log: [JBLAB-665] DownloadCountes are now persisted in database. Modified: labs/jbosslabs/trunk/portal-extensions/counters-ejb3/project.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/counters-ejb3/project.xml 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/counters-ejb3/project.xml 2006-05-13 00:27:10 UTC (rev 4212) @@ -39,6 +39,11 @@ <version></version> <jar>jboss-j2ee.jar</jar> </dependency> - + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-annotations-ejb3</artifactId> + <version></version> + <jar>jboss-annotations-ejb3.jar</jar> + </dependency> </dependencies> </project> Modified: labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersEntity.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersEntity.java 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersEntity.java 2006-05-13 00:27:10 UTC (rev 4212) @@ -28,6 +28,8 @@ import javax.persistence.Id; import javax.persistence.Table; +import org.jboss.forge.common.projects.Sorting; + /** * * @author Ryszard Kozmik @@ -44,6 +46,15 @@ private String projectId; private boolean visible; + + public CountersEntity () + { + this.path = ""; + this.order = Sorting.RANDOM.toString(); + this.projectId=""; + this.visible = true; + } + public CountersEntity (String path, long initValue, String projectId, boolean visible, String order) { this.path = path; Modified: labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersMDB.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersMDB.java 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersMDB.java 2006-05-13 00:27:10 UTC (rev 4212) @@ -32,7 +32,7 @@ import javax.naming.InitialContext; import javax.naming.NamingException; -import org.jboss.forge.common.projects.CountersService; +import org.jboss.forge.common.projects.CountersServiceInterface; import org.jboss.logging.Logger; @@ -69,7 +69,7 @@ TextMessage txtMsg = (TextMessage) msg; InitialContext ctx = new InitialContext(); CountersService countersService = - (CountersService) ctx.lookup(CountersService.class.getName()); + (CountersService) ctx.lookup(CountersServiceInterface.jndiName); countersService.incrementCounter(txtMsg.getText()); System.out.println("HELLO!!: "+txtMsg.getText()); } Added: labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersService.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersService.java 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersService.java 2006-05-13 00:27:10 UTC (rev 4212) @@ -0,0 +1,37 @@ + + /* + * 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.counters; + +import javax.ejb.Local; + +import org.jboss.forge.common.projects.CountersServiceInterface; + + +/** + * + * @author Ryszard Kozmik + * + */ +@Local +public interface CountersService extends CountersServiceInterface {} \ No newline at end of file Modified: labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersServiceBean.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersServiceBean.java 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/counters-ejb3/src/java/org/jboss/forge/counters/CountersServiceBean.java 2006-05-13 00:27:10 UTC (rev 4212) @@ -31,8 +31,9 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import org.jboss.annotation.ejb.LocalBinding; import org.jboss.forge.common.projects.Counter; -import org.jboss.forge.common.projects.CountersService; +import org.jboss.forge.common.projects.CountersServiceInterface; import org.jboss.forge.common.projects.Sorting; @@ -42,6 +43,7 @@ * */ @Stateless +@LocalBinding (jndiBinding=CountersServiceInterface.jndiName) public class CountersServiceBean implements CountersService { @@ -65,10 +67,11 @@ public void updateCounters(Map<String,Counter> downloadCounters) { - + System.out.println("HELLO UPDATECOUNTERS"); synchronized (downloadCounters) { for (String path : downloadCounters.keySet()) { + System.out.println("UPDATING PATH: "+path); Counter counter = downloadCounters.get(path); CountersEntity ce = em.find(CountersEntity.class,path); if (ce==null) Modified: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Counter.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Counter.java 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Counter.java 2006-05-13 00:27:10 UTC (rev 4212) @@ -23,15 +23,17 @@ package org.jboss.forge.common.projects; +import java.io.Serializable; + /** * Each Counter class object represents simply one counter for a download link. * Object contains the current counter value and projectId for this link. - * + * * @author Ryszard Kozmik */ -public class Counter { +public class Counter implements Serializable { /** * Current value of a download counter. Deleted: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/CountersService.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/CountersService.java 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/CountersService.java 2006-05-13 00:27:10 UTC (rev 4212) @@ -1,46 +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.common.projects; - -import java.util.Map; - -import javax.ejb.Local; - - -/** - * - * @author Ryszard Kozmik - * - */ -@Local -public interface CountersService -{ - - public Map<String,Counter> getCountersMap(); - - public void updateCounters(Map<String,Counter> downloadCounters); - - public void incrementCounter (String path); - -} Added: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/CountersServiceInterface.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/CountersServiceInterface.java 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/CountersServiceInterface.java 2006-05-13 00:27:10 UTC (rev 4212) @@ -0,0 +1,44 @@ + + /* + * 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.common.projects; + +import java.util.Map; + +/** + * + * @author Ryszard Kozmik + * + */ +public interface CountersServiceInterface +{ + + public static final String jndiName = "countersService/local"; + + public Map<String,Counter> getCountersMap(); + + public void updateCounters(Map<String,Counter> downloadCounters); + + public void incrementCounter (String path); + +} Modified: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDB.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDB.java 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDB.java 2006-05-13 00:27:10 UTC (rev 4212) @@ -56,8 +56,8 @@ try { ctx = new InitialContext(); - CountersService countersService = - (CountersService) ctx.lookup(CountersService.class.getName()); + CountersServiceInterface countersService = + (CountersServiceInterface) ctx.lookup(CountersServiceInterface.jndiName); downloadCounters = countersService.getCountersMap(); // SOD @@ -74,6 +74,8 @@ // Synchronizing tracked links in downloadConters with links from // projects download counter descriptors. synchronizeCounters(descriptors); + + countersService.updateCounters(downloadCounters); // SOD @@ -107,14 +109,19 @@ try { - CountersService countersService = - (CountersService) ctx.lookup(CountersService.class.getName()); + CountersServiceInterface countersService = + (CountersServiceInterface) ctx.lookup(CountersServiceInterface.jndiName); countersService.updateCounters(downloadCounters); } catch (Exception e) { getLogger().error("Failed to persist downloadCounters", e); } + // SOD + for (String path : downloadCounters.keySet()) + { + System.out.println("SOD 4.5 Path: "+path+" Value: "+downloadCounters.get(path)); + } } /** @@ -133,9 +140,9 @@ System.out.println("DownloadCounters: "+link); try { - CountersService countersService = - (CountersService) ctx.lookup(CountersService.class.getName()); - countersService.incrementCounter(link); + //CountersServiceInterface countersService = + // (CountersServiceInterface) ctx.lookup(CountersServiceInterface.jndiName); + //countersService.incrementCounter(link); QueueSession sess = null; Queue queue = null; Modified: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java 2006-05-13 00:27:10 UTC (rev 4212) @@ -246,10 +246,10 @@ } // SOD - //for (String path : downloadCounters.keySet()) - //{ - // System.out.println("SOD 3 Path: "+path+" Value: "+downloadCounters.get(path)); - // } + for (String path : downloadCounters.keySet()) + { + System.out.println("SOD 3 Path: "+path+" Value: "+downloadCounters.get(path)); + } // Iterating through projects nodes containing download counter descriptors. for (String projectId:counters.keySet()){ @@ -291,10 +291,10 @@ } // SOD - // for (String path : downloadCounters.keySet()) - // { - // System.out.println("SOD 5 Path: "+path+" Value: "+downloadCounters.get(path)); - // } + for (String path : downloadCounters.keySet()) + { + System.out.println("SOD 5 Path: "+path+" Value: "+downloadCounters.get(path)); + } // Changing status to false becouse downloadCounters Map // is now synchronized with projects' download counter descriptors. @@ -360,10 +360,20 @@ * Project id name for which the links are added. */ private synchronized void addLinksForCounting (Map<String,Boolean> links,String projectId,Sorting sorting) { + // SOD + for (String path : downloadCounters.keySet()) + { + System.out.println("SOD 10 Path: "+path+" Value: "+downloadCounters.get(path)); + } // Adding new download links for tracking. for (String link:links.keySet()) { downloadCounters.put(link,new Counter(0,projectId,links.get(link),sorting)); } + // SOD + for (String path : downloadCounters.keySet()) + { + System.out.println("SOD 11 Path: "+path+" Value: "+downloadCounters.get(path)); + } } private synchronized void removeLinksForProjects (Set<String> projects) { @@ -427,7 +437,23 @@ * Map<String,Long> containing link:value pairs. */ public synchronized Map<String,Long> getValuesForPortlet (String projectId) { + + System.out.println("GETVALUESFORPORTLET"); + System.out.println("PROJECTID: "+projectId); + // SOD + for (String path : downloadCounters.keySet()) + { + System.out.println("SOD 12 Path: "+path+" Value: "+downloadCounters.get(path)+ + " ProjectId: "+downloadCounters.get(path).getProjectId()+" Visible:"+downloadCounters.get(path).getVisible()); + } Map<String,Boolean> links = getProjectLinks(projectId); + + //SOD + for (String project : links.keySet()) + { + System.out.println("SOD: PROJECTLINK: "+project+" BOOLEAN: "+links.get(project)); + } + Map<String,Long> values = null; if (links.size()==0) { values = new Hashtable<String,Long>(0); @@ -451,7 +477,8 @@ * positive integer - when counter for the first link is greater than for second one */ public synchronized int compare(String link1, String link2) { - return (int)(downloadCounters.get(link1).getValue()-downloadCounters.get(link2).getValue()); + int valueCompare = (int)(downloadCounters.get(link1).getValue()-downloadCounters.get(link2).getValue()); + return valueCompare==0?link1.compareTo(link2):valueCompare; } }); } else if (sorting==Sorting.DESC || sorting==Sorting.DESCENDING) { @@ -469,7 +496,8 @@ * positive integer - when counter for the first link is lower than for second one */ public synchronized int compare(String link1, String link2) { - return (int)(downloadCounters.get(link2).getValue()-downloadCounters.get(link1).getValue()); + int valueCompare = (int)(downloadCounters.get(link2).getValue()-downloadCounters.get(link1).getValue()); + return valueCompare==0?link2.compareTo(link1):valueCompare; } }); } else { @@ -480,6 +508,18 @@ values.put(link,downloadCounters.get(link).getValue()); } } + + for (String link : values.keySet()) + { + System.out.println("SOD: VALUES || LINK: "+link+" LONGVAL: "+values.get(link)); + } + + // SOD + for (String path : downloadCounters.keySet()) + { + System.out.println("SOD 13 Path: "+path+" Value: "+downloadCounters.get(path).getValue() + + " ProjectId: "+downloadCounters.get(path).getProjectId()+" Visible:"+downloadCounters.get(path).getVisible()); + } return values; } Modified: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersWatcher.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersWatcher.java 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersWatcher.java 2006-05-13 00:27:10 UTC (rev 4212) @@ -69,7 +69,7 @@ */ private Object getDescriptor (String portalName) { DownloadCountersDescriptor descriptor = - new DownloadCountersDescriptor(portalName, contentManager); + new DownloadCountersDB(portalName, contentManager); rw = new ResourceWatcher(contentManager); // Registering ResourceWatcher to watch for main download counters xml file change. //rw.watchResource(DownloadCounterTools.getMainXmlPath(portalName)); Modified: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Sorting.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Sorting.java 2006-05-12 23:02:59 UTC (rev 4211) +++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Sorting.java 2006-05-13 00:27:10 UTC (rev 4212) @@ -23,12 +23,14 @@ package org.jboss.forge.common.projects; +import java.io.Serializable; + /** * This enum describes possible ways of sorting. - * + * * @author Ryszard Kozmik * */ -public enum Sorting { +public enum Sorting implements Serializable { ASCENDING,ASC,DESCENDING,DESC,RANDOM } |