Skip to content

Commit 1962cc8

Browse files
committed
Merge pull request #1070 from stephenplusplus/spp--grpc-rpc
pubsub: convert to grpc
2 parents 091e32c + 1bcc94d commit 1962cc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2110
-701
lines changed

lib/common/grpc-service-object.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*!
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*!
18+
* @module common/grpcServiceObject
19+
*/
20+
21+
'use strict';
22+
23+
var extend = require('extend');
24+
var nodeutil = require('util');
25+
26+
/**
27+
* @type {module:common/serviceObject}
28+
* @private
29+
*/
30+
var ServiceObject = require('./service-object.js');
31+
32+
/**
33+
* @type {module:common/util}
34+
* @private
35+
*/
36+
var util = require('./util.js');
37+
38+
/**
39+
* GrpcServiceObject is a base class, meant to be inherited from by a service
40+
* object that uses the gRPC protobuf API.
41+
*
42+
* @private
43+
*
44+
* @param {object} config - Configuration object.
45+
*/
46+
function GrpcServiceObject(config) {
47+
ServiceObject.call(this, config);
48+
}
49+
50+
nodeutil.inherits(GrpcServiceObject, ServiceObject);
51+
52+
/**
53+
* Delete the object.
54+
*
55+
* @param {function=} callback - The callback function.
56+
* @param {?error} callback.err - An error returned while making this request.
57+
*/
58+
GrpcServiceObject.prototype.delete = function(callback) {
59+
var protoOpts = this.methods.delete.protoOpts;
60+
var reqOpts = this.methods.delete.reqOpts;
61+
62+
this.request(protoOpts, reqOpts, callback || util.noop);
63+
};
64+
65+
/**
66+
* Get the metadata of this object.
67+
*
68+
* @param {function} callback - The callback function.
69+
* @param {?error} callback.err - An error returned while making this request.
70+
* @param {object} callback.metadata - The metadata for this object.
71+
*/
72+
GrpcServiceObject.prototype.getMetadata = function(callback) {
73+
var protoOpts = this.methods.getMetadata.protoOpts;
74+
var reqOpts = this.methods.getMetadata.reqOpts;
75+
76+
this.request(protoOpts, reqOpts, callback);
77+
};
78+
79+
/**
80+
* Set the metadata for this object.
81+
*
82+
* @param {object} metadata - The metadata to set on this object.
83+
* @param {function=} callback - The callback function.
84+
* @param {?error} callback.err - An error returned while making this request.
85+
*/
86+
GrpcServiceObject.prototype.setMetadata = function(metadata, callback) {
87+
var protoOpts = this.methods.setMetadata.protoOpts;
88+
var reqOpts = extend(true, {}, this.methods.setMetadata.reqOpts, metadata);
89+
90+
this.request(protoOpts, reqOpts, callback || util.noop);
91+
};
92+
93+
/**
94+
* Patch a request to the GrpcService object.
95+
*
96+
* @private
97+
*/
98+
GrpcServiceObject.prototype.request = function(protoOpts, reqOpts, callback) {
99+
this.parent.request(protoOpts, reqOpts, callback);
100+
};
101+
102+
module.exports = GrpcServiceObject;

0 commit comments

Comments
 (0)