mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
Add Stop methods for C# servers.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665538 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
907ad76c2d
commit
dc815f5402
@ -103,6 +103,8 @@ namespace Thrift.Server
|
||||
* The run method fires up the server and gets things going.
|
||||
*/
|
||||
public abstract void Serve();
|
||||
|
||||
public abstract void Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ namespace Thrift.Server
|
||||
/// </summary>
|
||||
class TSimpleServer : TServer
|
||||
{
|
||||
private bool stop = false;
|
||||
public TSimpleServer(TProcessor processor,
|
||||
TServerTransport serverTransport)
|
||||
:base(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory())
|
||||
@ -65,7 +66,7 @@ namespace Thrift.Server
|
||||
return;
|
||||
}
|
||||
|
||||
while (true)
|
||||
while (!stop)
|
||||
{
|
||||
TTransport client = null;
|
||||
TTransport inputTransport = null;
|
||||
@ -103,6 +104,24 @@ namespace Thrift.Server
|
||||
outputTransport.Close();
|
||||
}
|
||||
}
|
||||
|
||||
if (stop)
|
||||
{
|
||||
try
|
||||
{
|
||||
serverTransport.Close();
|
||||
}
|
||||
catch (TTransportException ttx)
|
||||
{
|
||||
Console.Error.WriteLine("TServerTrasnport failed on close: " + ttx.Message);
|
||||
}
|
||||
stop = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace Thrift.Server
|
||||
{
|
||||
private const int DEFAULT_MIN_THREADS = 10;
|
||||
private const int DEFAULT_MAX_THREADS = 100;
|
||||
private volatile bool stop = false;
|
||||
|
||||
public TThreadPoolServer(TProcessor processor, TServerTransport serverTransport)
|
||||
:this(processor, serverTransport,
|
||||
@ -81,7 +82,7 @@ namespace Thrift.Server
|
||||
return;
|
||||
}
|
||||
|
||||
while (true)
|
||||
while (!stop)
|
||||
{
|
||||
int failureCount = 0;
|
||||
try
|
||||
@ -95,6 +96,25 @@ namespace Thrift.Server
|
||||
Console.Error.WriteLine(ttx);
|
||||
}
|
||||
}
|
||||
|
||||
if (stop)
|
||||
{
|
||||
try
|
||||
{
|
||||
serverTransport.Close();
|
||||
}
|
||||
catch (TTransportException ttx)
|
||||
{
|
||||
Console.Error.WriteLine("TServerTrasnport failed on close: " + ttx.Message);
|
||||
}
|
||||
stop = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user