| Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 1 | /* | 
 | 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 |  */ | 
 | 19 | var thrift = require('thrift'); | 
 | 20 | var Thrift = thrift.Thrift; | 
 | 21 | var ThriftTransports = require('thrift/transport'); | 
 | 22 | var ThriftProtocols = require('thrift/protocol'); | 
 | 23 |  | 
 | 24 | var ThriftTest = require('./gen-nodejs/ThriftTest'), | 
 | 25 |   SecondService = require('./gen-nodejs/SecondService'), | 
 | 26 |   ttypes = require('./gen-nodejs/ThriftTest_types'); | 
 | 27 |  | 
 | 28 | var program = require('commander'); | 
 | 29 |  | 
 | 30 | program | 
 | 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 |  | 
 | 35 | var protocol = undefined; | 
 | 36 | var transport =  undefined; | 
 | 37 |  | 
 | 38 | if (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 |  | 
 | 47 | if (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 |  | 
 | 56 | var ThriftTestHandler = require("./test_handler").ThriftTestHandler; | 
 | 57 |  | 
 | 58 | var SecondServiceHandler = { | 
 | 59 |   secondtestString: function(thing, result) { | 
 | 60 |     console.log('testString(\'' + thing + '\')'); | 
 | 61 |     result(null, thing); | 
 | 62 |   } | 
 | 63 | }; | 
 | 64 |  | 
 | 65 | var processor = new thrift.MultiplexedProcessor(); | 
 | 66 |  | 
 | 67 | processor.registerProcessor( | 
 | 68 |   "ThriftTest", | 
 | 69 |   new ThriftTest.Processor(ThriftTestHandler)); | 
 | 70 |  | 
 | 71 | processor.registerProcessor( | 
 | 72 |   "SecondService", | 
 | 73 |   new SecondService.Processor(SecondServiceHandler)); | 
 | 74 |  | 
 | 75 | var server = thrift.createMultiplexServer(processor, { | 
 | 76 |   protocol: protocol, | 
 | 77 |   transport: transport | 
 | 78 | }); | 
 | 79 |  | 
 | 80 | server.listen(9090); |