You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Simon Massey <si...@hotmail.com> on 2002/08/15 04:31:43 UTC

starting the decoupled fulcrum SchedularService in a stand alone app

I am trying to get the decoupled Fulcrum schedular service working in in a
stand alone app using Jakarta Turbine 2.2-b.

I have been following the tutorial and the use group posts such as the "AW:
using the decoupled fulcrum services ?" and  "Decoupled Fulcrum 3.0-b2-dev
security sample application & configuration" but it is still driving me
nuts. I see that you guys have been really good at getting back to folks
asking questions so I thought that I would ask for some help.

Just now I am trying combinations of different properties files to try to
get things working. In the code below I am using the same config to
initialize Torque and Fulcrum. In the last couple of hours I have been
trying moving config data around between one or two files configure fiils
that I explicitly use. The best that I can get out of it is the following:

=================================================

2002-08-15 03:22:43,796 [main] INFO  org.apache.fulcrum.TurbineServices -
Added Mapping for Service: SchedulerService
2002-08-15 03:22:43,796 [main] INFO  org.apache.fulcrum.TurbineServices -
Added Mapping for Service: DatabaseService
2002-08-15 03:22:43,796 [main] INFO  org.apache.fulcrum.TurbineServices -
Start Initializing service (early): DatabaseService
2002-08-15 03:22:43,806 [main] INFO  org.apache.fulcrum.TurbineServices -
org.apache.fulcrum.InitializationException: Can't initialize Torque!
2002-08-15 03:22:43,806 [main] INFO  org.apache.fulcrum.TurbineServices -
java.lang.NullPointerException
 at org.apache.torque.Torque.initialize(Torque.java:227)
 at org.apache.torque.Torque.init(Torque.java:294)
 at org.apache.fulcrum.db.TurbineDatabaseService.init(Unknown Source)
 at org.apache.fulcrum.BaseServiceBroker.initService(Unknown Source)
 at org.apache.fulcrum.BaseServiceBroker.doInitService(Unknown Source)
 at org.apache.fulcrum.BaseServiceBroker.initServices(Unknown Source)
 at org.apache.fulcrum.BaseServiceBroker.init(Unknown Source)
 at
net.open2.schedular.modules.scheduledjobs.SimpleScheduledTask.initializeFram
ework(SimpleScheduledTask.java:62)
 at
net.open2.schedular.modules.scheduledjobs.SimpleScheduledTask.main(SimpleSch
eduledTask.java:75)
rethrown as org.apache.fulcrum.InitializationException: Can't initialize
Torque!
 at org.apache.fulcrum.db.TurbineDatabaseService.init(Unknown Source)
 at org.apache.fulcrum.BaseServiceBroker.initService(Unknown Source)
 at org.apache.fulcrum.BaseServiceBroker.doInitService(Unknown Source)
 at org.apache.fulcrum.BaseServiceBroker.initServices(Unknown Source)
 at org.apache.fulcrum.BaseServiceBroker.init(Unknown Source)
 at
net.open2.schedular.modules.scheduledjobs.SimpleScheduledTask.initializeFram
ework(SimpleScheduledTask.java:62)
 at
net.open2.schedular.modules.scheduledjobs.SimpleScheduledTask.main(SimpleSch
eduledTask.java:75)

2002-08-15 03:22:43,806 [main] INFO  org.apache.fulcrum.TurbineServices -
Finished initializing all services!
2002-08-15 03:22:43,826 [main] INFO  org.apache.fulcrum.TurbineServices -
Start Initializing service (late): SchedulerService
2002-08-15 03:22:44,016 [main] INFO  org.apache.fulcrum.TurbineServices -
Finish Initializing service (late): SchedulerService


=================================================

The torque log looks okay:

2002-08-15 03:26:58,663 [main] DEBUG org.apache.torque.adapter.DBFactory -
Using org.apache.torque.adapter.DBMM
2002-08-15 03:26:58,683 [main] DEBUG org.apache.torque.adapter.DBFactory -
Using org.apache.torque.adapter.DBMM
2002-08-15 03:26:58,803 [Thread-1] INFO  org.apache.torque.oid.IDBroker -
IDBroker thread was started.
2002-08-15 03:26:58,863 [main] DEBUG org.apache.torque.util.BasePeer -
SELECT TURBINE_SCHEDULED_JOB.JOB_ID, TURBINE_SCHEDULED_JOB.JOB_SECOND,
TURBINE_SCHEDULED_JOB.JOB_MINUTE, TURBINE_SCHEDULED_JOB.JOB_HOUR,
TURBINE_SCHEDULED_JOB.WEEK_DAY, TURBINE_SCHEDULED_JOB.DAY_OF_MONTH,
TURBINE_SCHEDULED_JOB.TASK, TURBINE_SCHEDULED_JOB.EMAIL,
TURBINE_SCHEDULED_JOB.JOB_PROPERTY FROM TURBINE_SCHEDULED_JOB
2002-08-15 03:26:58,883 [main] DEBUG org.apache.torque.util.BasePeer -
Elapsed time=10 ms
2002-08-15 03:26:58,903 [main] INFO  org.apache.torque.oid.IDBroker - Forced
id retrieval - no available vector
2002-08-15 03:26:58,933 [main] DEBUG org.apache.torque.util.BasePeer -
BasePeer.doUpdate: whereClause=TABLE_NAME='TURBINE_SCHEDULED_JOB'
2002-08-15 03:26:58,953 [main] DEBUG org.apache.torque.oid.IDBroker -
updateRow: UPDATE ID_TABLE SET NEXT_ID = 350 WHERE TABLE_NAME =
'TURBINE_SCHEDULED_JOB'


=================================================

package net.mycompany.schedular.modules.scheduledjobs;

//JDK
import java.util.Date;
import java.io.IOException;

//Turbine
import org.apache.stratum.configuration.Configuration;
import org.apache.stratum.configuration.PropertiesConfiguration;
import org.apache.turbine.util.TurbineConfig;
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import org.apache.torque.util.Criteria;
import org.apache.fulcrum.InitializationException;
import org.apache.fulcrum.TurbineServices;
import org.apache.fulcrum.schedule.JobEntry;
import org.apache.fulcrum.schedule.ScheduleService;
import org.apache.fulcrum.schedule.ScheduledJob;


public class SimpleScheduledTask extends ScheduledJob
{
 private int taskcount = 0;

 public SimpleScheduledTask()
 {
   //do Task initialization here
   System.out.println("SJM> SimpleScheduledTask()");
 }

 public void run( JobEntry job ) throws Exception
 {
  System.out.println("Scheduled job ran @: " +
      new Date(System.currentTimeMillis()).toString() +
        " taskcount " + taskcount);
  taskcount++;
 }

 /**
  * Initialize Torque (persistance) and Fulcrum (services)
  */
 private static void initializeFramework() {
   try {
    Configuration confTorque = (Configuration) new
PropertiesConfiguration("D:/turbine/2.2-b1/torque/Torque.properties");
    Torque.init(confTorque);
    Configuration confFulcrum = (Configuration) new
PropertiesConfiguration("D:/turbine/2.2-b1/torque/Torque.properties");
    TurbineServices.getInstance().setConfiguration(confFulcrum);
    TurbineServices.getInstance().init();
   } catch (InitializationException ie) {
    System.err.println(ie);
   } catch (IOException ioe) {
    System.err.println(ioe);
   } catch (TorqueException te) {
    System.err.println(te);
  }
 }

 public static void main(String[] arguments){
  initializeFramework();
  try
  {
   System.out.println("SJM> Getting service:
"+ScheduleService.SERVICE_NAME);

   //access the service singleton
   ScheduleService ss = (ScheduleService)TurbineServices
    .getInstance().getService(ScheduleService.SERVICE_NAME);

   System.out.println("SJM> Status: "+ss.getStatus());

   //create a new JobEntry with the time constraints from
   //the template as the arguments
   JobEntry je = new JobEntry(6,-1,-1,-1,-1,"SimpleScheduledTask");

   //set the email for notification
   je.setEmail("smassey@localhost");

   //add the job to the queue
   ss.addJob(je);

   //set the Message
   System.out.println("Task started successfully");

   while(true){
    Thread.currentThread().sleep(2500);
    System.out.print(".");
   }
  }
  catch (Exception e)
  {
   //set the Message
   System.out.println("Task failed to start!");
   e.printStackTrace();
  }
 }
}

=================================================

Here is the config file that I cannot seem to get right:

=================================================

log4j.category.default = ALL, default
log4j.appender.default = org.apache.log4j.FileAppender
log4j.appender.default.file = ./turbine.log
log4j.appender.default.layout = org.apache.log4j.PatternLayout
log4j.appender.default.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.default.append = false

torque.earlyInit = true

torque.database.earlyInit = true

torque.database.default=schedular
torque.database.schedular.driver = org.gjt.mm.mysql.Driver
torque.database.schedular.url = jdbc:mysql://127.0.0.1/schedular
torque.database.schedular.username = sa
torque.database.schedular.password = S3ymour

torque.database.default.maxConnections=80
torque.database.default.expiryTime=3600000
torque.database.default.connectionWaitTimeout=10000
torque.database.logInterval=0

torque.database.adapter=DBMM
torque.database.adapter.DBOdbc=sun.jdbc.odbc.JdbcOdbcDriver
torque.database.adapter.DBMM=
torque.database.adapter.DBMM=org.gjt.mm.mysql.Driver

torque.database.idbroker.cleverquantity=true

services.SchedulerService.classname=org.apache.fulcrum.schedule.TurbineSched
ulerService

services.DatabaseService.classname=org.apache.fulcrum.db.TurbineDatabaseServ
ice
services.DatabaseService.database.default=default
services.DatabaseService.database.default.driver=org.gjt.mm.mysql.Driver
services.DatabaseService.database.default.url=jdbc:mysql://localhost/schedul
ar
services.DatabaseService.database.default.username=sa
services.DatabaseService.database.default.password=S3ymour
services.DatabaseService.database.default.maxConnections=3
services.DatabaseService.database.default.expiryTime=3600000
services.DatabaseService.database.connectionWaitTimeout=10000
services.DatabaseService.database.logInterval=0
services.DatabaseService.database.adapter=DBMM
services.DatabaseService.database.adapter.DBMM=org.gjt.mm.mysql.Driver
services.DatabaseService.idbroker.cleverquantity=true
services.DatabaseService.idbroker.prefetch=true
services.DatabaseService.earlyInit = true

scheduler.enabled = true

=================================================

Something is working in Torque as after may restarts and a couple number of
restarts I get the following;

=================================================

mysql> select * from TURBINE_SCHEDULED_JOB;
+--------+------------+------------+----------+----------+--------------+---
------------------+-------------------+--------------+
| JOB_ID | JOB_SECOND | JOB_MINUTE | JOB_HOUR | WEEK_DAY | DAY_OF_MONTH |
TASK                | EMAIL             | JOB_PROPERTY |
+--------+------------+------------+----------+----------+--------------+---
------------------+-------------------+--------------+
.
.
.
|    340 |          6 |         -1 |       -1 |       -1 |           -1 |
SimpleScheduledTask | smassey@localhost | NULL         |
+--------+------------+------------+----------+----------+--------------+---
------------------+-------------------+--------------+
4 rows in set (0.00 sec)

=================================================

Could someone give me some pointers on what I should try next? It is
reasonable for me to expect to be able to do this? Is it possible to write
such a standalone cron job like this or am I way off base here?

Thanks

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>