drpcjs
Version:
Apache storm DRPC client for Node.js
224 lines (212 loc) • 6.25 kB
JavaScript
//
// Autogenerated by Thrift Compiler (0.9.1)
//
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
//
var Thrift = require('../thrift').Thrift;
var ttypes = require('./storm_types');
//HELPER FUNCTIONS AND STRUCTURES
DistributedRPC_execute_args = function(args) {
this.functionName = null;
this.funcArgs = null;
if (args) {
if (args.functionName !== undefined) {
this.functionName = args.functionName;
}
if (args.funcArgs !== undefined) {
this.funcArgs = args.funcArgs;
}
}
};
DistributedRPC_execute_args.prototype = {};
DistributedRPC_execute_args.prototype.read = function(input) {
input.readStructBegin();
while (true)
{
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.functionName = input.readString();
} else {
input.skip(ftype);
}
break;
case 2:
if (ftype == Thrift.Type.STRING) {
this.funcArgs = input.readString();
} else {
input.skip(ftype);
}
break;
default:
input.skip(ftype);
}
input.readFieldEnd();
}
input.readStructEnd();
return;
};
DistributedRPC_execute_args.prototype.write = function(output) {
output.writeStructBegin('DistributedRPC_execute_args');
if (this.functionName !== null && this.functionName !== undefined) {
output.writeFieldBegin('functionName', Thrift.Type.STRING, 1);
output.writeString(this.functionName);
output.writeFieldEnd();
}
if (this.funcArgs !== null && this.funcArgs !== undefined) {
output.writeFieldBegin('funcArgs', Thrift.Type.STRING, 2);
output.writeString(this.funcArgs);
output.writeFieldEnd();
}
output.writeFieldStop();
output.writeStructEnd();
return;
};
DistributedRPC_execute_result = function(args) {
this.success = null;
this.e = null;
if (args instanceof ttypes.DRPCExecutionException) {
this.e = args;
return;
}
if (args) {
if (args.success !== undefined) {
this.success = args.success;
}
if (args.e !== undefined) {
this.e = args.e;
}
}
};
DistributedRPC_execute_result.prototype = {};
DistributedRPC_execute_result.prototype.read = function(input) {
input.readStructBegin();
while (true)
{
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.STRING) {
this.success = input.readString();
} else {
input.skip(ftype);
}
break;
case 1:
if (ftype == Thrift.Type.STRUCT) {
this.e = new ttypes.DRPCExecutionException();
this.e.read(input);
} else {
input.skip(ftype);
}
break;
default:
input.skip(ftype);
}
input.readFieldEnd();
}
input.readStructEnd();
return;
};
DistributedRPC_execute_result.prototype.write = function(output) {
output.writeStructBegin('DistributedRPC_execute_result');
if (this.success !== null && this.success !== undefined) {
output.writeFieldBegin('success', Thrift.Type.STRING, 0);
output.writeString(this.success);
output.writeFieldEnd();
}
if (this.e !== null && this.e !== undefined) {
output.writeFieldBegin('e', Thrift.Type.STRUCT, 1);
this.e.write(output);
output.writeFieldEnd();
}
output.writeFieldStop();
output.writeStructEnd();
return;
};
DistributedRPCClient = exports.Client = function(output, pClass) {
this.output = output;
this.pClass = pClass;
this.seqid = 0;
this._reqs = {};
};
DistributedRPCClient.prototype = {};
DistributedRPCClient.prototype.execute = function(functionName, funcArgs, callback) {
this.seqid += 1;
this._reqs[this.seqid] = callback;
this.send_execute(functionName, funcArgs);
};
DistributedRPCClient.prototype.send_execute = function(functionName, funcArgs) {
var output = new this.pClass(this.output);
output.writeMessageBegin('execute', Thrift.MessageType.CALL, this.seqid);
var args = new DistributedRPC_execute_args();
args.functionName = functionName;
args.funcArgs = funcArgs;
args.write(output);
output.writeMessageEnd();
return this.output.flush();
};
DistributedRPCClient.prototype.recv_execute = 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 DistributedRPC_execute_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('execute failed: unknown result');
};
DistributedRPCProcessor = exports.Processor = function(handler) {
this._handler = handler
}
DistributedRPCProcessor.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();
}
}
DistributedRPCProcessor.prototype.process_execute = function(seqid, input, output) {
var args = new DistributedRPC_execute_args();
args.read(input);
input.readMessageEnd();
this._handler.execute(args.functionName, args.funcArgs, function (err, result) {
var result = new DistributedRPC_execute_result((err != null ? err : {success: result}));
output.writeMessageBegin("execute", Thrift.MessageType.REPLY, seqid);
result.write(output);
output.writeMessageEnd();
output.flush();
})
}