I'm looking for some suggestions for implementing an auto-login and auto-relogin.
Say I start my application, I will hit the REST service to get my CST and token. I will then log in to the Streaming service and subscribe. Now I'm all ready to roll!
My question is:
1) How do I know if I've been disconnected (lost internet connectivity, IG down, IG refusing etc)?
2) Once I realise I'm disconnected, what should I typically do? If the Streaming service goes down, should I automatically get a new CST and token too?
3) How do you handle out of hours (weekends)? Do you set a period not to bother trying to relogin for? Or do you just keep it polling?
Hi windsurfer,
For Lightstreamer, when the connection is made a ConnectionListener is supplied and this should tell you when the connection has dropped. Looking at the Java sample app, the SDK returns a listener which merely logs out the messages from Lightstreamer; so you would need to take that sample code and rewrite it. If you are writing directly to the LSClient library, then you are required to supply the listener.
This is the code (note the formatting will be very poor) ...
public ConnectionListener connect(String username,
ConversationContext conversationContext,
String lightstreamerEndpoint) throws Exception {
lsClient = new LSClient();
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.user = username;
connectionInfo.password = "CST-" + conversationContext.getClientSecurityToken() + "|" + "XST-" + conversationContext.getAccountSecurityToken();
connectionInfo.pushServerUrl = lightstreamerEndpoint;
final ConnectionListenerAdapter adapter = new ConnectionListenerAdapter();
lsClient.openConnection(connectionInfo, adapter);
return adapter;
}
I would suggest implementing a ConnectionListener directly rather than using the adapter.
For IG downtime, we stop the servers at 10pm (UK time) on Friday nights and we are up and running on Sunday. Although not all markets are open on the Sunday - sprint markets for instance. So I would expect that Lightstreamer will be available on Sunday but there will probably be some markets that you cannot subscribe to.
Hope that helps!
Chris