Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into performance
Conflicts: README.md lib/thrift/binary_parser.js lib/thrift/connection.js lib/thrift/server.js lib/thrift/transport.js package.json
- Loading branch information
Showing
21 changed files
with
2,887 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# Running the user example | ||
|
||
To run the user example, first start up the server in one terminal: | ||
#Generate the bindings: | ||
../../../compiler/cpp/thrift --gen js:node user.thrift | ||
|
||
node server.js | ||
#To run the user example, first start up the server in one terminal: | ||
NODE_PATH=../lib:../lib/thrift node server.js | ||
|
||
Now run the client: | ||
#Now run the client: | ||
NODE_PATH=../lib:../lib/thrift node client.js | ||
|
||
node client.js | ||
|
||
# Regenerating the bindings | ||
|
||
If you want to regenerated the bindings, you can run: | ||
|
||
thrift --gen js:node user.thrift | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var thrift = require('thrift'), | ||
ttransport = require('thrift/transport'); | ||
|
||
var UserStorage = require('./gen-nodejs/UserStorage'), | ||
ttypes = require('./gen-nodejs/user_types'); | ||
|
||
var f_conn = thrift.createConnection('localhost', 9090), // default: framed | ||
f_client = thrift.createClient(UserStorage, f_conn); | ||
var b_conn = thrift.createConnection('localhost', 9091, {transport: ttransport.TBufferedTransport}), | ||
b_client = thrift.createClient(UserStorage, b_conn); | ||
var user1 = new ttypes.UserProfile({uid: 1, | ||
name: "Mark Slee", | ||
blurb: "I'll find something to put here."}); | ||
var user2 = new ttypes.UserProfile({uid: 2, | ||
name: "Satoshi Tagomori", | ||
blurb: "ok, let's test with buffered transport."}); | ||
|
||
f_conn.on('error', function(err) { | ||
console.error("framed:", err); | ||
}); | ||
|
||
f_client.store(user1, function(err, response) { | ||
if (err) { console.error(err); return; } | ||
|
||
console.log("stored:", user1.uid, " as ", user1.name); | ||
b_client.retrieve(user1.uid, function(err, responseUser) { | ||
if (err) { console.error(err); return; } | ||
console.log("retrieved:", responseUser.uid, " as ", responseUser.name); | ||
}); | ||
}); | ||
|
||
b_client.store(user2, function(err, response) { | ||
if (err) { console.error(err); return; } | ||
|
||
console.log("stored:", user2.uid, " as ", user2.name); | ||
f_client.retrieve(user2.uid, function(err, responseUser) { | ||
if (err) { console.error(err); return; } | ||
console.log("retrieved:", responseUser.uid, " as ", responseUser.name); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
// | ||
// Autogenerated by Thrift | ||
// | ||
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | ||
// | ||
var Thrift = require('thrift').Thrift; | ||
|
||
var ttypes = require('./bucketupdater_types'); | ||
//HELPER FUNCTIONS AND STRUCTURES | ||
|
||
var BucketStoreMapping_getMapping_args = function(args){ | ||
this.category = null | ||
if( args != null ){ if (null != args.category) | ||
this.category = args.category | ||
}} | ||
BucketStoreMapping_getMapping_args.prototype = {} | ||
BucketStoreMapping_getMapping_args.prototype.read = function(input){ | ||
var ret = input.readStructBegin() | ||
while (1) | ||
{ | ||
var ret = input.readFieldBegin() | ||
var fname = ret.fname | ||
var ftype = ret.ftype | ||
var fid = ret.fid | ||
if (ftype == Thrift.Type.STOP) | ||
break | ||
switch(fid) | ||
{ | ||
case 1: if (ftype == Thrift.Type.STRING) { | ||
this.category = input.readString() | ||
} else { | ||
input.skip(ftype) | ||
} | ||
break | ||
default: | ||
input.skip(ftype) | ||
} | ||
input.readFieldEnd() | ||
} | ||
input.readStructEnd() | ||
return | ||
} | ||
|
||
BucketStoreMapping_getMapping_args.prototype.write = function(output){ | ||
output.writeStructBegin('BucketStoreMapping_getMapping_args') | ||
if (null != this.category) { | ||
output.writeFieldBegin('category', Thrift.Type.STRING, 1) | ||
output.writeString(this.category) | ||
output.writeFieldEnd() | ||
} | ||
output.writeFieldStop() | ||
output.writeStructEnd() | ||
return | ||
} | ||
|
||
var BucketStoreMapping_getMapping_result = function(args){ | ||
this.success = null | ||
this.e = null | ||
if( args != null ){ if (null != args.success) | ||
this.success = args.success | ||
if (null != args.e) | ||
this.e = args.e | ||
}} | ||
BucketStoreMapping_getMapping_result.prototype = {} | ||
BucketStoreMapping_getMapping_result.prototype.read = function(input){ | ||
var ret = input.readStructBegin() | ||
while (1) | ||
{ | ||
var ret = input.readFieldBegin() | ||
var fname = ret.fname | ||
var ftype = ret.ftype | ||
var fid = ret.fid | ||
if (ftype == Thrift.Type.STOP) | ||
break | ||
switch(fid) | ||
{ | ||
case 0: if (ftype == Thrift.Type.MAP) { | ||
{ | ||
var _size0 = 0 | ||
var rtmp3 | ||
this.success = {} | ||
var _ktype1 = 0 | ||
var _vtype2 = 0 | ||
rtmp3 = input.readMapBegin() | ||
_ktype1= rtmp3.ktype | ||
_vtype2= rtmp3.vtype | ||
_size0= rtmp3.size | ||
for (var _i4 = 0; _i4 < _size0; ++_i4) | ||
{ | ||
key5 = null | ||
val6 = null | ||
key5 = input.readI32() | ||
val6 = new ttypes.HostPort() | ||
val6.read(input) | ||
this.success[key5] = val6 | ||
} | ||
input.readMapEnd() | ||
} | ||
} else { | ||
input.skip(ftype) | ||
} | ||
break | ||
case 1: if (ftype == Thrift.Type.STRUCT) { | ||
this.e = new ttypes.BucketStoreMappingException() | ||
this.e.read(input) | ||
} else { | ||
input.skip(ftype) | ||
} | ||
break | ||
default: | ||
input.skip(ftype) | ||
} | ||
input.readFieldEnd() | ||
} | ||
input.readStructEnd() | ||
return | ||
} | ||
|
||
BucketStoreMapping_getMapping_result.prototype.write = function(output){ | ||
output.writeStructBegin('BucketStoreMapping_getMapping_result') | ||
if (null != this.success) { | ||
output.writeFieldBegin('success', Thrift.Type.MAP, 0) | ||
{ | ||
output.writeMapBegin(Thrift.Type.I32, Thrift.Type.STRUCT, Thrift.objectLength(this.success)) | ||
{ | ||
for(var kiter7 in this.success) { | ||
if (this.success.hasOwnProperty(kiter7)) | ||
{ | ||
var viter8 = this.success[kiter7] | ||
output.writeI32(kiter7) | ||
viter8.write(output) | ||
} | ||
} | ||
} | ||
output.writeMapEnd() | ||
} | ||
output.writeFieldEnd() | ||
} | ||
if (null != this.e) { | ||
output.writeFieldBegin('e', Thrift.Type.STRUCT, 1) | ||
this.e.write(output) | ||
output.writeFieldEnd() | ||
} | ||
output.writeFieldStop() | ||
output.writeStructEnd() | ||
return | ||
} | ||
|
||
var BucketStoreMappingClient = exports.Client = function(output, pClass) { | ||
this.output = output; | ||
this.pClass = pClass; | ||
this.seqid = 0; | ||
this._reqs = {} | ||
} | ||
BucketStoreMappingClient.prototype = {} | ||
BucketStoreMappingClient.prototype.getMapping = function(category,callback){ | ||
this.seqid += 1; | ||
this._reqs[this.seqid] = callback; | ||
this.send_getMapping(category) | ||
} | ||
|
||
BucketStoreMappingClient.prototype.send_getMapping = function(category){ | ||
var output = new this.pClass(this.output); | ||
output.writeMessageBegin('getMapping', Thrift.MessageType.CALL, this.seqid) | ||
var args = new BucketStoreMapping_getMapping_args() | ||
args.category = category | ||
args.write(output) | ||
output.writeMessageEnd() | ||
return this.output.flush() | ||
} | ||
|
||
BucketStoreMappingClient.prototype.recv_getMapping = function(input,mtype,rseqid){ | ||
var callback = this._reqs[rseqid] || function() {}; | ||
delete this._reqs[rseqid]; | ||
if (mtype == Thrift.MessageType.EXCEPTION) { | ||
var x = new Thrift.TApplicationException() | ||
x.read(input) | ||
input.readMessageEnd() | ||
return callback(x); | ||
} | ||
var result = new BucketStoreMapping_getMapping_result() | ||
result.read(input) | ||
input.readMessageEnd() | ||
|
||
if (null != result.e) { | ||
return callback(result.e); | ||
} | ||
if (null != result.success ) { | ||
return callback(null, result.success); | ||
} | ||
return callback("getMapping failed: unknown result"); | ||
} | ||
var BucketStoreMappingProcessor = exports.Processor = function(handler) { | ||
this._handler = handler | ||
} | ||
BucketStoreMappingProcessor.prototype.process = function(input, output) { | ||
var r = input.readMessageBegin() | ||
if (this['process_' + r.fname]) { | ||
return this['process_' + r.fname].call(this, r.rseqid, input, output) | ||
} else { | ||
input.skip(Thrift.Type.STRUCT) | ||
input.readMessageEnd() | ||
var x = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN_METHOD, 'Unknown function ' + r.fname) | ||
output.writeMessageBegin(r.fname, Thrift.MessageType.Exception, r.rseqid) | ||
x.write(output) | ||
output.writeMessageEnd() | ||
output.flush() | ||
} | ||
} | ||
|
||
BucketStoreMappingProcessor.prototype.process_getMapping = function(seqid, input, output) { | ||
var args = new BucketStoreMapping_getMapping_args() | ||
args.read(input) | ||
input.readMessageEnd() | ||
var result = new BucketStoreMapping_getMapping_result() | ||
this._handler.getMapping(args.category, function(success) { | ||
result.success = success | ||
output.writeMessageBegin("getMapping", Thrift.MessageType.REPLY, seqid) | ||
result.write(output) | ||
output.writeMessageEnd() | ||
output.flush() | ||
}) | ||
} | ||
|
Oops, something went wrong.