urbanairship-core/src/main/java/com/urbanairship/automation/AutomationEngine.java
@WorkerThread
    private void attemptExecution(@NonNull final ScheduleEntry scheduleEntry) {
        if (scheduleEntry.getExecutionState() != ScheduleEntry.STATE_WAITING_SCHEDULE_CONDITIONS) {
            Logger.error("Unable to execute schedule when state is " + scheduleEntry.getExecutionState() + " scheduleID: " + scheduleEntry.scheduleId);
            return;
        }

        // Verify the schedule is not expired
        if (scheduleEntry.isExpired()) {
            handleExpiredEntry(scheduleEntry);
            return;
        }

        final CountDownLatch latch = new CountDownLatch(1);
        ScheduleRunnable<Boolean> runnable = new ScheduleRunnable<Boolean>(scheduleEntry.scheduleId, scheduleEntry.group) {
            @Override
            public void run() {
                T schedule = null;
                result = false;

                if (isPaused.get()) {
                    return;
                }

                if (isScheduleConditionsSatisfied(scheduleEntry)) {
                    try {
                        schedule = driver.createSchedule(scheduleEntry.scheduleId, scheduleEntry);

                        if (driver.isScheduleReadyToExecute(schedule)) {
                            result = true;
                        }
                    } catch (ParseScheduleException e) {
                        Logger.error("Unable to create schedule.", e);
                        this.exception = e;
                    }
                }
                latch.countDown();

                if (result && schedule != null) {
                    driver.onExecuteTriggeredSchedule(schedule, new ScheduleExecutorCallback(scheduleEntry.scheduleId));
                }
            }
        };

        this.mainHandler.post(runnable);

        try {
            latch.await();
        } catch (InterruptedException ex) {
            Logger.error("Failed to execute schedule. ", ex);
        }

        if (runnable.exception != null) {
            Logger.error("Failed to check conditions. Deleting schedule: " + scheduleEntry.scheduleId);
            dataManager.deleteSchedule(scheduleEntry.scheduleId);
        } else if (runnable.result) {
            Logger.verbose("AutomationEngine - Schedule executing: " + scheduleEntry.scheduleId);
            scheduleEntry.setExecutionState(ScheduleEntry.STATE_EXECUTING);
            dataManager.saveSchedule(scheduleEntry);
        }
    }
/**
     * Called to attempt executing a schedule entry.
     *
     * @param scheduleEntry The schedule entry.
     */
Called to attempt executing a schedule entry.
@param scheduleEntry The schedule entry.
Called to attempt executing a schedule entry . @param scheduleEntry The schedule entry .
@WorkerThread
    private void attemptExecution(@NonNull final ScheduleEntry scheduleEntry) {
        if (scheduleEntry.getExecutionState() != ScheduleEntry.STATE_WAITING_SCHEDULE_CONDITIONS) {
            Logger.error("Unable to execute schedule when state is " + scheduleEntry.getExecutionState() + " scheduleID: " + scheduleEntry.scheduleId);
            return;
        }
        if (scheduleEntry.isExpired()) {
            handleExpiredEntry(scheduleEntry);
            return;
        }
        final CountDownLatch latch = new CountDownLatch(1);
        ScheduleRunnable<Boolean> runnable = new ScheduleRunnable<Boolean>(scheduleEntry.scheduleId, scheduleEntry.group) {
            @Override
            public void run() {
                T schedule = null;
                result = false;
                if (isPaused.get()) {
                    return;
                }
                if (isScheduleConditionsSatisfied(scheduleEntry)) {
                    try {
                        schedule = driver.createSchedule(scheduleEntry.scheduleId, scheduleEntry);
                        if (driver.isScheduleReadyToExecute(schedule)) {
                            result = true;
                        }
                    } catch (ParseScheduleException e) {
                        Logger.error("Unable to create schedule.", e);
                        this.exception = e;
                    }
                }
                latch.countDown();
                if (result && schedule != null) {
                    driver.onExecuteTriggeredSchedule(schedule, new ScheduleExecutorCallback(scheduleEntry.scheduleId));
                }
            }
        };
        this.mainHandler.post(runnable);
        try {
            latch.await();
        } catch (InterruptedException ex) {
            Logger.error("Failed to execute schedule. ", ex);
        }
        if (runnable.exception != null) {
            Logger.error("Failed to check conditions. Deleting schedule: " + scheduleEntry.scheduleId);
            dataManager.deleteSchedule(scheduleEntry.scheduleId);
        } else if (runnable.result) {
            Logger.verbose("AutomationEngine - Schedule executing: " + scheduleEntry.scheduleId);
            scheduleEntry.setExecutionState(ScheduleEntry.STATE_EXECUTING);
            dataManager.saveSchedule(scheduleEntry);
        }
    }
@ WorkerThread private void attemptExecution ( @ NonNull final ScheduleEntry scheduleEntry ) { if ( scheduleEntry . getExecutionState ( ) != ScheduleEntry . STATE_WAITING_SCHEDULE_CONDITIONS ) { Logger . error ( "Unable to execute schedule when state is " + scheduleEntry . getExecutionState ( ) + " scheduleID: " + scheduleEntry . scheduleId ) ; return ; } if ( scheduleEntry . isExpired ( ) ) { handleExpiredEntry ( scheduleEntry ) ; return ; } final CountDownLatch latch = new CountDownLatch ( 1 ) ; ScheduleRunnable < Boolean > runnable = new ScheduleRunnable < Boolean > ( scheduleEntry . scheduleId , scheduleEntry . group ) { @ Override public void run ( ) { T schedule = null ; result = false ; if ( isPaused . get ( ) ) { return ; } if ( isScheduleConditionsSatisfied ( scheduleEntry ) ) { try { schedule = driver . createSchedule ( scheduleEntry . scheduleId , scheduleEntry ) ; if ( driver . isScheduleReadyToExecute ( schedule ) ) { result = true ; } } catch ( ParseScheduleException e ) { Logger . error ( "Unable to create schedule." , e ) ; this . exception = e ; } } latch . countDown ( ) ; if ( result && schedule != null ) { driver . onExecuteTriggeredSchedule ( schedule , new ScheduleExecutorCallback ( scheduleEntry . scheduleId ) ) ; } } } ; this . mainHandler . post ( runnable ) ; try { latch . await ( ) ; } catch ( InterruptedException ex ) { Logger . error ( "Failed to execute schedule. " , ex ) ; } if ( runnable . exception != null ) { Logger . error ( "Failed to check conditions. Deleting schedule: " + scheduleEntry . scheduleId ) ; dataManager . deleteSchedule ( scheduleEntry . scheduleId ) ; } else if ( runnable . result ) { Logger . verbose ( "AutomationEngine - Schedule executing: " + scheduleEntry . scheduleId ) ; scheduleEntry . setExecutionState ( ScheduleEntry . STATE_EXECUTING ) ; dataManager . saveSchedule ( scheduleEntry ) ; } }
Called to attempt executing a schedule entry.
Called to attempt executing a schedule entry .
// Verify the schedule is not expired