Class RealSubscriptionManager
- java.lang.Object
-
- com.apollographql.apollo.internal.subscription.RealSubscriptionManager
-
- All Implemented Interfaces:
SubscriptionManager
public final class RealSubscriptionManager extends java.lang.Object implements SubscriptionManager
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.apollographql.apollo.internal.subscription.SubscriptionManager
SubscriptionManager.Callback<T>
-
-
Constructor Summary
Constructors Constructor Description RealSubscriptionManager(com.apollographql.apollo.api.ScalarTypeAdapters scalarTypeAdapters, SubscriptionTransport.Factory transportFactory, SubscriptionConnectionParamsProvider connectionParams, java.util.concurrent.Executor dispatcher, long connectionHeartbeatTimeoutMs, kotlin.jvm.functions.Function0<com.apollographql.apollo.cache.normalized.internal.ResponseNormalizer<java.util.Map<java.lang.String,java.lang.Object>>> responseNormalizer, boolean autoPersistSubscription)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddOnStateChangeListener(OnSubscriptionManagerStateChangeListener onStateChangeListener)Adds new listener for subscription manager state changes.SubscriptionManagerStategetState()Returns the current state of subscription manager.voidreconnect()Reconnect the web socket.voidremoveOnStateChangeListener(OnSubscriptionManagerStateChangeListener onStateChangeListener)Removes listener for subscription manager state changes.voidstart()Set theRealSubscriptionManagerto a connectible state.voidstop()Unsubscribe from all active subscriptions, and disconnect the web socket.<T> voidsubscribe(com.apollographql.apollo.api.Subscription<?,T,?> subscription, SubscriptionManager.Callback<T> callback)Starts provided subscription.voidunsubscribe(com.apollographql.apollo.api.Subscription subscription)Stops provided subscription.
-
-
-
Constructor Detail
-
RealSubscriptionManager
public RealSubscriptionManager(@NotNull com.apollographql.apollo.api.ScalarTypeAdapters scalarTypeAdapters, @NotNull SubscriptionTransport.Factory transportFactory, @NotNull SubscriptionConnectionParamsProvider connectionParams, @NotNull java.util.concurrent.Executor dispatcher, long connectionHeartbeatTimeoutMs, @NotNull kotlin.jvm.functions.Function0<com.apollographql.apollo.cache.normalized.internal.ResponseNormalizer<java.util.Map<java.lang.String,java.lang.Object>>> responseNormalizer, boolean autoPersistSubscription)
-
-
Method Detail
-
subscribe
public <T> void subscribe(@NotNull com.apollographql.apollo.api.Subscription<?,T,?> subscription, @NotNull SubscriptionManager.Callback<T> callback)Description copied from interface:SubscriptionManagerStarts provided subscription. Establishes connection to the subscription server if it was previously disconnected.- Specified by:
subscribein interfaceSubscriptionManager- Parameters:
subscription- to startcallback- to be called on result
-
unsubscribe
public void unsubscribe(@NotNull com.apollographql.apollo.api.Subscription subscription)Description copied from interface:SubscriptionManagerStops provided subscription. If there are no active subscriptions left, disconnects from the subscription server.- Specified by:
unsubscribein interfaceSubscriptionManager- Parameters:
subscription- to stop
-
start
public void start()
Set theRealSubscriptionManagerto a connectible state. It is safe to call this method at any time. Does nothing unless we are in the stopped state.- Specified by:
startin interfaceSubscriptionManager
-
stop
public void stop()
Unsubscribe from all active subscriptions, and disconnect the web socket. It will not be possible to add new subscriptions while theSubscriptionManageris stopping because we check the state indoSubscribe(Subscription, Callback). We pass true todisconnect(boolean)because we want to disconnect even if, somehow, a new subscription is added while or after we are doing thedoUnsubscribe(Subscription)loop.- Specified by:
stopin interfaceSubscriptionManager
-
getState
public SubscriptionManagerState getState()
Description copied from interface:SubscriptionManagerReturns the current state of subscription manager.- Specified by:
getStatein interfaceSubscriptionManager- Returns:
- current state
-
addOnStateChangeListener
public void addOnStateChangeListener(@NotNull OnSubscriptionManagerStateChangeListener onStateChangeListener)Description copied from interface:SubscriptionManagerAdds new listener for subscription manager state changes.- Specified by:
addOnStateChangeListenerin interfaceSubscriptionManager- Parameters:
onStateChangeListener- to be called when state changed
-
removeOnStateChangeListener
public void removeOnStateChangeListener(@NotNull OnSubscriptionManagerStateChangeListener onStateChangeListener)Description copied from interface:SubscriptionManagerRemoves listener for subscription manager state changes.- Specified by:
removeOnStateChangeListenerin interfaceSubscriptionManager- Parameters:
onStateChangeListener- to remove
-
reconnect
public void reconnect()
Description copied from interface:SubscriptionManagerReconnect the web socket. Use this together with SubscriptionConnectionParamsProvider if you need to update connectionParams.- Specified by:
reconnectin interfaceSubscriptionManager
-
-