5.5.1. vlcp.server.module¶
Note
This document is generated from the source file.
Created on 2015/9/30/
author: | hubo |
---|
-
class
vlcp.server.module.
Module
(server)¶ A functional part which can be loaded or unloaded dynamically
-
__init__
(server)¶ Constructor
-
changestate
(state, container)¶ Change the current load state.
-
createAPI
(*apidefs)¶ Create API definitions on this module. This creates a ModuleAPIHandler and register these apidefs to it.
Parameters: *apidefs – should be return values of api() or publicapi() functions.
-
getServiceName
()¶ Return the targetname (or servicename) for this module
-
load
(container)¶ Load module
-
unload
(container, force=False)¶ Unload module
-
-
class
vlcp.server.module.
ModuleAPICall
(*args, **kwargs)¶
-
exception
vlcp.server.module.
ModuleAPICallTimeoutException
¶
-
class
vlcp.server.module.
ModuleAPIHandler
(moduleinst, apidefs=None, allowdiscover=True, rejectunknown=True)¶ API Handler for modules
-
__init__
(moduleinst, apidefs=None, allowdiscover=True, rejectunknown=True)¶ Create the routine container.
Parameters: - scheduler – The scheduler. This must be set; if None is used, it must be set with container.bind(scheduler) before using.
- daemon – If daemon = True, the main routine container.main is set to be a daemon routine. A daemon routine does not stop the scheduler from quitting; if all non-daemon routines are quit, the scheduler stops.
-
close
()¶ Same as terminate()
-
discover
(details=False)¶ Discover API definitions. Set details=true to show details
-
registerAPI
(name, handler, container=None, discoverinfo=None, criteria=None)¶ Append new API to this handler
-
registerAPIs
(apidefs)¶ API definition is in format: (name, handler, container, discoverinfo)
if the handler is a generator, container should be specified handler should accept two arguments:
def handler(name, params): ...
name is the method name, params is a dictionary contains the parameters.
the handler can either return the result directly, or be a generator (async-api), and write the result to container.retvalue on exit. e.g:
('method1', self.method1), # method1 directly returns the result ('method2', self.method2, self) # method2 is an async-api
Use api() to automatically generate API definitions.
-
start
(asyncStart=False)¶ Start container.main as the main routine.
Parameters: asyncStart – if True, start the routine in background. By default, the routine starts in foreground, which means it is executed to the first yield statement before returning. If the started routine raises an exception, the exception is re-raised to the caller of start
-
unregisterAPI
(name)¶ Remove an API from this handler
-
-
class
vlcp.server.module.
ModuleAPIReply
(*args, **kwargs)¶
-
exception
vlcp.server.module.
ModuleLoadException
¶ Raised when module loading failed.
-
class
vlcp.server.module.
ModuleLoadStateChanged
(*args, **kwargs)¶
-
class
vlcp.server.module.
ModuleLoader
(server)¶ Module loader to load modules. The server object creates this instance automatically, usually you can retrieve the pre-created object from server.moduleloader
-
__init__
(server)¶ Create the routine container.
Parameters: - scheduler – The scheduler. This must be set; if None is used, it must be set with container.bind(scheduler) before using.
- daemon – If daemon = True, the main routine container.main is set to be a daemon routine. A daemon routine does not stop the scheduler from quitting; if all non-daemon routines are quit, the scheduler stops.
-
getModuleByName
(targetname)¶ Return the module instance for a target name.
-
loadByPath
(path)¶ Load a module by full path. If there are dependencies, they are also loaded.
-
loadmodule
(module)¶ Load a module class. Need delegate to call from other containers.
-
main
()¶ The main routine method, should be rewritten to a generator method
-
reloadModules
(pathlist)¶ Reload modules with a full path in the pathlist
-
unloadByPath
(path)¶ Unload a module by full path. Dependencies are automatically unloaded if they are marked to be services.
-
unloadmodule
(module, ignoreDependencies=False)¶ Unload a module class. Need delegate to call from other containers.
-
-
class
vlcp.server.module.
ModuleNotification
(*args, **kwargs)¶
-
vlcp.server.module.
api
(func, container=None, criteria=None)¶ Return an API def for a generic function
Parameters: - func – a function or bounded method
- container – if None, this is used as a synchronous method, the return value of the method is used for the return value. If not None, this is used as an asynchronous method, the return value should be a generator, and it is executed in container as a routine. The return value should be set to container.retvalue.
- criteria – An extra function used to test whether this function should process the API. This allows multiple API definitions to use the same API method name.
-
vlcp.server.module.
callAPI
(container, targetname, name, params={}, timeout=120.0)¶ Call module API targetname/name with parameters. The return value is stored at container.retvalue.
Parameters: - targetname – module targetname. Usually the lower-cased name of the module class, or ‘public’ for public APIs.
- name – method name
- params – module API parameters, should be a dictionary of {parameter: value}
- timeout – raise an exception if the API call is not returned for a long time
-
vlcp.server.module.
depend
(*args)¶ Decorator to declare dependencies to other modules. Recommended usage is:
import other_module @depend(other_module.ModuleClass) class MyModule(Module): ...
Parameters: *args – depended module classes.
-
vlcp.server.module.
proxy
(name, default=None)¶ Create a proxy module. A proxy module has a default implementation, but can be redirected to other implementations with configurations. Other modules can depend on proxy modules.
-
vlcp.server.module.
publicapi
(func, container=None, criteria=None)¶ Create an API def for public API processing. Target name of a public API is ‘public’.
Parameters: - func – a function or bounded method
- container – if None, this is used as a synchronous method, the return value of the method is used for the return value. If not None, this is used as an asynchronous method, the return value should be a generator, and it is executed in container as a routine. The return value should be set to container.retvalue.
- criteria – An extra function used to test whether this function should process the API. This allows multiple API definitions to use the same API method name.