Comparing version 0.2.2 to 0.2.4
99
index.js
@@ -31,3 +31,3 @@ // Copyright 2013 The Obvious Corporation | ||
* + Safe creation after dropping | ||
* + More Error checking | ||
* + Mock service for better testing. | ||
* ? StreamNoDelay configuration | ||
@@ -37,3 +37,7 @@ * | ||
* | ||
* debug: [false] Emit debug information | ||
* debug [false] Emit debug information | ||
* maxConnectionAttempts [0] The number of times to try reconnecting. 0 for infinite. | ||
* reconnectDelay [160] The additional time in ms between each reconnect retry. | ||
* maxErrors [0] The number of internal errors received from bloomd after which time | ||
* the service is marked as unavailable. 0 for infinite. | ||
* | ||
@@ -63,2 +67,6 @@ * @param {Object} stream | ||
// Error handling | ||
this.maxErrors = options.maxErrors || 0 | ||
this.errors = 0 | ||
var self = this | ||
@@ -112,4 +120,5 @@ | ||
* node-bloomd automatically attempts to connect or reconnect to the bloomd | ||
* server. However, if a connectTimeout option is specified, node-bloomd | ||
* eventually gives up. This method allows long running processes to request | ||
* server. However, if a connectTimeout option is specified, or if the | ||
* maximum number of internal errors is reached, node-bloomd eventually | ||
* gives up. This method allows long running processes to request | ||
* a reconnection in that eventuality. | ||
@@ -131,2 +140,3 @@ * | ||
this.connectionAttempts = 0 | ||
this.errors = 0 | ||
this._reconnect() | ||
@@ -152,3 +162,3 @@ } | ||
* | ||
* prob [0.0001] - The desired probability of false positives. | ||
* prob [0.0001] - The desired probability of false positives. | ||
* capacity [100000] - The required initial capacity of the filter. | ||
@@ -389,38 +399,49 @@ * in_memory [0] - Whether the filter should exist only in memory, with no disk backing. | ||
try { | ||
switch (command.responseType) { | ||
case responseTypes.BOOL: | ||
data = ResponseParser.parseBool(response) | ||
break | ||
if (ResponseParser.isError(response)) { | ||
this.errors++ | ||
if (this.maxErrors && (this.errors >= this.maxErrors)) { | ||
return this._unavailable() | ||
} | ||
error = new Error('Bloomd Internal Error') | ||
} else { | ||
if (this.errors > 0) { | ||
this.errors-- | ||
} | ||
try { | ||
switch (command.responseType) { | ||
case responseTypes.BOOL: | ||
data = ResponseParser.parseBool(response) | ||
break | ||
case responseTypes.BOOL_LIST: | ||
data = ResponseParser.parseBoolList(response, command.arguments.slice(2)) | ||
break | ||
case responseTypes.BOOL_LIST: | ||
data = ResponseParser.parseBoolList(response, command.arguments.slice(2)) | ||
break | ||
case responseTypes.FILTER_LIST: | ||
data = ResponseParser.parseFilterList(response) | ||
break | ||
case responseTypes.FILTER_LIST: | ||
data = ResponseParser.parseFilterList(response) | ||
break | ||
case responseTypes.CONFIRMATION: | ||
data = ResponseParser.parseConfirmation(response) | ||
break | ||
case responseTypes.CONFIRMATION: | ||
data = ResponseParser.parseConfirmation(response) | ||
break | ||
case responseTypes.CREATE_CONFIRMATION: | ||
data = ResponseParser.parseCreateConfirmation(response) | ||
break | ||
case responseTypes.CREATE_CONFIRMATION: | ||
data = ResponseParser.parseCreateConfirmation(response) | ||
break | ||
case responseTypes.DROP_CONFIRMATION: | ||
data = ResponseParser.parseDropConfirmation(response) | ||
break | ||
case responseTypes.DROP_CONFIRMATION: | ||
data = ResponseParser.parseDropConfirmation(response) | ||
break | ||
case responseTypes.INFO: | ||
data = ResponseParser.parseInfo(response, command.filterName) | ||
break | ||
case responseTypes.INFO: | ||
data = ResponseParser.parseInfo(response, command.filterName) | ||
break | ||
default: | ||
throw new Error('Unknown response type: ' + command.responseType) | ||
break | ||
default: | ||
throw new Error('Unknown response type: ' + command.responseType) | ||
break | ||
} | ||
} catch (err) { | ||
error = command.error || err | ||
} | ||
} catch (err) { | ||
error = command.error || err | ||
} | ||
@@ -430,2 +451,5 @@ | ||
if (command.callback) { | ||
if (error) { | ||
error.command = command.arguments | ||
} | ||
command.callback(error, data) | ||
@@ -480,4 +504,2 @@ } | ||
* Attempts to reconnect to the underlying stream. | ||
* | ||
* | ||
*/ | ||
@@ -517,3 +539,2 @@ BloomClient.prototype._reconnect = function () { | ||
this.reconnector.unref() | ||
} | ||
@@ -606,6 +627,4 @@ | ||
* | ||
* @param {string} commandName | ||
* @param {Array} args | ||
* @param {string} responseType one of ResponseParser.responseTypes | ||
* @param {Function} callback | ||
* @param {Object} command | ||
* @param {boolean} clearing | ||
*/ | ||
@@ -612,0 +631,0 @@ BloomClient.prototype._handle = function (command, clearing) { |
@@ -110,2 +110,12 @@ // Copyright 2013 The Obvious Corporation | ||
/** | ||
* Detects an internal error from bloomd. | ||
* | ||
* @param {string} data | ||
* @return {bool} | ||
*/ | ||
ResponseParser.isError = function (data) { | ||
return 'Internal Error' === data | ||
} | ||
/** | ||
* Parses a Yes/No response from bloomd into a boolean. | ||
@@ -112,0 +122,0 @@ * |
{ | ||
"name": "bloomd" | ||
, "description": "NodeJS Driver for BloomD" | ||
, "version": "0.2.2" | ||
, "version": "0.2.4" | ||
, "homepage": "https://github.com/obvious/node-bloomd" | ||
@@ -6,0 +6,0 @@ , "authors": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1378
2555007
9