Package com.epam.fixengine.storage.queue
Interface Queue<T extends Queueable>
- All Known Implementing Classes:
InMemoryQueue
,MMFPersistentInMemoryQueue
,PersistentInMemoryQueue
public interface Queue<T extends Queueable>
Queue interface.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Add object to the queue.boolean
addOutOfTurn
(T element) Add object to the queue out of turn.void
clear()
Clears the queue.default void
clearOutOfTurn
(Consumer<T> elementConsumer) Removes the elements which were added byaddOutOfTurn
.void
commit()
Removes polled object from the queue.void
Initializes queue.boolean
boolean
isEmpty()
Checks if queue is currently empty.boolean
Out of turn messages only mode.void
Notify a new application message exists.void
Notify a new session message exists.poll()
Poll object from the queue (doesn't remove it from queue yet!).void
setOutOfTurnOnlyMode
(boolean mode) Out of turn messages only mode.void
shutdown()
Gracefully shutdowns queue.int
size()
Returns current queue size.toArray()
Return all objects in the queue as array.int
Returns current total queue size.
-
Method Details
-
initialize
void initialize()Initializes queue. That includes restore of previously saved queue content for persistent queues. -
add
Add object to the queue.- Parameters:
element
- the element- Returns:
- true if element added successfully.
-
addOutOfTurn
Add object to the queue out of turn.- Parameters:
element
- the element- Returns:
- true if element added successfully.
-
setOutOfTurnOnlyMode
void setOutOfTurnOnlyMode(boolean mode) Out of turn messages only mode.- Parameters:
mode
- the mode
-
clearOutOfTurn
Removes the elements which were added byaddOutOfTurn
.- Parameters:
elementConsumer
- callback for each removed message. It is called after removing next message.
-
isAllEmpty
boolean isAllEmpty() -
poll
T poll()Poll object from the queue (doesn't remove it from queue yet!).- Returns:
- the head of this queue, or
null
if this queue is empty - See Also:
-
commit
void commit()Removes polled object from the queue. If nothing was polled - throws IllegalStateException- See Also:
-
isEmpty
boolean isEmpty()Checks if queue is currently empty.- Returns:
- true if empty
-
size
int size()Returns current queue size.- Returns:
- queue size
-
totalSize
int totalSize()Returns current total queue size. The total size of the usual queue and the OutOfTurn queue.- Returns:
- queue size
-
clear
void clear()Clears the queue. -
shutdown
void shutdown()Gracefully shutdowns queue. -
isOutOfTurnOnlyMode
boolean isOutOfTurnOnlyMode()Out of turn messages only mode. -
notifyAllApplication
void notifyAllApplication()Notify a new application message exists.The methods works only if turn "mode on" is off.
- See Also:
-
notifyAllSession
void notifyAllSession()Notify a new session message exists. -
toArray
Queueable[] toArray()Return all objects in the queue as array. Method has no impact on poll / commit operations.- Returns:
- array of Queueable
-