blob: 9786189bb31b7f9348561000784e46da3c6e947e [file] [log] [blame]
Jens Geyer72034242013-05-08 18:46:57 +02001/*
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
20using System;
21using System.Collections.Generic;
22using Thrift.Collections;
23using Thrift.Transport;
24using Thrift.Protocol;
25using Thrift.Server;
26using Thrift;
27using Test.Multiplex;
28
29namespace Test.Multiplex.Server
30{
Jens Geyerd5436f52014-10-03 19:50:38 +020031 public class TestServer
32 {
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090033 class BenchmarkServiceImpl : BenchmarkService.Iface
Jens Geyer72034242013-05-08 18:46:57 +020034 {
35 public int fibonacci(sbyte n)
36 {
37 int prev, next, result;
38 prev = 0;
39 result = 1;
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090040 while (n > 0)
Jens Geyer72034242013-05-08 18:46:57 +020041 {
42 next = result + prev;
43 prev = result;
44 result = next;
45 --n;
46 }
47 return result;
48 }
49 }
50
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090051 class AggrServiceImpl : Aggr.Iface
Jens Geyer72034242013-05-08 18:46:57 +020052 {
53 List<int> values = new List<int>();
54
55 public void addValue(int value)
56 {
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090057 values.Add(value);
Jens Geyer72034242013-05-08 18:46:57 +020058 }
59
60 public List<int> getValues()
61 {
62 return values;
63 }
64 }
65
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090066 static void Execute(int port)
67 {
68 try
69 {
70 // create protocol factory, default to BinaryProtocol
71 TProtocolFactory ProtocolFactory = new TBinaryProtocol.Factory(true,true);
72 TServerTransport servertrans = new TServerSocket(port, 0, false);
73 TTransportFactory TransportFactory = new TFramedTransport.Factory();
Jens Geyer72034242013-05-08 18:46:57 +020074
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090075 BenchmarkService.Iface benchHandler = new BenchmarkServiceImpl();
76 TProcessor benchProcessor = new BenchmarkService.Processor(benchHandler);
Jens Geyer72034242013-05-08 18:46:57 +020077
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090078 Aggr.Iface aggrHandler = new AggrServiceImpl();
79 TProcessor aggrProcessor = new Aggr.Processor(aggrHandler);
Jens Geyer72034242013-05-08 18:46:57 +020080
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090081 TMultiplexedProcessor multiplex = new TMultiplexedProcessor();
82 multiplex.RegisterProcessor(Constants.NAME_BENCHMARKSERVICE, benchProcessor);
83 multiplex.RegisterProcessor(Constants.NAME_AGGR, aggrProcessor);
Jens Geyer72034242013-05-08 18:46:57 +020084
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090085 TServer ServerEngine = new TSimpleServer(multiplex, servertrans, TransportFactory, ProtocolFactory);
Jens Geyer72034242013-05-08 18:46:57 +020086
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090087 Console.WriteLine("Starting the server ...");
88 ServerEngine.Serve();
89 }
90 catch (Exception e)
91 {
92 Console.WriteLine(e.Message);
93 }
94 }
Jens Geyer72034242013-05-08 18:46:57 +020095
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090096 static void Main(string[] args)
97 {
98 int port = 9090;
99 if (args.Length > 0)
100 {
101 port = ushort.Parse(args[0]);
102 }
103 Execute(port);
104 }
Jens Geyer72034242013-05-08 18:46:57 +0200105 }
Jens Geyer72034242013-05-08 18:46:57 +0200106}
107