Package esmska.data
Class Queue
- java.lang.Object
-
- esmska.data.Queue
-
public class Queue extends java.lang.ObjectClass representing queue of SMS
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQueue.Events
-
Field Summary
Fields Modifier and Type Field Description static intTIMER_TICKInternal tick interval of the queue in milliseconds.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(SMS sms)Add new SMS to the queue.booleanaddAll(java.util.Collection<SMS> collection)Add collection of new SMS to the queue.voidaddValuedListener(ValuedListener<Queue.Events,SMS> valuedListener)voidclear()Remove all SMS from the queue.booleancontains(SMS sms)Checks whether the SMS is in the queue.SMSextractSMS(java.lang.String id, boolean remove)Extract all message fragments (according to ID) from the queue and join them into a full message.java.util.List<SMS>getAll()Get all SMS in the queue.java.util.List<SMS>getAll(java.lang.String gatewayName)Get all SMS in the queue for specified gateway.java.util.List<SMS>getAllWithId(java.lang.String id)Get all SMS (fragments) in the queue with a specified ID.java.util.List<SMS>getAllWithStatus(SMS.Status status)Get a collection of SMS with particular status.java.util.List<SMS>getAllWithStatus(SMS.Status status, java.lang.String gatewayName)Get a collection of SMS with particular status and gateway.longgetGatewayDelay(java.lang.String gatewayName)Return current delay for specified gateway.static QueuegetInstance()Get shared instancelonggetSMSDelay(SMS sms)Return current delay for specified sms.booleanisEmpty()Check if the queue is emptybooleanisPaused()Whether queue is currently pausedvoidmovePosition(SMS sms, int positionDelta)Move SMS in the queue to another position.booleanremove(SMS sms)Remove SMS from the queue.voidremove(java.lang.String id)Remove all SMS with a specified ID from the queue.voidremoveValuedListener(ValuedListener<Queue.Events,SMS> valuedListener)voidsetPaused(boolean paused)Sets whether queue is currently pausedvoidsetSMSFailed(SMS sms)Mark SMS as failed during sending.voidsetSMSSending(SMS sms)Mark SMS as currently being sent.voidsetSMSSent(SMS sms)Mark the SMS as successfully sent.intsize()Get the number of SMS in the queue
-
-
-
Field Detail
-
TIMER_TICK
public static final int TIMER_TICK
Internal tick interval of the queue in milliseconds. After each tick the current delay of all messages is recomputed.- See Also:
- Constant Field Values
-
-
Method Detail
-
addValuedListener
public void addValuedListener(ValuedListener<Queue.Events,SMS> valuedListener)
-
removeValuedListener
public void removeValuedListener(ValuedListener<Queue.Events,SMS> valuedListener)
-
getInstance
public static Queue getInstance()
Get shared instance
-
getAll
public java.util.List<SMS> getAll()
Get all SMS in the queue. This is a shortcut for getAll(null).
-
getAll
public java.util.List<SMS> getAll(java.lang.String gatewayName)
Get all SMS in the queue for specified gateway. The queue is always sorted by the gateway name, the messages are not sorted.- Parameters:
gatewayName- name of the gateway. May be null for any gateway.- Returns:
- unmodifiable list of SMS for specified gateway.
-
getAllWithStatus
public java.util.List<SMS> getAllWithStatus(SMS.Status status)
Get a collection of SMS with particular status. This a shortcut for getAllWithStatus(status, null).
-
getAllWithStatus
public java.util.List<SMS> getAllWithStatus(SMS.Status status, java.lang.String gatewayName)
Get a collection of SMS with particular status and gateway. The queue is always sorted by the gateway name, the messages are not sorted.- Parameters:
status- SMS status, not nullgatewayName- name of the gateway of the SMS, may be null for any gateway- Returns:
- unmodifiable list of SMS with that status in the queue
-
getAllWithId
public java.util.List<SMS> getAllWithId(java.lang.String id)
Get all SMS (fragments) in the queue with a specified ID. The queue is always sorted by the gateway name, the messages are not sorted.- Parameters:
id- message ID. Must not be empty.- Returns:
- unmodifiable list of SMS with the specified ID.
-
add
public boolean add(SMS sms)
Add new SMS to the queue. May not be null.- Returns:
- See
Collection.add(E).
-
addAll
public boolean addAll(java.util.Collection<SMS> collection)
Add collection of new SMS to the queue.- Parameters:
collection- Collection of SMS. May not be null, may not contain null element.- Returns:
- See
Collection.addAll(java.util.Collection)
-
remove
public boolean remove(SMS sms)
Remove SMS from the queue. If the SMS is not present nothing happens.- Parameters:
sms- SMS to be removed. Not null.- Returns:
- See
Collection.remove(java.lang.Object)
-
remove
public void remove(java.lang.String id)
Remove all SMS with a specified ID from the queue.- Parameters:
id- SMS to be removed. Not null.
-
clear
public void clear()
Remove all SMS from the queue.
-
contains
public boolean contains(SMS sms)
Checks whether the SMS is in the queue.- Parameters:
sms- SMS, not null- Returns:
- See
Collection.contains(java.lang.Object)
-
size
public int size()
Get the number of SMS in the queue
-
isEmpty
public boolean isEmpty()
Check if the queue is empty
-
isPaused
public boolean isPaused()
Whether queue is currently paused
-
setPaused
public void setPaused(boolean paused)
Sets whether queue is currently paused
-
movePosition
public void movePosition(SMS sms, int positionDelta)
Move SMS in the queue to another position. Queue is always sorted by gateway, therefore SMS may be moved only within section of its gateway.- Parameters:
sms- sms to be moved, not nullpositionDelta- direction and amount of movement. Positive number moves to the back of the queue, negative number moves to the front of the queue. The number corresponds to the number of positions to change. If the number is larger than current queue dimensions, the element will simply stop as the first or as the last element.
-
getGatewayDelay
public long getGatewayDelay(java.lang.String gatewayName)
Return current delay for specified gateway.- Parameters:
gatewayName- name of the gateway. May be null.- Returns:
- number of milliseconds next message from the gateway must wait. If no such gateway found, return 0.
-
getSMSDelay
public long getSMSDelay(SMS sms)
Return current delay for specified sms. The delay is taking into account all previous messages from the same gateway which are waiting to be sent. If sms is not found in the queue, it is considered to be at the end of the queue.- Parameters:
sms- sms, not null- Returns:
- number of milliseconds a message must wait
-
setSMSSent
public void setSMSSent(SMS sms)
Mark the SMS as successfully sent.- Parameters:
sms- sent SMS, not null
-
setSMSSending
public void setSMSSending(SMS sms)
Mark SMS as currently being sent.- Parameters:
sms- SMS that is currently being sent, not null
-
setSMSFailed
public void setSMSFailed(SMS sms)
Mark SMS as failed during sending. Pauses the queue.- Parameters:
sms- SMS that has failed, not null
-
extractSMS
public SMS extractSMS(java.lang.String id, boolean remove)
Extract all message fragments (according to ID) from the queue and join them into a full message.- Parameters:
id- id of all the message fragments; not emptyremove- whether to remove all the fragments from the queue in the process- Returns:
- sms the whole message with concatenated fragments' text; or null if no such ID was present
-
-