我想在同一个程序中运行两个TThreadedPoolServers
以处理不同种类的请求。但是,如果客户端尝试连接到最后一个TThreadedPoolServer
,它将始终拒绝该连接。我已经尝试在不同的线程中运行服务器,但无济于事。
服务器1:
public class RERunner extends Thread {
private static ReceiveEndpoint receiveEndpoint;
private static ReceiveEndpointInterface.Processor<ReceiveEndpoint> masterProcessor;
public RERunner() throws TTransportException {
receiveEndpoint = new ReceiveEndpoint();
masterProcessor = new ReceiveEndpointInterface.Processor<>(receiveEndpoint);
TServerTransport transport = new TServerSocket(Elements.MASTER_SERVER_RC_ENDPOINT_PORT);
TSimpleServer server = new TSimpleServer(new TSimpleServer.Args(transport).processor(masterProcessor));
server.serve();
}
}
服务器2:
public class RETableRunner extends Thread {
private static ReceiveEndpointTable receiveEndpointTable;
private static ReceiveEndpointTableInterface.Processor<ReceiveEndpointTable> masterProcessorTable;
public RETableRunner() throws TTransportException {
receiveEndpointTable = new ReceiveEndpointTable();
masterProcessorTable = new ReceiveEndpointTableInterface.Processor<>(receiveEndpointTable);
TServerTransport transportAll = new TServerSocket(Elements.MASTER_SERVER_RC_ENDPOINT_TABLE_PORT);
TThreadPoolServer serverAll = new TThreadPoolServer(new TThreadPoolServer.Args(transportAll).processor(masterProcessorTable));
serverAll.serve();
}
}
和抛出异常的客户端:
org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused: connect
at org.apache.thrift.transport.TSocket.open(TSocket.java:226)
at DataPropagator.acquireEndpointTable(DataPropagator.java:27)
at DataPropagator.run(DataPropagator.java:98)
Caused by: java.net.ConnectException: Connection refused: connect
at java.base/java.net.PlainSocketImpl.connect0(Native Method)
at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:101)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
at java.base/java.net.Socket.connect(Socket.java:591)
at org.apache.thrift.transport.TSocket.open(TSocket.java:221)
... 2 more
解决方案不必包含两个TThreadedPoolServers
,但是如果没有,我将需要帮助来启动它们。
我结合了两个* .thrift文件和其中定义的服务,因此我可以仅通过一个TThreadedServer访问这两个功能。