Esempio n. 1
0
    def waitAndGet(self, event_name, timeout=DEFAULT_TIMEOUT):
        """Blocks until an event of the specified name has been received and
        return the event, or timeout.

        Args:
            event_name: string, name of the event to get.
            timeout: float, the number of seconds to wait before giving up.

        Returns:
            SnippetEvent, the oldest entry of the specified event.

        Raises:
            Error: If the specified timeout is longer than the max timeout
                   supported.
            TimeoutError: The expected event does not occur within time limit.
        """
        if timeout:
            if timeout > MAX_TIMEOUT:
                raise Error(
                    'Specified timeout %s is longer than max timeout %s.' %
                    (timeout, MAX_TIMEOUT))
            timeout *= 1000  # convert to milliseconds for java side
        try:
            raw_event = self._event_client.eventWaitAndGet(
                self._id, event_name, timeout)
        except Exception as e:
            if 'EventSnippetException: timeout.' in str(e):
                raise TimeoutError(
                    'Timed out after waiting %ss for event "%s" triggered by'
                    ' %s (%s).' %
                    (timeout, event_name, self._method_name, self._id))
            raise
        return snippet_event.from_dict(raw_event)
Esempio n. 2
0
    def getAll(self, event_name):
        """Gets all the events of a certain name that have been received so
        far. This is a non-blocking call.

        Args:
            callback_id: The id of the callback.
            event_name: string, the name of the event to get.

        Returns:
            A list of SnippetEvent, each representing an event from the Java
            side.
        """
        raw_events = self._event_client.eventGetAll(self._id, event_name)
        return [snippet_event.from_dict(msg) for msg in raw_events]