blob: a2a17099a514deecaa206ae426bc4e8f9e79c540 [file] [log] [blame]
Roger Meier8909cbd2014-01-26 11:44:27 +01001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * 'License'); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19var thrift = require('thrift');
20var Thrift = thrift.Thrift;
21var ThriftTransports = require('thrift/transport');
22var ThriftProtocols = require('thrift/protocol');
23
24var ThriftTest = require('./gen-nodejs/ThriftTest'),
25 SecondService = require('./gen-nodejs/SecondService'),
26 ttypes = require('./gen-nodejs/ThriftTest_types');
27
28var program = require('commander');
29
30program
31 .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
32 .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
33 .parse(process.argv);
34
35var protocol = undefined;
36var transport = undefined;
37
38if (program.protocol === "binary") {
39 protocol = ThriftProtocols.TBinaryProtocol;
40} else if (program.protocol === "json") {
41 protocol = ThriftProtocols.TJSONProtocol;
42} else {
43 //default
44 protocol = ThriftProtocols.TBinaryProtocol;
45}
46
47if (program.transport === "framed") {
48 transport = ThriftTransports.TFramedTransport;
49} else if (program.transport === "buffered") {
50 transport = ThriftTransports.TBufferedTransport;
51} else {
52 //default
53 transport = ThriftTransports.TBufferedTransport;
54}
55
56var ThriftTestHandler = require("./test_handler").ThriftTestHandler;
57
58var SecondServiceHandler = {
59 secondtestString: function(thing, result) {
60 console.log('testString(\'' + thing + '\')');
61 result(null, thing);
62 }
63};
64
65var processor = new thrift.MultiplexedProcessor();
66
67processor.registerProcessor(
68 "ThriftTest",
69 new ThriftTest.Processor(ThriftTestHandler));
70
71processor.registerProcessor(
72 "SecondService",
73 new SecondService.Processor(SecondServiceHandler));
74
75var server = thrift.createMultiplexServer(processor, {
76 protocol: protocol,
77 transport: transport
78});
79
80server.listen(9090);