Beispiel #1
0
    def __init__(self, config, state, state_callback, publish_callback, exception_callback=None):
        super(AntelopeOrbParser, self).__init__(
            config, None, state, None, state_callback, publish_callback, exception_callback
        )

        # NOTE Still need this?
        self.stop = False

        if state is None:
            state = {}
        self._state = state

        orbname = config[ParserConfigKey.ORBNAME]
        select = config[ParserConfigKey.SELECT]
        reject = config[ParserConfigKey.REJECT]

        keys = (ParserConfigKey.SELECT, ParserConfigKey.REJECT)
        if [select, reject] != [state.get(k) for k in keys]:
            log.warning("select/reject changed; resetting tafter to 0")
            state.update({k: config[k] for k in keys})
            state[StateKey.TAFTER] = 0.0

        tafter = state[StateKey.TAFTER]

        self._orbreapthr = OrbReapThr(orbname, select, reject, float(tafter), timeout=0, queuesize=100)
        log.info("Connected to ORB %s %s %s %s" % (orbname, select, reject, tafter))
Beispiel #2
0
class AntelopeOrbParser(Parser):
    """
    Pseudo-parser for Antelope ORB data.

    This class doesn't really parse anything, but it fits into the DSA
    architecture in the same place as the other parsers, so leaving it named
    parser for consistency.

    What this class does do is connect to an Antelope ORB and get packets from
    it.
    """

    def __init__(self, config, state, state_callback, publish_callback, exception_callback=None):
        super(AntelopeOrbParser, self).__init__(
            config, None, state, None, state_callback, publish_callback, exception_callback
        )

        # NOTE Still need this?
        self.stop = False

        if state is None:
            state = {}
        self._state = state

        orbname = config[ParserConfigKey.ORBNAME]
        select = config[ParserConfigKey.SELECT]
        reject = config[ParserConfigKey.REJECT]

        keys = (ParserConfigKey.SELECT, ParserConfigKey.REJECT)
        if [select, reject] != [state.get(k) for k in keys]:
            log.warning("select/reject changed; resetting tafter to 0")
            state.update({k: config[k] for k in keys})
            state[StateKey.TAFTER] = 0.0

        tafter = state[StateKey.TAFTER]

        self._orbreapthr = OrbReapThr(orbname, select, reject, float(tafter), timeout=0, queuesize=100)
        log.info("Connected to ORB %s %s %s %s" % (orbname, select, reject, tafter))

    def kill_threads(self):
        self._orbreapthr.stop_and_wait()
        self._orbreapthr.destroy()

    def get_records(self):
        """
        Go ahead and execute the data parsing loop up to a point. This involves
        getting data from the file, stuffing it in to the chunker, then parsing
        it and publishing.
        @param num_records The number of records to gather
        @retval Return the list of particles requested, [] if none available
        """
        log.trace("GET RECORDS")
        try:
            if self.stop:
                return
            get_r = self._orbreapthr.get()
            pktid, srcname, orbtimestamp, raw_packet = get_r
            log.trace("get_r: %s %s %s %s", pktid, srcname, orbtimestamp, len(raw_packet))
            particle = AntelopeOrbPacketParticle(
                get_r, preferred_timestamp=DataParticleKey.INTERNAL_TIMESTAMP, new_sequence=False
            )
            self._publish_sample(particle)
            # TODO rate limit state updates?
            self._state[StateKey.TAFTER] = orbtimestamp
            log.debug("State: ", self._state)
            self._state_callback(self._state, False)  # push new state to driver
        except (Timeout, NoData), e:
            log.debug("orbreapthr.get exception %r" % type(e))
            return None
        return get_r