Skip to content

Commit

Permalink
Added missing channel state check cases for attach and detach
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Nov 20, 2024
1 parent dc4d464 commit 145e254
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/src/main/java/io/ably/lib/realtime/ChannelBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,19 @@ private void attachImpl(final boolean forceReattach, final CompletionListener li
if(!forceReattach) {
/* check preconditions */
switch(state) {
case attaching:
case attaching: //RTL4h
if(listener != null) {
on(new ChannelStateCompletionListener(listener, ChannelState.attached, ChannelState.failed));
}
return;
case detaching: //RTL4h
pendingAttachRequest = new AttachRequest(forceReattach,listener);
return;
case attached:
case attached: //RTL4a
callCompletionListenerSuccess(listener);
return;
case failed: //RTL4g
this.reason = null;
default:
}
}
Expand Down Expand Up @@ -312,19 +314,28 @@ private void detachImpl(CompletionListener listener) throws AblyException {
Log.v(TAG, "detach(); channel = " + name);
/* check preconditions */
switch(state) {
case initialized:
case initialized: // RTL5a
case detached: {
callCompletionListenerSuccess(listener);
return;
}
case detaching:
case detaching: //RTL5i
if (listener != null) {
on(new ChannelStateCompletionListener(listener, ChannelState.detached, ChannelState.failed));
}
return;
case attaching: //RTL5i
pendingDetachRequest = new DetachRequest(listener);
return;
case failed: //RTL5b
ErrorInfo error = this.reason != null ?
this.reason : new ErrorInfo("Channel state is failed", 90000);
callCompletionListenerError(listener, error);
return;
case suspended: //RTL5j
setState(ChannelState.detached, null);
callCompletionListenerSuccess(listener);
return;
default:
}
ConnectionManager connectionManager = ably.connection.connectionManager;
Expand Down

0 comments on commit 145e254

Please sign in to comment.