Package org.apache.hadoop.hbase
Class ScheduledChore
java.lang.Object
org.apache.hadoop.hbase.ScheduledChore
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
BalancerChore
,BrokenStoreFileCleaner
,CatalogJanitor
,CleanerChore
,ClusterStatusChore
,ClusterStatusPublisher
,CompactedHFilesDischarger
,FileSystemUtilizationChore
,HbckChore
,HealthCheckChore
,HeapMemoryManager.HeapMemoryTunerChore
,HRegionServer.CompactionChecker
,HRegionServer.PeriodicMemStoreFlusher
,MobFileCleanerChore
,MobFileCompactionChore
,NamedQueueServiceChore
,OldWALsDirSizeChore
,QuotaCache.QuotaRefresherChore
,QuotaObserverChore
,RegionNormalizerChore
,RegionSizeReportingChore
,RegionsRecoveryChore
,ReplicationBarrierCleaner
,ReplicationMarkerChore
,ReplicationSinkServiceImpl.ReplicationStatisticsChore
,RollingUpgradeChore
,RSMobFileCleanerChore
,SnapshotCleanerChore
,SnapshotQuotaObserverChore
,SpaceQuotaRefresherChore
,SplitLogManager.TimeoutMonitor
,StorefileRefresherChore
ScheduledChore is a task performed on a period in hbase. ScheduledChores become active once
scheduled with a
ChoreService
via ChoreService.scheduleChore(ScheduledChore)
. The
chore is run in a ScheduledThreadPoolExecutor
and competes with other ScheduledChores for
access to the threads in the core thread pool. If an unhandled exception occurs, the chore
cancellation is logged. Implementers should consider whether or not the Chore will be able to
execute within the defined period. It is bad practice to define a ScheduledChore whose execution
time exceeds its period since it will try to hog one of the threads in the ChoreService
's
thread pool.
Don't subclass ScheduledChore if the task relies on being woken up for something to do, such as
an entry being added to a queue, etc.-
Field Summary
Modifier and TypeFieldDescriptionprivate ChoreService
Interface to the ChoreService that this ScheduledChore is scheduled with.private static final long
private static final TimeUnit
Default values for scheduling parameters should they be excluded during constructionprivate boolean
private final long
private static final org.slf4j.Logger
private final String
private final int
Scheduling parameters.private final Stoppable
A means by which a ScheduledChore can be stopped.private long
Variables that encapsulate the meaningful state informationprivate long
private final TimeUnit
-
Constructor Summary
ModifierConstructorDescriptionprotected
Construct a ScheduledChoreScheduledChore
(String name, Stoppable stopper, int period) Construct a ScheduledChoreScheduledChore
(String name, Stoppable stopper, int period, long initialDelay) Construct a ScheduledChoreScheduledChore
(String name, Stoppable stopper, int period, long initialDelay, TimeUnit unit) Construct a ScheduledChore -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
void
cancel
(boolean mayInterruptIfRunning) protected abstract void
chore()
The task to execute on each scheduled execution of the Chorevoid
protected void
cleanup()
Override to run cleanup tasks when the Chore encounters an error and must stop running(package private) ChoreService
long
Returns initial delay before executing chore in getTimeUnit() unitsprivate double
Returns max allowed time in millis between runs.getName()
int
Returns period to execute chore in getTimeUnit() units(package private) long
Return how long in millis has it been since this chore last run.(package private) long
(package private) long
protected boolean
Override to run a task before we start looping.boolean
boolean
Returns true when this Chore is scheduled with a ChoreServiceprivate boolean
isValidTime
(long time) Return true if time is earlier or equal to current timeprivate boolean
Returns true when the time between runs exceeds the acceptable thresholdprivate void
Notify the ChoreService that this chore has missed its start time.void
run()
(package private) void
setChoreService
(ChoreService service) void
shutdown()
Callshutdown(boolean)
withtrue
.void
shutdown
(boolean mayInterruptIfRunning) Completely shutdown the ScheduleChore, which means we will call cleanup and you should not schedule it again.toString()
A summation of this chore in human readable format.boolean
Returns false when the Chore is not currently scheduled with a ChoreServiceprivate void
Update our time tracking members.
-
Field Details
-
LOG
-
name
-
DEFAULT_TIME_UNIT
Default values for scheduling parameters should they be excluded during construction -
DEFAULT_INITIAL_DELAY
- See Also:
-
period
Scheduling parameters. Used by ChoreService when scheduling the chore to run periodically -
timeUnit
-
initialDelay
-
choreService
Interface to the ChoreService that this ScheduledChore is scheduled with. null if the chore is not scheduled. -
timeOfLastRun
Variables that encapsulate the meaningful state information -
timeOfThisRun
-
initialChoreComplete
-
stopper
A means by which a ScheduledChore can be stopped. Once a chore recognizes that it has been stopped, it will cancel itself. This is particularly useful in the case where a single stopper instance is given to multiple chores. In such a case, a singleStoppable.stop(String)
command can cause many chores to stop together.
-
-
Constructor Details
-
ScheduledChore
Construct a ScheduledChoreThis constructor is for test only. It allows us to create an object and to call chore() on it.
-
ScheduledChore
Construct a ScheduledChore- Parameters:
name
- Name assigned to Chore. Useful for identification amongst chores of the same typestopper
- WhenStoppable.isStopped()
is true, this chore will cancel and cleanupperiod
- Period in millis with which this Chore repeats execution when scheduled.
-
ScheduledChore
Construct a ScheduledChore- Parameters:
name
- Name assigned to Chore. Useful for identification amongst chores of the same typestopper
- WhenStoppable.isStopped()
is true, this chore will cancel and cleanupperiod
- Period in millis with which this Chore repeats execution when scheduled.initialDelay
- Delay before this Chore begins to execute once it has been scheduled. A value of 0 means the chore will begin to execute immediately. Negative delays are invalid and will be corrected to a value of 0.
-
ScheduledChore
Construct a ScheduledChore- Parameters:
name
- Name assigned to Chore. Useful for identification amongst chores of the same typestopper
- WhenStoppable.isStopped()
is true, this chore will cancel and cleanupperiod
- Period in Timeunit unit with which this Chore repeats execution when scheduled.initialDelay
- Delay in Timeunit unit before this Chore begins to execute once it has been scheduled. A value of 0 means the chore will begin to execute immediately. Negative delays are invalid and will be corrected to a value of 0.unit
- The unit that is used to measure period and initialDelay
-
-
Method Details
-
run
-
updateTimeTrackingBeforeRun
Update our time tracking members. Called at the start of an execution of this chore's run() method so that a correct decision can be made as to whether or not we missed the start time -
onChoreMissedStartTime
Notify the ChoreService that this chore has missed its start time. Allows the ChoreService to make the decision as to whether or not it would be worthwhile to increase the number of core pool threads -
getTimeBetweenRuns
long getTimeBetweenRuns()Return how long in millis has it been since this chore last run. Useful for checking if the chore has missed its scheduled start time by too large of a margin -
missedStartTime
Returns true when the time between runs exceeds the acceptable threshold -
getMaximumAllowedTimeBetweenRuns
Returns max allowed time in millis between runs. -
isValidTime
Return true if time is earlier or equal to current time -
triggerNow
Returns false when the Chore is not currently scheduled with a ChoreService -
setChoreService
-
cancel
-
cancel
-
getName
-
getStopper
-
getPeriod
Returns period to execute chore in getTimeUnit() units -
getInitialDelay
Returns initial delay before executing chore in getTimeUnit() units -
getTimeUnit
-
isInitialChoreComplete
-
getChoreService
-
getTimeOfLastRun
long getTimeOfLastRun() -
getTimeOfThisRun
long getTimeOfThisRun() -
isScheduled
Returns true when this Chore is scheduled with a ChoreService -
choreForTesting
-
chore
The task to execute on each scheduled execution of the Chore -
initialChore
Override to run a task before we start looping.- Returns:
- true if initial chore was successful
-
cleanup
Override to run cleanup tasks when the Chore encounters an error and must stop running -
shutdown
Callshutdown(boolean)
withtrue
.- See Also:
-
shutdown
Completely shutdown the ScheduleChore, which means we will call cleanup and you should not schedule it again. This is another path to cleanup the chore, comparing to stop the stopper instance passed in. -
toString
A summation of this chore in human readable format. Downstream users should not presume parsing of this string can relaibly be done between versions. Instead, they should rely on the public accessor methods to get the information they desire.
-