2023-08-23 11:45:18 -06:00
|
|
|
##
|
|
|
|
# This software was developed and / or modified by Raytheon Company,
|
|
|
|
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
|
|
|
#
|
|
|
|
# U.S. EXPORT CONTROLLED TECHNICAL DATA
|
|
|
|
# This software product contains export-restricted data whose
|
|
|
|
# export/transfer/disclosure is restricted by U.S. law. Dissemination
|
|
|
|
# to non-U.S. persons whether in the United States or abroad requires
|
|
|
|
# an export license or other authorization.
|
|
|
|
#
|
|
|
|
# Contractor Name: Raytheon Company
|
|
|
|
# Contractor Address: 6825 Pine Street, Suite 340
|
|
|
|
# Mail Stop B8
|
|
|
|
# Omaha, NE 68106
|
|
|
|
# 402.291.0100
|
|
|
|
#
|
|
|
|
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
|
|
|
# further licensing information.
|
|
|
|
##
|
|
|
|
|
2018-09-05 15:52:38 -06:00
|
|
|
#
|
|
|
|
# Implements IData for use by native Python clients to the Data Access
|
|
|
|
# Framework.
|
|
|
|
#
|
2023-08-23 11:45:18 -06:00
|
|
|
# SOFTWARE HISTORY
|
2018-09-05 15:52:38 -06:00
|
|
|
#
|
2023-08-23 11:45:18 -06:00
|
|
|
# Date Ticket# Engineer Description
|
|
|
|
# ------------- -------- ------------ --------------------------------------------
|
|
|
|
# Jun 22, 2016 2416 rjpeter Initial creation
|
|
|
|
# Jul 22, 2016 2416 tgurney Finish implementation
|
|
|
|
# Sep 07, 2017 6175 tgurney Override messageReceived in subclasses
|
|
|
|
# Nov 05, 2019 7884 tgurney Fix in subscribed()
|
|
|
|
# Jun 24, 2020 8187 randerso Added program for qpid connection_id
|
2018-09-05 15:52:38 -06:00
|
|
|
#
|
|
|
|
|
2023-08-23 11:45:18 -06:00
|
|
|
|
2018-09-05 15:52:38 -06:00
|
|
|
import abc
|
|
|
|
|
2023-09-12 13:38:19 -06:00
|
|
|
from ufpy.dataaccess import DataAccessLayer
|
|
|
|
from ufpy.dataaccess import INotificationSubscriber
|
|
|
|
from ufpy.QpidSubscriber import QpidSubscriber
|
2018-09-05 15:52:38 -06:00
|
|
|
from dynamicserialize.dstypes.com.raytheon.uf.common.time import DataTime
|
|
|
|
|
|
|
|
|
2023-08-23 11:45:18 -06:00
|
|
|
class PyNotification(INotificationSubscriber, metaclass=abc.ABCMeta):
|
2018-09-05 15:52:38 -06:00
|
|
|
"""
|
|
|
|
Receives notifications for new data and retrieves the data that meets
|
|
|
|
specified filtering criteria.
|
|
|
|
"""
|
|
|
|
|
2023-08-23 11:45:18 -06:00
|
|
|
def __init__(self, request, filter, host='localhost', port=5672, requestHost='localhost', program="PyNotification"):
|
2018-09-05 15:52:38 -06:00
|
|
|
self.DAL = DataAccessLayer
|
|
|
|
self.DAL.changeEDEXHost(requestHost)
|
|
|
|
self.request = request
|
2023-08-23 11:45:18 -06:00
|
|
|
self.notificationFilter = filter
|
|
|
|
self.host = host
|
|
|
|
self.port = port
|
|
|
|
self.program=program
|
2018-09-05 15:52:38 -06:00
|
|
|
self.__topicName = "edex.alerts"
|
|
|
|
self.callback = None
|
|
|
|
|
|
|
|
def subscribe(self, callback):
|
|
|
|
"""
|
|
|
|
Start listening for notifications.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
callback: Function to call with a list of received data objects.
|
|
|
|
Will be called once for each request made for data.
|
|
|
|
"""
|
|
|
|
assert hasattr(callback, '__call__'), 'callback arg must be callable'
|
|
|
|
self.callback = callback
|
2023-08-23 11:45:18 -06:00
|
|
|
self.qs = QpidSubscriber(host=self.host, port=self.port, decompress=True, program=self.program)
|
|
|
|
self.qs.topicSubscribe(self.__topicName, self.messageReceived)
|
2018-09-05 15:52:38 -06:00
|
|
|
# Blocks here
|
|
|
|
|
|
|
|
def close(self):
|
2023-08-23 11:45:18 -06:00
|
|
|
self.qs.close()
|
2018-09-05 15:52:38 -06:00
|
|
|
|
|
|
|
def getDataTime(self, dataURI):
|
|
|
|
dataTimeStr = dataURI.split('/')[2]
|
|
|
|
return DataTime(dataTimeStr)
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
def messageReceived(self, msg):
|
|
|
|
"""Called when a message is received from QpidSubscriber.
|
|
|
|
|
|
|
|
This method must call self.callback once for each request made for data
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
def getData(self, request, dataTimes):
|
|
|
|
"""
|
|
|
|
Retrieve and return data
|
|
|
|
|
|
|
|
Args:
|
|
|
|
request: IDataRequest to send to the server
|
|
|
|
dataTimes: list of data times
|
|
|
|
Returns:
|
|
|
|
list of IData
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@property
|
|
|
|
def subscribed(self):
|
|
|
|
"""True if currently subscribed to notifications."""
|
2023-08-23 11:45:18 -06:00
|
|
|
try:
|
|
|
|
return self.qs.queueStarted
|
|
|
|
except AttributeError:
|
|
|
|
return False
|