'This gets called when we have some new events we might want to
send out to other servers.'

@defer.inlineCallbacks
def notify_new_events(self, current_id):

    self._last_poked_id = max(current_id, self._last_poked_id)
    if self._is_processing:
        return
    try:
        self._is_processing = True
        while True:
            last_token = (yield self.store.get_federation_out_pos('events'))
            (next_token, events) = (yield self.store.get_all_new_events_stream(last_token, self._last_poked_id, limit=20))
            logger.debug('Handling    %s    ->    %s', last_token, next_token)
            if ((not events) and (next_token >= self._last_poked_id)):
                break
            for event in events:
                send_on_behalf_of = event.internal_metadata.get_send_on_behalf_of()
                is_mine = self.is_mine_id(event.event_id)
                if ((not is_mine) and (send_on_behalf_of is None)):
                    continue
                destinations = (yield self.state.get_current_hosts_in_room(event.room_id, latest_event_ids=[prev_id for (prev_id, _) in event.prev_events]))
                destinations = set(destinations)
                if (send_on_behalf_of is not None):
                    destinations.discard(send_on_behalf_of)
                logger.debug('Sending    %s    to    %r', event, destinations)
                self._send_pdu(event, destinations)
            (yield self.store.update_federation_out_pos('events', next_token))
    finally:
        self._is_processing = False
