Package org.apache.roller.business.runnable

Examples of org.apache.roller.business.runnable.ThreadManager


     *
     * Roller tasks should put their logic in the runTask() method.
     */
    public final void run() {
       
        ThreadManager mgr = null;
        try {
            mgr = RollerFactory.getRoller().getThreadManager();
        } catch (Exception ex) {
            log.fatal("Unable to obtain ThreadManager", ex);
            return;
        }
       
        boolean lockAcquired = false;
        try {
           
            if(!mgr.isLocked(this)) {
               
                log.debug("Attempting to acquire lock");
               
                lockAcquired = mgr.acquireLock(this);
               
                // now if we have a lock then run the task
                if(lockAcquired) {
                    log.debug("Lock acquired, running task");
                    this.runTask();
                } else {
                    log.debug("Lock NOT acquired, cannot continue");
                   
                    // when we don't have a lock we can't continue, so bail
                    return;
                }
               
            } else {
                log.debug("Task already locked, nothing to do");
            }
           
        } catch (Exception ex) {
            log.error("Unexpected exception running task", ex);
        } finally {
           
            if(lockAcquired) {
               
                log.debug("Attempting to release lock");
               
                boolean lockReleased = mgr.releaseLock(this);
               
                if(lockReleased) {
                    log.debug("Lock released, time to sleep");
                } else {
                    log.debug("Lock NOT released, some kind of problem");
View Full Code Here


    /**
     * Test basic persistence operations ... Create, Update, Delete.
     */
    public void testTaskLockCRUD() throws Exception {
       
        ThreadManager mgr = RollerFactory.getRoller().getThreadManager();
       
        // need a test task to play with
        RollerTask task = new TestTask();
       
        // try to acquire a lock
        boolean lockAcquired = mgr.acquireLock(task);
        assertTrue(lockAcquired);
        TestUtils.endSession(true);
       
        // make sure task is locked
        boolean stillLocked = mgr.isLocked(task);
        assertTrue(stillLocked);
        TestUtils.endSession(true);
       
        // try to release a lock
        boolean lockReleased = mgr.releaseLock(task);
        assertTrue(lockReleased);
        TestUtils.endSession(true);
       
        // make sure task is not locked
        stillLocked = mgr.isLocked(task);
        assertFalse(stillLocked);
        TestUtils.endSession(true);
    }
View Full Code Here

    }
   
   
    private void setupTasks() throws RollerException {
       
        ThreadManager tmgr = RollerFactory.getRoller().getThreadManager();
       
        Date now = new Date();
       
        // okay, first we look for what tasks have been enabled
        String tasksStr = RollerConfig.getProperty("tasks.enabled");
        String[] tasks = StringUtils.stripAll(StringUtils.split(tasksStr, ","));
        for (int i=0; i < tasks.length; i++) {
           
            String taskClassName = RollerConfig.getProperty("tasks."+tasks[i]+".class");
            if(taskClassName != null) {
                mLogger.info("Initializing task: "+tasks[i]);
               
                try {
                    Class taskClass = Class.forName(taskClassName);
                    RollerTask task = (RollerTask) taskClass.newInstance();
                    task.init();
                   
                    Date startTime = task.getStartTime(now);
                    if(startTime == null || now.after(startTime)) {
                        startTime = now;
                    }
                   
                    // schedule it
                    tmgr.scheduleFixedRateTimerTask(task, startTime, task.getInterval());
                   
                } catch (ClassCastException ex) {
                    mLogger.warn("Task does not extend RollerTask class", ex);
                } catch (RollerException ex) {
                    mLogger.error("Error scheduling task", ex);
View Full Code Here

TOP

Related Classes of org.apache.roller.business.runnable.ThreadManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.