Class SchedulerQueue
- java.lang.Object
-
- com.gurock.smartinspect.scheduler.SchedulerQueue
-
public class SchedulerQueue extends Object
Manages a queue of scheduler commands.This class is responsible for managing a queue of scheduler commands. This functionality is needed by the asynchronous protocol mode and the Scheduler class. New commands can be added with the enqueue method. Commands can be dequeued with dequeue. This queue does not have a maximum size or count.
This class is not guaranteed to be thread-safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSchedulerQueue.QueueEnd
-
Constructor Summary
Constructors Constructor Description SchedulerQueue()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all scheduler commands from this queue.SchedulerCommanddequeue()Returns a scheduler command and removes it from the queue.voidenqueue(SchedulerCommand command, SchedulerQueue.QueueEnd insertTo)Adds a new scheduler command to the queue.intgetCount()Returns the current amount of scheduler commands in this queue.longgetSize()Returns the current size of this queue in bytes.booleantrim(int size)Tries to skip and remove scheduler commands from this queue.
-
-
-
Field Detail
-
logger
public static final Logger logger
-
-
Method Detail
-
enqueue
public void enqueue(SchedulerCommand command, SchedulerQueue.QueueEnd insertTo)
Adds a new scheduler command to the queue.This method adds the supplied scheduler command to the queue. The size of the queue is incremented by the size of the supplied command (plus some internal management overhead). This queue does not have a maximum size or count.
- Parameters:
command- The command to addinsertTo- The queue end to insert the command to (head or tail)
-
dequeue
public SchedulerCommand dequeue()
Returns a scheduler command and removes it from the queue. If the queue is not empty, this method removes the oldest scheduler command from the queue (also known as FIFO) and returns it. The total size of the queue is decremented by the size of the returned command (plus some internal management overhead).- Returns:
- The removed scheduler command or null if the queue does not contain any packets
-
trim
public boolean trim(int size)
Tries to skip and remove scheduler commands from this queue. This method removes the next WritePacket scheduler commands from this queue until the specified minimum amount of bytes has been removed. Administrative scheduler commands (connect, disconnect or dispatch) are not removed. If the queue is currently empty or does not contain enough WritePacket commands to achieve the specified minimum amount of bytes, this method returns false.- Parameters:
size- The minimum amount of bytes to remove from this queue- Returns:
- True if enough scheduler commands could be removed and false otherwise
-
clear
public void clear()
Removes all scheduler commands from this queue.Removing all scheduler commands of the queue is done by calling the dequeue method for each command in the current queue
-
getCount
public int getCount()
Returns the current amount of scheduler commands in this queue.For each added scheduler command this counter is incremented by one and for each removed command (with dequeue) this counter is decremented by one. If the queue is empty, this method returns 0.
- Returns:
- The current amount of scheduler commands in this queue
-
getSize
public long getSize()
Returns the current size of this queue in bytes.For each added scheduler command this counter is incremented by the size of the command (plus some internal management overhead) and for each removed command (with dequeue) this counter is then decremented again. If the queue is empty, this method returns 0.
- Returns:
- The current size of this queue in bytes
-
-