net.kenblair.scheduler.entity.Schedulable.java Source code

Java tutorial

Introduction

Here is the source code for net.kenblair.scheduler.entity.Schedulable.java

Source

/*
 * Copyright 2014 Ken Blair
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.kenblair.scheduler.entity;

import org.apache.commons.configuration.Configuration;

/**
 * A bean that may be run on a schedule.
 * <p/>
 * Beans will have {@link #configure(ScheduledJob, Configuration)} called exactly once, followed by zero or more
 * invocations of {@link #run()} on the specified schedule.  If a job is canceled or the scheduler is shutdown then
 * {@link #cancel()} will be called exactly once. If a job changes in such a way that a bean must be reconfigured it
 * will be canceled and rescheduled.
 * <p/>
 * Note that jobs are run asynchronously and can be scheduled repeatedly with varying configurations.  If this is
 * undesirable special consideration must be given to the code itself.
 *
 * @author kblair
 * @see net.kenblair.scheduler.service.Scheduler
 */
public interface Schedulable extends Runnable {

    /**
     * Configure the bean.
     * <p/>
     * This will be called exactly once before the beans first execution.  If an exception is thrown no execution will
     * occur.
     *
     * @param job    The scheduled job that is running this bean.
     * @param config The specified configuration for this bean.
     */
    public void configure(ScheduledJob job, Configuration config);

    /**
     * Called when a job is canceled.
     * <p/>
     * Note that the scheduler may not wait (or be able to wait) for this method to complete.
     */
    public void cancel();

}