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 TypeMethodDescriptionbooleanAdd object to the queue.booleanaddOutOfTurn(T element) Add object to the queue out of turn.voidclear()Clears the queue.default voidclearOutOfTurn(Consumer<T> elementConsumer) Removes the elements which were added byaddOutOfTurn.voidcommit()Removes polled object from the queue.voidInitializes queue.booleanbooleanisEmpty()Checks if queue is currently empty.booleanOut of turn messages only mode.voidNotify a new application message exists.voidNotify a new session message exists.poll()Poll object from the queue (doesn't remove it from queue yet!).voidsetOutOfTurnOnlyMode(boolean mode) Out of turn messages only mode.voidshutdown()Gracefully shutdowns queue.intsize()Returns current queue size.toArray()Return all objects in the queue as array.intReturns 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
nullif 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
-