directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r718534 - in /directory/sandbox/kayyagari/server-scheduler: ./ src/main/java/org/apache/directory/server/scheduler/store/
Date Tue, 18 Nov 2008 09:41:09 GMT
Author: kayyagari
Date: Tue Nov 18 01:41:08 2008
New Revision: 718534

URL: http://svn.apache.org/viewvc?rev=718534&view=rev
Log:
o implemented few more methods of JobStore
o added enhancer plugin to the pom file

Modified:
    directory/sandbox/kayyagari/server-scheduler/pom.xml
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/DefaultJobStore.java
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapJobStore.java
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapQuartzDelegate.java

Modified: directory/sandbox/kayyagari/server-scheduler/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/server-scheduler/pom.xml?rev=718534&r1=718533&r2=718534&view=diff
==============================================================================
--- directory/sandbox/kayyagari/server-scheduler/pom.xml (original)
+++ directory/sandbox/kayyagari/server-scheduler/pom.xml Tue Nov 18 01:41:08 2008
@@ -60,7 +60,7 @@
     <dependency>
       <groupId>quartz</groupId>
       <artifactId>quartz</artifactId>
-      <version>1.5.2</version>
+      <version>1.6.0</version>
     </dependency>
 
     <dependency>
@@ -68,6 +68,12 @@
       <artifactId>apacheds-server-unit</artifactId>
       <version>1.5.5-SNAPSHOT</version>
     </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-olm</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+     </dependency>
   </dependencies>
 
   <build>
@@ -83,12 +89,59 @@
           </systemProperties>
         </configuration>
       </plugin>
+      <plugin>
+	      <groupId>org.apache.directory.server</groupId>
+	      <artifactId>apacheds-olm</artifactId>
+	      <version>0.0.1-SNAPSHOT</version>
+	      <configuration>
+	      <schemaFiles>
+	        <param>/opt/workspace/apacheds/apacheds/schema-extras/src/main/schema/java.schema</param>
+	        <param>/opt/workspace/apacheds/apacheds/schema-bootstrap/src/main/schema/system.schema</param>
+	        <param>/opt/workspace/apacheds/apacheds/schema-bootstrap/src/main/schema/core.schema</param>
+	        <param>/opt/workspace/apacheds/apacheds/schema-bootstrap/src/main/schema/apache.schema</param>
+	        <param>/opt/workspace/apacheds/apacheds/schema-bootstrap/src/main/schema/quartz.schema</param>
+	      </schemaFiles>
+	      </configuration>
+	      <executions>
+	       <execution>
+	        <goals>
+	         <goal>generate</goal>
+	         <goal>enhance</goal>
+	        </goals>
+	       </execution>
+	      </executions>
+	    </plugin>
+
+	    <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <version>1.1</version>
+        <executions>
+          <execution>
+            <id>add-source</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>add-source</goal>
+            </goals>
+            <configuration>
+              <sources>
+                <source>target/generated-sources/</source>
+              </sources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
+
+    <resources>
+      <resource>
+       <directory>target/generated-sources/</directory>
+       <includes>
+        <include>classmapping.properties</include>
+       </includes>
+      </resource>
+    </resources>      
+
   </build>
   
-  <properties>
-    <!-- let.the.test.server.run -->
-    <keeprunning>false</keeprunning>
-  </properties>
-  
 </project>
\ No newline at end of file

Modified: directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/DefaultJobStore.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/DefaultJobStore.java?rev=718534&r1=718533&r2=718534&view=diff
==============================================================================
--- directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/DefaultJobStore.java
(original)
+++ directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/DefaultJobStore.java
Tue Nov 18 01:41:08 2008
@@ -36,7 +36,7 @@
 
 // FIXME this is a dummy clas to help incremental development of the original implementation
of JobStore
 // which helps in avoiding this eclipse TODO boilerplate stuff
-public class DefaultJobStore implements JobStore
+public abstract class DefaultJobStore implements JobStore
 {
 
     public Trigger acquireNextTrigger( SchedulingContext ctxt, long noLaterThan ) throws
JobPersistenceException
@@ -46,75 +46,6 @@
     }
 
 
-    public String[] getCalendarNames( SchedulingContext ctxt ) throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-    public String[] getJobGroupNames( SchedulingContext ctxt ) throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-    public String[] getJobNames( SchedulingContext ctxt, String groupName ) throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-    public int getNumberOfCalendars( SchedulingContext ctxt ) throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-
-    public int getNumberOfJobs( SchedulingContext ctxt ) throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-
-    public int getNumberOfTriggers( SchedulingContext ctxt ) throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-
-    public Set getPausedTriggerGroups( SchedulingContext ctxt ) throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-    public String[] getTriggerGroupNames( SchedulingContext ctxt ) throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-    public String[] getTriggerNames( SchedulingContext ctxt, String groupName ) throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-    public int getTriggerState( SchedulingContext ctxt, String triggerName, String triggerGroup
)
-        throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return 0;
-    }
 
 
     public Trigger[] getTriggersForJob( SchedulingContext ctxt, String jobName, String groupName
)
@@ -175,36 +106,6 @@
     }
 
 
-    public boolean removeCalendar( SchedulingContext ctxt, String calName ) throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-
-    public boolean removeJob( SchedulingContext ctxt, String jobName, String groupName )
throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-
-    public boolean removeTrigger( SchedulingContext ctxt, String triggerName, String groupName
)
-        throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-
-    public boolean replaceTrigger( SchedulingContext ctxt, String triggerName, String groupName,
Trigger newTrigger )
-        throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-
     public void resumeAll( SchedulingContext ctxt ) throws JobPersistenceException
     {
         // TODO Auto-generated method stub
@@ -241,29 +142,6 @@
     }
 
 
-    public Calendar retrieveCalendar( SchedulingContext ctxt, String calName ) throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-    public JobDetail retrieveJob( SchedulingContext ctxt, String jobName, String groupName
)
-        throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
-    public Trigger retrieveTrigger( SchedulingContext ctxt, String triggerName, String groupName
)
-        throws JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-
     public void schedulerStarted() throws SchedulerException
     {
         // TODO Auto-generated method stub
@@ -278,45 +156,6 @@
     }
 
 
-    public void storeCalendar( SchedulingContext ctxt, String name, Calendar calendar, boolean
replaceExisting,
-        boolean updateTriggers ) throws ObjectAlreadyExistsException, JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-
-    }
-
-
-    public void storeJob( SchedulingContext ctxt, JobDetail newJob, boolean replaceExisting
)
-        throws ObjectAlreadyExistsException, JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-
-    }
-
-
-    public void storeJobAndTrigger( SchedulingContext ctxt, JobDetail newJob, Trigger newTrigger
)
-        throws ObjectAlreadyExistsException, JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-
-    }
-
-
-    public void storeTrigger( SchedulingContext ctxt, Trigger newTrigger, boolean replaceExisting
)
-        throws ObjectAlreadyExistsException, JobPersistenceException
-    {
-        // TODO Auto-generated method stub
-
-    }
-
-
-    public boolean supportsPersistence()
-    {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-
     public TriggerFiredBundle triggerFired( SchedulingContext ctxt, Trigger trigger ) throws
JobPersistenceException
     {
         // TODO Auto-generated method stub

Modified: directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapJobStore.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapJobStore.java?rev=718534&r1=718533&r2=718534&view=diff
==============================================================================
--- directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapJobStore.java
(original)
+++ directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapJobStore.java
Tue Nov 18 01:41:08 2008
@@ -22,12 +22,19 @@
 
 import static org.quartz.impl.jdbcjobstore.Constants.STATE_ACQUIRED;
 import static org.quartz.impl.jdbcjobstore.Constants.STATE_BLOCKED;
+import static org.quartz.impl.jdbcjobstore.Constants.STATE_COMPLETE;
+import static org.quartz.impl.jdbcjobstore.Constants.STATE_DELETED;
+import static org.quartz.impl.jdbcjobstore.Constants.STATE_ERROR;
 import static org.quartz.impl.jdbcjobstore.Constants.STATE_PAUSED;
 import static org.quartz.impl.jdbcjobstore.Constants.STATE_PAUSED_BLOCKED;
 import static org.quartz.impl.jdbcjobstore.Constants.STATE_WAITING;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.directory.olm.Entry;
 import org.apache.directory.olm.FiredTriggerEntry;
@@ -37,6 +44,7 @@
 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.quartz.Calendar;
 import org.quartz.CronTrigger;
 import org.quartz.JobDetail;
 import org.quartz.JobPersistenceException;
@@ -46,6 +54,7 @@
 import org.quartz.SimpleTrigger;
 import org.quartz.Trigger;
 import org.quartz.core.SchedulingContext;
+import org.quartz.impl.jdbcjobstore.Constants;
 import org.quartz.spi.ClassLoadHelper;
 import org.quartz.spi.JobStore;
 import org.quartz.spi.SchedulerSignaler;
@@ -85,6 +94,12 @@
 
     private LdapQuartzDelegate delegate;
 
+    private long misfireThreshold = 60000L; // one minute
+
+    private boolean isClustered = false;
+
+    protected HashMap<String, Calendar> calendarCache = new HashMap<String, Calendar>();
+
 
     //    private MisfireHandler misfireHandler;
 
@@ -209,6 +224,45 @@
     }
 
 
+    public String[] getJobGroupNames( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        try
+        {
+            return delegate.selectJobGroups();
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't obtain job groups: " + e.getMessage(),
e );
+        }
+    }
+
+
+    public String[] getJobNames( SchedulingContext ctxt, String groupName ) throws JobPersistenceException
+    {
+        try
+        {
+            return getDelegate().selectJobsInGroup( groupName );
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't obtain job names: " + e.getMessage(),
e );
+        }
+    }
+
+
+    public int getNumberOfJobs( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        try
+        {
+            return delegate.selectNumJobs();
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't obtain number of jobs: " + e.getMessage(),
e );
+        }
+    }
+
+
     /**
      * @see JobStore#removeJob(SchedulingContext, String, String)
      */
@@ -266,6 +320,162 @@
     }
 
 
+    public int getNumberOfTriggers( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        try
+        {
+            return delegate.selectNumTriggers();
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't obtain number of triggers: " + e.getMessage(),
e );
+        }
+    }
+
+
+    public Set getPausedTriggerGroups( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        try
+        {
+            Iterator<String> itr = getDelegate().selectPausedTriggerGroups();
+
+            if ( itr != null )
+            {
+                Set<String> pausedGroups = new HashSet<String>();
+                while ( itr.hasNext() )
+                {
+                    pausedGroups.add( itr.next() );
+                }
+                return pausedGroups;
+            }
+            else
+            {
+                return null;
+            }
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't determine paused trigger groups:
" + e.getMessage(), e );
+        }
+    }
+
+
+    public String[] getTriggerGroupNames( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        try
+        {
+            return getDelegate().selectTriggerGroups();
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't obtain trigger groups: " + e.getMessage(),
e );
+        }
+    }
+
+
+    public String[] getTriggerNames( SchedulingContext ctxt, String groupName ) throws JobPersistenceException
+    {
+        try
+        {
+            return getDelegate().selectTriggersInGroup( groupName );
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't obtain trigger names: " + e.getMessage(),
e );
+        }
+    }
+
+
+    public int getTriggerState( SchedulingContext ctxt, String triggerName, String groupName
)
+        throws JobPersistenceException
+    {
+        try
+        {
+            String ts = getDelegate().selectTriggerState( triggerName, groupName );
+
+            if ( ts == null )
+            {
+                return Trigger.STATE_NONE;
+            }
+
+            if ( ts.equals( STATE_DELETED ) )
+            {
+                return Trigger.STATE_NONE;
+            }
+
+            if ( ts.equals( STATE_COMPLETE ) )
+            {
+                return Trigger.STATE_COMPLETE;
+            }
+
+            if ( ts.equals( STATE_PAUSED ) )
+            {
+                return Trigger.STATE_PAUSED;
+            }
+
+            if ( ts.equals( STATE_PAUSED_BLOCKED ) )
+            {
+                return Trigger.STATE_PAUSED;
+            }
+
+            if ( ts.equals( STATE_ERROR ) )
+            {
+                return Trigger.STATE_ERROR;
+            }
+
+            if ( ts.equals( STATE_BLOCKED ) )
+            {
+                return Trigger.STATE_BLOCKED;
+            }
+
+            return Trigger.STATE_NORMAL;
+
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't determine state of trigger (" +
groupName + "." + triggerName
+                + "): " + e.getMessage(), e );
+        }
+    }
+
+
+    public boolean replaceTrigger( SchedulingContext ctxt, String triggerName, String groupName,
Trigger newTrigger )
+        throws JobPersistenceException
+    {
+        try
+        {
+            // this must be called before we delete the trigger, obviously
+            JobDetail job = getDelegate().selectJobForTrigger( triggerName, groupName, classLoadHelper
);
+
+            if ( job == null )
+            {
+                return false;
+            }
+
+            if ( !newTrigger.getJobName().equals( job.getName() ) || !newTrigger.getJobGroup().equals(
job.getGroup() ) )
+            {
+                throw new JobPersistenceException( "New trigger is not related to the same
job as the old trigger." );
+            }
+
+            delegate.searchNDeleteTrigger( triggerName, groupName );
+
+            storeTrigger( ctxt, newTrigger, job, false, STATE_WAITING, false, false );
+
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new JobPersistenceException( "Couldn't remove trigger: " + e.getMessage(),
e );
+        }
+        catch ( Exception e )
+        {
+            return false;
+            //throw new JobPersistenceException( "Couldn't remove trigger: " + e.getMessage(),
e );
+        }
+
+        return true;
+    }
+
+
     public boolean removeTrigger( SchedulingContext ctxt, String triggerName, String groupName
)
         throws JobPersistenceException
     {
@@ -301,7 +511,166 @@
     }
 
 
-    // ---------------------- private utility methods ---------------------------
+    public void storeJobAndTrigger( SchedulingContext ctxt, JobDetail newJob, Trigger newTrigger
)
+        throws ObjectAlreadyExistsException, JobPersistenceException
+    {
+        if ( newJob.isVolatile() && !newTrigger.isVolatile() )
+        {
+            JobPersistenceException jpe = new JobPersistenceException(
+                "Cannot associate non-volatile trigger with a volatile job!" );
+            jpe.setErrorCode( SchedulerException.ERR_CLIENT_ERROR );
+            throw jpe;
+        }
+
+        storeJob( ctxt, newJob, false );
+        storeTrigger( ctxt, newTrigger, newJob, false, Constants.STATE_WAITING, false, false
);
+    }
+
+
+    public void storeCalendar( SchedulingContext ctxt, String calName, Calendar calendar,
boolean replaceExisting,
+        boolean updateTriggers ) throws ObjectAlreadyExistsException, JobPersistenceException
+    {
+        try
+        {
+            boolean existingCal = delegate.calendarExists( calName );
+            if ( existingCal && !replaceExisting )
+            {
+                throw new ObjectAlreadyExistsException( "Calendar with name '" + calName
+ "' already exists." );
+            }
+
+            if ( existingCal )
+            {
+                getDelegate().updateCalendar( calName, calendar );
+
+                if ( updateTriggers )
+                {
+                    Trigger[] trigs = getDelegate().selectTriggersForCalendar( calName );
+
+                    for ( int i = 0; i < trigs.length; i++ )
+                    {
+                        trigs[i].updateWithNewCalendar( calendar, getMisfireThreshold() );
+                        storeTrigger( ctxt, trigs[i], null, true, STATE_WAITING, false, false
);
+                    }
+                }
+            }
+            else
+            {
+                getDelegate().insertCalendar( calName, calendar );
+            }
+
+            //FIXME didn't get what is this
+            if ( !isClustered )
+            {
+                calendarCache.put( calName, calendar ); // lazy-cache
+            }
+
+        }
+        catch ( IOException e )
+        {
+            throw new JobPersistenceException( "Couldn't store calendar because the BLOB
couldn't be serialized: "
+                + e.getMessage(), e );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new JobPersistenceException( "Couldn't store calendar: " + e.getMessage(),
e );
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't store calendar: " + e.getMessage(),
e );
+        }
+    }
+
+
+    public Calendar retrieveCalendar( SchedulingContext ctxt, String calName ) throws JobPersistenceException
+    {
+        // all calendars are persistent, but we can lazy-cache them during run
+        // time as long as we aren't running clustered.
+        Calendar cal = ( isClustered ) ? null : ( Calendar ) calendarCache.get( calName );
+        if ( cal != null )
+        {
+            return cal;
+        }
+
+        try
+        {
+            cal = getDelegate().selectCalendar( calName );
+            if ( !isClustered )
+            {
+                calendarCache.put( calName, cal ); // lazy-cache...
+            }
+            return cal;
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new JobPersistenceException( "Couldn't retrieve calendar because a required
class was not found: "
+                + e.getMessage(), e );
+        }
+        catch ( IOException e )
+        {
+            throw new JobPersistenceException( "Couldn't retrieve calendar because the BLOB
couldn't be deserialized: "
+                + e.getMessage(), e );
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't retrieve calendar: " + e.getMessage(),
e );
+        }
+    }
+
+
+    public String[] getCalendarNames( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        try
+        {
+            return delegate.selectCalendars();
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't obtain calendar names: " + e.getMessage(),
e );
+        }
+    }
+
+
+    public int getNumberOfCalendars( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        try
+        {
+            return getDelegate().selectNumCalendars();
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't obtain number of calendars: " +
e.getMessage(), e );
+        }
+    }
+
+
+    public boolean removeCalendar( SchedulingContext ctxt, String calName ) throws JobPersistenceException
+    {
+        try
+        {
+            if ( getDelegate().calendarIsReferenced( calName ) )
+            {
+                throw new JobPersistenceException( "Calender cannot be removed if it referenced
by a trigger!" );
+            }
+
+            if ( !isClustered )
+            {
+                calendarCache.remove( calName );
+            }
+
+            getDelegate().deleteCalendar( calName );
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+            return false;
+            // throw new JobPersistenceException( "Couldn't remove calendar: " + e.getMessage(),
e );
+        }
+
+        return true;
+    }
+
+
+    // ---------------------- private methods ---------------------------
 
     private void storeTrigger( SchedulingContext ctxt, Trigger newTrigger, JobDetail job,
boolean replaceExisting,
         String state, boolean forceState, boolean recovering ) throws ObjectAlreadyExistsException,
@@ -402,7 +771,7 @@
      * 
      * @return STATE_PAUSED_BLOCKED, STATE_BLOCKED, or the currentState. 
      */
-    protected String checkBlockedState( SchedulingContext ctxt, String jobName, String jobGroupName,
String currentState )
+    private String checkBlockedState( SchedulingContext ctxt, String jobName, String jobGroupName,
String currentState )
         throws JobPersistenceException
     {
 
@@ -444,6 +813,22 @@
     }
 
 
+    public long getMisfireThreshold()
+    {
+        return misfireThreshold;
+    }
+
+
+    public void setMisfireThreshold( long misfireThreshold )
+    {
+        if ( misfireThreshold < 1 )
+        {
+            throw new IllegalArgumentException( "Misfirethreshold must be larger than 0"
);
+        }
+        this.misfireThreshold = misfireThreshold;
+    }
+
+
     // FIXME remove this if not required later cause the 'delegate'variable is available

     public LdapQuartzDelegate getDelegate()
     {

Modified: directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapQuartzDelegate.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapQuartzDelegate.java?rev=718534&r1=718533&r2=718534&view=diff
==============================================================================
--- directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapQuartzDelegate.java
(original)
+++ directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapQuartzDelegate.java
Tue Nov 18 01:41:08 2008
@@ -2,6 +2,7 @@
 
 
 import static org.quartz.impl.jdbcjobstore.Constants.ALL_GROUPS_PAUSED;
+import static org.quartz.impl.jdbcjobstore.Constants.STATE_DELETED;
 import static org.quartz.impl.jdbcjobstore.Constants.TTYPE_BLOB;
 import static org.quartz.impl.jdbcjobstore.Constants.TTYPE_CRON;
 import static org.quartz.impl.jdbcjobstore.Constants.TTYPE_SIMPLE;
@@ -16,11 +17,11 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.TimeZone;
 
 import org.apache.directory.olm.BlobData;
 import org.apache.directory.olm.BlobTriggerEntry;
+import org.apache.directory.olm.CalendarName;
 import org.apache.directory.olm.CronTriggerEntry;
 import org.apache.directory.olm.Entry;
 import org.apache.directory.olm.FiredTriggerEntry;
@@ -32,6 +33,7 @@
 import org.apache.directory.olm.OrganizationalUnitEntry;
 import org.apache.directory.olm.PausedTriggerGroup;
 import org.apache.directory.olm.PausedTriggersEntry;
+import org.apache.directory.olm.QuartzCalendarEntry;
 import org.apache.directory.olm.QuartzGroupEntry;
 import org.apache.directory.olm.SimpleTriggerEntry;
 import org.apache.directory.olm.TaskDesc;
@@ -46,6 +48,7 @@
 import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
 import org.apache.directory.shared.ldap.filter.AndNode;
 import org.apache.directory.shared.ldap.filter.EqualityNode;
+import org.apache.directory.shared.ldap.filter.PresenceNode;
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.name.LdapDN;
@@ -327,15 +330,18 @@
 
     public boolean calendarExists( String calendarName ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return false;
+        return ldapUtil.exists( getChildDn( CalendarName.NAME + "=" + calendarName, calendarsDn
) );
     }
 
 
     public boolean calendarIsReferenced( String calendarName ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return false;
+        EqualityNode<String> filter = new EqualityNode<String>( CalendarName.NAME,
new ClientStringValue( calendarName ) );
+
+        List<Entry> entries = ldapUtil.search( triggersDn, SearchScope.ONELEVEL, filter,
+            AliasDerefMode.NEVER_DEREF_ALIASES, null );
+
+        return entries.isEmpty();
     }
 
 
@@ -353,10 +359,9 @@
     }
 
 
-    public int deleteCalendar( String calendarName ) throws Exception
+    public void deleteCalendar( String calendarName ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return 0;
+        ldapUtil.delete( getChildDn( CalendarName.NAME + "=" + calendarName, calendarsDn
) );
     }
 
 
@@ -591,12 +596,12 @@
         triggerEntry.setJobGroup( trigger.getJobGroup() );
         triggerEntry.setVolatileFlag( trigger.isVolatile() );
 
-        if( trigger.getDescription() != null )
+        if ( trigger.getDescription() != null )
         {
             triggerEntry.setTaskDesc( trigger.getDescription() );
         }
 
-        if( trigger.getNextFireTime() != null )
+        if ( trigger.getNextFireTime() != null )
         {
             triggerEntry.setNextFireTime( DateUtils.getGeneralizedTime( trigger.getNextFireTime()
) );
         }
@@ -619,9 +624,9 @@
         {
             tType = TTYPE_CRON;
         }
-        
+
         triggerEntry.setTriggerType( tType );
-        
+
         triggerEntry.setStartTime( DateUtils.getGeneralizedTime( trigger.getStartTime() )
);
 
         if ( trigger.getEndTime() != null )
@@ -659,35 +664,21 @@
 
     public boolean isTriggerGroupPaused( String tGroupName ) throws Exception
     {
-        Entry entry = null;
         boolean paused = false;
 
-        try
+        Iterator<String> itr = selectPausedTriggerGroups();
+        if ( itr != null )
         {
-            entry = ldapUtil.fetch( schedulerRootDn );
-
-            PausedTriggerGroup pausedTrgGrp = ( PausedTriggerGroup ) entry
-                .getAttribute( PausedTriggerGroup.NAME );
-            Iterator<String> itr = pausedTrgGrp.getValues();
-
-            if ( itr != null )
+            while ( itr.hasNext() )
             {
-                while ( itr.hasNext() )
+                String s = itr.next();
+                if ( s.equalsIgnoreCase( tGroupName ) || s.equalsIgnoreCase( ALL_GROUPS_PAUSED
) )
                 {
-                    String s = itr.next();
-                    if ( s.equalsIgnoreCase( tGroupName ) || s.equalsIgnoreCase( ALL_GROUPS_PAUSED
) )
-                    {
-                        paused = true;
-                        break;
-                    }
+                    paused = true;
+                    break;
                 }
             }
         }
-        catch ( Exception e )
-        {
-            LOG.error( "Failed to check whether the trigger group '{}' is paused", tGroupName
);
-            e.printStackTrace();
-        }
 
         return paused;
     }
@@ -702,15 +693,32 @@
 
     public Calendar selectCalendar( String calendarName ) throws ClassNotFoundException,
Exception
     {
-        // TODO Auto-generated method stub
-        return null;
+        QuartzCalendarEntry entry = ( QuartzCalendarEntry ) ldapUtil.fetch( getChildDn( CalendarName.NAME
+ "="
+            + calendarName, calendarsDn ) );
+
+        if ( entry == null )
+        {
+            return null;
+        }
+
+        return ( Calendar ) bytesToObject( entry.getCalendar().getValue() );
     }
 
 
     public String[] selectCalendars() throws Exception
     {
-        // TODO Auto-generated method stub
-        return null;
+        List<Entry> entries = ldapUtil.search( calendarsDn, SearchScope.ONELEVEL,
+            new PresenceNode( CalendarName.NAME ), AliasDerefMode.NEVER_DEREF_ALIASES, null
);
+
+        String[] calNames = new String[entries.size()];
+
+        int index = 0;
+        for ( Entry e : entries )
+        {
+            calNames[index++] = ( ( QuartzCalendarEntry ) e ).getCalendarName().getValue();
+        }
+
+        return calNames;
     }
 
 
@@ -728,17 +736,14 @@
 
         if ( jobName != null )
         {
-            EqualityNode<String> jEq = new EqualityNode<String>( JobName.NAME,
-                new ClientStringValue( jobName ) );
-            EqualityNode<String> gEq = new EqualityNode<String>( JobGroup.NAME,
new ClientStringValue(
-                groupName ) );
+            EqualityNode<String> jEq = new EqualityNode<String>( JobName.NAME,
new ClientStringValue( jobName ) );
+            EqualityNode<String> gEq = new EqualityNode<String>( JobGroup.NAME,
new ClientStringValue( groupName ) );
 
             filter = new AndNode( jEq, gEq ).toString();
         }
         else
         {
-            EqualityNode<String> gEq = new EqualityNode<String>( JobGroup.NAME,
new ClientStringValue(
-                groupName ) );
+            EqualityNode<String> gEq = new EqualityNode<String>( JobGroup.NAME,
new ClientStringValue( groupName ) );
             filter = gEq.toString();
         }
 
@@ -808,22 +813,31 @@
         throws ClassNotFoundException, Exception
     {
         JobDetail job = null;
-        
+
         TriggerEntry trgEntry = getTriggerEntry( triggerName, groupName );
-        
-        if( trgEntry != null )
+
+        if ( trgEntry != null )
         {
             job = selectJobDetail( trgEntry.getJobName().getValue(), trgEntry.getJobGroup().getValue(),
loadHelper );
         }
-        
+
         return job;
     }
 
 
     public String[] selectJobGroups() throws Exception
     {
-        // TODO Auto-generated method stub
-        return null;
+        List<Entry> entries = ldapUtil.search( jobDetailsDn, SearchScope.ONELEVEL,
new PresenceNode( JobGroup.NAME ),
+            AliasDerefMode.NEVER_DEREF_ALIASES, null );
+
+        String[] jobGroups = new String[ entries.size() ];
+        int index = 0;
+        for ( Entry e : entries )
+        {
+            jobGroups[index++] = ( ( QuartzGroupEntry ) e ).getJobGroup().getValue();
+        }
+
+        return jobGroups;
     }
 
 
@@ -836,8 +850,18 @@
 
     public String[] selectJobsInGroup( String groupName ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return null;
+        LdapDN dn = getChildDn( JobGroup.NAME + "=" + groupName, jobDetailsDn );
+
+        List<Entry> entries = ldapUtil.search( dn, SearchScope.ONELEVEL, new PresenceNode(
JobName.NAME ),
+            AliasDerefMode.NEVER_DEREF_ALIASES, null );
+        int index = 0;
+        String[] jobs = new String[entries.size()];
+        for ( Entry e : entries )
+        {
+            jobs[index++] = ( ( JobDetailEntry ) e ).getJobName().getValue();
+        }
+
+        return jobs;
     }
 
 
@@ -871,22 +895,25 @@
 
     public int selectNumCalendars() throws Exception
     {
-        // TODO Auto-generated method stub
-        return 0;
+        List<Entry> entries = ldapUtil.search( calendarsDn, SearchScope.ONELEVEL,
+            new PresenceNode( CalendarName.NAME ), AliasDerefMode.NEVER_DEREF_ALIASES, null
);
+        return entries.size();
     }
 
 
     public int selectNumJobs() throws Exception
     {
-        // TODO Auto-generated method stub
-        return 0;
+        List<Entry> entries = ldapUtil.search( jobDetailsDn, SearchScope.SUBTREE, new
PresenceNode( JobName.NAME ),
+            AliasDerefMode.NEVER_DEREF_ALIASES, null );
+        return entries.size();
     }
 
 
     public int selectNumTriggers() throws Exception
     {
-        // TODO Auto-generated method stub
-        return 0;
+        List<Entry> entries = ldapUtil.search( triggersDn, SearchScope.SUBTREE, new
PresenceNode( TriggerName.NAME ),
+            AliasDerefMode.NEVER_DEREF_ALIASES, null );
+        return entries.size();
     }
 
 
@@ -896,9 +923,22 @@
     }
 
 
-    public Set selectPausedTriggerGroups() throws Exception
+    public Iterator<String> selectPausedTriggerGroups() throws Exception
     {
-        // TODO Auto-generated method stub
+        try
+        {
+            Entry entry = ldapUtil.fetch( schedulerRootDn );
+
+            PausedTriggerGroup pausedTrgGrp = ( PausedTriggerGroup ) entry.getAttribute(
PausedTriggerGroup.NAME );
+            
+            return pausedTrgGrp.getValues();
+        }
+        catch ( Exception e )
+        {
+            //LOG.error( "Failed to check whether the trigger group '{}' is paused", tGroupName
);
+            e.printStackTrace();
+        }
+        
         return null;
     }
 
@@ -919,8 +959,6 @@
 
     public Trigger selectTrigger( String triggerName, String groupName ) throws Exception
     {
-        Trigger trigger = null;
-
         TriggerEntry entry = ( TriggerEntry ) ldapUtil.fetch( getTriggerDn( triggerName,
groupName, triggersDn ) );
 
         if ( entry == null )
@@ -928,6 +966,16 @@
             return null;
         }
 
+        return entryToTrigger( entry );
+    }
+
+
+    private Trigger entryToTrigger( TriggerEntry entry ) throws Exception
+    {
+        Trigger trigger = null;
+
+        String triggerName = entry.getTriggerName().getValue();
+        String groupName = entry.getTriggerGroup().getValue();
         String jobName = entry.getJobName().getValue();
         String jobGroup = entry.getJobGroup().getValue();
         boolean volatility = entry.getVolatileFlag().getValue();
@@ -1113,8 +1161,17 @@
 
     public String[] selectTriggerGroups() throws Exception
     {
-        // TODO Auto-generated method stub
-        return null;
+        List<Entry> entries = ldapUtil.search( triggersDn, SearchScope.ONELEVEL, new
PresenceNode( TriggerGroup.NAME ),
+            AliasDerefMode.NEVER_DEREF_ALIASES, null );
+
+        String[] triggerGroups = new String[ entries.size() ];
+        int index = 0;
+        for ( Entry e : entries )
+        {
+            triggerGroups[index++] = ( ( QuartzGroupEntry ) e ).getTriggerGroup().getValue();
+        }
+
+        return triggerGroups;
     }
 
 
@@ -1150,22 +1207,33 @@
         return triggers;
     }
 
+
     private List<Entry> getTriggerEntriesForJob( String jobName, String groupName )
throws Exception
     {
-        EqualityNode<String> jobNameNode = new EqualityNode<String>( JobName.NAME,
new ClientStringValue(
-            jobName ) );
-        EqualityNode<String> jobGroupNode = new EqualityNode<String>( JobGroup.NAME,
new ClientStringValue(
-            groupName ) );
+        EqualityNode<String> jobNameNode = new EqualityNode<String>( JobName.NAME,
new ClientStringValue( jobName ) );
+        EqualityNode<String> jobGroupNode = new EqualityNode<String>( JobGroup.NAME,
new ClientStringValue( groupName ) );
 
         AndNode filterExpr = new AndNode( jobNameNode, jobGroupNode );
 
         return ldapUtil.search( triggersDn, SearchScope.SUBTREE, filterExpr, AliasDerefMode.NEVER_DEREF_ALIASES,
null );
     }
 
+
     public Trigger[] selectTriggersForCalendar( String calName ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return null;
+        EqualityNode<String> filterNode = new EqualityNode<String>( CalendarName.NAME,
new ClientStringValue( calName ) );
+
+        List<Entry> entries = ldapUtil.search( triggersDn, SearchScope.SUBTREE, filterNode,
+            AliasDerefMode.NEVER_DEREF_ALIASES, null );
+
+        Trigger[] triggers = new Trigger[entries.size()];
+        int index = 0;
+        for ( Entry entry : entries )
+        {
+            triggers[index++] = entryToTrigger( ( TriggerEntry ) entry );
+        }
+
+        return triggers;
     }
 
 
@@ -1185,8 +1253,18 @@
 
     public String[] selectTriggersInGroup( String groupName ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return null;
+        LdapDN dn = getChildDn( TriggerGroup.NAME + "=" + groupName, triggersDn );
+
+        List<Entry> entries = ldapUtil.search( dn, SearchScope.ONELEVEL, new PresenceNode(
TriggerName.NAME ),
+            AliasDerefMode.NEVER_DEREF_ALIASES, null );
+        int index = 0;
+        String[] triggerNames = new String[ entries.size() ];
+        for ( Entry e : entries )
+        {
+            triggerNames[index++] = ( ( TriggerEntry ) e ).getTriggerName().getValue();
+        }
+
+        return triggerNames;
     }
 
 
@@ -1199,8 +1277,16 @@
 
     public String selectTriggerState( String triggerName, String groupName ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return null;
+        TriggerEntry entry = ( TriggerEntry ) getTriggerEntry( triggerName, groupName );
+        
+        if( entry == null )
+        {
+            return STATE_DELETED;
+        }
+        else
+        {
+            return entry.getTriggerState().getValue();
+        }
     }
 
 
@@ -1240,10 +1326,10 @@
     }
 
 
-    public int updateCalendar( String calendarName, Calendar calendar ) throws Exception
+    public void updateCalendar( String calendarName, Calendar calendar ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return 0;
+        LdapDN dn = getChildDn( CalendarName.NAME + "=" + calendarName, calendarsDn );
+        ldapUtil.replaceAttributeValue( dn, org.apache.directory.olm.Calendar.NAME, objectToBytes(
calendar ) );
     }
 
 



Mime
View raw message