Ejemplo n.º 1
0
 public TServer(TProcessor processor, TServerTransport serverTransport, TTransportFactory inputTransportFactory, TTransportFactory outputTransportFactory, TProtocolFactory inputProtocolFactory, TProtocolFactory outputProtocolFactory, TServer.LogDelegate logDelegate)
 {
     this.processor              = processor;
     this.serverTransport        = serverTransport;
     this.inputTransportFactory  = inputTransportFactory;
     this.outputTransportFactory = outputTransportFactory;
     this.inputProtocolFactory   = inputProtocolFactory;
     this.outputProtocolFactory  = outputProtocolFactory;
     this.logDelegate            = logDelegate;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 启动ThriftS服务器
        /// </summary>
        /// <param name="httpPort">http端口</param>
        /// <param name="thriftPort">thrift端口</param>
        /// <param name="minThreads">最小线程数</param>
        /// <param name="maxThreads">最大线程数</param>
        /// <param name="clientTimeout">客户端超时设置</param>
        /// <param name="useBufferedSockets">启动缓存Socket</param>
        public void Start(int httpPort, int thriftPort, int minThreads, int maxThreads, int clientTimeout, bool useBufferedSockets)
        {
            this.Port = thriftPort;
            var clientTimeoutMS = (int)TimeSpan.FromSeconds(clientTimeout).TotalMilliseconds;
            var serverTransport = new TServerSocket(thriftPort, clientTimeoutMS, useBufferedSockets);

            var logDelegate = new TServer.LogDelegate((message) => ThriftSEnvirnment.Logger.Error(message));

            this.threadPoolServer = new TThreadPoolServer(
                this.multiplexedProcessor,
                serverTransport,
                new TFramedTransport.Factory(),
                new TFramedTransport.Factory(),
                new TBinaryProtocol.Factory(),
                new TBinaryProtocol.Factory(),
                minThreads,
                maxThreads,
                logDelegate);
            this.multiplexedProcessor.RegisterProcessor("ThriftSHandler", new ThriftSHandler.Processor(new ThriftSHandlerProcessor()));

            // this.threadPoolServer.setEventHandler(new ServerEventHandler());
            ThriftSEnvirnment.Logger.Info(
                "Starting thriftS server. ThriftPort:{0}, HttpPort:{1}, Version:{2}",
                thriftPort,
                httpPort,
                Utils.Version);

            var task = new Task(this.threadPoolServer.Serve);

            task.Start();

            if (httpPort > 0)
            {
                this.httpServer = new SimpleHttpServer(httpPort);
                var httpTask = new Task(this.httpServer.Start);
                httpTask.Start();
            }

            ThriftSEnvirnment.MinThreadPoolSize = minThreads;
            ThriftSEnvirnment.MaxThreadPoolSize = maxThreads;
            ThriftSEnvirnment.ClientTimeout     = clientTimeout;
        }
Ejemplo n.º 3
0
 public TServer(TProcessor processor, TServerTransport serverTransport, TServer.LogDelegate logDelegate) : this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), new TServer.LogDelegate(TServer.DefaultLogDelegate))
 {
 }
Ejemplo n.º 4
0
 public TThreadPoolServer(TProcessor processor, TServerTransport serverTransport, TTransportFactory inputTransportFactory, TTransportFactory outputTransportFactory, TProtocolFactory inputProtocolFactory, TProtocolFactory outputProtocolFactory, int minThreadPoolThreads, int maxThreadPoolThreads, TServer.LogDelegate logDel) : base(processor, serverTransport, inputTransportFactory, outputTransportFactory, inputProtocolFactory, outputProtocolFactory, logDel)
 {
     //lock (typeof(TThreadPoolServer))
     //{
     //	if (!ThreadPool.SetMinThreads(minThreadPoolThreads, minThreadPoolThreads))
     //	{
     //		throw new Exception("Error: could not SetMinThreads in ThreadPool");
     //	}
     //	if (!ThreadPool.SetMaxThreads(maxThreadPoolThreads, maxThreadPoolThreads))
     //	{
     //		throw new Exception("Error: could not SetMaxThreads in ThreadPool");
     //	}
     //}
 }
Ejemplo n.º 5
0
 public TThreadPoolServer(TProcessor processor, TServerTransport serverTransport, TServer.LogDelegate logDelegate) : this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), 10, 100, logDelegate)
 {
 }
Ejemplo n.º 6
0
 public TThreadedServer(TProcessor processor, TServerTransport serverTransport, TTransportFactory inputTransportFactory, TTransportFactory outputTransportFactory, TProtocolFactory inputProtocolFactory, TProtocolFactory outputProtocolFactory, int maxThreads, TServer.LogDelegate logDel) : base(processor, serverTransport, inputTransportFactory, outputTransportFactory, inputProtocolFactory, outputProtocolFactory, logDel)
 {
     this.maxThreads    = maxThreads;
     this.clientQueue   = new Queue <TTransport>();
     this.clientLock    = new object();
     this.clientThreads = new THashSet <Thread>();
 }
Ejemplo n.º 7
0
 public TSimpleServer(TProcessor processor, TServerTransport serverTransport, TServer.LogDelegate logDel) : base(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), logDel)
 {
 }