changed to syncMethod
This commit is contained in:
parent
e5f16812b3
commit
b6fe47efe1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -58,6 +58,9 @@ adaptConnector = function(connector, engine, HB, execution_listener) {
|
|||||||
connector.getStateVector = getStateVector;
|
connector.getStateVector = getStateVector;
|
||||||
connector.getHB = getHB;
|
connector.getHB = getHB;
|
||||||
connector.applyHB = applyHB;
|
connector.applyHB = applyHB;
|
||||||
|
if (connector.receive_handlers == null) {
|
||||||
|
connector.receive_handlers = [];
|
||||||
|
}
|
||||||
return connector.receive_handlers.push(function(sender, op) {
|
return connector.receive_handlers.push(function(sender, op) {
|
||||||
if (op.uid.creator !== HB.getUserId()) {
|
if (op.uid.creator !== HB.getUserId()) {
|
||||||
return engine.applyOp(op);
|
return engine.applyOp(op);
|
||||||
|
@ -16,7 +16,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
req("syncMode", ["syncAll", "master-slave"]);
|
req("syncMethod", ["syncAll", "master-slave"]);
|
||||||
req("role", ["master", "slave"]);
|
req("role", ["master", "slave"]);
|
||||||
req("user_id");
|
req("user_id");
|
||||||
if (typeof this.on_user_id_set === "function") {
|
if (typeof this.on_user_id_set === "function") {
|
||||||
@ -28,11 +28,13 @@ module.exports = {
|
|||||||
this.perform_send_again = true;
|
this.perform_send_again = true;
|
||||||
}
|
}
|
||||||
if (this.role === "master") {
|
if (this.role === "master") {
|
||||||
this.syncMode = "syncAll";
|
this.syncMethod = "syncAll";
|
||||||
}
|
}
|
||||||
this.is_synced = false;
|
this.is_synced = false;
|
||||||
this.connections = {};
|
this.connections = {};
|
||||||
this.receive_handlers = [];
|
if (this.receive_handlers == null) {
|
||||||
|
this.receive_handlers = [];
|
||||||
|
}
|
||||||
this.is_bound_to_y = false;
|
this.is_bound_to_y = false;
|
||||||
this.connections = {};
|
this.connections = {};
|
||||||
this.current_sync_target = null;
|
this.current_sync_target = null;
|
||||||
@ -47,7 +49,7 @@ module.exports = {
|
|||||||
findNewSyncTarget: function() {
|
findNewSyncTarget: function() {
|
||||||
var c, user, _ref;
|
var c, user, _ref;
|
||||||
this.current_sync_target = null;
|
this.current_sync_target = null;
|
||||||
if (this.syncMode === "syncAll") {
|
if (this.syncMethod === "syncAll") {
|
||||||
_ref = this.connections;
|
_ref = this.connections;
|
||||||
for (user in _ref) {
|
for (user in _ref) {
|
||||||
c = _ref[user];
|
c = _ref[user];
|
||||||
@ -75,8 +77,8 @@ module.exports = {
|
|||||||
_base[user] = {};
|
_base[user] = {};
|
||||||
}
|
}
|
||||||
this.connections[user].is_synced = false;
|
this.connections[user].is_synced = false;
|
||||||
if ((!this.is_synced) || this.syncMode === "syncAll") {
|
if ((!this.is_synced) || this.syncMethod === "syncAll") {
|
||||||
if (this.syncMode === "syncAll") {
|
if (this.syncMethod === "syncAll") {
|
||||||
return this.performSync(user);
|
return this.performSync(user);
|
||||||
} else if (role === "master") {
|
} else if (role === "master") {
|
||||||
return this.performSyncWithMaster(user);
|
return this.performSyncWithMaster(user);
|
||||||
@ -248,7 +250,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
} else if (res.sync_step === "applyHB") {
|
} else if (res.sync_step === "applyHB") {
|
||||||
this.applyHB(res.data, sender === this.current_sync_target);
|
this.applyHB(res.data, sender === this.current_sync_target);
|
||||||
if ((this.syncMode === "syncAll" || (res.sent_again != null)) && (!this.is_synced) && (this.current_sync_target === sender)) {
|
if ((this.syncMethod === "syncAll" || (res.sent_again != null)) && (!this.is_synced) && (this.current_sync_target === sender)) {
|
||||||
this.connections[sender].is_synced = true;
|
this.connections[sender].is_synced = true;
|
||||||
return this.findNewSyncTarget();
|
return this.findNewSyncTarget();
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -53,6 +53,7 @@ adaptConnector = (connector, engine, HB, execution_listener)->
|
|||||||
connector.getHB = getHB
|
connector.getHB = getHB
|
||||||
connector.applyHB = applyHB
|
connector.applyHB = applyHB
|
||||||
|
|
||||||
|
connector.receive_handlers ?= []
|
||||||
connector.receive_handlers.push (sender, op)->
|
connector.receive_handlers.push (sender, op)->
|
||||||
if op.uid.creator isnt HB.getUserId()
|
if op.uid.creator isnt HB.getUserId()
|
||||||
engine.applyOp op
|
engine.applyOp op
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
module.exports =
|
module.exports =
|
||||||
#
|
#
|
||||||
# @params new Connector(options)
|
# @params new Connector(options)
|
||||||
# @param options.syncMode {String} is either "syncAll" or "master-slave".
|
# @param options.syncMethod {String} is either "syncAll" or "master-slave".
|
||||||
# @param options.role {String} The role of this client
|
# @param options.role {String} The role of this client
|
||||||
# (slave or master (only used when syncMode is master-slave))
|
# (slave or master (only used when syncMethod is master-slave))
|
||||||
# @param options.perform_send_again {Boolean} Whetehr to whether to resend the HB after some time period. This reduces sync errors, but has some overhead (optional)
|
# @param options.perform_send_again {Boolean} Whetehr to whether to resend the HB after some time period. This reduces sync errors, but has some overhead (optional)
|
||||||
#
|
#
|
||||||
init: (options)->
|
init: (options)->
|
||||||
@ -17,7 +17,7 @@ module.exports =
|
|||||||
else
|
else
|
||||||
throw new Error "You must specify "+name+", when initializing the Connector!"
|
throw new Error "You must specify "+name+", when initializing the Connector!"
|
||||||
|
|
||||||
req "syncMode", ["syncAll", "master-slave"]
|
req "syncMethod", ["syncAll", "master-slave"]
|
||||||
req "role", ["master", "slave"]
|
req "role", ["master", "slave"]
|
||||||
req "user_id"
|
req "user_id"
|
||||||
@on_user_id_set?(@user_id)
|
@on_user_id_set?(@user_id)
|
||||||
@ -31,14 +31,14 @@ module.exports =
|
|||||||
|
|
||||||
# A Master should sync with everyone! TODO: really? - for now its safer this way!
|
# A Master should sync with everyone! TODO: really? - for now its safer this way!
|
||||||
if @role is "master"
|
if @role is "master"
|
||||||
@syncMode = "syncAll"
|
@syncMethod = "syncAll"
|
||||||
|
|
||||||
# is set to true when this is synced with all other connections
|
# is set to true when this is synced with all other connections
|
||||||
@is_synced = false
|
@is_synced = false
|
||||||
# Peerjs Connections: key: conn-id, value: object
|
# Peerjs Connections: key: conn-id, value: object
|
||||||
@connections = {}
|
@connections = {}
|
||||||
# List of functions that shall process incoming data
|
# List of functions that shall process incoming data
|
||||||
@receive_handlers = []
|
@receive_handlers ?= []
|
||||||
|
|
||||||
# whether this instance is bound to any y instance
|
# whether this instance is bound to any y instance
|
||||||
@is_bound_to_y = false
|
@is_bound_to_y = false
|
||||||
@ -54,7 +54,7 @@ module.exports =
|
|||||||
|
|
||||||
findNewSyncTarget: ()->
|
findNewSyncTarget: ()->
|
||||||
@current_sync_target = null
|
@current_sync_target = null
|
||||||
if @syncMode is "syncAll"
|
if @syncMethod is "syncAll"
|
||||||
for user, c of @connections
|
for user, c of @connections
|
||||||
if not c.is_synced
|
if not c.is_synced
|
||||||
@performSync user
|
@performSync user
|
||||||
@ -74,8 +74,8 @@ module.exports =
|
|||||||
@connections[user] ?= {}
|
@connections[user] ?= {}
|
||||||
@connections[user].is_synced = false
|
@connections[user].is_synced = false
|
||||||
|
|
||||||
if (not @is_synced) or @syncMode is "syncAll"
|
if (not @is_synced) or @syncMethod is "syncAll"
|
||||||
if @syncMode is "syncAll"
|
if @syncMethod is "syncAll"
|
||||||
@performSync user
|
@performSync user
|
||||||
else if role is "master"
|
else if role is "master"
|
||||||
# TODO: What if there are two masters? Prevent sending everything two times!
|
# TODO: What if there are two masters? Prevent sending everything two times!
|
||||||
@ -229,7 +229,7 @@ module.exports =
|
|||||||
else if res.sync_step is "applyHB"
|
else if res.sync_step is "applyHB"
|
||||||
@applyHB(res.data, sender is @current_sync_target)
|
@applyHB(res.data, sender is @current_sync_target)
|
||||||
|
|
||||||
if (@syncMode is "syncAll" or res.sent_again?) and (not @is_synced) and (@current_sync_target is sender)
|
if (@syncMethod is "syncAll" or res.sent_again?) and (not @is_synced) and (@current_sync_target is sender)
|
||||||
@connections[sender].is_synced = true
|
@connections[sender].is_synced = true
|
||||||
@findNewSyncTarget()
|
@findNewSyncTarget()
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user