class NotificationManager(object):
This class defines functionalities to handle subscriptions and notifications.
| Method | add |
Add a new crossResourceSubscription. |
| Method | add |
Add a new subscription. |
| Method | check |
Check for and perform a notification for an operation subscription. |
| Method | check |
Perform a blocking RETRIEVE. If this notification event type is configured a RETRIEVE operation to a resource causes a notification to a target. It is expected that the target is updating the resource ... |
| Method | check |
Check for and perform a blocking update request for resource updates that have this event type configured. |
| Method | check |
Check and handle resource events. |
| Method | count |
This method count and stores the number of notification events for a subscription. It increments the count for each of the notification targets. |
| Method | count |
If Notification Stats are enabled for a <sub> or <crs> resource, then increase the count for sent notifications or received responses. |
| Method | evaluate |
Evaluate a policy deletion rule. |
| Method | get |
Returns a (possible empty) list of subscriptions for a resource. |
| Method | initialize |
Initialization of a NotificationManager instance. |
| Method | received |
Handle a received notification for a <crs> resource. |
| Method | remove |
Remove a crossResourcesubscription. |
| Method | remove |
Remove a notification target from a subscription and perform the necessary actions based on the associated policies. |
| Method | remove |
Remove a subscription. |
| Method | restart |
Restart the NotificationManager service. |
| Method | send |
Send a Deletion Notification to a single or a list of target. |
| Method | send |
Send a notification to a single URI or a list of URIs. |
| Method | send |
Define the callback function for verification notifications and send the notification. |
| Method | shutdown |
Shutdown the Notification Manager. |
| Method | start |
Start a periodic window for a <crs> resource. |
| Method | start |
Start a sliding window for a <crs> resource. |
| Method | stop |
Stop a periodic window for a <crs> resource. |
| Method | stop |
Stop a sliding window for a <crs> resource. |
| Method | update |
Update a crossResourcesubscription. |
| Method | update |
Handle an update of the notificationStatsEnable attribute of a <sub> or <crs> resource. |
| Method | update |
Update a subscription. |
| Method | validate |
Update and fill the notificationStatsInfo attribute of a <sub> or <crs> resource. |
| Class Variable | __slots__ |
Slots for NotificationManager instance attributes. |
| Class Variable | dispatcher |
Injected Dispatcher instance. |
| Class Variable | request |
Injected RequestManager instance. |
| Class Variable | storage |
Injected Storage instance. |
| Instance Variable | lock |
An internal lock instance for locking certain batch notification methods. |
| Instance Variable | lock |
An internal lock instance for locking the notification event stats. |
| Method | _crs |
Test whether a notification must be sent for a a <crs> window. |
| Method | _crs |
Check for a <crs> periodic window and send notifications if the window requirements are met. |
| Method | _crs |
Actor function to monitor a sliding window for a <crs> resource. |
| Method | _flush |
Send and remove any outstanding batch notifications for a subscription. |
| Method | _get |
Return the name of a periodic window worker. |
| Method | _get |
Return the name of a sliding window worker. |
| Method | _handle |
Send a subscription notification. |
| Method | _send |
Send a notification to a single or to multiple targets if necessary. |
| Method | _send |
Send and remove(!) the available BatchNotifications for an ri & nu. |
| Method | _start |
Start a new batch notification worker. |
| Method | _stop |
Stop a batch notification worker for a given ri and nu. |
| Method | _store |
Store a subscription's notification for later sending. For a single nu. |
| Method | _verify |
Check all the notification URI's in a subscription. |
| Method | _worker |
Return an ID for a batch notification background worker. |
| Instance Variable | _event |
Cached reference to the notification event for optimized access. |
Add a new crossResourceSubscription.
Check each receipient in the nu attribute with verification requests.
| Parameters | |
crs:CRS | The new <crs> resource to check. |
originator:str | The request originator. |
| Returns | |
| Result object. |
Add a new subscription.
Check each receipient with verification requests.
| Parameters | |
subscription:SUB | The new <sub> resource. |
originator:str | The request originator. |
| Raises | |
INTERNAL_SERVER_ERROR | In case there is an internal DB error. |
Check for and perform a notification for an operation subscription.
| Parameters | |
resource:Resource | The resource that received the event resp. request. |
op:Operation | The operation to check. |
originator:str | The originator of the request that caused the event. |
| Raises | |
INTERNAL_SERVER_ERROR | If there are issues retrieving the necessary resources or if multiple default NTP resources are found. |
Resource, request: CSERequest, finished: Callable | None = None):
¶
Perform a blocking RETRIEVE. If this notification event type is configured a RETRIEVE operation to a resource causes a notification to a target. It is expected that the target is updating the resource before responding to the notification.
A NOTIFY permission check is done against the originator of the <subscription> resource, not the originator of the request.
Note
This functionality is experimental and not part of the oneM2M spec yet.
| Parameters | |
resource:Resource | The resource that is the target of the RETRIEVE request. |
request:CSERequest | The original request. |
finished:Callable | None | Callable that is called when the notifications were successfully sent and received. |
| Returns | |
| Result instance indicating success or failure. |
Resource, originator: str, updatedAttributes: JSON, finished: Callable | None = None):
¶
Check for and perform a blocking update request for resource updates that have this event type configured.
| Parameters | |
resource:Resource | The updated resource. |
originator:str | The originator of the original request. |
updatedJSON | A structure of all the updated attributes. |
finished:Callable | None | Callable that is called when the notifications were successfully sent and a response was received. |
Resource | None, reason: NotificationEventType, originator: str, childResource: Resource | None = None, modifiedAttributes: JSON | None = None, ri: str | None = None, missingData: dict[ str, MissingData] | None = None, operation: Operation | None = None):
¶
Check and handle resource events.
This method looks for subscriptions of a resource and tests, whether an event, like update etc, will lead to a notification. It then creates and sends the notification to all targets.
| Parameters | |
resource:Resource | None | The resource that received the event resp. request. |
reason:NotificationEventType | The NotificationEventType to check. |
originator:str | The originator of the request that caused the event. |
childResource | None | An optional child resource of resource that might be updated or created etc. |
modifiedJSON | None | An optional JSON structure that contains updated attributes. |
ri:str | None | Optionally provided resource ID of Resource. If it is provided, then resource might be None.
It will then be used to retrieve the resource. |
missingdict[ | An optional dictionary of missing data structures in case the TimeSeries missing data functionality is handled. |
operation:Operation | None | An optional operation that is checked against the subscription's operationMonitor. This overrides the reason. |
This method count and stores the number of notification events for a subscription. It increments the count for each of the notification targets.
After handling the resource is updated in the database.
| Parameters | |
ri:str | Resource ID of a <sub> or <csr> resource to handle. |
sub:SUB | CRS | None | Undocumented |
SUB | CRS, target: str, isResponse: bool | None = False, count: int | None = 1):
¶
If Notification Stats are enabled for a <sub> or <crs> resource, then increase the count for sent notifications or received responses.
| Parameters | |
sub:SUB | CRS | <sub> or <crs> resource. |
target:str | URI of the notification target. |
isbool | None | Indicates whether a sent notification or a received response should be counted for. |
count:int | None | Number of notifications to count. |
Evaluate a policy deletion rule.
| Parameters | |
pdr:PDR | The <policyDeletionRules> resource. |
| Returns | |
bool | True if the rule is satisfied, False otherwise. |
str, net: list[ NotificationEventType] | None = None, chty: ResourceTypes | None = None) -> JSONLIST:
¶
Returns a (possible empty) list of subscriptions for a resource.
| Parameters | |
ri:str | Undocumented |
net:list[ | optional filter for enc/net |
chty:ResourceTypes | None | optional single child resource typ |
| Returns | |
JSONLIST | List of storage subscription documents, NOT Subscription resources. |
Handle a received notification for a <crs> resource.
| Parameters | |
sur:str | The notification source received in the notification. |
crs:Resource | The <crs> resource for which the notification was received. |
Remove a crossResourcesubscription.
Send a deletion request to the subscriberURI target.
| Parameters | |
crs:CRS | The new <crs> resource to remove. |
| Returns | |
| Result object. |
Remove a notification target from a subscription and perform the necessary actions based on the associated policies.
| Parameters | |
ntsr:NTSR | The notification target subscription resource. |
originator:str | The originator to be removed. |
| Raises | |
ORIGINATOR_HAS_NO_PRIVILEGE | If the policies evaluated to false for the given originator and the notification target subscription resource. |
INTERNAL_SERVER_ERROR | If there are issues retrieving the necessary resources or if multiple default NTP resources are found. |
Restart the NotificationManager service.
| Parameters | |
eventEventData | The event data. Not used in this handler. |
Send a Deletion Notification to a single or a list of target.
| Parameters | |
uri:str | list[ | Single or a list of notification target URIs. |
ri:str | ResourceID of the subscription. |
creator:str | Undocumented |
| Returns | |
bool | Boolean indicat |
JSON, nus: list[ str] | str, originator: str | None = None, background: bool | None = False, preFunc: Callable | None = None, postFunc: Callable | None = None) -> RequestResponseList:
¶
Send a notification to a single URI or a list of URIs.
A URI may be a resource ID, then the poa of that resource is taken. Also, the serialization is determined when each of the notifications is actually sent.
Pre- and post-functions can be given that are called before and after sending each notification.
| Parameters | |
dct:JSON | Dictionary to send as the notification. It already contains the full request. |
nus:list[ | A single URI or a list of URIs. |
originator:str | None | The originator on which behalf to send the notification. |
background:bool | None | Send the notifications in a background task. |
preCallable | None | Function that is called before each notification sending, with the notification target as a single argument. |
postCallable | None | Function that is called after each notification sending, with the notification target as a single argument. |
| Returns | |
RequestResponseList | A list of results for each notification sent. An empty list is returned if background is set to True. |
str | list[ str], ri: str, originator: str | None = None) -> bool:
¶
Define the callback function for verification notifications and send the notification.
| Parameters | |
uri:str | list[ | The URI to send the verification request to. This may be a list of URI's. Each URI could be a direct URL, or an entity. |
ri:str | The resource ID of the subscription. |
originator:str | None | The originator on which behalf to send the notification. |
| Returns | |
bool | Undocumented |
str, tws: str, expectedCount: int, eem: EventEvaluationMode = EventEvaluationMode.ALL_EVENTS_PRESENT):
¶
Start a periodic window for a <crs> resource.
| Parameters | |
crsstr | Resource ID of the <crs> resource for which to start the periodic window. |
tws:str | Time window size as a duration string. |
expectedint | The expected number of notifications. |
eem:EventEvaluationMode | Event evaluation mode. |
str, tws: str, sur: str, subCount: int, eem: EventEvaluationMode = EventEvaluationMode.ALL_EVENTS_PRESENT) -> BackgroundWorker:
¶
Start a sliding window for a <crs> resource.
| Parameters | |
crsstr | Resource ID of the <crs> resource for which to start the sliding window. |
tws:str | Time window size as a duration string. |
sur:str | The notification source. |
subint | The expected number of notifications. |
eem:EventEvaluationMode | Event evaluation mode. |
| Returns | |
BackgroundWorker | The background worker handling the sliding window. |
Stop a periodic window for a <crs> resource.
| Parameters | |
crsstr | Resource ID of the <crs> resource for which to stop the periodic window. |
Stop a sliding window for a <crs> resource.
| Parameters | |
crsstr | Resource ID of the <crs> resource for which to stop the sliding window. |
Update a crossResourcesubscription.
Check each new receipient in the nu attribute with verification requests.
This method indirectly updates or rebuild the notificationStatsInfo attribute. It should be called add the end when updating a subscription.
| Parameters | |
crs:CRS | The new <crs> resource to check. |
previouslist[ | A list of the resource's previous NUs. |
originator:str | The request originator. |
| Returns | |
| Result object. |
Handle an update of the notificationStatsEnable attribute of a <sub> or <crs> resource.
Note
This removes the notificationStatsEnable attribute, which must be added and filled later again, e.g. when validating the notificationURIs attribute. For this the notificationURIs attribute must be fully validated first.
| Parameters | |
sub:CRS | SUB | Either a <sub> or <crs> resource. |
newbool | The new value for the nse attribute. This may be empty if not present in the update. |
Update a subscription.
This method indirectly updates or rebuild the notificationStatsInfo attribute. It should be called add the end when updating a subscription.
| Parameters | |
subscription:SUB | The <sub> resource to update. |
previouslist[ | List of previous NUs of the same <sub> resoure. |
originator:str | The request originator. |
| Returns | |
| Result object. |
Update and fill the notificationStatsInfo attribute of a <sub> or <crs> resource.
This method adds, if necessary, the necessarry stat info structures for each notification URI. It also removes structures for notification URIs that are not present anymore.
Note
For this the notificationURIs attribute must be fully validated first.
| Parameters | |
sub:SUB | CRS | The <sub> or <crs> resource for whoich to validate the attribute. |
add:bool | None | If True, add the notificationStatsInfo attribute if not present. |
list[ str], crsRi: str, subCount: int, eem: EventEvaluationMode = EventEvaluationMode.ALL_EVENTS_PRESENT):
¶
Test whether a notification must be sent for a a <crs> window.
This method also sends the notification(s) if the window requirements are met.
| Parameters | |
data:list[ | List of unique resource IDs. |
crsstr | The resource ID of the <crs> resource for the window. |
subint | Maximum number of expected resource IDs in data. |
eem:EventEvaluationMode | EventEvaluationMode. |
list[ str], _worker: BackgroundWorker, crsRi: str, expectedCount: int, eem: EventEvaluationMode = EventEvaluationMode.ALL_EVENTS_PRESENT) -> bool:
¶
Check for a <crs> periodic window and send notifications if the window requirements are met.
| Parameters | |
_data:list[ | List of notification sources. |
_worker:BackgroundWorker | The background worker handling this periodic window. |
crsstr | Resource ID of the <crs>. |
expectedint | The expected number of notifications. |
eem:EventEvaluationMode | Event evaluation mode. |
| Returns | |
bool | Always returns True. |
Any, _worker: BackgroundWorker, crsRi: str, subCount: int, eem: EventEvaluationMode = EventEvaluationMode.ALL_EVENTS_PRESENT) -> bool:
¶
Actor function to monitor a sliding window for a <crs> resource.
| Parameters | |
_data:Any | List of notification sources. |
_worker:BackgroundWorker | The background worker handling this sliding window. |
crsstr | Resource ID of the <crs>. |
subint | The expected number of notifications. |
eem:EventEvaluationMode | Event evaluation mode. |
| Returns | |
bool | Always returns True. |
Return the name of a periodic window worker.
| Parameters | |
ri:str | Resource ID for which the worker is running. |
| Returns | |
str | String with the worker name. |
Return the name of a sliding window worker.
| Parameters | |
ri:str | Resource ID for which the worker is running. |
| Returns | |
str | String with the worker name. |
JSON, notificationEventType: NotificationEventType, resource: Resource | None = None, modifiedAttributes: JSON | None = None, missingData: MissingData | None = None, asynchronous: bool = False, operationMonitor: OperationMonitor | None = None, originator: str = None) -> bool:
¶
Send a subscription notification.
| Parameters | |
sub:JSON | The <sub> resource. |
notificationNotificationEventType | The notification event type. |
resource:Resource | None | The resource that triggered the notification. |
modifiedJSON | None | The modified attributes of the resource. |
missingMissingData | None | The missing data of the resource. |
asynchronous:bool | If True, send the notification in the background. |
operationOperationMonitor | None | The operationMonitor information. |
originator:str | The originator on which behalf to send the notification. |
| Returns | |
bool | True if the notification was sent successfully, False otherwise. |
Send a notification to a single or to multiple targets if necessary.
Call the infividual callback functions to do the resource preparation and the the actual sending.
| Parameters | |
uris:str | list[ | Either a string or a list of strings of notification receivers. |
senderSenderFunction | A function that is called to perform the actual notification sending. |
| Returns | |
bool | Returns True, even when nothing was sent, and False when any senderFunction returned False. |
str, nu: str, ln: bool, sub: JSON) -> bool:
¶
Send and remove(!) the available BatchNotifications for an ri & nu.
While the sent notifications and the respective received responses are counted here, the expiration counter is not. It depends on the events, not the notifications.
| Parameters | |
ri:str | Resource ID of the <sub> or <crs> resource. |
nu:str | A single notification URI. |
ln:bool | latestNotify, if True then only send the latest notification. |
sub:JSON | The internal sub structure. |
| Returns | |
bool | Indication of the success of the sending. |
str, nu: str, ln: bool, sub: JSON, dur: float) -> bool:
¶
Start a new batch notification worker.
| Parameters | |
ri:str | Resource ID of the subscription. |
nu:str | Notification URI of the notification target. |
ln:bool | latestNotify, if True then only send the latest notification. |
sub:JSON | The internal sub structure. |
dur:float | Duration for the batch notification. |
| Returns | |
bool | Indication of the success of the operation. |
Stop a batch notification worker for a given ri and nu.
| Parameters | |
ri:str | Resource ID of the subscription. |
nu:str | Notification URI of the notification target. |
SUB | CRS, previousNus: list[ str] | None = None, originator: str | None = None):
¶
Check all the notification URI's in a subscription.
A verification request is sent to new URI's. Notifications to the originator are not sent.
If previousNus is given then only new nus are notified.
| Parameters | |
subscription:SUB | CRS | <sub> or <crs> resource. |
previouslist[ | The list of previous NUs. |
originator:str | None | The originator on which behalf to send the notification. |
| Raises | |
SUBSCRIPTION_VERIFICATION_INITIATION_FAILED | In case a subscription verification fails. |