import ServiceBuilder from 'foglet-core/src/fprotocol/builders/service-builder.js'
ServiceBuilder
A ServiceBuilder build a service into the prototype of a protocol, including the service method, the handler & the possible hooks.
Constructor Summary
Public Constructor | ||
public |
constructor(serviceName: string) Constructor |
Member Summary
Public Members | ||
public get |
Helper used to define hooks executed after a message is sent/received. |
|
public get |
Helper used to define hooks executed before a message is sent/received. |
|
public get |
Helper used to define the type of the service. |
|
public get |
Helper used to define the callback invoked when a message is received for this service. |
Private Members | ||
private |
_afterHooks: {"send": *, "receive": *} |
|
private |
_beforeHooks: {"send": *, "receive": *} |
|
private |
_builder: * |
|
private |
_handler: * |
|
private |
_serviceName: * |
Method Summary
Public Methods | ||
public |
Apply the builder on a protocol subclass to build the service in it. |
Private Methods | ||
private |
Validate the builder |
Public Constructors
Public Members
public get after: Object: {"send": *, "receive": *} source
Helper used to define hooks executed after a message is sent/received.
Example:
// define a hook after a message is sent
mysService.after.send(msg => console.log(`You just send ${msg}`));
// define a hook after a message is received
mysService.after.receive(msg => console.log(`You juste finished processing ${msg}`));
public get before: Object: {"send": *, "receive": *} source
Helper used to define hooks executed before a message is sent/received.
Example:
// define a hook before a message is sent
mysService.before.send(msg => console.log(`You are going to send ${msg}`));
// define a hook before a message is received
mysService.before.receive(msg => console.log(`You are about to receive ${msg}`));
public get is: Object: {"unicast": *, "broadcast": *} source
Helper used to define the type of the service.
Example:
// define an unicast service
myService.is.unicast();
// define a broadcast service
myService.is.broadcast();
public get on: Object: {"receive": *} source
Helper used to define the callback invoked when a message is received for this service.
Example:
myService.on.receive((msg, reply, reject) => {
if (msg.number % 2 === 0)
reply('You send an even number');
else
reject('You send a odd number!');
});
Private Members
private _afterHooks: {"send": *, "receive": *} source
private _beforeHooks: {"send": *, "receive": *} source
private _builder: * source
private _handler: * source
private _serviceName: * source
Public Methods
public apply(protocol: function): void source
Apply the builder on a protocol subclass to build the service in it. The builder must have been properly configured before calling this function, otherwise an error will be thrown. A valid builder has a type and a handler set.
Params:
Name | Type | Attribute | Description |
protocol | function | The protocol class |
Return:
void |