Rev 30 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/env ruby## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.#$:.push('../gen-rb')$:.unshift '../../lib/rb/lib'require 'thrift'require 'calculator'require 'shared_types'class CalculatorHandlerdef initialize()@log = {}enddef ping()puts "ping()"enddef add(n1, n2)print "add(", n1, ",", n2, ")\n"return n1 + n2enddef calculate(logid, work)print "calculate(", logid, ", {", work.op, ",", work.num1, ",", work.num2,"})\n"if work.op == Operation::ADDval = work.num1 + work.num2elsif work.op == Operation::SUBTRACTval = work.num1 - work.num2elsif work.op == Operation::MULTIPLYval = work.num1 * work.num2elsif work.op == Operation::DIVIDEif work.num2 == 0x = InvalidOperation.new()x.what = work.opx.why = "Cannot divide by 0"raise xendval = work.num1 / work.num2elsex = InvalidOperation.new()x.what = work.opx.why = "Invalid operation"raise xendentry = SharedStruct.new()entry.key = logidentry.value = "#{val}"@log[logid] = entryreturn valenddef getStruct(key)print "getStruct(", key, ")\n"return @log[key]enddef zip()print "zip\n"endendhandler = CalculatorHandler.new()processor = Calculator::Processor.new(handler)transport = Thrift::ServerSocket.new(9090)transportFactory = Thrift::BufferedTransportFactory.new()server = Thrift::SimpleServer.new(processor, transport, transportFactory)puts "Starting the server..."server.serve()puts "done."