Package org.apache.roller.weblogger.pojos

Examples of org.apache.roller.weblogger.pojos.TaskLock


       
        // keep a copy of the current time
        Date currentTime = new Date();
       
        // query for existing lease record first
        TaskLock taskLock = null;
        try {
            taskLock = getTaskLockByName(task.getName());
            if(taskLock == null) {
                log.warn("Cannot acquire lease when no tasklock record exists for task - "+task.getName());
            }
        } catch (WebloggerException ex) {
            log.warn("Error getting TaskLock", ex);
            return false;
        }

        // try to acquire lease
        if(taskLock != null) try {
            // calculate lease expiration time
            Date leaseExpiration = taskLock.getLeaseExpiration();
           
            // calculate run time for task, this is expected time, not actual time
            // i.e. if a task is meant to run daily at midnight this should
            // reflect 00:00:00 on the current day
            Date runTime = currentTime;
            if("startOfDay".equals(task.getStartTimeDesc())) {
                // start of today
                runTime = DateUtil.getStartOfDay(currentTime);
            } else if("startOfHour".equals(task.getStartTimeDesc())) {
                // start of this hour
                runTime = DateUtil.getStartOfHour(currentTime);
            } else {
                // start of this minute
                runTime = DateUtil.getStartOfMinute(currentTime);
            }
           
            if(log.isDebugEnabled()) {
                log.debug("last run = "+taskLock.getLastRun());
                log.debug("new run time = "+runTime);
                log.debug("last acquired = "+taskLock.getTimeAquired());
                log.debug("time leased = "+taskLock.getTimeLeased());
                log.debug("lease expiration = "+leaseExpiration);
            }

            Query q = strategy.getNamedUpdate(
                    "TaskLock.updateClient&Timeacquired&Timeleased&LastRunByName&Timeacquired");
            q.setParameter(1, task.getClientId());
            q.setParameter(2, Integer.valueOf(task.getLeaseTime()));
            q.setParameter(3, new Timestamp(runTime.getTime()));
            q.setParameter(4, task.getName());
            q.setParameter(5, taskLock.getTimeAquired());
            q.setParameter(6, new Timestamp(leaseExpiration.getTime()));
            int result = q.executeUpdate();
           
            if(result == 1) {
                return true;
View Full Code Here


     */
    @Override
    public boolean unregisterLease(RollerTask task) {

        // query for existing lease record first
        TaskLock taskLock = null;
        try {
            taskLock = this.getTaskLockByName(task.getName());

            if(taskLock == null) {
                return false;
View Full Code Here

                    Class taskClass = Class.forName(taskClassName);
                    RollerTask task = (RollerTask) taskClass.newInstance();
                    task.init();
                   
                    // make sure there is a tasklock record in the db
                    TaskLock taskLock = getTaskLockByName(task.getName());
                    if (taskLock == null) {
                        log.debug("Task record does not exist, inserting empty record to start with");

                        // insert an empty record
                        taskLock = new TaskLock();
                        taskLock.setName(task.getName());
                        taskLock.setLastRun(new Date(0));
                        taskLock.setTimeAquired(new Date(0));
                        taskLock.setTimeLeased(0);

                        // save it
                        this.saveTaskLock(taskLock);
                    }
                   
View Full Code Here

        ThreadManager tmgr = WebloggerFactory.getWeblogger().getThreadManager();
       
        for( RollerTask task : tasks ) {
            try {
                // get tasklock for the task
                TaskLock tasklock = tmgr.getTaskLockByName(task.getName());
               
                // TODO: check if task is enabled, otherwise skip
                if(tasklock == null) {
                    log.debug("SKIPPING task : "+tasklock.getName());
                    continue;
                }
               
                // first, calculate the next allowed run time for the task
                // based on when the task was last run
                Date nextRunTime = tasklock.getNextAllowedRun(task.getInterval());
                log.debug(task.getName()+": next allowed run time = "+nextRunTime);
               
                // if we missed the last scheduled run time then see when the
                // most appropriate next run time should be and wait 'til then
                boolean needToWait = false;
View Full Code Here

                    Class taskClass = Class.forName(taskClassName);
                    RollerTask task = (RollerTask) taskClass.newInstance();
                    task.init(taskName);
                   
                    // make sure there is a tasklock record in the db
                    TaskLock taskLock = getTaskLockByName(task.getName());
                    if (taskLock == null) {
                        log.debug("Task record does not exist, inserting empty record to start with");

                        // insert an empty record
                        taskLock = new TaskLock();
                        taskLock.setName(task.getName());
                        taskLock.setLastRun(new Date(0));
                        taskLock.setTimeAquired(new Date(0));
                        taskLock.setTimeLeased(0);

                        // save it
                        this.saveTaskLock(taskLock);
                    }
                   
View Full Code Here

       
        // keep a copy of the current time
        Date currentTime = new Date();
       
        // query for existing lease record first
        TaskLock taskLock = null;
        try {
            taskLock = getTaskLockByName(task.getName());
            if(taskLock == null) {
                log.warn("Cannot acquire lease when no tasklock record exists for task - "+task.getName());
            }
        } catch (WebloggerException ex) {
            log.warn("Error getting TaskLock", ex);
            return false;
        }

        // try to acquire lease
        if(taskLock != null) try {
            // calculate lease expiration time
            Date leaseExpiration = taskLock.getLeaseExpiration();
           
            // calculate run time for task, this is expected time, not actual time
            // i.e. if a task is meant to run daily at midnight this should
            // reflect 00:00:00 on the current day
            Date runTime = currentTime;
            if("startOfDay".equals(task.getStartTimeDesc())) {
                // start of today
                runTime = DateUtil.getStartOfDay(currentTime);
            } else if("startOfHour".equals(task.getStartTimeDesc())) {
                // start of this hour
                runTime = DateUtil.getStartOfHour(currentTime);
            } else {
                // start of this minute
                runTime = DateUtil.getStartOfMinute(currentTime);
            }
           
            if(log.isDebugEnabled()) {
                log.debug("last run = "+taskLock.getLastRun());
                log.debug("new run time = "+runTime);
                log.debug("last acquired = "+taskLock.getTimeAquired());
                log.debug("time leased = "+taskLock.getTimeLeased());
                log.debug("lease expiration = "+leaseExpiration);
            }

            Query q = strategy.getNamedUpdate(
                    "TaskLock.updateClient&Timeacquired&Timeleased&LastRunByName&Timeacquired");
            q.setParameter(1, task.getClientId());
            q.setParameter(2, Integer.valueOf(task.getLeaseTime()));
            q.setParameter(3, new Timestamp(runTime.getTime()));
            q.setParameter(4, task.getName());
            q.setParameter(5, taskLock.getTimeAquired());
            q.setParameter(6, new Timestamp(leaseExpiration.getTime()));
            int result = q.executeUpdate();
           
            if(result == 1) {
                strategy.flush();
View Full Code Here

     */
    @Override
    public boolean unregisterLease(RollerTask task) {

        // query for existing lease record first
        TaskLock taskLock = null;
        try {
            taskLock = this.getTaskLockByName(task.getName());

            if(taskLock == null) {
                return false;
View Full Code Here

TOP

Related Classes of org.apache.roller.weblogger.pojos.TaskLock

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.