'Creates a thread which will continuously check the changes
coming from other instances of Faraday. Return the thread on any
exception, of if self.stream is None.'

def continously_get_changes(self):

    def filter_changes(change, obj_type):
        local_changes = models.local_changes()
        cool_types = ('Host', 'Interface', 'Service', 'Vulnerability', 'VulnerabilityWeb', 'CommandRunInfomation', 'Cred', 'Note')
        if ((not change.get('changes')) or (not change['changes'][0].get('rev'))):
            return None
        is_deleted = bool(change.get('deleted'))
        if ((obj_type is None) and (not is_deleted)):
            return None
        if ((obj_type is not None) and (obj_type not in cool_types)):
            return None
        if (change['changes'][0]['rev'] == local_changes.get(change['id'])):
            del local_changes[change['id']]
            return None
        if ((not change) or change.get('last_seq')):
            return None
        if change['id'].startswith('_design'):
            return None
        return change
    def notification_dispatcher(obj_id, obj_type, obj_name, deleted, revision):
        if deleted:
            (obj_name, obj_type) = self.get_deleted_object_name_and_type(obj_id)
            notification_center.deleteObject(obj_id)
            update = False
        else:
            is_new_object = (revision.split('-')[0] == '1')
            obj = self.get_object(obj_type, obj_id)
            if obj:
                if is_new_object:
                    notification_center.addObject(obj)
                    update = False
                else:
                    notification_center.editObject(obj)
                    update = True
            else:
                update = False
        for var in [var for var in [obj_id, obj_type, obj_name] if (var is None)]:
            var = ''
        notification_center.changeFromInstance(obj_id, obj_type, obj_name, deleted=deleted, update=update)
    def get_changes():
        if self.stream:
            try:
                for (change, obj_type, obj_name) in self.stream:
                    with self.changes_lock:
                        change = filter_changes(change, obj_type)
                    if change:
                        deleted = bool(change.get('deleted'))
                        obj_id = change.get('id')
                        revision = change.get('changes')[(-1)].get('rev')
                        notification_dispatcher(obj_id, obj_type, obj_name, deleted, revision)
            except server_io_exceptions.ChangesStreamStoppedAbruptly:
                notification_center.WorkspaceProblem()
                return False
        else:
            return False
    get_changes_thread = threading.Thread(target=get_changes)
    get_changes_thread.daemon = True
    get_changes_thread.start()
