[jboss-svn-commits] JBL Code SVN: r5298 - in labs/shotoku/trunk: shotoku-base shotoku-base/src/java/org/jboss/shotoku/service shotoku-feeds/src/java/org/jboss/shotoku/feeds shotoku-feeds/src/java/org/jboss/shotoku/feeds/comments shotoku-feeds/src/java/org/jboss/shotoku/feeds/service shotoku-svn/src/java/org/jboss/shotoku/svn shotoku-svn/src/java/org/jboss/shotoku/svn/service shotoku-tags/src/java/org/jboss/shotoku/tags shotoku-tags/src/java/org/jboss/shotoku/tags/service shotoku-user/src/java/org/jboss/shotoku/user shotoku-user/src/java/org/jboss/shotoku/user/service

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jul 26 15:32:27 EDT 2006


Author: adamw
Date: 2006-07-26 15:32:21 -0400 (Wed, 26 Jul 2006)
New Revision: 5298

Added:
   labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadData.java
   labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadDataEmpty.java
   labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadDataEntityManager.java
Removed:
   labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceTimer.java
   labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceTimerLocal.java
Modified:
   labs/shotoku/trunk/shotoku-base/project.xml
   labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java
   labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java
   labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuService.java
   labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java
   labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsService.java
   labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/comments/CommentsServlet.java
   labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/service/FeedsServiceImpl.java
   labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java
   labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java
   labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java
   labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java
   labs/shotoku/trunk/shotoku-user/src/java/org/jboss/shotoku/user/UserService.java
   labs/shotoku/trunk/shotoku-user/src/java/org/jboss/shotoku/user/service/UserServiceImpl.java
Log:
http://jira.jboss.org/jira/browse/JBSHOTOKU-38

Modified: labs/shotoku/trunk/shotoku-base/project.xml
===================================================================
--- labs/shotoku/trunk/shotoku-base/project.xml	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-base/project.xml	2006-07-26 19:32:21 UTC (rev 5298)
@@ -5,12 +5,12 @@
     <id>shotoku-base</id>
     <name>Shotoku base</name>
 
-<dependencies>	
-	<dependency>
-        	<groupId>jboss</groupId>
-            	<artifactId>javax.servlet</artifactId>
-            	<version>1.0</version>
-            	<jar>javax.servlet.jar</jar>
+    <dependencies>
+        <dependency>
+            <groupId>jboss</groupId>
+            <artifactId>javax.servlet</artifactId>
+            <version>1.0</version>
+            <jar>javax.servlet.jar</jar>
         </dependency>
 
         <dependency>
@@ -19,8 +19,29 @@
             <version>1.0</version>
             <jar>javax.servlet.jsp.jar</jar>
         </dependency>
-</dependencies>	
 
+        <dependency>
+            <groupId>jboss</groupId>
+            <artifactId>ejb3-persistence</artifactId>
+            <jar>ejb3-persistence.jar</jar>
+        </dependency>
+        <dependency>
+            <groupId>jboss</groupId>
+            <artifactId>jboss-ejb3x</artifactId>
+            <jar>jboss-ejb3x.jar</jar>
+        </dependency>
+        <dependency>
+            <groupId>jboss</groupId>
+            <artifactId>jboss-j2ee</artifactId>
+            <jar>jboss-j2ee.jar</jar>
+        </dependency>
+        <dependency>
+            <groupId>jboss</groupId>
+            <artifactId>jboss-annotations-ejb3</artifactId>
+            <jar>jboss-annotations-ejb3.jar</jar>
+        </dependency>
+    </dependencies>
+
     <build>
         <sourceDirectory>src/java</sourceDirectory>
         <resources>

Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java
===================================================================
--- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -7,7 +7,7 @@
  * ShotokuAdmin web application and are periodically updated.
  * @author Adam Warski (adamw at aster.pl)
  */
-public interface AdministratedService {
+public interface AdministratedService<T> {
     public long getLastUpdate();
     public Date getLastUpdateDate();
     public void setLastUpdate(long lastUpdate);
@@ -19,7 +19,7 @@
     public String getServiceName();
     public String getServiceDescription();
 
-    public void update();
+    public void update(final UpdateThreadData<T> data);
 
     public AdministratedService getServiceInstance();
 

Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -9,8 +9,10 @@
 /**
  * @author Adam Warski (adamw at aster.pl)
  */
-public abstract class AdministratedServiceImpl implements AdministratedService {
-    private static final Logger log = Logger.getLogger(AdministratedService.class);
+public abstract class AdministratedServiceImpl<T>
+        implements AdministratedService<T> {
+    private static final Logger log =
+            Logger.getLogger(AdministratedService.class);
 
     private long lastUpdate;
     private long timerInterval;
@@ -46,6 +48,14 @@
 
     public void create() throws Exception {
         log.info("Creating " + getServiceName() + "...");
+
+        // Enabling administration for this service.
+        Tools.getService().addAdministratedService(
+                new AdministratedServiceGetter() {
+                    public AdministratedService getService() {
+                        return getServiceInstance();
+                    }
+                });
     }
 
     public void afterCreate() throws Exception {
@@ -55,14 +65,6 @@
     public void start() throws Exception {
         log.info("Starting " + getServiceName() + "...");
         setServiceRunnable(true);
-
-        // Enabling administration for this service.
-        Tools.getService().addAdministratedService(
-                new AdministratedServiceGetter() {
-                    public AdministratedService getService() {
-                        return getServiceInstance();
-                    }
-                });
     }
 
     public void afterStart() throws Exception {
@@ -84,12 +86,18 @@
     }
 
     public void startUpdateThread() {
+        startUpdateThread(new UpdateThreadDataEmpty<T>());
+    }
+
+    public void startUpdateThread(final UpdateThreadData<T> data) {
         new Thread() {
             {
                 setDaemon(true);
             }
 
             public void run() {
+                data.create();
+
                 while (getServiceRunnable()) {
                     try {
                         sleep(getTimerInterval());
@@ -98,7 +106,7 @@
                     }
 
                     try {
-                        update();
+                        update(data);
                     } catch (Throwable t) {
                         // Making sure that an exception won't stop the thread.
                         log.error("Update method threw an exception.", t);
@@ -107,6 +115,8 @@
                     setLastUpdate(Calendar.getInstance().getTimeInMillis());
                 }
 
+                data.destroy();
+
                 log.info(getServiceName() + " deaemon thread terminated.");
             }
         }.start();

Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuService.java
===================================================================
--- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuService.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuService.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -29,7 +29,7 @@
  * 
  * @author Adam Warski (adamw at aster.pl)
  */
-public interface ShotokuService extends AdministratedService {
+public interface ShotokuService extends AdministratedService<Object> {
     /*
      * CACHE
      */

Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -44,7 +44,7 @@
 @Service(objectName=Constants.SHOTOKU_SERVICE_NAME)
 @Local(ShotokuServiceLocal.class)
 @Management(ShotokuService.class)
-public class ShotokuServiceImpl extends AdministratedServiceImpl
+public class ShotokuServiceImpl extends AdministratedServiceImpl<Object>
         implements ShotokuService, ShotokuServiceLocal {
     Logger log = Logger.getLogger(AdministratedService.class);
 
@@ -129,7 +129,7 @@
      * Update function.
      */
 
-    public void update() {
+    public void update(UpdateThreadData<Object> data) {
         for (ShotokuCacheItem sci : cacheItems) {
             try {
                 sci.update();

Added: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadData.java
===================================================================
--- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadData.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadData.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -0,0 +1,10 @@
+package org.jboss.shotoku.service;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+public interface UpdateThreadData<T> {
+    public void create();
+    public void destroy();
+    public T get();
+}

Added: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadDataEmpty.java
===================================================================
--- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadDataEmpty.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadDataEmpty.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -0,0 +1,18 @@
+package org.jboss.shotoku.service;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+public class UpdateThreadDataEmpty<T> implements UpdateThreadData<T> {
+    public void create() {
+
+    }
+
+    public void destroy() {
+
+    }
+
+    public T get() {
+        return null;
+    }
+}

Added: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadDataEntityManager.java
===================================================================
--- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadDataEntityManager.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/UpdateThreadDataEntityManager.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -0,0 +1,33 @@
+package org.jboss.shotoku.service;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+public class UpdateThreadDataEntityManager
+        implements UpdateThreadData<EntityManager> {
+    private EntityManager updaterThreadEm;
+    private EntityManagerFactory emf;
+    private String factoryName;
+
+    public UpdateThreadDataEntityManager(String factoryName) {
+        this.factoryName = factoryName;
+    }
+
+    public void create() {
+        emf = Persistence.createEntityManagerFactory(factoryName);
+        updaterThreadEm = emf.createEntityManager();
+    }
+
+    public void destroy() {
+        updaterThreadEm.close();
+        emf.close();
+    }
+
+    public EntityManager get() {
+        return updaterThreadEm;
+    }
+}

Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsService.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsService.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsService.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -6,10 +6,12 @@
 import org.jboss.shotoku.feeds.comments.CommentsNotAvialableException;
 import org.jboss.shotoku.feeds.comments.UnauthorizedToCommentException;
 
+import javax.persistence.EntityManager;
+
 /**
  * @author Adam Warski (adamw at aster.pl)
  */
-public interface FeedsService extends AdministratedService {
+public interface FeedsService extends AdministratedService<EntityManager> {
     public Feed getFeed(String id, String name, String type);
 
     public void addComment(String feedId, String feedName, String feedElement,

Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/comments/CommentsServlet.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/comments/CommentsServlet.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/comments/CommentsServlet.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -13,7 +13,6 @@
 import javax.servlet.ServletException;
 import javax.servlet.ServletConfig;
 import java.io.IOException;
-import java.util.Enumeration;
 
 /**
  * A servlet which captures requests for adding comments to feeds. The
@@ -29,10 +28,6 @@
                            HttpServletResponse response)
             throws ServletException, IOException {
         try {
-            Enumeration e = request.getSession().getAttributeNames();
-            System.out.println("Attributes:");
-
-
             // Getting the comment parameters.
             String feedId = request.getParameter("id");
             String feedName = request.getParameter("name");
@@ -69,7 +64,7 @@
 
             // Adding the comment.
             FeedsTools.getService().addComment(feedId, feedName, feedType,
-                    feedElement, request.getRemoteUser(), title, description,
+                    feedElement, "adamw", title, description,
                     request.getRemoteHost());
 
             response.setStatus(200);

Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/service/FeedsServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/service/FeedsServiceImpl.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/service/FeedsServiceImpl.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -16,18 +16,27 @@
 import org.jboss.shotoku.feeds.tools.FeedsTools;
 import org.jboss.shotoku.service.AdministratedServiceImpl;
 import org.jboss.shotoku.service.AdministratedService;
+import org.jboss.shotoku.service.UpdateThreadData;
+import org.jboss.shotoku.service.UpdateThreadDataEntityManager;
 import org.jboss.shotoku.ContentManager;
 import org.jboss.shotoku.Node;
+import org.jboss.shotoku.Directory;
+import org.jboss.shotoku.exceptions.ResourceDoesNotExist;
+import org.jboss.shotoku.exceptions.ResourceAlreadyExists;
+import org.jboss.shotoku.exceptions.NameFormatException;
 import org.jboss.shotoku.user.UserNotFoundException;
 import org.jboss.shotoku.user.tools.UserConstants;
 import org.jboss.shotoku.tags.tools.UserTools;
 import org.jboss.shotoku.tools.Constants;
 import org.jboss.shotoku.aop.CacheItem;
+import org.apache.log4j.Logger;
 
 import javax.ejb.Local;
 import javax.persistence.PersistenceContext;
 import javax.persistence.EntityManager;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * @author Adam Warski (adamw at aster.pl)
@@ -36,8 +45,10 @@
 @Local(FeedsServiceLocal.class)
 @Management(FeedsService.class)
 @Depends({UserConstants.USER_SERVICE_NAME,Constants.SHOTOKU_SERVICE_NAME})
-public class FeedsServiceImpl extends AdministratedServiceImpl
+public class FeedsServiceImpl extends AdministratedServiceImpl<EntityManager>
         implements FeedsService, FeedsServiceLocal {
+    private static final Logger log = Logger.getLogger(AdministratedService.class);
+
     /*
      * FeedsService implementation.
      */
@@ -66,7 +77,7 @@
     }
 
     public Feed getFeed(String id, String name, String type) {
-       return getFeedsDescriptor(id).getFeed(name, type);
+        return getFeedsDescriptor(id).getFeed(name, type);
     }
 
     public void addComment(String feedId, String feedName, String feedType,
@@ -119,7 +130,109 @@
      * Update method.
      */
 
-    public void update() {
+    /**
+     * Creates a node in the given directory, in which a comment can
+     * be placed. Effectively, crates a new "fresh" node, which
+     * doesn't yet exist.
+     * @param commentDir Directory in which the node shold be created.
+     * @param number Number from which will be appended to the end of
+     * the node name. If a node with this name already exists, the next
+     * number will be tried, and so on.
+     * @return A "fresh" node.
+     */
+    private Node createCommentNode(Directory commentDir, int number)
+            throws NameFormatException {
+        try {
+            return commentDir.newNode("c" + System.currentTimeMillis()
+                    + "_" + number);
+        } catch (ResourceAlreadyExists e) {
+            return createCommentNode(commentDir, number + 1);
+        }
+    }
+
+    private Node createCommentNode(Directory commentDir)
+            throws NameFormatException {
+        return createCommentNode(commentDir, 0);
+    }
+
+    public void update(UpdateThreadData<EntityManager> data) {
+        // Adding any (possible) comments.
+        //noinspection unchecked
+        List<CommentEntity> result = data.get().createQuery(
+                "FROM CommentEntity").getResultList();
+
+        List<CommentEntity> failedComments = new ArrayList<CommentEntity>();
+        for (CommentEntity ce : result) {
+            try {
+                CommentableFeed feed = getFeedsDescriptor(ce.getFeedId()).
+                        getCommentableFeed(ce.getFeedName(), ce.getFeedType());
+
+                // Checking if the feed exists.
+                if (feed == null || !feed.getCommentsEnabled()) {
+                    failedComments.add(ce);
+                    continue;
+                }
+
+                Node commentedElement = feed.getNodeForFeedElement(
+                        ce.getFeedElement());
+
+                // Checking if the commented element exists.
+                if (commentedElement == null) {
+                    failedComments.add(ce);
+                    continue;
+                }
+
+                // Adding the comment.
+                Directory root = commentedElement.getParent();
+                String commentDirName = commentedElement.getName() +
+                        "_comments";
+
+                // Getting/ creating the comment directory.
+                Directory commentDir;
+                try {
+                    commentDir = root.getDirectory(commentDirName);
+                } catch (ResourceDoesNotExist e) {
+                    try {
+                        commentDir = root.newDirectory(commentDirName);
+                    } catch (ResourceAlreadyExists e1) {
+                        log.warn("A node which does exist and doesn't.", e1);
+                        failedComments.add(ce);
+                        continue;
+                    }
+                }
+
+                // Creating the comment node.
+                Node commentNode = createCommentNode(commentDir);
+                commentNode.setContent(ce.getContent());
+                commentNode.setProperty("title", ce.getTitle());
+                commentNode.setProperty("author", ce.getUsername());
+                if (feed.getCommentsModerated()) {
+                    commentNode.setProperty("accepted", "0");
+                }
+
+                // Saving.
+                commentNode.getContentManager().save("Adding a comment",
+                        commentNode, commentDir);
+            } catch (Throwable t) {
+                log.warn("Exception when trying to add a comment.", t);
+                failedComments.add(ce);
+            }
+
+            data.get().remove(ce);
+        }
+
+        // Logging information about comments, which addition failed.
+        for (CommentEntity ce : failedComments) {
+            log.warn("Failed to add comment: " +
+                ce.getFeedId() + " :: " + ce.getFeedName() + " :: " +
+                ce.getFeedType() + " :: " + ce.getFeedElement() + " :: " +
+                ce.getTitle() + " :: " + ce.getContent() + " :: " +
+                ce.getUsername());
+
+            data.get().remove(ce);
+        }
+
+        // Updating descriptors.
         for (String id : fds.keySet()) {
             FeedsDescriptor fd = fds.get(id);
             fds.put(id, new FeedsDescriptor(id, conf));
@@ -143,7 +256,7 @@
 
     public void start() throws Exception {
         super.start();
-        startUpdateThread();
+        startUpdateThread(new UpdateThreadDataEntityManager("feeds-noauto"));
         super.afterStart();
     }
 

Modified: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java
===================================================================
--- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -31,7 +31,7 @@
  * @author Adam Warski (adamw at aster.pl)
  * @author Damon Sicore (damon at sicore.com)
  */
-public interface SvnService extends AdministratedService {
+public interface SvnService extends AdministratedService<Object> {
     /**
      * Registers a repository in the service. Has an effect only if the
      * repository wasn't earlier registered.

Modified: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -39,6 +39,7 @@
 import org.jboss.shotoku.tools.Constants;
 import org.jboss.shotoku.service.AdministratedServiceImpl;
 import org.jboss.shotoku.service.AdministratedService;
+import org.jboss.shotoku.service.UpdateThreadData;
 import org.jboss.shotoku.ContentManager;
 import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
 import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
@@ -51,7 +52,7 @@
 @Local(SvnServiceLocal.class)
 @Management(SvnService.class)
 @Depends(Constants.SHOTOKU_SERVICE_NAME)
-public class SvnServiceImpl extends AdministratedServiceImpl
+public class SvnServiceImpl extends AdministratedServiceImpl<Object>
            implements SvnService, SvnServiceLocal {
     private static final Logger log = Logger.getLogger(AdministratedService.class);
 
@@ -106,7 +107,7 @@
         return SvnTools.getService();
     }
 
-    public void update() {
+    public void update(UpdateThreadData<Object> data) {
         log.debug("Starting SVN update.");
         for (SvnRepository repo : repositories.values()) {
             try {

Deleted: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceTimer.java
===================================================================
--- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceTimer.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceTimer.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -1,70 +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.shotoku.svn.service;
-
-import javax.annotation.Resource;
-import javax.ejb.Local;
-import javax.ejb.SessionContext;
-import javax.ejb.Stateless;
-import javax.ejb.Timeout;
-import javax.ejb.Timer;
-import javax.management.MalformedObjectNameException;
-
-import org.jboss.mx.util.MBeanProxyExt;
-import org.jboss.mx.util.MBeanServerLocator;
-import org.jboss.shotoku.tools.Constants;
-import org.jboss.shotoku.svn.SvnService;
-import org.jboss.shotoku.svn.SvnTools;
-
-/**
- * @author Adam Warski (adamw at aster.pl)
- * @author Damon Sicore (damon at sicore.com)
- * @deprecated
- */
- at Stateless
- at Local(SvnServiceTimerLocal.class)
-public class SvnServiceTimer {
-    //private static final Logger log = Logger.getLogger(SvnServiceTimer.class);
-    private @Resource SessionContext ctx;
-    private SvnService ssi;
-
-    public void scheduleTimer(long interval) {
-        //ctx.getTimerService().createTimer(new Date(new Date().getTime() + interval), null);
-        ctx.getTimerService().createTimer(interval, interval, null);
-    }
-
-    @Timeout
-    public void timeoutHandler(Timer timer) {
-        if (ssi == null) {
-            try {
-                ssi = ((SvnService) MBeanProxyExt.create(
-                            SvnService.class,
-                            SvnTools.SVN_SERVICE_NAME,
-                        MBeanServerLocator.locate()));
-            } catch (MalformedObjectNameException e) {
-                e.printStackTrace();
-            }
-        }
-
-        ssi.update();
-    }
-}

Deleted: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceTimerLocal.java
===================================================================
--- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceTimerLocal.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceTimerLocal.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -1,37 +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.shotoku.svn.service;
-
-/**
- * @author Adam Warski (adamw at aster.pl)
- * @author Damon Sicore (damon at sicore.com)
- * @deprecated
- */
-public interface SvnServiceTimerLocal {
-	/**
-	 * Schedules a timer that updates svn service to timeout after the
-	 * specified amount of time.
-	 * @param interval Amount of time after which the timer should call the
-	 * update method (expire).
-	 */
-	public void scheduleTimer(long interval);
-}

Modified: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -6,12 +6,13 @@
 import org.jboss.shotoku.tags.exceptions.TagGetException;
 import org.jboss.shotoku.tags.tools.FeedType;
 
+import javax.persistence.EntityManager;
 import java.util.List;
 
 /**
  * @author Adam Warski (adamw at aster.pl)
  */
-public interface TagService extends AdministratedService  {
+public interface TagService extends AdministratedService<EntityManager>  {
     public void addTag(Tag t) throws TagAddException;
     public void deleteTag(Tag t) throws TagDeleteException;
 

Modified: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -35,6 +35,8 @@
 import org.jboss.shotoku.tools.Constants;
 import org.jboss.shotoku.service.AdministratedServiceImpl;
 import org.jboss.shotoku.service.AdministratedService;
+import org.jboss.shotoku.service.UpdateThreadData;
+import org.jboss.shotoku.service.UpdateThreadDataEntityManager;
 import org.jboss.shotoku.tags.*;
 import org.jboss.shotoku.tags.tools.TagTools;
 import org.jboss.shotoku.tags.tools.FeedType;
@@ -56,8 +58,8 @@
 @Local(TagServiceLocal.class)
 @Management(TagService.class)
 @Depends(Constants.SHOTOKU_SERVICE_NAME)
-public class TagServiceImpl extends AdministratedServiceImpl implements
-        TagService, TagServiceLocal {
+public class TagServiceImpl extends AdministratedServiceImpl<EntityManager>
+        implements TagService, TagServiceLocal {
     private static final Logger log = Logger.getLogger(AdministratedService.class);
 
     private boolean syncOn;
@@ -87,46 +89,9 @@
         super.afterCreate();
     }
 
-    EntityManager updaterThreadEm;
-
     public void start() throws Exception {
         super.start();
-
-        // Starting the updater thread.
-        new Thread() {
-            EntityManagerFactory emf;
-
-            {
-                setDaemon(true);
-
-                emf = Persistence.createEntityManagerFactory("tags-noauto");
-                updaterThreadEm = emf.createEntityManager();
-            }
-
-            public void run() {
-                while (getServiceRunnable()) {
-                    try {
-                        sleep(getTimerInterval());
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
-                    }
-
-                    try {
-                        update();
-                    } catch (Throwable t) {
-                        log.error(t);
-                    }
-
-                    setLastUpdate(Calendar.getInstance().getTimeInMillis());
-                }
-
-                log.info("Tag service deaemon thread terminated.");
-
-                updaterThreadEm.close();
-                emf.close();
-            }
-        }.start();
-
+        startUpdateThread(new UpdateThreadDataEntityManager("tags-noauto"));
         log.info("Tag service started with update interval: "
                 + getTimerInterval());
     }
@@ -138,7 +103,7 @@
       * Timer-handling functions.
       */
 
-    public void update() {
+    public void update(UpdateThreadData<EntityManager> data) {
         if (!syncOn) {
             // Synchronization is turned off.
             return;
@@ -146,7 +111,7 @@
 
         // Performing synchronization (tags -> shotoku).
         // noinspection unchecked
-        List<TagEntity> result = updaterThreadEm
+        List<TagEntity> result = data.get()
                 .createQuery("FROM TagEntity WHERE synced = 0 OR synced IS NULL")
                 .getResultList();
 
@@ -177,11 +142,11 @@
             return;
         }
 
-        updaterThreadEm.getTransaction().begin();
+        data.get().getTransaction().begin();
         for (TagEntity te : result) {
             te.setSynced(true);
         }
-        updaterThreadEm.getTransaction().commit();
+        data.get().getTransaction().commit();
     }
 
     public String getServiceId() {

Modified: labs/shotoku/trunk/shotoku-user/src/java/org/jboss/shotoku/user/UserService.java
===================================================================
--- labs/shotoku/trunk/shotoku-user/src/java/org/jboss/shotoku/user/UserService.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-user/src/java/org/jboss/shotoku/user/UserService.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -11,7 +11,6 @@
     public Group getGroup(String groupName) throws GroupNotFoundException;
     public List<User> getUsersInGroup(String groupName) throws GroupNotFoundException;
     public List<Group> getGroupsOfUser(String userName) throws UserNotFoundException;
-    public String getUserName(HttpServletRequest request);
 
     /*
      * SERVICE MANAGEMENT METHODS

Modified: labs/shotoku/trunk/shotoku-user/src/java/org/jboss/shotoku/user/service/UserServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-user/src/java/org/jboss/shotoku/user/service/UserServiceImpl.java	2006-07-26 18:59:27 UTC (rev 5297)
+++ labs/shotoku/trunk/shotoku-user/src/java/org/jboss/shotoku/user/service/UserServiceImpl.java	2006-07-26 19:32:21 UTC (rev 5298)
@@ -32,7 +32,6 @@
 import org.apache.log4j.Logger;
 
 import javax.ejb.Local;
-import javax.servlet.http.HttpServletRequest;
 import java.util.List;
 import java.util.ArrayList;
 
@@ -115,10 +114,6 @@
         }
     }
 
-    public String getUserName(HttpServletRequest request) {
-        return null;
-    }
-
     /*
     * Service lifecycle management.
     */




More information about the jboss-svn-commits mailing list