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
54632d59
Commit
54632d59
authored
Feb 20, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding extra on error handler
parent
dd29cdd7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
168 additions
and
129 deletions
+168
-129
DDPClientImpl.java
.../src/main/java/chat/rocket/android_ddp/DDPClientImpl.java
+148
-113
AbstractDDPDocEventSubscriber.java
...et/android/service/ddp/AbstractDDPDocEventSubscriber.java
+20
-16
No files found.
android-ddp/src/main/java/chat/rocket/android_ddp/DDPClientImpl.java
View file @
54632d59
...
@@ -54,17 +54,25 @@ public class DDPClientImpl {
...
@@ -54,17 +54,25 @@ public class DDPClientImpl {
flowable
=
websocket
.
connect
(
url
).
autoConnect
();
flowable
=
websocket
.
connect
(
url
).
autoConnect
();
CompositeDisposable
subscriptions
=
new
CompositeDisposable
();
CompositeDisposable
subscriptions
=
new
CompositeDisposable
();
subscriptions
.
add
(
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Open
)
subscriptions
.
add
(
.
subscribe
(
callback
->
{
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Open
)
.
subscribe
(
callback
->
{
sendMessage
(
"connect"
,
sendMessage
(
"connect"
,
json
->
(
TextUtils
.
isEmpty
(
session
)
?
json
:
json
.
put
(
"session"
,
session
)).
put
(
json
->
(
TextUtils
.
isEmpty
(
session
)
?
json
:
json
.
put
(
"session"
,
session
))
"version"
,
"pre2"
).
put
(
"support"
,
new
JSONArray
().
put
(
"pre2"
).
put
(
"pre1"
)),
.
put
(
"version"
,
"pre2"
)
.
put
(
"support"
,
new
JSONArray
().
put
(
"pre2"
).
put
(
"pre1"
)),
task
);
task
);
},
err
->
{
},
}));
err
->
{
}
)
);
subscriptions
.
add
(
subscriptions
.
add
(
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Message
)
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Message
)
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
DDPClientImpl:
:
toJson
)
.
map
(
DDPClientImpl:
:
toJson
)
.
timeout
(
7
,
TimeUnit
.
SECONDS
)
.
timeout
(
7
,
TimeUnit
.
SECONDS
)
...
@@ -83,9 +91,10 @@ public class DDPClientImpl {
...
@@ -83,9 +91,10 @@ public class DDPClientImpl {
new
DDPClientCallback
.
Connect
.
Failed
(
client
,
response
.
optString
(
"version"
)));
new
DDPClientCallback
.
Connect
.
Failed
(
client
,
response
.
optString
(
"version"
)));
subscriptions
.
dispose
();
subscriptions
.
dispose
();
}
}
},
err
->
{
},
task
.
trySetError
(
new
DDPClientCallback
.
Connect
.
Timeout
(
client
));
err
->
task
.
trySetError
(
new
DDPClientCallback
.
Connect
.
Timeout
(
client
))
}));
)
);
addErrorCallback
(
subscriptions
,
task
);
addErrorCallback
(
subscriptions
,
task
);
...
@@ -110,7 +119,8 @@ public class DDPClientImpl {
...
@@ -110,7 +119,8 @@ public class DDPClientImpl {
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
DDPClientImpl:
:
toJson
)
.
map
(
DDPClientImpl:
:
toJson
)
.
timeout
(
4
,
TimeUnit
.
SECONDS
)
.
timeout
(
4
,
TimeUnit
.
SECONDS
)
.
subscribe
(
response
->
{
.
subscribe
(
response
->
{
String
msg
=
extractMsg
(
response
);
String
msg
=
extractMsg
(
response
);
if
(
"pong"
.
equals
(
msg
))
{
if
(
"pong"
.
equals
(
msg
))
{
if
(
response
.
isNull
(
"id"
))
{
if
(
response
.
isNull
(
"id"
))
{
...
@@ -124,9 +134,10 @@ public class DDPClientImpl {
...
@@ -124,9 +134,10 @@ public class DDPClientImpl {
}
}
}
}
}
}
},
err
->
{
},
task
.
setError
(
new
DDPClientCallback
.
Ping
.
Timeout
(
client
));
err
->
task
.
setError
(
new
DDPClientCallback
.
Ping
.
Timeout
(
client
))
}));
)
);
addErrorCallback
(
subscriptions
,
task
);
addErrorCallback
(
subscriptions
,
task
);
}
else
{
}
else
{
...
@@ -146,7 +157,8 @@ public class DDPClientImpl {
...
@@ -146,7 +157,8 @@ public class DDPClientImpl {
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Message
)
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Message
)
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
DDPClientImpl:
:
toJson
)
.
map
(
DDPClientImpl:
:
toJson
)
.
subscribe
(
response
->
{
.
subscribe
(
response
->
{
String
msg
=
extractMsg
(
response
);
String
msg
=
extractMsg
(
response
);
if
(
"ready"
.
equals
(
msg
)
&&
!
response
.
isNull
(
"subs"
))
{
if
(
"ready"
.
equals
(
msg
)
&&
!
response
.
isNull
(
"subs"
))
{
JSONArray
ids
=
response
.
optJSONArray
(
"subs"
);
JSONArray
ids
=
response
.
optJSONArray
(
"subs"
);
...
@@ -167,8 +179,11 @@ public class DDPClientImpl {
...
@@ -167,8 +179,11 @@ public class DDPClientImpl {
subscriptions
.
dispose
();
subscriptions
.
dispose
();
}
}
}
}
},
err
->
{
},
}));
err
->
{
}
)
);
addErrorCallback
(
subscriptions
,
task
);
addErrorCallback
(
subscriptions
,
task
);
}
else
{
}
else
{
...
@@ -188,7 +203,8 @@ public class DDPClientImpl {
...
@@ -188,7 +203,8 @@ public class DDPClientImpl {
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Message
)
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Message
)
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
DDPClientImpl:
:
toJson
)
.
map
(
DDPClientImpl:
:
toJson
)
.
subscribe
(
response
->
{
.
subscribe
(
response
->
{
String
msg
=
extractMsg
(
response
);
String
msg
=
extractMsg
(
response
);
if
(
"nosub"
.
equals
(
msg
)
&&
response
.
isNull
(
"error"
)
&&
!
response
.
isNull
(
"id"
))
{
if
(
"nosub"
.
equals
(
msg
)
&&
response
.
isNull
(
"error"
)
&&
!
response
.
isNull
(
"id"
))
{
String
_id
=
response
.
optString
(
"id"
);
String
_id
=
response
.
optString
(
"id"
);
...
@@ -197,8 +213,11 @@ public class DDPClientImpl {
...
@@ -197,8 +213,11 @@ public class DDPClientImpl {
subscriptions
.
dispose
();
subscriptions
.
dispose
();
}
}
}
}
},
err
->
{
},
}));
err
->
{
}
)
);
addErrorCallback
(
subscriptions
,
task
);
addErrorCallback
(
subscriptions
,
task
);
}
else
{
}
else
{
...
@@ -220,7 +239,8 @@ public class DDPClientImpl {
...
@@ -220,7 +239,8 @@ public class DDPClientImpl {
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
DDPClientImpl:
:
toJson
)
.
map
(
DDPClientImpl:
:
toJson
)
.
timeout
(
timeoutMs
,
TimeUnit
.
MILLISECONDS
)
.
timeout
(
timeoutMs
,
TimeUnit
.
MILLISECONDS
)
.
subscribe
(
response
->
{
.
subscribe
(
response
->
{
String
msg
=
extractMsg
(
response
);
String
msg
=
extractMsg
(
response
);
if
(
"result"
.
equals
(
msg
))
{
if
(
"result"
.
equals
(
msg
))
{
String
_id
=
response
.
optString
(
"id"
);
String
_id
=
response
.
optString
(
"id"
);
...
@@ -235,11 +255,14 @@ public class DDPClientImpl {
...
@@ -235,11 +255,14 @@ public class DDPClientImpl {
subscriptions
.
dispose
();
subscriptions
.
dispose
();
}
}
}
}
},
err
->
{
},
err
->
{
if
(
err
instanceof
TimeoutException
)
{
if
(
err
instanceof
TimeoutException
)
{
task
.
setError
(
new
DDPClientCallback
.
RPC
.
Timeout
(
client
));
task
.
setError
(
new
DDPClientCallback
.
RPC
.
Timeout
(
client
));
}
}
}));
}
)
);
addErrorCallback
(
subscriptions
,
task
);
addErrorCallback
(
subscriptions
,
task
);
}
else
{
}
else
{
...
@@ -258,7 +281,8 @@ public class DDPClientImpl {
...
@@ -258,7 +281,8 @@ public class DDPClientImpl {
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Message
)
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Message
)
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
callback
->
((
RxWebSocketCallback
.
Message
)
callback
).
responseBodyString
)
.
map
(
DDPClientImpl:
:
toJson
)
.
map
(
DDPClientImpl:
:
toJson
)
.
subscribe
(
response
->
{
.
subscribe
(
response
->
{
String
msg
=
extractMsg
(
response
);
String
msg
=
extractMsg
(
response
);
if
(
"ping"
.
equals
(
msg
))
{
if
(
"ping"
.
equals
(
msg
))
{
if
(
response
.
isNull
(
"id"
))
{
if
(
response
.
isNull
(
"id"
))
{
...
@@ -267,8 +291,11 @@ public class DDPClientImpl {
...
@@ -267,8 +291,11 @@ public class DDPClientImpl {
sendMessage
(
"pong"
,
json
->
json
.
put
(
"id"
,
response
.
getString
(
"id"
)));
sendMessage
(
"pong"
,
json
->
json
.
put
(
"id"
,
response
.
getString
(
"id"
)));
}
}
}
}
},
err
->
{
},
}));
err
->
{
}
)
);
}
}
public
Flowable
<
DDPSubscription
.
Event
>
getDDPSubscription
()
{
public
Flowable
<
DDPSubscription
.
Event
>
getDDPSubscription
()
{
...
@@ -325,13 +352,16 @@ public class DDPClientImpl {
...
@@ -325,13 +352,16 @@ public class DDPClientImpl {
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Close
)
flowable
.
filter
(
callback
->
callback
instanceof
RxWebSocketCallback
.
Close
)
.
cast
(
RxWebSocketCallback
.
Close
.
class
)
.
cast
(
RxWebSocketCallback
.
Close
.
class
)
.
subscribe
(
task:
:
setResult
,
err
->
{
.
subscribe
(
task:
:
setResult
,
err
->
{
if
(
err
instanceof
Exception
)
{
if
(
err
instanceof
Exception
)
{
task
.
setError
((
Exception
)
err
);
task
.
setError
((
Exception
)
err
);
}
else
{
}
else
{
task
.
setError
(
new
Exception
(
err
));
task
.
setError
(
new
Exception
(
err
));
}
}
});
}
);
return
task
.
getTask
().
onSuccessTask
(
_task
->
{
return
task
.
getTask
().
onSuccessTask
(
_task
->
{
unsubscribeBaseListeners
();
unsubscribeBaseListeners
();
...
@@ -358,11 +388,16 @@ public class DDPClientImpl {
...
@@ -358,11 +388,16 @@ public class DDPClientImpl {
}
}
private
void
addErrorCallback
(
CompositeDisposable
subscriptions
,
TaskCompletionSource
<?>
task
)
{
private
void
addErrorCallback
(
CompositeDisposable
subscriptions
,
TaskCompletionSource
<?>
task
)
{
subscriptions
.
add
(
flowable
.
subscribe
(
base
->
{
subscriptions
.
add
(
},
err
->
{
flowable
.
subscribe
(
base
->
{
},
err
->
{
task
.
trySetError
(
new
Exception
(
err
));
task
.
trySetError
(
new
Exception
(
err
));
subscriptions
.
dispose
();
subscriptions
.
dispose
();
}));
}
)
);
}
}
public
void
close
(
int
code
,
String
reason
)
{
public
void
close
(
int
code
,
String
reason
)
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/AbstractDDPDocEventSubscriber.java
View file @
54632d59
...
@@ -99,7 +99,8 @@ public abstract class AbstractDDPDocEventSubscriber implements Registrable {
...
@@ -99,7 +99,8 @@ public abstract class AbstractDDPDocEventSubscriber implements Registrable {
.
filter
(
event
->
event
instanceof
DDPSubscription
.
DocEvent
)
.
filter
(
event
->
event
instanceof
DDPSubscription
.
DocEvent
)
.
cast
(
DDPSubscription
.
DocEvent
.
class
)
.
cast
(
DDPSubscription
.
DocEvent
.
class
)
.
filter
(
event
->
isTarget
(
event
.
collection
))
.
filter
(
event
->
isTarget
(
event
.
collection
))
.
subscribe
(
docEvent
->
{
.
subscribe
(
docEvent
->
{
try
{
try
{
if
(
docEvent
instanceof
DDPSubscription
.
Added
.
Before
)
{
if
(
docEvent
instanceof
DDPSubscription
.
Added
.
Before
)
{
onDocumentAdded
((
DDPSubscription
.
Added
)
docEvent
);
//ignore Before
onDocumentAdded
((
DDPSubscription
.
Added
)
docEvent
);
//ignore Before
...
@@ -115,7 +116,10 @@ public abstract class AbstractDDPDocEventSubscriber implements Registrable {
...
@@ -115,7 +116,10 @@ public abstract class AbstractDDPDocEventSubscriber implements Registrable {
}
catch
(
Exception
exception
)
{
}
catch
(
Exception
exception
)
{
RCLog
.
w
(
exception
,
"failed to handle subscription callback"
);
RCLog
.
w
(
exception
,
"failed to handle subscription callback"
);
}
}
});
},
throwable
->
{
}
);
}
}
protected
void
onDocumentAdded
(
DDPSubscription
.
Added
docEvent
)
{
protected
void
onDocumentAdded
(
DDPSubscription
.
Added
docEvent
)
{
...
...
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