org.rhq.core.pc.drift
Interface ScheduleQueue

All Known Implementing Classes:
ScheduleQueueImpl

public interface ScheduleQueue

Manages the drift detection schedules that are processed by the drift detector. The queue has a concept of the currently "active" schedule. This is identified simply as the schedule returned from getNextSchedule() which is the previous head of the queue. A reference to the active schedule needs to be maintained because at any point in time the server can send a request to update the drift definition that is attached to a schedule. That schedule will either be on the queue waiting to be processed or in the "active" state meaning it is currently being processed by the drift detector.


Method Summary
 boolean addSchedule(DriftDetectionSchedule schedule)
          Adds a schedule to the queue for processing by the drift detector
 void clear()
          Removes all elements from the queue and deactivates the active schedule.
 boolean contains(int resourceId, org.rhq.core.domain.drift.DriftDefinition driftDef)
          Checks the queue for a schedule with specified resource id and drift definition whose name matches the specified definition.
 boolean contains(int resourceId, org.rhq.core.domain.drift.DriftDefinition driftDef, org.rhq.core.domain.drift.DriftDefinitionComparator comparator)
           
 void deactivateSchedule(boolean updateSchedule)
          This method does two things.
 DriftDetectionSchedule find(int resourceId, String defName)
          Searches the queue for a schedule with a matching resource id and drift definition name.
 DriftDetectionSchedule getNextSchedule()
          Removes the head of the queue and returns a copy of the schedule that was removed.
 DriftDetectionSchedule remove(int resourceId, org.rhq.core.domain.drift.DriftDefinition driftDef)
          Removes the schedule identified by the resource id and the drift definition.
 DriftDetectionSchedule remove(int resourceId, String defName)
          Removes the schedule identified by the resource id and drift definition name.
 DriftDetectionSchedule removeAndExecute(int resourceId, org.rhq.core.domain.drift.DriftDefinition driftDef, Runnable task)
          Removes the schedule identified by the resource id and the drift definition name.
 DriftDetectionSchedule removeAndExecute(int resourceId, String configName, Runnable task)
          Removes the schedule
 DriftDetectionSchedule[] toArray()
           
 DriftDetectionSchedule update(int resourceId, org.rhq.core.domain.drift.DriftDefinition driftDef)
          This method attempts to update the schedule identified by the resource id the and the drift definition.
 

Method Detail

toArray

DriftDetectionSchedule[] toArray()

getNextSchedule

DriftDetectionSchedule getNextSchedule()
Removes the head of the queue and returns a copy of the schedule that was removed. That schedule is also marked as the active schedule.

Returns:
A copy of the schedule that is removed from the head of the queue.
Throws:
IllegalStateException - if there is already an active schedule. The active schedule must be deactivated before getting the next schedule.
See Also:
DriftDetectionSchedule

deactivateSchedule

void deactivateSchedule(boolean updateSchedule)
This method does two things. First it updates the active schedule's nextScan property. Then it adds the schedule back onto the queue, allowing the next schedule at the head of the queue to become active. If there is no active schedule this method simply does nothing and returns.


addSchedule

boolean addSchedule(DriftDetectionSchedule schedule)
Adds a schedule to the queue for processing by the drift detector

Parameters:
schedule - A DriftDetectionSchedule object
Returns:
true if the schedule is added, false otherwise

find

DriftDetectionSchedule find(int resourceId,
                            String defName)
Searches the queue for a schedule with a matching resource id and drift definition name. If found, a copy of the schedule is returned.

Parameters:
resourceId - The resource id of the schedule being sought
defName - The name of the drift definition in the schedule being sought
Returns:
A copy of the schedule or null if no match is found

contains

boolean contains(int resourceId,
                 org.rhq.core.domain.drift.DriftDefinition driftDef)
Checks the queue for a schedule with specified resource id and drift definition whose name matches the specified definition.

Parameters:
resourceId - The resource id of the schedule
driftDef - The drift definition of the schedule
Returns:
true if the queue contains a schedule with the specified resource id and a drift definition whose name matches the name of the specified definition.

contains

boolean contains(int resourceId,
                 org.rhq.core.domain.drift.DriftDefinition driftDef,
                 org.rhq.core.domain.drift.DriftDefinitionComparator comparator)

update

DriftDetectionSchedule update(int resourceId,
                              org.rhq.core.domain.drift.DriftDefinition driftDef)
This method attempts to update the schedule identified by the resource id the and the drift definition. More specifically, the schedule is identified by a combination of resource id and drift definition name. If the schedule to be updated is the active schedule, it is immediately updated and then placed back on the queue the next time #deactivateSchedule() is called. If the schedule is on the queue, it is removed, updated, and then added back onto the queue.

Parameters:
resourceId - The resource id
driftDef - A DriftDefinition belonging the resource with the specified id
Returns:
A copy of the updated schedule or null if no update was performed

remove

DriftDetectionSchedule remove(int resourceId,
                              org.rhq.core.domain.drift.DriftDefinition driftDef)
Removes the schedule identified by the resource id and the drift definition. More specifically, the schedule is identified by a combination of resource id drift definition name. This method can remove either the active schedule or a schedule on the queue.

Parameters:
resourceId - The resource id
driftDef - A DriftDefinition belonging the resource with the specified id
Returns:
The DriftDetectionSchedule that is removed or null if no matching schedule is found.

remove

DriftDetectionSchedule remove(int resourceId,
                              String defName)
Removes the schedule identified by the resource id and drift definition name. This method will remove the currently active schedule or a schedule that is on the queue.

Parameters:
resourceId - The resource id
defName - The drift definition name
Returns:
The DriftDetectionSchedule that is removed or null if no matching schedule is found.

removeAndExecute

DriftDetectionSchedule removeAndExecute(int resourceId,
                                        org.rhq.core.domain.drift.DriftDefinition driftDef,
                                        Runnable task)
Removes the schedule identified by the resource id and the drift definition name. This method can remove either the active schedule or a schedule on the queue. When the schedule is in the queue, task is executed immediately after the schedule is removed from the queue. If the schedule is active, then task will be executed when the schedule is deactivated. If the schedule is not in the queue, that is it is neither the active schedule nor waiting in the queue, then taskis never invoked and is discarded.

task will only be invoked once regardless of whether or the schedule is active or waiting in the queue.

The reason for accepting a task to execute upon removal of the schedule has to do with the active schedule. If a schedule is active, that means it is being processed by DriftDetector. The task may very well involve some clean up work that could interfere with DriftDetector. This approach ensures that the schedule is not in used before task is executed.

Parameters:
resourceId - The resource id
driftDef - A DriftDefinition belonging the resource with the specified id
task - A callback to perform any post-processing when the schedule is removed from the queue
Returns:
The DriftDetectionSchedule that is removed or null if no matching schedule is found.

removeAndExecute

DriftDetectionSchedule removeAndExecute(int resourceId,
                                        String configName,
                                        Runnable task)
Removes the schedule

Parameters:
resourceId -
configName -
task -
Returns:

clear

void clear()
Removes all elements from the queue and deactivates the active schedule.



Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.