Preventing a NPE

- We're now checking that there is a selected node before trying to use it, and in case there is none we schedule a
retry in DEFAULT_INITIAL_DELAY ms.
This commit is contained in:
Nelson R. Perez 2019-06-06 15:59:55 -05:00
parent b5e2961834
commit b032db80bc

View file

@ -229,9 +229,13 @@ public class NetworkService extends Service {
.writeTimeout(5, TimeUnit.SECONDS)
.build();
mSelectedNode = nodeProvider.getBestNode();
Log.v(TAG,"connect.url: "+ mSelectedNode.getUrl()+", latency: "+mSelectedNode.getLatencyValue());
Request request = new Request.Builder().url(mSelectedNode.getUrl()).build();
mWebSocket = client.newWebSocket(request, mWebSocketListener);
if(mSelectedNode != null){
Request request = new Request.Builder().url(mSelectedNode.getUrl()).build();
mWebSocket = client.newWebSocket(request, mWebSocketListener);
}else{
// If no node could be found yet, schedule a new attempt in DEFAULT_INITIAL_DELAY ms
mHandler.postDelayed(mConnectAttempt, DEFAULT_INITIAL_DELAY);
}
}
public long sendMessage(String message){