Renamed method and changed its functionality
- Renamed the 'removeCurrentNodeAndReconnect' as 'reconnectNode' since it will not be removing nodes from the list anymore - Adapted the sample app to work accordingly
This commit is contained in:
parent
2a64a9ec22
commit
7a5a975e4b
5 changed files with 26 additions and 34 deletions
|
@ -351,10 +351,9 @@ public class NetworkService extends Service {
|
|||
}
|
||||
|
||||
/**
|
||||
* Public method that can be called from classes that bind to the service and find out that
|
||||
* for any reason want the service to connect to a different node.
|
||||
* Used to close the current connection and cause the service to attempt a reconnection.
|
||||
*/
|
||||
public void removeCurrentNodeAndReconnect() {
|
||||
public void reconnectNode() {
|
||||
mWebSocket.close(GOING_AWAY_STATUS, null);
|
||||
}
|
||||
|
||||
|
@ -669,10 +668,8 @@ public class NetworkService extends Service {
|
|||
@Override
|
||||
public void onClosed(WebSocket webSocket, int code, String reason) {
|
||||
super.onClosed(webSocket, code, reason);
|
||||
Log.d(TAG,"onClosed");
|
||||
|
||||
if (code == GOING_AWAY_STATUS)
|
||||
handleWebSocketDisconnection(true, true);
|
||||
if(code == GOING_AWAY_STATUS)
|
||||
handleWebSocketDisconnection(true, false);
|
||||
else
|
||||
handleWebSocketDisconnection(false, false);
|
||||
}
|
||||
|
@ -691,7 +688,7 @@ public class NetworkService extends Service {
|
|||
Log.e(TAG,"Response: "+response.message());
|
||||
}
|
||||
|
||||
handleWebSocketDisconnection(true, false);
|
||||
handleWebSocketDisconnection(true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -699,9 +696,10 @@ public class NetworkService extends Service {
|
|||
* potentially tries to reconnect to another one.
|
||||
*
|
||||
* @param tryReconnection States if a reconnection to other node should be tried.
|
||||
* @param removeSelectedNode States if the current node should be removed from the nodes list.
|
||||
* @param penalizeNode Whether or not to penalize the current node with a very high latency reading.
|
||||
*/
|
||||
private void handleWebSocketDisconnection(boolean tryReconnection, boolean removeSelectedNode) {
|
||||
private void handleWebSocketDisconnection(boolean tryReconnection, boolean penalizeNode) {
|
||||
Log.d(TAG,"handleWebSocketDisconnection. try reconnection: " + tryReconnection + ", penalizeNode: " + penalizeNode);
|
||||
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.DISCONNECTED, ApiAccess.API_NONE));
|
||||
|
||||
isLoggedIn = false;
|
||||
|
@ -716,6 +714,13 @@ public class NetworkService extends Service {
|
|||
// Updating the selected node's 'connected' status on the NodeLatencyVerifier instance
|
||||
if(nodeLatencyVerifier != null)
|
||||
nodeLatencyVerifier.updateActiveNodeInformation(mSelectedNode);
|
||||
|
||||
if (penalizeNode){
|
||||
// Adding a very high latency value to this node in order to prevent
|
||||
// us from getting it again
|
||||
mSelectedNode.addLatencyValue(Long.MAX_VALUE);
|
||||
nodeProvider.updateNode(mSelectedNode);
|
||||
}
|
||||
}
|
||||
|
||||
if(tryReconnection) {
|
||||
|
@ -723,20 +728,6 @@ public class NetworkService extends Service {
|
|||
mCurrentId = 0;
|
||||
mApiIds.clear();
|
||||
|
||||
if (removeSelectedNode && mSelectedNode != null) {
|
||||
// Remove node from node provider so that it is not returned for following connections
|
||||
nodeProvider.removeNode(mSelectedNode);
|
||||
|
||||
// Remove node from nodeLatencyVerifier, so that it publishes its removal
|
||||
nodeLatencyVerifier.removeNode(mSelectedNode);
|
||||
// Avoid crash #133
|
||||
} else if (mSelectedNode != null){
|
||||
// Adding a very high latency value to this node in order to prevent
|
||||
// us from getting it again
|
||||
mSelectedNode.addLatencyValue(Long.MAX_VALUE);
|
||||
nodeProvider.updateNode(mSelectedNode);
|
||||
}
|
||||
|
||||
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.DISCONNECTED, ApiAccess.API_NONE));
|
||||
|
||||
if (nodeProvider.getBestNode() == null) {
|
||||
|
@ -746,7 +737,6 @@ public class NetworkService extends Service {
|
|||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, "Retrying");
|
||||
connect();
|
||||
}
|
||||
}, DEFAULT_RETRY_DELAY);
|
||||
|
|
|
@ -25,7 +25,7 @@ import io.reactivex.functions.Consumer;
|
|||
public class CallsActivity extends AppCompatActivity {
|
||||
private final String TAG = this.getClass().getName();
|
||||
|
||||
private static final String REMOVE_CURRENT_NODE = "remove_current_node";
|
||||
private static final String RECONNECT_NODE = "reconnect_node";
|
||||
private static final String TEST_BRAINKEY_DERIVATION = "test_brainkey_derivation";
|
||||
|
||||
@BindView(R.id.call_list)
|
||||
|
@ -82,7 +82,7 @@ public class CallsActivity extends AppCompatActivity {
|
|||
RPC.CALL_GET_ACCOUNT_BALANCES,
|
||||
RPC.CALL_BROADCAST_TRANSACTION,
|
||||
RPC.CALL_GET_TRANSACTION,
|
||||
REMOVE_CURRENT_NODE,
|
||||
RECONNECT_NODE,
|
||||
TEST_BRAINKEY_DERIVATION
|
||||
};
|
||||
|
||||
|
@ -104,7 +104,7 @@ public class CallsActivity extends AppCompatActivity {
|
|||
Intent intent;
|
||||
if(selectedCall.equals(RPC.CALL_SET_SUBSCRIBE_CALLBACK)){
|
||||
intent = new Intent(CallsActivity.this, SubscriptionActivity.class);
|
||||
} else if (selectedCall.equals(REMOVE_CURRENT_NODE)){
|
||||
} else if (selectedCall.equals(RECONNECT_NODE)){
|
||||
intent = new Intent(CallsActivity.this, RemoveNodeActivity.class);
|
||||
} else if (selectedCall.equals(TEST_BRAINKEY_DERIVATION)){
|
||||
intent = new Intent(CallsActivity.this, BrainkeyActivity.class);
|
||||
|
|
|
@ -68,9 +68,9 @@ public class RemoveNodeActivity extends AppCompatActivity implements ServiceConn
|
|||
rvNodes.setAdapter(nodesAdapter);
|
||||
}
|
||||
|
||||
@OnClick(R.id.btnRemoveCurrentNode)
|
||||
@OnClick(R.id.btnReconnectNode)
|
||||
public void removeCurrentNode() {
|
||||
mNetworkService.removeCurrentNodeAndReconnect();
|
||||
mNetworkService.reconnectNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,9 @@ public class SampleApplication extends Application {
|
|||
String[] nodeURLs = new String[]{
|
||||
"wss://bitshares.openledger.info/ws",
|
||||
"wss://us.nodes.bitshares.ws",
|
||||
"wss://eu.nodes.bitshares.ws"
|
||||
"wss://eu.nodes.bitshares.ws",
|
||||
"wss://citadel.li/node",
|
||||
"wss://api.bts.mobi/ws"
|
||||
};
|
||||
List<String> nodeList = Arrays.asList(nodeURLs);
|
||||
String nodes = join(nodeList, ",");
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@+id/btnRemoveCurrentNode"
|
||||
app:layout_constraintBottom_toTopOf="@+id/btnReconnectNode"
|
||||
tools:listitem="@layout/item_node"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnRemoveCurrentNode"
|
||||
android:id="@+id/btnReconnectNode"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Remove current node"
|
||||
android:text="Reconnect node"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
|
Loading…
Reference in a new issue