drpcjs
Version:
Apache storm DRPC client for Node.js
454 lines (426 loc) • 13.1 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
DistributedRPCInvocations_result_args = function(args) {
this.id = null;
this.result = null;
if (args) {
if (args.id !== undefined) {
this.id = args.id;
}
if (args.result !== undefined) {
this.result = args.result;
}
}
};
DistributedRPCInvocations_result_args.prototype = {};
DistributedRPCInvocations_result_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.id = input.readString();
} else {
input.skip(ftype);
}
break;
case 2:
if (ftype == Thrift.Type.STRING) {
this.result = input.readString();
} else {
input.skip(ftype);
}
break;
default:
input.skip(ftype);
}
input.readFieldEnd();
}
input.readStructEnd();
return;
};
DistributedRPCInvocations_result_args.prototype.write = function(output) {
output.writeStructBegin('DistributedRPCInvocations_result_args');
if (this.id !== null && this.id !== undefined) {
output.writeFieldBegin('id', Thrift.Type.STRING, 1);
output.writeString(this.id);
output.writeFieldEnd();
}
if (this.result !== null && this.result !== undefined) {
output.writeFieldBegin('result', Thrift.Type.STRING, 2);
output.writeString(this.result);
output.writeFieldEnd();
}
output.writeFieldStop();
output.writeStructEnd();
return;
};
DistributedRPCInvocations_result_result = function(args) {
};
DistributedRPCInvocations_result_result.prototype = {};
DistributedRPCInvocations_result_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;
}
input.skip(ftype);
input.readFieldEnd();
}
input.readStructEnd();
return;
};
DistributedRPCInvocations_result_result.prototype.write = function(output) {
output.writeStructBegin('DistributedRPCInvocations_result_result');
output.writeFieldStop();
output.writeStructEnd();
return;
};
DistributedRPCInvocations_fetchRequest_args = function(args) {
this.functionName = null;
if (args) {
if (args.functionName !== undefined) {
this.functionName = args.functionName;
}
}
};
DistributedRPCInvocations_fetchRequest_args.prototype = {};
DistributedRPCInvocations_fetchRequest_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 0:
input.skip(ftype);
break;
default:
input.skip(ftype);
}
input.readFieldEnd();
}
input.readStructEnd();
return;
};
DistributedRPCInvocations_fetchRequest_args.prototype.write = function(output) {
output.writeStructBegin('DistributedRPCInvocations_fetchRequest_args');
if (this.functionName !== null && this.functionName !== undefined) {
output.writeFieldBegin('functionName', Thrift.Type.STRING, 1);
output.writeString(this.functionName);
output.writeFieldEnd();
}
output.writeFieldStop();
output.writeStructEnd();
return;
};
DistributedRPCInvocations_fetchRequest_result = function(args) {
this.success = null;
if (args) {
if (args.success !== undefined) {
this.success = args.success;
}
}
};
DistributedRPCInvocations_fetchRequest_result.prototype = {};
DistributedRPCInvocations_fetchRequest_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.STRUCT) {
this.success = new ttypes.DRPCRequest();
this.success.read(input);
} else {
input.skip(ftype);
}
break;
case 0:
input.skip(ftype);
break;
default:
input.skip(ftype);
}
input.readFieldEnd();
}
input.readStructEnd();
return;
};
DistributedRPCInvocations_fetchRequest_result.prototype.write = function(output) {
output.writeStructBegin('DistributedRPCInvocations_fetchRequest_result');
if (this.success !== null && this.success !== undefined) {
output.writeFieldBegin('success', Thrift.Type.STRUCT, 0);
this.success.write(output);
output.writeFieldEnd();
}
output.writeFieldStop();
output.writeStructEnd();
return;
};
DistributedRPCInvocations_failRequest_args = function(args) {
this.id = null;
if (args) {
if (args.id !== undefined) {
this.id = args.id;
}
}
};
DistributedRPCInvocations_failRequest_args.prototype = {};
DistributedRPCInvocations_failRequest_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.id = input.readString();
} else {
input.skip(ftype);
}
break;
case 0:
input.skip(ftype);
break;
default:
input.skip(ftype);
}
input.readFieldEnd();
}
input.readStructEnd();
return;
};
DistributedRPCInvocations_failRequest_args.prototype.write = function(output) {
output.writeStructBegin('DistributedRPCInvocations_failRequest_args');
if (this.id !== null && this.id !== undefined) {
output.writeFieldBegin('id', Thrift.Type.STRING, 1);
output.writeString(this.id);
output.writeFieldEnd();
}
output.writeFieldStop();
output.writeStructEnd();
return;
};
DistributedRPCInvocations_failRequest_result = function(args) {
};
DistributedRPCInvocations_failRequest_result.prototype = {};
DistributedRPCInvocations_failRequest_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;
}
input.skip(ftype);
input.readFieldEnd();
}
input.readStructEnd();
return;
};
DistributedRPCInvocations_failRequest_result.prototype.write = function(output) {
output.writeStructBegin('DistributedRPCInvocations_failRequest_result');
output.writeFieldStop();
output.writeStructEnd();
return;
};
DistributedRPCInvocationsClient = exports.Client = function(output, pClass) {
this.output = output;
this.pClass = pClass;
this.seqid = 0;
this._reqs = {};
};
DistributedRPCInvocationsClient.prototype = {};
DistributedRPCInvocationsClient.prototype.result = function(id, result, callback) {
this.seqid += 1;
this._reqs[this.seqid] = callback;
this.send_result(id, result);
};
DistributedRPCInvocationsClient.prototype.send_result = function(id, result) {
var output = new this.pClass(this.output);
output.writeMessageBegin('result', Thrift.MessageType.CALL, this.seqid);
var args = new DistributedRPCInvocations_result_args();
args.id = id;
args.result = result;
args.write(output);
output.writeMessageEnd();
return this.output.flush();
};
DistributedRPCInvocationsClient.prototype.recv_result = 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 DistributedRPCInvocations_result_result();
result.read(input);
input.readMessageEnd();
callback(null)
};
DistributedRPCInvocationsClient.prototype.fetchRequest = function(functionName, callback) {
this.seqid += 1;
this._reqs[this.seqid] = callback;
this.send_fetchRequest(functionName);
};
DistributedRPCInvocationsClient.prototype.send_fetchRequest = function(functionName) {
var output = new this.pClass(this.output);
output.writeMessageBegin('fetchRequest', Thrift.MessageType.CALL, this.seqid);
var args = new DistributedRPCInvocations_fetchRequest_args();
args.functionName = functionName;
args.write(output);
output.writeMessageEnd();
return this.output.flush();
};
DistributedRPCInvocationsClient.prototype.recv_fetchRequest = 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 DistributedRPCInvocations_fetchRequest_result();
result.read(input);
input.readMessageEnd();
if (null !== result.success) {
return callback(null, result.success);
}
return callback('fetchRequest failed: unknown result');
};
DistributedRPCInvocationsClient.prototype.failRequest = function(id, callback) {
this.seqid += 1;
this._reqs[this.seqid] = callback;
this.send_failRequest(id);
};
DistributedRPCInvocationsClient.prototype.send_failRequest = function(id) {
var output = new this.pClass(this.output);
output.writeMessageBegin('failRequest', Thrift.MessageType.CALL, this.seqid);
var args = new DistributedRPCInvocations_failRequest_args();
args.id = id;
args.write(output);
output.writeMessageEnd();
return this.output.flush();
};
DistributedRPCInvocationsClient.prototype.recv_failRequest = 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 DistributedRPCInvocations_failRequest_result();
result.read(input);
input.readMessageEnd();
callback(null)
};
DistributedRPCInvocationsProcessor = exports.Processor = function(handler) {
this._handler = handler
}
DistributedRPCInvocationsProcessor.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();
}
}
DistributedRPCInvocationsProcessor.prototype.process_result = function(seqid, input, output) {
var args = new DistributedRPCInvocations_result_args();
args.read(input);
input.readMessageEnd();
this._handler.result(args.id, args.result, function (err, result) {
var result = new DistributedRPCInvocations_result_result((err != null ? err : {success: result}));
output.writeMessageBegin("result", Thrift.MessageType.REPLY, seqid);
result.write(output);
output.writeMessageEnd();
output.flush();
})
}
DistributedRPCInvocationsProcessor.prototype.process_fetchRequest = function(seqid, input, output) {
var args = new DistributedRPCInvocations_fetchRequest_args();
args.read(input);
input.readMessageEnd();
this._handler.fetchRequest(args.functionName, function (err, result) {
var result = new DistributedRPCInvocations_fetchRequest_result((err != null ? err : {success: result}));
output.writeMessageBegin("fetchRequest", Thrift.MessageType.REPLY, seqid);
result.write(output);
output.writeMessageEnd();
output.flush();
})
}
DistributedRPCInvocationsProcessor.prototype.process_failRequest = function(seqid, input, output) {
var args = new DistributedRPCInvocations_failRequest_args();
args.read(input);
input.readMessageEnd();
this._handler.failRequest(args.id, function (err, result) {
var result = new DistributedRPCInvocations_failRequest_result((err != null ? err : {success: result}));
output.writeMessageBegin("failRequest", Thrift.MessageType.REPLY, seqid);
result.write(output);
output.writeMessageEnd();
output.flush();
})
}