Home Reference Source
public class | source

FogletProtocol

FogletProtocol represent an abstract protocol. A Protocol is a a set of behaviours used to interact with others foglet that shares the same protocol.

Constructor Summary

Public Constructor
public

constructor(name: string, foglet: Foglet, args: ...*)

Constructor

Member Summary

Private Members
private
private

_foglet: *

private

_name: *

Method Summary

Private Methods
private

Handler which reject answers to messages

private

Handler which resolve answers to messages

private

_handleBroadcast(senderID: string, msg: Object): void

Handle the reception of a broadcast message

private

_handleUnicast(senderID: string, msg: Object): void

Handle the reception of an unicast message

private

_initHandlers(): void

Initialize the reception of messages from unicast & broadcast channels

private

_sendBroadcast(msg: *): void

Helper to send a broadcast message

private

_sendUnicast(id: string, msg: *, resolve: function, reject: function): void

Helper to send a unicast message

Public Constructors

public constructor(name: string, foglet: Foglet, args: ...*) source

Constructor

Params:

NameTypeAttributeDescription
name string

The protocol's name

foglet Foglet

The Foglet instance used by the protocol to communicate

args ...*

Additional arguments passed down to the _init function

Private Members

private _answerQueue: * source

private _foglet: * source

private _name: * source

Private Methods

private _answerReject(id: string, msg: Object) source

Handler which reject answers to messages

Params:

NameTypeAttributeDescription
id string

Sender's id

msg Object

Answer received @return{void}

private _answerReply(id: string, msg: Object) source

Handler which resolve answers to messages

Params:

NameTypeAttributeDescription
id string

Sender's id

msg Object

Answer received @return{void}

private _handleBroadcast(senderID: string, msg: Object): void source

Handle the reception of a broadcast message

Params:

NameTypeAttributeDescription
senderID string

ID of the peer who send the message

msg Object

The message received

Return:

void

private _handleUnicast(senderID: string, msg: Object): void source

Handle the reception of an unicast message

Params:

NameTypeAttributeDescription
senderID string

ID of the peer who send the message

msg Object

The message received

Return:

void

private _initHandlers(): void source

Initialize the reception of messages from unicast & broadcast channels

Return:

void

private _sendBroadcast(msg: *): void source

Helper to send a broadcast message

Params:

NameTypeAttributeDescription
msg *

The message to send

Return:

void

private _sendUnicast(id: string, msg: *, resolve: function, reject: function): void source

Helper to send a unicast message

Params:

NameTypeAttributeDescription
id string

ID of the peer to which the message should be sent

msg *

The message to send

resolve function

Function used to resolve a related promise when an answer to the message is received

reject function

Function used to reject a related promise when an answer to the message is received

Return:

void