cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giac...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/cron/samples cron.js cron.xml samples.xml
Date Fri, 05 Sep 2003 10:23:17 GMT
giacomo     2003/09/05 03:23:17

  Modified:    src/blocks/cron/samples cron.js cron.xml samples.xml
  Log:
  finished samples
  
  Revision  Changes    Path
  1.2       +120 -39   cocoon-2.1/src/blocks/cron/samples/cron.js
  
  Index: cron.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/cron/samples/cron.js,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -d -b -u -r1.1 -r1.2
  --- cron.js	4 Sep 2003 16:01:33 -0000	1.1
  +++ cron.js	5 Sep 2003 10:23:17 -0000	1.2
  @@ -1,7 +1,32 @@
  +function Format() {
  +}
  +    
  +Format.prototype.format = function(date) {
  +    if( date == null || date == undefined )
  +        return "-";
  +       return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
  +}
  +Format.prototype.parse = function(date) {
  +    if( date == null || date == undefined )
  +        return "";
  +       return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
  +}
  +
   function cron( realPath )
   {
   	var done = false;
   	var scheduler = cocoon.getComponent(Packages.org.apache.cocoon.components.cron.JobScheduler.ROLE);
  +    var msg_param_key = Packages.org.apache.cocoon.components.cron.TestCronJob.PARAMETER_MESSAGE;
  +    var sleep_param_key = Packages.org.apache.cocoon.components.cron.TestCronJob.PARAMETER_SLEEP;
  +    var testjobrole = "org.apache.cocoon.components.cron.CronJob/test";
  +    var logsize = 15;
  +    var formatter = new Format();
  +    var jobname = "";
  +    var message = "I'm here";
  +    var sleep = "23";
  +    var cronexpr = "";
  +    var intervalexpr = "";
  +    var atexpr = "";
   	while( ! done )
   	{
   		var jobnames = scheduler.getJobNames();
  @@ -20,23 +45,79 @@
   		{
   			count++;
   			lines.addLast( line );
  -			if( count > 20 )
  +            if( count > logsize )
   			{
   				lines.removeFirst();
   			}
   			line = rdr.readLine();
   		}
  -		print( "sending page" );
  -		cocoon.sendPageAndWait( "cron.view", { "entries" : list, "log" : lines } );
  -		print( "back again" );
  +        cocoon.sendPageAndWait( "cron.view", { "entries"      : list, 
  +                                               "log"          : lines,
  +                                               "formatter"    : formatter,
  +                                               "jobname"      : jobname,
  +                                               "message"      : message,
  +                                               "sleep"        : sleep,
  +                                               "cronexpr"     : cronexpr,
  +                                               "intervalexpr" : intervalexpr,
  +                                               "atexpr"       : atexpr
  +                                             } 
  +        );
   		var action = cocoon.request.getParameter( "action" );
  -		print( "action=" + action );
   		if( action == "remove" )
   		{
  -			print( "going to remove job " + name );
   			var name = cocoon.request.getParameter( "name" );
   			scheduler.removeJob( name );
  -			print( "job " + name + " removed" );
  +        }
  +        else if( action == "add" )
  +        {
  +            jobname = cocoon.request.getParameter( "jobname" );
  +            message = cocoon.request.getParameter( "message" );
  +            sleep = cocoon.request.getParameter( "sleep" );
  +            cronexpr = cocoon.request.getParameter( "cronexpr" );
  +            intervalexpr = cocoon.request.getParameter( "intervalexpr" );
  +            atexpr = cocoon.request.getParameter( "atexpr" );
  +            
  +            var scheduletype = cocoon.request.getParameter( "cron" );
  +            if( scheduletype != null )
  +            {
  +                var params = new Packages.org.apache.avalon.framework.parameters.Parameters();
  +                params.setParameter( msg_param_key, message );
  +                var sleepms = sleep * 1000;
  +                params.setParameter( sleep_param_key, sleepms );
  +                scheduler.addJob(jobname, testjobrole, cronexpr, false, params, null);
  +            }
  +            scheduletype = cocoon.request.getParameter( "periodic" );
  +            if( scheduletype != null )
  +            {
  +                var params = new Packages.org.apache.avalon.framework.parameters.Parameters();
  +                params.setParameter( msg_param_key, message );
  +                var sleepms = sleep * 1000;
  +                params.setParameter( sleep_param_key, sleepms );
  +                scheduler.addPeriodicJob(jobname, testjobrole, intervalexpr, false, params,
null);
  +            }
  +            scheduletype = cocoon.request.getParameter( "at" );
  +            if( scheduletype != null )
  +            {
  +                var params = new Packages.org.apache.avalon.framework.parameters.Parameters();
  +                params.setParameter( msg_param_key, message );
  +                var sleepms = sleep * 1000;
  +                params.setParameter( sleep_param_key, sleepms );
  +                var date = formatter.parse( atexpr );
  +                scheduler.fireJobAt(date, jobname, testjobrole, params, null)
  +            }
  +            scheduletype = cocoon.request.getParameter( "immediately" );
  +            if( scheduletype != null )
  +            {
  +                var params = new Packages.org.apache.avalon.framework.parameters.Parameters();
  +                params.setParameter( msg_param_key, message );
  +                var sleepms = sleep * 1000;
  +                params.setParameter( sleep_param_key, sleepms );
  +                scheduler.fireJob(testjobrole, params, null)
  +            }
  +        }
  +        else
  +        {
  +            // do a refresh
   		}
   	}
   }
  
  
  
  1.2       +95 -6     cocoon-2.1/src/blocks/cron/samples/cron.xml
  
  Index: cron.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/cron/samples/cron.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -d -b -u -r1.1 -r1.2
  --- cron.xml	4 Sep 2003 16:01:33 -0000	1.1
  +++ cron.xml	5 Sep 2003 10:23:17 -0000	1.2
  @@ -12,15 +12,28 @@
                               <th>Job name</th>
                               <th>Next scheduled run</th>
                               <th>Is running</th>
  +                            <th>The Schedule</th>
                               <th>Action</th>
                           </tr>
                           <jx:forEach var="entry" items="${entries}">
                               <tr>
                                   <td>${entry.name}</td>
                                   <td>${entry.jobName}</td>
  -                                <td>${entry.nextTime}</td>
  -                                <td>${entry.isRunning()}</td>
  -                                <td><a href="continue.${continuation.id}?action=remove&amp;name=${entry.name}">remove</a></td>
  +                                <td>${formatter.format(entry.nextTime)}</td>
  +                                <td>
  +                                    <jx:choose>
  +                                        <jx:when test="${entry.isRunning() == true}">
  +                                            <div style="color: red">${entry.isRunning()}</div>
  +                                        </jx:when>
  +                                        <jx:otherwise>
  +                                            <div style="color: green">${entry.isRunning()}</div>
  +                                        </jx:otherwise>
  +                                    </jx:choose>
  +                                </td>
  +                                <td>${entry.schedule}</td>
  +                                <td>
  +                                    <a href="continue.${continuation.id}?action=remove&amp;name=${entry.name}">remove</a>
  +                                </td>
                               </tr>
                           </jx:forEach>
                       </table>
  @@ -31,10 +44,86 @@
               <column>
                   <section>
                       <title>Manage Cron Jobs scheduled</title>
  -
                       <p>
  -                        Some sample will follow ...
  +                        Here you can define new CronJobs
                       </p>
  +                    <form method="post" action="continue.${continuation.id}?action=add">
  +                        <table>
  +                            <tr>
  +                                <td align="right">Name the new job should have:</td>
  +                                <td><input name="jobname" size="10" value="${jobname}"/></td>
  +                            </tr>
  +                            <tr>
  +                                <td align="right">Message the job should print into
the log:</td>
  +                                <td><input name="message" size="40" value="${message}"/></td>
  +                            </tr>
  +                            <tr>
  +                                <td align="right">The seconds the job should sleep
before finishing:</td>
  +                                <td><input name="sleep" size="4" value="${sleep}"/></td>
  +                            </tr>
  +                            <tr>
  +                                <td align="right">
  +                                    <p>Choose the type of triggering:</p>
  +                                </td>
  +                                <td>
  +                                    <table border="1">
  +                                        <tr>
  +                                            <td>
  +                                                <table>
  +                                                    <tr>
  +                                                        <td align="right">
  +                                                            Enter a 
  +                                                            <a href="http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html">
  +                                                                Cron
  +                                                            </a>
  +                                                            expression:
  +                                                        </td>
  +                                                        <td>
  +                                                            <input name="cronexpr" size="20"
value="${cronexpr}"/> 
  +                                                        </td>
  +                                                        <td>
  +                                                            <input type="submit" name="cron"
value="Add Cron"/>
  +                                                        </td>
  +                                                    </tr>
  +                                                    <tr>
  +                                                        <td align="right">
  +                                                            Enter the interval in seconds:
  +                                                        </td>
  +                                                        <td>
  +                                                            <input name="intervalexpr"
size="4" value="${intervalexpr}"/> 
  +                                                        </td>
  +                                                        <td>
  +                                                            <input type="submit" name="periodic"
value="Add Periodic"/>
  +                                                        </td>
  +                                                    </tr>
  +                                                    <tr>
  +                                                        <td align="right">
  +                                                            Fire at yyyy-MM-dd HH:mm:ss
  +                                                        </td>
  +                                                        <td>
  +                                                            <input name="atexpr" size="20"
value="${atexpr}"/> 
  +                                                        </td>
  +                                                        <td>
  +                                                            <input type="submit" name="at"
value="Fire at"/>
  +                                                        </td>
  +                                                    </tr>
  +                                                    <tr>
  +                                                        <td align="right">
  +                                                            Fire immediately
  +                                                        </td>
  +                                                        <td>&#160;</td>
  +                                                        <td>
  +                                                            <input type="submit" name="immediately"
value="Fire now"/>
  +                                                        </td>
  +                                                    </tr>
  +                                                </table>
  +                                            </td>
  +                                        </tr>
  +                                    </table>
  +                                </td>
  +                            </tr>
  +                        </table>
  +                    </form>
                   </section>
               </column>
           </row>
  
  
  
  1.3       +23 -11    cocoon-2.1/src/blocks/cron/samples/samples.xml
  
  Index: samples.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/cron/samples/samples.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -d -b -u -r1.2 -r1.3
  --- samples.xml	4 Sep 2003 16:00:16 -0000	1.2
  +++ samples.xml	5 Sep 2003 10:23:17 -0000	1.3
  @@ -4,8 +4,17 @@
   
   <samples xmlns:xlink="http://www.w3.org/1999/xlink" name="Cron block">
   
  -  <group name="Cron">
  -     <sample name="Component documentation" href="docs.html">
  +    <group name="Main examples page.">
  +        <sample name="Back" href="..">to Cocoon main examples page</sample>
  +        <sample name="Back" href="../blocks">to Cocoon block examples page</sample>
  +    </group>
  +
  +    <group name="Documentation">
  +        <note>
  +            The Cron component/block is a utility component to manage execute immediate,
  +            once at some future time, and periodic execution of a Java class or Avalon
Component.
  +        </note>
  +        <sample name="Cron Component documentation" href="docs.html">
          Documentation for the Cron component.
        </sample>
     </group>
  @@ -15,5 +24,8 @@
         Cron samples.
        </sample>
     </group>
  +
  +    <group name="">
  +    </group>
     
   </samples>
  
  
  

Mime
View raw message