Reputation: 508
Software Stack:
Tomcat v7.0.54
Atmosphere Server v2.2.3 (@ManagedService annotated class)
We have two server instances in which one provides an endpoint using @ManagedService annotation and a second uses Wasync lib as the client to connect to it. The server client needs the connection to be persistent at all times and different use cases make this a bit challenging.
Our main problem use cases are:
So we need a way to make the client dynamic in these situations.
IE:
Firstly, we've tried to use the built in reconnect options that Wasync provides with no dice:
OptionsBuilder<DefaultOptions, DefaultOptionsBuilder> optBuilder = wsAuthClient.newOptionsBuilder()
.reconnect(true)
.pauseBeforeReconnectInSeconds(10);
The listener:
}).on(Event.REOPENED, new Function<String>() {
@Override
public void on(String t) {
logger.info("Re-opened connection to server.");
}
Based on what I've read in the documentation, this gets triggered when the connection is purposely closed by the @ManagedService?
Has anyone encountered these types of use cases and have a solution for it?
Upvotes: 2
Views: 671
Reputation: 508
I've solved this by using the @Get or @Post annotation on a method in the @ManagedService class endpoint. So my client polls this endpoint by doing an HTTP request, if it returns a 200 OK then this means the server is ready to accept connections.
SUDO:
while(!connected){
//Do GET/POST to server to see if status is 200 OK.
if (request.status == 200){
connected = true;
connectToWs();
}
// otherwise delay and re-attempt request.
}
Upvotes: 1