Exemple #1
0
    def initialize(self):
        if self.current_state(self.INITIAL):
            with self.action_lock:
                # Can only start a backend iff in the INITIAL state.
                Logging.log(
                    'Starting backend \'{0}\''.format(
                        self.current_backend_name), Logging.LOG_INFO)
                backend_info = self.possible_backends.get(
                    self.current_backend_name, {})
                backend_clazz = self.BACKEND_META.get(
                    backend_info.get('backend')
                    or Backend.NullHaskellBackend.backend_name())
                if backend_clazz is not None:
                    the_backend = backend_clazz(
                        self, **backend_info.get('options', {}))
                else:
                    the_backend = None

                if the_backend is not None:
                    self.state_startup(the_backend)
                    self.state_connect(the_backend)
                    self.state_active(the_backend)

                    if self.current_state(self.INITIAL):
                        # Something failed during startup, revert to the null backend
                        self.set_backend(Backend.NullHaskellBackend(self))
                    elif not self.current_state(self.ACTIVE):
                        state_str = self.STATES_TO_NAME.get(
                            self.state, str(self.state))
                        Logging.log(
                            'BackendManager: Invalid state after starting backend: {0}'
                            .format(state_str), Logging.LOG_ERROR)
Exemple #2
0
 def shutdown_backend(self, get_action_lock=True):
     '''Step through the backend shutdown process: disconnect (if active), stop backend (if disconnected). Backend
     manager's state should end up in INITIAL.
     '''
     # If the action lock was previously acquired, don't try to re-acquire it.
     got_lock = get_action_lock and self.action_lock.acquire()
     try:
         the_backend = BackendManager.ACTIVE_BACKEND
         self.set_backend(Backend.NullHaskellBackend(self))
         self.state_disconnect(the_backend)
         self.state_shutdown(the_backend)
         self.state_inactive()
     finally:
         if got_lock:
             self.action_lock.release()
Exemple #3
0
    def __init__(self):
        '''Initializes the backend manager.

        .. py:attribute:: state

        The :py:class:`BackendManager`'s current state.

        .. py:attribute:: state_lock

        Recursive lock to mediate access to :py:attr:`state`.

        .. py:attribute:: action_lock

        Hard lock to serialize backend life cycle actions. This lock is acquired while initializing and shutting down
        the backend.

        .. py:attribute:: src_inspector

        The source inspector object, :py:class:`Inspector`.

        .. py:attribute:: current_backend_name

        The name of the current backend. This starts out as the default backend's name, but can be changed to a different
        backend name.

        .. py:attribute:: possible_backends

        Filtered list of backend names. This is a subset of the *backends* settings, filtered on whether the backend's *type*
        is avaiable. For example, if *hsdev* is not installed (not available), then none of the *hsdev* backend names are
        possible (and not in this list).

        .. py:attribute:: project_cache

        A mapping between project names and files associated with each project.
        '''
        super().__init__()
        BackendManager.ACTIVE_BACKEND = Backend.NullHaskellBackend(self)
        self.state = self.INITIAL
        self.state_lock = threading.RLock()
        self.action_lock = threading.Lock()
        self.src_inspector = Inspector.Inspector(BackendManager.ACTIVE_BACKEND)
        self.current_backend_name = BackendManager.ACTIVE_BACKEND.backend_name(
        )
        self.possible_backends = {}
        self.project_cache = {}
 def __init__(self, view):
     super().__init__(view)
     self.candidates = None
     self.backend = Backend.NullHaskellBackend(BackendManager.BackendManager())