Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
1ec0835c
Commit
1ec0835c
authored
Aug 08, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do make connection attempts with exponential backoff retries on all cases
parent
77102f5b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
19 deletions
+7
-19
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+7
-19
No files found.
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
1ec0835c
...
@@ -12,7 +12,6 @@ import java.util.Iterator;
...
@@ -12,7 +12,6 @@ import java.util.Iterator;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
bolts.Task
;
import
bolts.Task
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.api.DDPClientWrapper
;
import
chat.rocket.android.api.DDPClientWrapper
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.helper.LogIfError
;
import
chat.rocket.android.helper.LogIfError
;
...
@@ -22,7 +21,6 @@ import chat.rocket.android.log.RCLog;
...
@@ -22,7 +21,6 @@ import chat.rocket.android.log.RCLog;
import
chat.rocket.android.service.ddp.base.ActiveUsersSubscriber
;
import
chat.rocket.android.service.ddp.base.ActiveUsersSubscriber
;
import
chat.rocket.android.service.ddp.base.LoginServiceConfigurationSubscriber
;
import
chat.rocket.android.service.ddp.base.LoginServiceConfigurationSubscriber
;
import
chat.rocket.android.service.ddp.base.UserDataSubscriber
;
import
chat.rocket.android.service.ddp.base.UserDataSubscriber
;
import
chat.rocket.android.service.ddp.stream.StreamRoomMessage
;
import
chat.rocket.android.service.observer.CurrentUserObserver
;
import
chat.rocket.android.service.observer.CurrentUserObserver
;
import
chat.rocket.android.service.observer.FileUploadingToUrlObserver
;
import
chat.rocket.android.service.observer.FileUploadingToUrlObserver
;
import
chat.rocket.android.service.observer.FileUploadingWithUfsObserver
;
import
chat.rocket.android.service.observer.FileUploadingWithUfsObserver
;
...
@@ -69,7 +67,6 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -69,7 +67,6 @@ public class RocketChatWebSocketThread extends HandlerThread {
private
final
ArrayList
<
Registrable
>
listeners
=
new
ArrayList
<>();
private
final
ArrayList
<
Registrable
>
listeners
=
new
ArrayList
<>();
private
DDPClientWrapper
ddpClient
;
private
DDPClientWrapper
ddpClient
;
private
boolean
listenersRegistered
;
private
boolean
listenersRegistered
;
private
RocketChatCache
rocketChatCache
;
private
final
DDPClientRef
ddpClientRef
=
new
DDPClientRef
()
{
private
final
DDPClientRef
ddpClientRef
=
new
DDPClientRef
()
{
@Override
@Override
public
DDPClientWrapper
get
()
{
public
DDPClientWrapper
get
()
{
...
@@ -103,7 +100,6 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -103,7 +100,6 @@ public class RocketChatWebSocketThread extends HandlerThread {
this
.
hostname
=
hostname
;
this
.
hostname
=
hostname
;
this
.
realmHelper
=
RealmStore
.
getOrCreate
(
hostname
);
this
.
realmHelper
=
RealmStore
.
getOrCreate
(
hostname
);
this
.
connectivityManager
=
ConnectivityManager
.
getInstanceForInternal
(
appContext
);
this
.
connectivityManager
=
ConnectivityManager
.
getInstanceForInternal
(
appContext
);
this
.
rocketChatCache
=
new
RocketChatCache
(
appContext
);
}
}
/**
/**
...
@@ -185,7 +181,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -185,7 +181,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
@DebugLog
@DebugLog
public
Single
<
Boolean
>
keepAlive
()
{
public
Single
<
Boolean
>
keepAlive
()
{
return
checkIfConnectionAlive
()
return
checkIfConnectionAlive
()
.
flatMap
(
alive
->
alive
?
Single
.
just
(
true
)
:
connect
());
.
flatMap
(
alive
->
alive
?
Single
.
just
(
true
)
:
connect
WithExponentialBackoff
());
}
}
private
Single
<
Boolean
>
checkIfConnectionAlive
()
{
private
Single
<
Boolean
>
checkIfConnectionAlive
()
{
...
@@ -247,13 +243,11 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -247,13 +243,11 @@ public class RocketChatWebSocketThread extends HandlerThread {
// TODO: Should update to RxJava 2
// TODO: Should update to RxJava 2
final
CompositeSubscription
subscriptions
=
new
CompositeSubscription
();
final
CompositeSubscription
subscriptions
=
new
CompositeSubscription
();
subscriptions
.
add
(
subscriptions
.
add
(
connect
().
retryWhen
(
RxHelper
.
exponentialBackoff
(
3
,
500
,
TimeUnit
.
MILLISECONDS
)
)
connect
WithExponentialBackoff
(
)
.
subscribe
(
.
subscribe
(
connected
->
{
connected
->
{
if
(!
connected
)
{
if
(!
connected
)
{
connectivityManager
.
notifyConnectionLost
(
connectivityManager
.
notifyConnecting
(
hostname
);
hostname
,
ConnectivityManagerInternal
.
REASON_NETWORK_ERROR
);
}
}
subscriptions
.
clear
();
subscriptions
.
clear
();
},
},
...
@@ -295,6 +289,10 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -295,6 +289,10 @@ public class RocketChatWebSocketThread extends HandlerThread {
subscriptions
.
clear
();
subscriptions
.
clear
();
}
}
private
Single
<
Boolean
>
connectWithExponentialBackoff
()
{
return
connect
().
retryWhen
(
RxHelper
.
exponentialBackoff
(
Integer
.
MAX_VALUE
,
500
,
TimeUnit
.
MILLISECONDS
));
}
@DebugLog
@DebugLog
private
Single
<
Boolean
>
connect
()
{
private
Single
<
Boolean
>
connect
()
{
return
connectDDPClient
()
return
connectDDPClient
()
...
@@ -343,16 +341,6 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -343,16 +341,6 @@ public class RocketChatWebSocketThread extends HandlerThread {
RCLog
.
w
(
exception
,
"Failed to register listeners!!"
);
RCLog
.
w
(
exception
,
"Failed to register listeners!!"
);
}
}
}
}
// Register for room stream messages
String
roomId
=
rocketChatCache
.
getSelectedRoomId
();
if
(
roomId
!=
null
&&
!
roomId
.
isEmpty
())
{
StreamRoomMessage
streamRoomMessage
=
new
StreamRoomMessage
(
appContext
,
hostname
,
realmHelper
,
ddpClientRef
,
roomId
);
streamRoomMessage
.
register
();
listeners
.
add
(
streamRoomMessage
);
}
}
}
@DebugLog
@DebugLog
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment