]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/netcore/Thrift/Server/TBaseServer.cs
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / netcore / Thrift / Server / TBaseServer.cs
1 // Licensed to the Apache Software Foundation(ASF) under one
2 // or more contributor license agreements.See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership.The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17
18 using System;
19 using System.Threading;
20 using System.Threading.Tasks;
21 using Microsoft.Extensions.Logging;
22 using Thrift.Protocols;
23 using Thrift.Transports;
24
25 namespace Thrift.Server
26 {
27 // ReSharper disable once InconsistentNaming
28 public abstract class TBaseServer
29 {
30 protected readonly ILogger Logger;
31 protected ITProtocolFactory InputProtocolFactory;
32 protected TTransportFactory InputTransportFactory;
33 protected ITProcessorFactory ItProcessorFactory;
34 protected ITProtocolFactory OutputProtocolFactory;
35 protected TTransportFactory OutputTransportFactory;
36
37 protected TServerEventHandler ServerEventHandler;
38 protected TServerTransport ServerTransport;
39
40 protected TBaseServer(ITProcessorFactory itProcessorFactory, TServerTransport serverTransport,
41 TTransportFactory inputTransportFactory, TTransportFactory outputTransportFactory,
42 ITProtocolFactory inputProtocolFactory, ITProtocolFactory outputProtocolFactory,
43 ILogger logger)
44 {
45 ItProcessorFactory = itProcessorFactory ?? throw new ArgumentNullException(nameof(itProcessorFactory));
46 ServerTransport = serverTransport;
47 InputTransportFactory = inputTransportFactory ?? throw new ArgumentNullException(nameof(inputTransportFactory));
48 OutputTransportFactory = outputTransportFactory ?? throw new ArgumentNullException(nameof(outputTransportFactory));
49 InputProtocolFactory = inputProtocolFactory ?? throw new ArgumentNullException(nameof(inputProtocolFactory));
50 OutputProtocolFactory = outputProtocolFactory ?? throw new ArgumentNullException(nameof(outputProtocolFactory));
51 Logger = logger ?? throw new ArgumentNullException(nameof(logger));
52 }
53
54 public void SetEventHandler(TServerEventHandler seh)
55 {
56 ServerEventHandler = seh;
57 }
58
59 public TServerEventHandler GetEventHandler()
60 {
61 return ServerEventHandler;
62 }
63
64 public abstract void Stop();
65
66 public virtual void Start()
67 {
68 // do nothing
69 }
70
71 public virtual async Task ServeAsync(CancellationToken cancellationToken)
72 {
73 if (cancellationToken.IsCancellationRequested)
74 {
75 await Task.FromCanceled(cancellationToken);
76 }
77 }
78 }
79 }