I have very little experience with server-side programming, and I am taking on a task where I need to implement part of a Back-end Server using Apache thrift.
Right now, my application consists of a "Front-End" server and a "Back-End" server. The Front-End Server will make RPC calls to the Backend.
Right now, if I start the backend server from the command-line, I want that backend server to stay alive and, in a sense, keep polling for other nodes that want to establish a connection with it. Currently, the backend just spits out an error when it's not immediately able to connect to a front-end node. The backend code right now looks like this:
public class BENode {
public static void main(String [] args) throws Exception {
...
TSocket sock = new TSocket(hostFE, portFE);
TTransport transport = new TFramedTransport(sock);
TProtocol protocol = new TBinaryProtocol(transport);
BcryptService.Client client = new BcryptService.Client(protocol);
transport.open();
}
}
I believe it's the last line that throws an Exception (java.net.ConnectException: Connection refused) when the front-end (FE) node is not available to connect. However, the intended behaviour is that the back-end server will stay alive and keep polling to establish a connection with the front-end node, until it finally is able to connect successfully. I am quite sure I am not supposed to use an infinite while loop with a try-catch block as that is inefficient and bad practice:
try{
transport.open();
} catch() {
}
What is the best way to do this?