public final class MultiSimQueueNotificationProcessor<J extends SimJob,Q extends SimQueue> extends DefaultSimQueueListener<J,Q>
SimQueueListener (of atomic events) to a fixed set of SimQueues with features to
operate on the target queues once they are finished with their listener notifications.
By contract of SimEntity and SimJQListener,
it is illegal to operate on an entity from within the context of a listener (notification).
However, in certain cases this feature is highly desired, like in CTandem2.
In order to facilitate this to some extent,
objects of the current class listen to state-change and update notifications from a fixed set of queues,
and store (copies of) these notifications temporarily as MultiSimQueueNotificationProcessor.Notification objects.
Through the use of SimEntity.doAfterNotifications(org.javades.jqueues.r5.entity.SimEntity.Action), objects of this class then invoke a registered MultiSimQueueNotificationProcessor.Processor
to act upon the stored notifications, and since the queue is no longer notifying listeners by then,
the processor can initiate operations on the entity.
If such operations backfire, and new notifications arrive (perhaps from other registered queues), these are simple appended to the stored notifications in the object of this class; the processor can simply proceed to "eat them" and do its thing until there are no more notifications left. Actually, any pending notifications upon return from the processor are discarded.
This class was designed in order to meet some requirements highly specific to implementing,
e.g., CTandem2,
and not really meant for general-purpose use.
Copyright (C) 2005-2017 Jan de Jongh, TNO
This file is covered by the LICENSE file in the root of this project.
| Modifier and Type | Class and Description |
|---|---|
static class |
MultiSimQueueNotificationProcessor.Notification<J extends SimJob,Q extends SimQueue>
A representation of an (atomic) notification from a
SimQueue, consisting of sub-notifications. |
static interface |
MultiSimQueueNotificationProcessor.Processor<J extends SimJob,Q extends SimQueue>
A processor for a list of
MultiSimQueueNotificationProcessor.Notifications. |
| Constructor and Description |
|---|
MultiSimQueueNotificationProcessor(Set<Q> queues)
Creates the listener (without registered processor).
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterNotificationsTrigger()
Invokes the processor if present, if not already processing and if there are notifications to process.
|
static <J extends SimJob,Q extends SimQueue> |
compact(List<MultiSimQueueNotificationProcessor.Notification<J,Q>> notifications)
Compacts a
List of MultiSimQueueNotificationProcessor.Notifications. |
static <J extends SimJob,Q extends SimQueue> |
contains(List<MultiSimQueueNotificationProcessor.Notification<J,Q>> notifications,
SimEntitySimpleEventType.Member eventType)
Checks for the presence of a specific
SimEntitySimpleEventType.Member in a list of MultiSimQueueNotificationProcessor.Notifications. |
void |
notifyStateChanged(double time,
SimEntity entity,
List<Map<SimEntitySimpleEventType.Member,SimEntityEvent>> notifications)
Stores the atomic notification from the issuing
SimQueue, and triggers the processor. |
void |
setProcessor(MultiSimQueueNotificationProcessor.Processor processor)
Sets the (single) processor.
|
notifyNewStartArmed, notifyOutOfServerAccessCredits, notifyRegainedServerAccessCredits, notifyStartQueueAccessVacation, notifyStopQueueAccessVacationnotifyArrival, notifyAutoRevocation, notifyDeparture, notifyDrop, notifyRevocation, notifyStartnotifyResetEntity, notifyUpdateclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitnotifyArrival, notifyAutoRevocation, notifyDeparture, notifyDrop, notifyRevocation, notifyStartnotifyResetEntity, notifyUpdatepublic MultiSimQueueNotificationProcessor(Set<Q> queues)
An internal copy of the supplied set is created, hence future changes to the set do not have any effect.
queues - The set of SimQueues to which the object listens.IllegalArgumentException - If the argument is null or contains null.SimEntity.registerSimEntityListener(org.javades.jqueues.r5.entity.SimEntityListener)public final void setProcessor(MultiSimQueueNotificationProcessor.Processor processor)
processor - The processor, may be null, in which case no processor is invoked.IllegalStateException - If notifications are currently being processed.public final void notifyStateChanged(double time,
SimEntity entity,
List<Map<SimEntitySimpleEventType.Member,SimEntityEvent>> notifications)
SimQueue, and triggers the processor.notifyStateChanged in interface SimEntityListenernotifyStateChanged in class DefaultSimEntityListenertime - The time of the notification.entity - The entity (queue) that issues the notification.notifications - The (atomic) notification.IllegalArgumentException - If the entity is not one of the monitored SimQueues,
or if the notifications are null, empty or illegally structured.SimEntity.doAfterNotifications(org.javades.jqueues.r5.entity.SimEntity.Action),
afterNotificationsTrigger()protected final void afterNotificationsTrigger()
Clears the notifications upon return from the processor.
Non-private for documentation purposes.
public static <J extends SimJob,Q extends SimQueue> boolean contains(List<MultiSimQueueNotificationProcessor.Notification<J,Q>> notifications, SimEntitySimpleEventType.Member eventType)
SimEntitySimpleEventType.Member in a list of MultiSimQueueNotificationProcessor.Notifications.
Convenience method.
J - The type of SimJobs supported in the notifications.Q - The type of SimQueues supported in the notifications.notifications - The notifications, if null or empty, false is returned.eventType - The event-type, must be non-null.True if the (sub-)notifications contain at least one notification of given type, false otherwise.IllegalArgumentException - If eventType == null.public static <J extends SimJob,Q extends SimQueue> void compact(List<MultiSimQueueNotificationProcessor.Notification<J,Q>> notifications)
List of MultiSimQueueNotificationProcessor.Notifications.
Removes, in situ, all MultiSimQueueNotificationProcessor.Notifications
that are null or empty (in terms of sub-notifications).
J - The type of SimJobs supported.Q - The type of SimQueues supported.notifications - The notifications (changed in situ).MultiSimQueueNotificationProcessor.Notification.getSubNotifications()Copyright © 2018. All rights reserved.