Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- # # Copyright (C) 2007-2010 Andrew Resch <andrewresch@gmail.com> # # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with # the additional special exception to link portions of this program with the OpenSSL library. # See LICENSE for more details. #
""" Component objects are singletons managed by the :class:`ComponentRegistry`. When a new Component object is instantiated, it will be automatically registered with the :class:`ComponentRegistry`.
The ComponentRegistry has the ability to start, stop, pause and shutdown the components registered with it.
**Events:**
**start()** - This method is called when the client has connected to a Deluge core.
**stop()** - This method is called when the client has disconnected from a Deluge core.
**update()** - This method is called every 1 second by default while the Componented is in a *Started* state. The interval can be specified during instantiation. The update() timer can be paused by instructing the :class:`ComponentRegistry` to pause this Component.
**shutdown()** - This method is called when the client is exiting. If the Component is in a "Started" state when this is called, a call to stop() will be issued prior to shutdown().
**States:**
A Component can be in one of these 5 states.
**Started** - The Component has been started by the :class:`ComponentRegistry` and will have it's update timer started.
**Starting** - The Component has had it's start method called, but it hasn't fully started yet.
**Stopped** - The Component has either been stopped or has yet to be started.
**Stopping** - The Component has had it's stop method called, but it hasn't fully stopped yet.
**Paused** - The Component has had it's update timer stopped, but will still be considered in a Started state.
"""
self._component_state = "Stopped" self._component_starting_deferred = None log.error(result) return result
else: d = maybeDeferred(on_start, None) else: d = fail("Cannot start a component not in a Stopped state!")
self._component_state = "Started" self._component_stopping_deferred = None log.error(result) return result
else: d = maybeDeferred(on_stop, None)
else: d = succeed(None) elif self._component_state == "Paused": d = succeed(None) else: d = fail("Cannot pause a component in a non-Started state!")
else: d = fail("Component cannot be resumed from a non-Paused state!")
return succeed(None)
""" The ComponentRegistry holds a list of currently registered :class:`Component` objects. It is used to manage the Components by starting, stopping, pausing and shutting them down. """ # Stores all of the components that are dependent on a particular component
""" Registers a component object with the registry. This is done automatically when a Component object is instantiated.
:param obj: the Component object :type obj: object
:raises ComponentAlreadyRegistered: if a component with the same name is already registered.
""" "Component already registered with name %s" % name)
""" Deregisters a component from the registry. A stop will be issued to the component prior to deregistering it.
:param obj: the Component object :type obj: object
"""
else:
""" Starts Components that are currently in a Stopped state and their dependencies. If *names* is specified, will only start those Components and their dependencies and if not it will start all registered components.
:param names: a list of Components to start :type names: list
:returns: a Deferred object that will fire once all Components have been sucessfully started :rtype: twisted.internet.defer.Deferred
""" # Start all the components if names is empty names = [names]
# This component has depends, so we need to start them first. else:
""" Stops Components that are currently not in a Stopped state. If *names* is specified, then it will only stop those Components, and if not it will stop all the registered Components.
:param names: a list of Components to start :type names: list
:returns: a Deferred object that will fire once all Components have been sucessfully stopped :rtype: twisted.internet.defer.Deferred
""" names = [names]
# If other components depend on this component, stop them first else:
""" Pauses Components that are currently in a Started state. If *names* is specified, then it will only pause those Components, and if not it will pause all the registered Components.
:param names: a list of Components to pause :type names: list
:returns: a Deferred object that will fire once all Components have been sucessfully paused :rtype: twisted.internet.defer.Deferred
""" names = self.components.keys()
""" Resumes Components that are currently in a Paused state. If *names* is specified, then it will only resume those Components, and if not it will resume all the registered Components.
:param names: a list of Components to resume :type names: list
:returns: a Deferred object that will fire once all Components have been successfully resumed :rtype: twisted.internet.defer.Deferred
""" names = self.components.keys()
""" Shutdowns all Components regardless of state. This will call :meth:`stop` on call the components prior to shutting down. This should be called when the program is exiting to ensure all Components have a chance to properly shutdown.
:returns: a Deferred object that will fire once all Components have been successfully shut down :rtype: twisted.internet.defer.Deferred
"""
""" Updates all Components that are in a Started state.
""" for component in self.components.items(): component.update()
""" Return a reference to a component.
:param name: the Component name to get :type name: string
:returns: the Component object :rtype: object
:raises KeyError: if the Component does not exist
""" |