]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/netstd/Thrift/Server/TServer.cs
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / netstd / Thrift / Server / TServer.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.Protocol;
23 using Thrift.Transport;
24 using Thrift.Processor;
25
26 namespace Thrift.Server
27 {
28 // ReSharper disable once InconsistentNaming
29 public abstract class TServer
30 {
31 protected readonly ILogger Logger;
32 protected TProtocolFactory InputProtocolFactory;
33 protected TTransportFactory InputTransportFactory;
34 protected ITProcessorFactory ProcessorFactory;
35 protected TProtocolFactory OutputProtocolFactory;
36 protected TTransportFactory OutputTransportFactory;
37
38 protected TServerEventHandler ServerEventHandler;
39 protected TServerTransport ServerTransport;
40
41 protected TServer(ITProcessorFactory processorFactory, TServerTransport serverTransport,
42 TTransportFactory inputTransportFactory, TTransportFactory outputTransportFactory,
43 TProtocolFactory inputProtocolFactory, TProtocolFactory outputProtocolFactory,
44 ILogger logger = null)
45 {
46 ProcessorFactory = processorFactory ?? throw new ArgumentNullException(nameof(processorFactory));
47 ServerTransport = serverTransport;
48 InputTransportFactory = inputTransportFactory ?? new TTransportFactory();
49 OutputTransportFactory = outputTransportFactory ?? new TTransportFactory();
50 InputProtocolFactory = inputProtocolFactory ?? throw new ArgumentNullException(nameof(inputProtocolFactory));
51 OutputProtocolFactory = outputProtocolFactory ?? throw new ArgumentNullException(nameof(outputProtocolFactory));
52 Logger = logger; // null is absolutely legal
53 }
54
55 public void SetEventHandler(TServerEventHandler seh)
56 {
57 ServerEventHandler = seh;
58 }
59
60 public TServerEventHandler GetEventHandler()
61 {
62 return ServerEventHandler;
63 }
64
65 // Log delegation? deprecated, use ILogger
66 protected void LogError( string msg)
67 {
68 if (Logger != null)
69 Logger.LogError(msg);
70 }
71
72 public abstract void Stop();
73
74 public virtual void Start()
75 {
76 // do nothing
77 }
78
79 public virtual async Task ServeAsync(CancellationToken cancellationToken)
80 {
81 if (cancellationToken.IsCancellationRequested)
82 {
83 await Task.FromCanceled(cancellationToken);
84 }
85 }
86 }
87 }