|
ContactCenters V. 0.9.9. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractQueue<DequeueEvent>
umontreal.iro.lecuyer.contactcenters.queue.WaitingQueue
public abstract class WaitingQueue
Represents a waiting queue where contacts are added if they cannot be served
immediately.
The queue contains DequeueEvent
objects
being scheduled to happen at the time of automatic removal, e.g.,
abandonment, disconnection, etc.
These dequeue events, which encapsulate contacts,
are used
to support abandonment as well as other types of exits of queue.
When a contact is added at the end of the
queue using the add(Contact)
method, its dequeue event is constructed, and
scheduled if a maximal queue time is available.
If the dequeue event occurs, the associated
queued contact is removed from the queue.
Queued contacts can also be
removed manually using the removeFirst(int)
or removeLast(int)
methods (this cancels the appropriate dequeue event),
or visited by an iterator returned by iterator(int)
. An
iterator is useful to enumerate queued contacts, and to remove arbitrary
ones.
All registered waiting-queue listeners are notified about added and removed contacts. The reason of the removal is available for listeners through an integer called the dequeue type, encapsulated in the dequeue event. For example, this permits statistical collectors to distinguish abandonment from disconnection.
This abstract class does not implement a data structure for storing queued
contacts. The subclasses StandardWaitingQueue
,
QueueWaitingQueue
, and
PriorityWaitingQueue
implement such data structures.
Note: the WaitingQueueListener
implementations are notified in the
order of the list returned by getWaitingQueueListeners()
, and a
waiting-queue listener modifying the list of listeners by using
addWaitingQueueListener(WaitingQueueListener)
or removeWaitingQueueListener(WaitingQueueListener)
could
result in unpredictable behavior.
Field Summary | |
---|---|
protected int |
dqTypeRet
Contains the dequeue type generated by getMaximalQueueTime(DequeueEvent) . |
Constructor Summary | |
---|---|
WaitingQueue()
Constructs a new waiting queue. |
Method Summary | |
---|---|
DequeueEvent |
add(Contact contact)
Adds the contact contact to the waiting queue and returns a reference to the constructed dequeue event. |
DequeueEvent |
add(Contact contact,
double enqueueTime,
double maxQueueTime,
int dqType)
This is the same as add(Contact) , except that the
enqueue time, maximal queue
time and dequeue type if the queue time is reached, are specified
explicitly. |
DequeueEvent |
addFromOldEvent(DequeueEvent oldDequeueEvent)
Adds a contact into the queue by using the information stored in an old dequeue event oldDequeueEvent. |
void |
addWaitingQueueListener(WaitingQueueListener listener)
Adds the new waiting-queue listener listener to this object. |
void |
clear()
|
void |
clear(int dqType)
Removes all the contacts contained into this waiting queue with dequeue type dqType. |
void |
clearWaitingQueueListeners()
Removes all waiting-queue listeners registered with this waiting queue. |
protected abstract void |
elementsAdd(DequeueEvent dqEvent)
Adds the new dequeued event dqEvent to the internal data structure representing the waiting queue. |
protected abstract void |
elementsClear()
Clears all elements in the data structure representing the queued contacts. |
protected abstract DequeueEvent |
elementsGetFirst()
Returns the first element of the waiting queue's internal data structure, or throws a NoSuchElementException if no such element exists. |
protected abstract DequeueEvent |
elementsGetLast()
Returns the last element of the waiting queue's internal data structure, or throws a NoSuchElementException if no such element exists. |
protected abstract boolean |
elementsIsEmpty()
Determines if the internal waiting queue data structure is empty. |
protected abstract Iterator<DequeueEvent> |
elementsIterator()
Returns an iterator capable of traversing, in the correct order, the elements in the waiting queue's internal data structure. |
protected abstract DequeueEvent |
elementsRemoveFirst()
Removes and returns the first element in the waiting queue's internal data structure. |
protected abstract DequeueEvent |
elementsRemoveLast()
Removes and returns the last element in the waiting queue's internal data structure. |
Map<Object,Object> |
getAttributes()
Returns the map containing the attributes for this waiting queue. |
int |
getDefaultDequeueType()
Returns the default dequeue type used by this object when the user does not specify a dequeue type explicitly. |
DequeueEvent |
getDequeueEvent(Contact contact)
Returns the dequeue event for the contact contact. |
DequeueEvent |
getFirst()
Returns the dequeue event representing the first contact in the queue, or throws a NoSuchElementException if the queue is empty. |
int |
getId()
Returns the identifier associated with this queue. |
DequeueEvent |
getLast()
Returns the dequeue event representing the last contact in the queue, or throws a NoSuchElementException if the queue is empty. |
protected double |
getMaximalQueueTime(DequeueEvent ev)
Generates and returns the maximal queue time for the queued contact represented by ev. |
ValueGenerator |
getMaximalQueueTimeGenerator(int dqType)
Returns the maximal queue time generator associated with dequeue type dqType for this waiting queue. |
String |
getName()
Returns the name associated with this object. |
List<WaitingQueueListener> |
getWaitingQueueListeners()
Returns an unmodifiable list containing all the waiting-queue listeners registered with this waiting queue. |
void |
init()
Initializes this waiting queue for a new simulation replication. |
boolean |
isEmpty()
|
Iterator<DequeueEvent> |
iterator()
This is similar to iterator(int) , except it uses the default
dequeue type returned by getDefaultDequeueType() . |
Iterator<DequeueEvent> |
iterator(int dqType)
Returns an iterator allowing the dequeue events representing contacts in queue to be enumerated. |
protected void |
notifyDequeued(DequeueEvent ev)
Notifies every registered listener that a contact left this queue, this event being represented by ev. |
protected void |
notifyEnqueued(DequeueEvent ev)
Notifies every registered listener that a contact was enqueued, this event being represented by ev. |
protected void |
notifyInit()
Notifies every registered listener that this waiting queue was initialized. |
boolean |
offer(DequeueEvent ev)
|
DequeueEvent |
peek()
|
DequeueEvent |
poll()
|
boolean |
remove(Contact contact,
int dqType)
Removes the contact contact from the waiting queue. |
boolean |
remove(DequeueEvent dqEvent,
int dqType)
Removes the contact identified by the dequeue event dqEvent, setting its effective dequeue type to dqType. |
boolean |
remove(Object o)
|
DequeueEvent |
removeFirst(int dqType)
Removes the first contact in the waiting queue and returns the corresponding dequeue event. |
DequeueEvent |
removeLast(int dqType)
Removes the last contact in the waiting queue and returns the corresponding dequeue event. |
void |
removeWaitingQueueListener(WaitingQueueListener listener)
Removes the waiting-queue listener listener from this object. |
void |
restore(WaitingQueueState state)
Restores the state of the waiting queue by using the restore method of
state. |
WaitingQueueState |
save()
Constructs a new WaitingQueueState object holding the current
state of this waiting queue, i.e., every queued contact. |
void |
setDefaultDequeueType(int dqTypeDefault)
Sets the default dequeue type to dqTypeDefault. |
void |
setId(int id)
Sets the identifier of this queue to id. |
void |
setMaximalQueueTimeGenerator(int dqType,
ValueGenerator dqgen)
Changes the maximal queue time generator associated with dequeue type dqType for this waiting queue to dqgen. |
void |
setName(String name)
Sets the name of this object to name. |
int |
size()
Returns the number of contacts in this waiting queue. |
int |
size(int k)
Returns the number of contacts of type k in this waiting queue. |
String |
toString()
|
Methods inherited from class java.util.AbstractQueue |
---|
add, addAll, element, remove |
Methods inherited from class java.util.AbstractCollection |
---|
contains, containsAll, removeAll, retainAll, toArray, toArray |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
---|
contains, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray |
Field Detail |
---|
protected int dqTypeRet
getMaximalQueueTime(DequeueEvent)
.
Constructor Detail |
---|
public WaitingQueue()
Method Detail |
---|
public String getName()
Named
getName
in interface Named
public void setName(String name)
Named
UnsupportedOperationException
if the name is read-only.
setName
in interface Named
name
- the new name of the object.public void init()
init
in interface Initializable
public void clear()
clear
in interface Collection<DequeueEvent>
clear
in class AbstractQueue<DequeueEvent>
public boolean isEmpty()
isEmpty
in interface Collection<DequeueEvent>
isEmpty
in class AbstractCollection<DequeueEvent>
public boolean offer(DequeueEvent ev)
offer
in interface Queue<DequeueEvent>
public DequeueEvent peek()
peek
in interface Queue<DequeueEvent>
public DequeueEvent poll()
poll
in interface Queue<DequeueEvent>
public void clear(int dqType)
init()
, any removed contact
is notified to the registered listeners.
dqType
- the dequeue type of the removed contacts.public int size()
size
in interface Collection<DequeueEvent>
size
in class AbstractCollection<DequeueEvent>
public int size(int k)
k
- the tested contact type.
public DequeueEvent add(Contact contact)
getMaximalQueueTime(DequeueEvent)
, and an event is scheduled
with its corresponding dequeue type. In case of a zero or negative maximal
queue time, the contact is enqueued then immediately dequeued. Otherwise,
the contact is enqueued and a dequeue event is scheduled if the maximal
queue time is not Double.POSITIVE_INFINITY
or Double.NaN
.
The returned event can be used to get information about the queued contact
and to manually remove it from the queue. If it is directly cancelled, the
contact will not leave the queue automatically.
contact
- the contact to be added.
public DequeueEvent add(Contact contact, double enqueueTime, double maxQueueTime, int dqType)
add(Contact)
, except that the
enqueue time, maximal queue
time and dequeue type if the queue time is reached, are specified
explicitly.
contact
- the contact being queued.enqueueTime
- the time at which the contact joined the queue.maxQueueTime
- the maximal queue time.dqType
- the dequeue type if the maximal queue time is reached.
public DequeueEvent addFromOldEvent(DequeueEvent oldDequeueEvent)
add(Contact,double,double,int)
.
oldDequeueEvent
- the old dequeue event.
protected double getMaximalQueueTime(DequeueEvent ev)
dqTypeRet
if the default value of 1 is not
appropriate.
By default, a MinValueGenerator
is used. For each dequeue type q
with an associated value generator, a maximal queue time Vq is
generated. The scheduled queue time is
Vq* = {Vq}, and the
dequeue type is q*.
ev
- the dequeue event representing the queued contact.
public boolean remove(DequeueEvent dqEvent, int dqType)
dqEvent
- the dequeue event.dqType
- the effective dequeue type.
public boolean remove(Object o)
remove
in interface Collection<DequeueEvent>
remove
in class AbstractCollection<DequeueEvent>
public boolean remove(Contact contact, int dqType)
getDequeueEvent(Contact)
,
which is less efficient than when a dequeue event is given.
contact
- the contact being removed from the queue.dqType
- the effective dequeue type of the contact.
public DequeueEvent getDequeueEvent(Contact contact)
add(Contact)
when they are needed.
contact
- the queried contact.
public DequeueEvent getFirst()
NoSuchElementException
if the queue is empty.
NoSuchElementException
- if the queue is empty.public DequeueEvent getLast()
NoSuchElementException
if the queue is empty.
NoSuchElementException
- if the queue is empty.public DequeueEvent removeFirst(int dqType)
NoSuchElementException
is thrown. The getFirst()
method is
used to get the dequeue event.
dqType
- the effective dequeue type.
NoSuchElementException
- if the queue is empty.public DequeueEvent removeLast(int dqType)
NoSuchElementException
is thrown. The getLast()
method is
used to get the dequeue event.
dqType
- the effective dequeue type.
NoSuchElementException
- if the queue is empty.public Iterator<DequeueEvent> iterator(int dqType)
next()
method are instances of
the DequeueEvent
class. The optional
remove()
method is implemented and
removes contacts with dequeue type dqType. If
remove()
is never called on the returned
iterator, dqType is not used.
dqType
- the dequeue type of any removed contact.
public Iterator<DequeueEvent> iterator()
iterator(int)
, except it uses the default
dequeue type returned by getDefaultDequeueType()
.
iterator
in interface Iterable<DequeueEvent>
iterator
in interface Collection<DequeueEvent>
iterator
in class AbstractCollection<DequeueEvent>
public int getDefaultDequeueType()
public void setDefaultDequeueType(int dqTypeDefault)
dqTypeDefault
- the new default dequeue type.public void addWaitingQueueListener(WaitingQueueListener listener)
listener
- the listener being added.
NullPointerException
- if listener is null.public void removeWaitingQueueListener(WaitingQueueListener listener)
listener
- the waiting-queue listener being removed.public void clearWaitingQueueListeners()
public List<WaitingQueueListener> getWaitingQueueListeners()
protected void notifyInit()
protected void notifyEnqueued(DequeueEvent ev)
ev
- the dequeue event representing the
queued contact.protected void notifyDequeued(DequeueEvent ev)
ev
- the event representing the contact
having left the queue.public WaitingQueueState save()
WaitingQueueState
object holding the current
state of this waiting queue, i.e., every queued contact.
public void restore(WaitingQueueState state)
restore
method of
state.
state
- the saved state of the waiting queue.public int getId()
public void setId(int id)
IllegalStateException
is thrown.
id
- the new identifier associated with the queue.
IllegalStateException
- if the identifier was already set.public ValueGenerator getMaximalQueueTimeGenerator(int dqType)
dqType
- the queried dequeue type.
public void setMaximalQueueTimeGenerator(int dqType, ValueGenerator dqgen)
dqType
- the affected dequeue type.dqgen
- the new maximal queue time generator.
IllegalArgumentException
- if the given dequeue type is negative.
NullPointerException
- if dqgen is null.protected abstract Iterator<DequeueEvent> elementsIterator()
iterator(int)
method because this iterator returns the
contacts marked for dequeue as well as the contacts still enqueued. If the
returned iterator does not implement remove()
,
remove(Contact,int)
and getDequeueEvent(Contact)
will not work
properly.
protected abstract void elementsClear()
protected abstract void elementsAdd(DequeueEvent dqEvent)
dqEvent
- the dequeue event being added.protected abstract boolean elementsIsEmpty()
protected abstract DequeueEvent elementsGetFirst()
NoSuchElementException
if no such element exists.
NoSuchElementException
- if the queue's data structure is empty.protected abstract DequeueEvent elementsGetLast()
NoSuchElementException
if no such element exists.
NoSuchElementException
- if the queue's data structure is empty.protected abstract DequeueEvent elementsRemoveFirst()
NoSuchElementException
if no such element
exists.
NoSuchElementException
- if the queue's data structure is empty.protected abstract DequeueEvent elementsRemoveLast()
NoSuchElementException
if no such element
exists.
NoSuchElementException
- if the queue's data structure is empty.public Map<Object,Object> getAttributes()
public String toString()
toString
in class AbstractCollection<DequeueEvent>
|
ContactCenters V. 0.9.9. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |