Why does my HAClient appear to hang when my server is down or URI is incorrect?

Follow

In most cases, the client isn't actually hung, but the ServerChooser is continuing to try to connect to the list of URIs without success. The client appears to be hung because none of the servers are responding.

This behavior is actually dependent on the ServerChooser that you are using with your HAClient. Inside the HAClient, the connectAndLogon function will run continuously until it succeeds in connecting. The only other way it will stop is if either the ServerChooser throws an exception from its getCurrentURI function, or if the ServerChooser returns an empty string for the URI. The AMPS Client DefaultServerChooser does not ever do either of those things. It simply returns the next URI from self and will loop through its internal list repeatedly.

There are two ways to prevent this behavior in recent AMPS client releases. First, you can set a maximum timeout in the DelayStrategy that you use.

Second, you can also implement your own ServerChooser class if you need a different behavior. Once implemented, use it in the same way you are currently using the DefaultServerChooser and you will see the client no longer appear to hang. Here is a simple example in Java.

import com.crankuptheamps.client.DefaultServerChooser;


public class TryOnceServerChooser extends DefaultServerChooser
{
  int _count = 0;
  int _next = 0;

@Override
public String getCurrentURI()
 {
  if (_next >= _count)
  {
    System.out.println("try once returning null");
    return null;
  }
 return super.getCurrentURI();
 }

@Override
public DefaultServerChooser add(String uri)
 {
 ++_count;
 return super.add(uri);
 }
@Override
public void next()
 {  _next++;
  super.next();
 }
}
Have more questions? Submit a request

Comments

Powered by Zendesk