def METHOD_NAME(self, new_state, generation=None, existing_generation=None):
    with self._lock:
        if existing_generation is not None and self._generation != existing_generation:
            raise ConcurrentModificationError
        new_state = self._transform_state(new_state)
        if new_state != self._raw_state or (generation is not None and generation != self._generation):
            if generation is None:
                generation = make_random_token()
            self._raw_state = new_state
            self._wrapped_state = None
            self._generation = generation
            self._dispatch_changed_callbacks()
        return self._generation