Permalink
Browse files

THRIFT-1129: Merge remote-tracking branch 'tagomoris/master'

  • Loading branch information...
wadey committed Apr 3, 2011
2 parents c012903 + 5b77068 commit ae8be1ff8af50607da52f51c06556f05842692e5
@@ -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);
+ });
+});
@@ -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.

0 comments on commit ae8be1f

Please sign in to comment.