Save events.

        Args:
            state_change_identifier: Id of the state change that generate these events.
            events: List of Event objects.
422738
def write_events(self, events):
        
        with self.write_lock, self.conn:
            self.conn.executemany(
                'INSERT INTO state_events('
                '   identifier, source_statechange_id, log_time, data'
                ') VALUES(?, ?, ?, ?)',
                events,
            )
793137
def get_snapshot_closest_to_state_change(
            self,
            state_change_identifier: int,
    ) -> Tuple[int, Any]:
        

        row = super().get_snapshot_closest_to_state_change(state_change_identifier)

        if row[1]:
            last_applied_state_change_id = row[0]
            snapshot_state = self.serializer.deserialize(row[1])
            result = (last_applied_state_change_id, snapshot_state)
        else:
            result = (0, None)

        return result
1058712
def _set_state(self, state):
        
        if state != self._association_state:
            self.__log_debug('- %s -> %s', self._association_state, state)
            self._association_state = state

        if state == self.State.ESTABLISHED:
            self.__state = 'connected'
            for channel in list(self._data_channels.values()):
                if channel.negotiated and channel.readyState != 'open':
                    channel._setReadyState('open')
            asyncio.ensure_future(self._data_channel_flush())
        elif state == self.State.CLOSED:
            self._t1_cancel()
            self._t2_cancel()
            self._t3_cancel()
            self.__state = 'closed'

            # close data channels
            for stream_id in list(self._data_channels.keys()):
                self._data_channel_closed(stream_id)

            # no more events will be emitted, so remove all event listeners
            # to facilitate garbage collection.
            self.remove_all_listeners()
732296
def _events(self):
        
        with self.app.events_lock:
            res = self.app.get_events()
        return serialize(res, True)
1239156
protected void notifyChangeListeners() {
        ChangeEvent e = new ChangeEvent(this);
        for (ChangeListener l : changeListeners) {
            l.stateChanged(e);
        }
    }
142408
def snapshot(self):
        
        with self._lock:
            current_state = self.state_manager.current_state
            state_change_id = self.state_change_id

            # otherwise no state change was dispatched
            if state_change_id:
                self.storage.write_state_snapshot(state_change_id, current_state)
914957
def register_updates(self, callback):
        """"""
        _LOGGER.debug("Registered callback for state: %s", self._stateName)
        self._observer_callbacks.append(callback)
539102
def :
    
    changes = True
    deletedStates = []
    while changes:
        changes = False
        for i in range(1, len(tempStates)):
            if i in deletedStates:
                continue
            for j in range(0, i):
                if j in deletedStates:
                    continue
                if sameState(tempStates[i], tempStates[j]):
                    deletedStates.append(i)
                    for k in range(0, len(tempStates)):
                        if k in deletedStates:
                            continue
                        for arc in tempStates[k][1]:
                            if arc[1] == i:
                                arc[1] = j
                    changes = True
                    break
    for stateIndex in deletedStates:
        tempStates[stateIndex] = None
    return tempStates
171422
def event(from_states=None, to_state=None):
    
    from_states_tuple = (from_states, ) if isinstance(from_states, State) else tuple(from_states or [])
    if not len(from_states_tuple) >= 1:
        raise ValueError()
    if not all(isinstance(state, State) for state in from_states_tuple):
        raise TypeError()
    if not isinstance(to_state, State):
        raise TypeError()

    def wrapper(wrapped):

        @functools.wraps(wrapped)
        def transition(instance, *a, **kw):
            if instance.current_state not in from_states_tuple:
                raise InvalidStateTransition()
            try:
                result = wrapped(instance, *a, **kw)
            except Exception as error:
                error_handlers = getattr(instance, '___pystatemachine_transition_failure_handlers', [])
                for error_handler in error_handlers:
                    error_handler(instance, wrapped, instance.current_state, to_state, error)
                if not error_handlers:
                    raise error
            else:
                StateInfo.set_current_state(instance, to_state)
                return result

        return transition

    return wrapper
293948
def change_state(identifier, state)
      params = {:freshmail_subscriber => identifier, :state => state}

      path = client.path_for(:change_state)
      make_post_request(path, params)
    end
847731
def when_change_raw(
        self,
        *,
        live: bool = False,
        timeout: float = None,
        identical_okay: bool = False,
        start_time: bool = None,
        count: int = None,
    ) -> StateWatcher:
        
        return StateWatcher(
            state=self,
            live=live,
            timeout=timeout,
            identical_okay=identical_okay,
            start_time=start_time,
            count=count,
        )
108821
protected IdleStateEvent newIdleStateEvent(IdleState state, boolean first) {
        switch (state) {
            case ALL_IDLE:
                return first ? IdleStateEvent.FIRST_ALL_IDLE_STATE_EVENT : IdleStateEvent.ALL_IDLE_STATE_EVENT;
            case READER_IDLE:
                return first ? IdleStateEvent.FIRST_READER_IDLE_STATE_EVENT : IdleStateEvent.READER_IDLE_STATE_EVENT;
            case WRITER_IDLE:
                return first ? IdleStateEvent.FIRST_WRITER_IDLE_STATE_EVENT : IdleStateEvent.WRITER_IDLE_STATE_EVENT;
            default:
                throw new IllegalArgumentException("Unhandled: state=" + state + ", first=" + first);
        }
    }
1143380
def SetEventTag(self, event_tag):
    
    event_identifier = event_tag.GetEventIdentifier()

    lookup_key = event_identifier.CopyToString()
    self._index[lookup_key] = event_tag.GetIdentifier()
941128
def AddEventData(self, event_data):
    
    self._RaiseIfNotWritable()

    event_data = self._PrepareAttributeContainer(event_data)

    identifier = event_data.GetIdentifier()
    lookup_key = identifier.CopyToString()
    self._event_data[lookup_key] = event_data
933966
def register(transition)
      event_type = transition.class.instance_variable_get(:@event_type)
      event_trigger_value = transition.event_trigger_value

      transition_map[event_type] ||= {}

      transitions =
        (transition_map[event_type][event_trigger_value] ||= [])
      transitions << transition

      transition
    end
28159
def initialize_state(self):
        
        if self.__hardware_source:
            self.__profile_changed_event_listener = self.__hardware_source.profile_changed_event.listen(self.__update_profile_index)
            self.__frame_parameters_changed_event_listener = self.__hardware_source.frame_parameters_changed_event.listen(self.__update_frame_parameters)
            self.__data_item_states_changed_event_listener = self.__hardware_source.data_item_states_changed_event.listen(self.__data_item_states_changed)
            self.__acquisition_state_changed_event_listener = self.__hardware_source.acquisition_state_changed_event.listen(self.__acquisition_state_changed)
            self.__log_messages_event_listener = self.__hardware_source.log_messages_event.listen(self.__log_messages)
        if self.on_display_name_changed:
            self.on_display_name_changed(self.display_name)
        if self.on_binning_values_changed:
            self.on_binning_values_changed(self.__hardware_source.binning_values)
        if self.on_monitor_button_state_changed:
            has_monitor = self.__hardware_source and self.__hardware_source.features.get("has_monitor", False)
            self.on_monitor_button_state_changed(has_monitor, has_monitor)
        self.__update_buttons()
        if self.on_profiles_changed:
            profile_items = self.__hardware_source.modes
            self.on_profiles_changed(profile_items)
            self.__update_profile_index(self.__hardware_source.selected_profile_index)
        if self.on_data_item_states_changed:
            self.on_data_item_states_changed(list())
706886
def initialize_state(self):
        
        if self.__hardware_source:
            self.__data_item_states_changed_event_listener = self.__hardware_source.data_item_states_changed_event.listen(self.__data_item_states_changed)
            self.__acquisition_state_changed_event_listener = self.__hardware_source.acquisition_state_changed_event.listen(self.__acquisition_state_changed)
        if self.on_display_name_changed:
            self.on_display_name_changed(self.display_name)
        self.__update_buttons()
        if self.on_data_item_states_changed:
            self.on_data_item_states_changed(list())