API Reference
This page contains auto-generated API documentation.
IFBroker
- class IFBroker(binding='*', manager=None)
IFBroker is the center server of InteractionFree.
- Parameters:
binding (str) – The address to bind. Default is
'*'. The full address is expected to be in the format of'tcp://ip:port', whiletcp://can be omitted, and the default port is1061.manager (Manager) – The manager to use. If not given, a default manager will be created.
- close()
Close the server. All the connections will be closed.
- startWebSocket(port, path, sslOptions=None)
Start a WebSocket server on the given port, with the given path. If sslOptions is given, the WebSocket server will use SSL.
- Parameters:
port (int) – The port to listen.
path (str) – The path to listen.
sslOptions (dict) – The SSL options. If not given, the WebSocket server will not use SSL. sslOptions should be a dict with two keys:
'certfile'and'keyfile'.
- Returns:
None
IFWorker
- class IFWorker(endpoint, serviceName=None, serviceObject=None, interfaces=None, blocking=True, timeout=None, force=False)
InteractionFreePy Worker class.
- asyncInvoker(target=None)
Create an async invoker.
- Args:
target (str): The target of the invoker.
- Returns:
AsyncRemoteObject: The invoker.
- asynchronousInvoker(target=None)
Create a non-blocking invoker.
- Args:
target (str): The target of the invoker.
- Returns:
AsyncRemoteObject: The invoker.
- Deprecated:
This method is deprecated. Remove it in the future. Use asyncInvoker instead.
- bindService(serviceName, serviceObject, interfaces=None)
Bind the worker as a service.
- Args:
serviceName (str): The name of the service. serviceObject (object): The object to be bind. interfaces (list): The interfaces of the service.
- Returns:
None
- blockingInvoker(target=None, timeout=None)
Create a blocking invoker.
- Args:
target (str): The target of the invoker.
- Returns:
DynamicRemoteObject: The invoker.
- close()
Close the worker. If the worker is a service, it will be unregistered.
- Returns:
None
- send(msg)
Send a message by the worker.
- Args:
msg (Message): The message to send.
- Returns:
InvokeFuture: The future of the sending.
- classmethod start()
- toMessageInvoker(target=None)
Create a invoker that generate Message objects only, without sending.
- Args:
target (str): The target of the invoker.
- Returns:
DynamicRemoteObject: The invoker.
Manager
- class Manager(broker=None)
A service to manager workers of IFBroker. It can register workers as services, and distribute messages to workers. The functions below are also the default functions provided by the IFBroker. You can override them to customize the behavior of the IFBroker. Note: when invoking the functions by
worker.function(argv), the parametersourcePointwill be passed automatically. You don’t need to pass it manually.- getAddressOfService(sourcePoint, serviceName)
Get the address of a service.
- Args:
sourcePoint (str): The source point of the invoker. Not used. serviceName (str): The name of the service.
- Returns:
str: The address of the service.
- heartbeat(sourcePoint)
Sending heartbeat package to the IFBroker.
- Args:
sourcePoint (str): The source point of the invoker.
- Returns:
bool: True if the worker is registered as a service.
- listServiceMeta(sourcePoint)
List all service with meta informations.
- Args:
sourcePoint (str): The source point of the invoker. Not used.
- Returns:
list: A list of service meta informations.
- listServiceNames(sourcePoint)
List all service names.
- Args:
sourcePoint (str): The source point of the invoker. Not used.
- protocol(sourcePoint)
Get the protocol of IFBroker.
- Args:
sourcePoint (str): The source point of the invoker. Not used.
- Returns:
str: The protocol of IFBroker. Default is
b'IF1'.
- registerAsService(sourcePoint, name, interfaces=None, force=False)
Register a worker as a service.
- Args:
sourcePoint (str): The source point of the invoker. name (str): The name of the service. interfaces (list): The interfaces of the service. force (bool): If True, the service will be registered even if the name is occupied. The old service will be replaced.
- statistics(sourcePoint, isReceived, message)
Get the statistics information of the IFBroker.
- Args:
sourcePoint (str): The source point of the invoker. isReceived (bool): If True, the message is received. message (list): The message.
- Returns:
list: A list of statistics information.
- time(sourcePoint)
- unregister(sourcePoint)
Unregister a worker.
- Args:
sourcePoint (str): The source point of the invoker.