[Groonga-commit] droonga/express-droonga at 7a3670d [master] Operate given timeout as a part of envelope

Back to archive index

YUKI Hiroshi null+****@clear*****
Mon Apr 20 16:22:05 JST 2015


YUKI Hiroshi	2015-04-20 16:22:05 +0900 (Mon, 20 Apr 2015)

  New Revision: 7a3670dedf50e75d77bbf4373697a9829904204f
  https://github.com/droonga/express-droonga/commit/7a3670dedf50e75d77bbf4373697a9829904204f

  Message:
    Operate given timeout as a part of envelope

  Modified files:
    lib/adapter/api/droonga.js
    lib/adapter/wrapper.js
    lib/droonga-protocol/connection.js

  Modified: lib/adapter/api/droonga.js (+12 -6)
===================================================================
--- lib/adapter/api/droonga.js    2015-04-20 16:14:03 +0900 (36b5395)
+++ lib/adapter/api/droonga.js    2015-04-20 16:22:05 +0900 (c9c5194)
@@ -14,10 +14,13 @@ module.exports = {
     onRequest: function(request, connection) {
       var messageType = pathToMessageType(request.params[0]);
       var body = {};
-      if (typeof body.timeout != 'number' &&
+      var options = {
+        timeout: body.timeout
+      };
+      if (typeof options.timeout != 'number' &&
           typeof request.query.timeout == 'number')
-        body.timeout = request.query.timeout;
-      connection.emit(messageType, body);
+        options.timeout = request.query.timeout;
+      connection.emit(messageType, body, options);
     }
   }),
   // XXX dangerous! this must be disabled on public services.
@@ -32,11 +35,14 @@ module.exports = {
       });
       request.on('end', function() {
         body = JSON.parse(body);
-        if (typeof body.timeout != 'number' &&
+        var options = {
+          timeout: body.timeout
+        };
+        if (typeof options.timeout != 'number' &&
             typeof request.query.timeout == 'number')
-          body.timeout = request.query.timeout;
+          options.timeout = request.query.timeout;
         body.type = body.type || 'droonga-' + messageType;
-        connection.emit(messageType, body);
+        connection.emit(messageType, body, options);
       });
     }
   }),

  Modified: lib/adapter/wrapper.js (+20 -3)
===================================================================
--- lib/adapter/wrapper.js    2015-04-20 16:14:03 +0900 (3c3c91e)
+++ lib/adapter/wrapper.js    2015-04-20 16:22:05 +0900 (aa2c601)
@@ -23,12 +23,29 @@ DroongaProtocolConnectionWrapper.prototype = {
     return this._routeToSelf ||
            (this._routeToSelf = this._connection.getRouteToSelf(this._options));
   },
-  emit: function(event, data, callback) {
+  emit: function(event, data, callback, options) {
     if (this._connection.closed) {
       this._logger.warn('connection is already closed.');
       return;
     }
 
+    // support emitMessage(type, body, options)
+    if (callback && typeof callback != 'function') {
+      options = callback;
+      callback = null;
+    }
+
+    var unifiedOptions = this._options;
+    if (options && typeof options == 'object') {
+      unifiedOptions = {};
+      Object.keys(this._options).forEach(key) {
+        unifiedOptions[key] = this._options[key];
+      }, this);
+      Object.keys(options).forEach(key) {
+        options[key] = this._options[key];
+      }, this);
+    }
+
     if (callback) {
       var originalCallback = callback;
       callback = function(error, response) {
@@ -38,9 +55,9 @@ DroongaProtocolConnectionWrapper.prototype = {
       callback = this._callback;
     }
     if (callback)
-      this._connection.emitMessage(event, data, callback, this._options);
+      this._connection.emitMessage(event, data, callback, unifiedOptions);
     else
-      this._connection.emitMessage(event, data, this._options);
+      this._connection.emitMessage(event, data, unifiedOptions);
   },
   on: function(event, listener) {
     this._connection.on(event, listener);

  Modified: lib/droonga-protocol/connection.js (+8 -4)
===================================================================
--- lib/droonga-protocol/connection.js    2015-04-20 16:14:03 +0900 (3015168)
+++ lib/droonga-protocol/connection.js    2015-04-20 16:22:05 +0900 (906f038)
@@ -236,10 +236,14 @@ Connection.prototype.emitMessage = function(type, body, callback, options) {
     type:       type,
     body:       body
   };
-  if (typeof options.timeout == 'number')
-    envelope.timeout = options.timeout;
-  else if (typeof this.defaultTimeout == 'number')
-    envelope.timeout = this.defaultTimeout;
+  if (typeof envelope.timeout != 'number') {
+    if (typeof options.timeout == 'number')
+      envelope.timeout = options.timeout;
+    else if (typeof this.defaultTimeout == 'number')
+      envelope.timeout = this.defaultTimeout;
+  }
+  if (typeof envelope.timeout == 'number')
+    envelope.timeout = toFloat(envelope.timeout);
 
   this._logger.trace('emitMessage: trying to send message: ',
                      envelope);
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index