Rev 30 | Blame | Compare with Previous | Last modification | View Log | RSS feed
## 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.#$:.unshift File.dirname(__FILE__) + '/../lib'require 'thrift'$:.unshift File.dirname(__FILE__) + "/gen-rb"require 'benchmark_service'module Serverinclude Thriftclass BenchmarkHandler# 1-based index into the fibonacci sequencedef fibonacci(n)seq = [1, 1]3.upto(n) doseq << seq[-1] + seq[-2]endseq[n-1] # n is 1-basedendenddef self.start_server(host, port, serverClass)handler = BenchmarkHandler.newprocessor = ThriftBenchmark::BenchmarkService::Processor.new(handler)transport = ServerSocket.new(host, port)transport_factory = FramedTransportFactory.newargs = [processor, transport, transport_factory, nil, 20]if serverClass == NonblockingServerlogger = Logger.new(STDERR)logger.level = Logger::WARNargs << loggerendserver = serverClass.new(*args)@server_thread = Thread.new doserver.serveend@server = serverenddef self.shutdownreturn if @server.nil?if @server.respond_to? :shutdown@server.shutdownelse@server_thread.killendendenddef resolve_const(const)const and const.split('::').inject(Object) { |k,c| k.const_get(c) }endhost, port, serverklass = ARGVServer.start_server(host, port.to_i, resolve_const(serverklass))# let our host know that the interpreter has started# ideally we'd wait until the server was serving, but we don't have a hook for thatMarshal.dump(:started, STDOUT)STDOUT.flushMarshal.load(STDIN) # wait until we're instructed to shut downServer.shutdown