svn commit: r727741 - /lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/scheduling/impl/UsecaseSchedulerImpl.java

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: andreas
Date: Thu Dec 18 07:16:59 2008
New Revision: 727741

URL: http://svn.apache.org/viewvc?rev=727741&view=rev
Log:
Using UUIDs as scheduler job names to avoid clashes.

Modified:
    lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/scheduling/impl/UsecaseSchedulerImpl.java

Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/scheduling/impl/UsecaseSchedulerImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/scheduling/impl/UsecaseSchedulerImpl.java?rev=727741&r1=727740&r2=727741&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/scheduling/impl/UsecaseSchedulerImpl.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/scheduling/impl/UsecaseSchedulerImpl.java Thu Dec 18 07:16:59 2008
@@ -21,6 +21,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
@@ -39,6 +40,7 @@
 import org.apache.lenya.ac.Machine;
 import org.apache.lenya.ac.User;
 import org.apache.lenya.cms.publication.URLInformation;
+import org.apache.lenya.cms.repository.UUIDGenerator;
 import org.apache.lenya.cms.usecase.Usecase;
 import org.apache.lenya.cms.usecase.scheduling.UsecaseScheduler;
 
@@ -53,7 +55,9 @@
  * @version $Id$
  */
 public class UsecaseSchedulerImpl extends AbstractLogEnabled implements UsecaseScheduler,
-        Serviceable, Contextualizable {
+        Serviceable, Contextualizable, Disposable {
+
+    private UUIDGenerator uuidGenerator;
 
     /**
      * @see org.apache.lenya.cms.usecase.scheduling.UsecaseScheduler#schedule(org.apache.lenya.cms.usecase.Usecase,
@@ -101,7 +105,7 @@
             }
 
             String role = CronJob.class.getName() + "/usecase";
-            String name = getJobName(usecase, userId);
+            String name = getJobName();
             scheduler.fireJobAt(date, name, role, parameters, objects);
 
         } catch (Exception e) {
@@ -113,10 +117,20 @@
             }
         }
     }
+    
+    protected UUIDGenerator getUuidGenerator() {
+        if (this.uuidGenerator == null) {
+            try {
+                this.uuidGenerator = (UUIDGenerator) this.manager.lookup(UUIDGenerator.ROLE);
+            } catch (ServiceException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return this.uuidGenerator;
+    }
 
-    protected String getJobName(Usecase usecase, String userId) {
-        return usecase.getName() + ":" + userId + ":" + 
-                   getPublicationName(usecase);
+    protected String getJobName() {
+        return getUuidGenerator().nextUUID();
     }
 
     protected ServiceManager manager;
@@ -169,4 +183,10 @@
         URLInformation info = new URLInformation(usecase.getSourceURL());
         return info.getPublicationId();
     }
+
+    public void dispose() {
+        if (this.uuidGenerator != null) {
+            this.manager.release(this.uuidGenerator);
+        }
+    }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.