Preventing a potential problem at the NetworkServiceManager and introducing some getters
- Preventing accidentally calling the 'bindService' twice at the NetworkServiceManager - Providing a getter for the node list at the NodeLatencyVerifier - Created a getter for the NodeLatencyVerifier at the NetworkService
This commit is contained in:
parent
b032db80bc
commit
562955586b
3 changed files with 18 additions and 4 deletions
|
@ -230,9 +230,11 @@ public class NetworkService extends Service {
|
||||||
.build();
|
.build();
|
||||||
mSelectedNode = nodeProvider.getBestNode();
|
mSelectedNode = nodeProvider.getBestNode();
|
||||||
if(mSelectedNode != null){
|
if(mSelectedNode != null){
|
||||||
|
Log.d(TAG,"Trying to connect to: "+ mSelectedNode.getUrl());
|
||||||
Request request = new Request.Builder().url(mSelectedNode.getUrl()).build();
|
Request request = new Request.Builder().url(mSelectedNode.getUrl()).build();
|
||||||
mWebSocket = client.newWebSocket(request, mWebSocketListener);
|
mWebSocket = client.newWebSocket(request, mWebSocketListener);
|
||||||
}else{
|
}else{
|
||||||
|
Log.d(TAG,"Could not find best node, reescheduling");
|
||||||
// If no node could be found yet, schedule a new attempt in DEFAULT_INITIAL_DELAY ms
|
// If no node could be found yet, schedule a new attempt in DEFAULT_INITIAL_DELAY ms
|
||||||
mHandler.postDelayed(mConnectAttempt, DEFAULT_INITIAL_DELAY);
|
mHandler.postDelayed(mConnectAttempt, DEFAULT_INITIAL_DELAY);
|
||||||
}
|
}
|
||||||
|
@ -797,4 +799,6 @@ public class NetworkService extends Service {
|
||||||
public PublishSubject<FullNode> getNodeLatencyObservable(){
|
public PublishSubject<FullNode> getNodeLatencyObservable(){
|
||||||
return fullNodePublishSubject;
|
return fullNodePublishSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NodeLatencyVerifier getNodeLatencyVerifier(){ return nodeLatencyVerifier; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,8 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb
|
||||||
private List<String> mCustomNodeUrls = new ArrayList<>();
|
private List<String> mCustomNodeUrls = new ArrayList<>();
|
||||||
private boolean mAutoConnect;
|
private boolean mAutoConnect;
|
||||||
private boolean mVerifyLatency;
|
private boolean mVerifyLatency;
|
||||||
private double alpha;
|
// Flag used to make sure we only call 'bindService' once.
|
||||||
|
private boolean mStartingService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runnable used to schedule a service disconnection once the app is not visible to the user for
|
* Runnable used to schedule a service disconnection once the app is not visible to the user for
|
||||||
|
@ -85,7 +86,9 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResumed(Activity activity) {
|
public void onActivityResumed(Activity activity) {
|
||||||
mHandler.removeCallbacks(mDisconnectRunnable);
|
mHandler.removeCallbacks(mDisconnectRunnable);
|
||||||
if(mService == null){
|
if(mService == null && !mStartingService){
|
||||||
|
// Setting this flag to 'true' to avoid repeated calls to the bindService.
|
||||||
|
mStartingService = true;
|
||||||
// Creating a new Intent that will be used to start the NetworkService
|
// Creating a new Intent that will be used to start the NetworkService
|
||||||
Context context = mContextReference.get();
|
Context context = mContextReference.get();
|
||||||
Intent intent = new Intent(context, NetworkService.class);
|
Intent intent = new Intent(context, NetworkService.class);
|
||||||
|
@ -143,12 +146,15 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb
|
||||||
// We've bound to LocalService, cast the IBinder and get LocalService instance
|
// We've bound to LocalService, cast the IBinder and get LocalService instance
|
||||||
NetworkService.LocalBinder binder = (NetworkService.LocalBinder) service;
|
NetworkService.LocalBinder binder = (NetworkService.LocalBinder) service;
|
||||||
mService = binder.getService();
|
mService = binder.getService();
|
||||||
|
// Setting the 'starting service' flag back to false
|
||||||
|
mStartingService = false;
|
||||||
passRequiredInfoToConfigureService();
|
passRequiredInfoToConfigureService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceDisconnected(ComponentName componentName) {}
|
public void onServiceDisconnected(ComponentName componentName) {
|
||||||
|
mStartingService = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public String getUserName() {
|
public String getUserName() {
|
||||||
|
|
|
@ -203,4 +203,8 @@ public class NodeLatencyVerifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FullNode> getNodeList(){
|
||||||
|
return mNodeList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue