org.rhq.core.pc.drift
Class ScheduleQueueImpl

java.lang.Object
  extended by org.rhq.core.pc.drift.ScheduleQueueImpl
All Implemented Interfaces:
ScheduleQueue

public class ScheduleQueueImpl
extends Object
implements ScheduleQueue


Constructor Summary
ScheduleQueueImpl()
           
 
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 defName, Runnable task)
          Removes the schedule
 DriftDetectionSchedule[] toArray()
           
 String toString()
          Generates a string representation of the schedules in the queue.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ScheduleQueueImpl

public ScheduleQueueImpl()
Method Detail

getNextSchedule

public DriftDetectionSchedule getNextSchedule()
Description copied from interface: ScheduleQueue
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.

Specified by:
getNextSchedule in interface ScheduleQueue
Returns:
A copy of the schedule that is removed from the head of the queue.
See Also:
DriftDetectionSchedule

deactivateSchedule

public void deactivateSchedule(boolean updateSchedule)
Description copied from interface: ScheduleQueue
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.

Specified by:
deactivateSchedule in interface ScheduleQueue

addSchedule

public boolean addSchedule(DriftDetectionSchedule schedule)
Description copied from interface: ScheduleQueue
Adds a schedule to the queue for processing by the drift detector

Specified by:
addSchedule in interface ScheduleQueue
Parameters:
schedule - A DriftDetectionSchedule object
Returns:
true if the schedule is added, false otherwise

contains

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

Specified by:
contains in interface ScheduleQueue
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

public boolean contains(int resourceId,
                        org.rhq.core.domain.drift.DriftDefinition driftDef,
                        org.rhq.core.domain.drift.DriftDefinitionComparator comparator)
Specified by:
contains in interface ScheduleQueue

find

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

Specified by:
find in interface ScheduleQueue
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

remove

public DriftDetectionSchedule remove(int resourceId,
                                     org.rhq.core.domain.drift.DriftDefinition driftDef)
Description copied from interface: ScheduleQueue
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.

Specified by:
remove in interface ScheduleQueue
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

public DriftDetectionSchedule remove(int resourceId,
                                     String defName)
Description copied from interface: ScheduleQueue
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.

Specified by:
remove in interface ScheduleQueue
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

public DriftDetectionSchedule removeAndExecute(int resourceId,
                                               org.rhq.core.domain.drift.DriftDefinition driftDef,
                                               Runnable task)
Description copied from interface: ScheduleQueue
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.

Specified by:
removeAndExecute in interface ScheduleQueue
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

public DriftDetectionSchedule removeAndExecute(int resourceId,
                                               String defName,
                                               Runnable task)
Description copied from interface: ScheduleQueue
Removes the schedule

Specified by:
removeAndExecute in interface ScheduleQueue
Returns:

update

public DriftDetectionSchedule update(int resourceId,
                                     org.rhq.core.domain.drift.DriftDefinition driftDef)
Description copied from interface: ScheduleQueue
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.

Specified by:
update in interface ScheduleQueue
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

clear

public void clear()
Description copied from interface: ScheduleQueue
Removes all elements from the queue and deactivates the active schedule.

Specified by:
clear in interface ScheduleQueue

toString

public String toString()
Generates a string representation of the schedules in the queue. The schedules that appear in the string are in sorted order. If there is an active schedule it will appear first. This method can be useful for debugging since it shows the contents of the queue in sorted order. Use it cautiously however as writes to the queue are blocked until this method returns.

Overrides:
toString in class Object
Returns:
A string representation of the queue with the schedules appearing in sorted order.

toArray

public DriftDetectionSchedule[] toArray()
Specified by:
toArray in interface ScheduleQueue


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