Top Description Constructors Methods
io.grpc

public abstract Class ManagedChannel

extends Channel
Class Inheritance
Annotations
@ThreadSafe
Imports
java.util.concurrent.TimeUnit, javax.annotation.concurrent.ThreadSafe

A Channel that provides lifecycle management.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract boolean

Returns:

whether the channel is terminated, as would be done by isTerminated().
awaitTermination
(long timeout, TimeUnit unit)

Waits for the channel to become terminated, giving up if the timeout is reached.

public void
enterIdle()

Invoking this method moves the channel into the IDLE state and triggers tear-down of the channel's name resolver and load balancer, while still allowing on-going RPCs on the channel to continue.

public ConnectivityState
getState(boolean
if true, the channel will try to make a connection if it is currently IDLE
requestConnection
)

Gets the current connectivity state.

public abstract boolean
isShutdown()

Returns whether the channel is shutdown.

public abstract boolean
isTerminated()

Returns whether the channel is terminated.

public void
notifyWhenStateChanged(ConnectivityState
the assumed current state, typically just returned by getState
source
,
Runnable
the one-off callback
callback
)

Registers a one-off callback that will be run if the connectivity state of the channel diverges from the given source, which is typically what has just been returned by getState.

public void
resetConnectBackoff()

For subchannels that are in TRANSIENT_FAILURE state, short-circuit the backoff timer and make them reconnect immediately.

public abstract ManagedChannel

Returns:

this
shutdown
()

Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.

public abstract ManagedChannel

Returns:

this
shutdownNow
()

Initiates a forceful shutdown in which preexisting and new calls are cancelled.

Inherited from io.grpc.Channel:
authoritynewCall

Constructor Detail

ManagedChannelback to summary
public ManagedChannel()

Method Detail

awaitTerminationback to summary
public abstract boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException

Waits for the channel to become terminated, giving up if the timeout is reached.

Returns:boolean

whether the channel is terminated, as would be done by isTerminated().

Since
1.0.0
enterIdleback to summary
public void enterIdle()

Invoking this method moves the channel into the IDLE state and triggers tear-down of the channel's name resolver and load balancer, while still allowing on-going RPCs on the channel to continue. New RPCs on the channel will trigger creation of a new connection.

This is primarily intended for Android users when a device is transitioning from a cellular to a wifi connection. The OS will issue a notification that a new network (wifi) has been made the default, but for approximately 30 seconds the device will maintain both the cellular and wifi connections. Apps may invoke this method to ensure that new RPCs are created using the new default wifi network, rather than the soon-to-be-disconnected cellular network.

No-op if not supported by implementation.

Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/4056
Since
1.11.0
getStateback to summary
public ConnectivityState getState(boolean requestConnection)

Gets the current connectivity state. Note the result may soon become outdated.

Note that the core library did not provide an implementation of this method until v1.6.1.

Parameters
requestConnection:boolean

if true, the channel will try to make a connection if it is currently IDLE

Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/4359
Exceptions
UnsupportedOperationException:
if not supported by implementation
Since
1.1.0
isShutdownback to summary
public abstract boolean isShutdown()

Returns whether the channel is shutdown. Shutdown channels immediately cancel any new calls, but may still have some calls being processed.

Since
1.0.0
See Also
shutdown(), isTerminated()
isTerminatedback to summary
public abstract boolean isTerminated()

Returns whether the channel is terminated. Terminated channels have no running calls and relevant resources released (like TCP connections).

Since
1.0.0
See Also
isShutdown()
notifyWhenStateChangedback to summary
public void notifyWhenStateChanged(ConnectivityState source, Runnable callback)

Registers a one-off callback that will be run if the connectivity state of the channel diverges from the given source, which is typically what has just been returned by getState. If the states are already different, the callback will be called immediately. The callback is run in the same executor that runs Call listeners.

There is an inherent race between the notification to callback and any call to getState(). There is a similar race between getState() and a call to notifyWhenStateChanged(). The state can change during those races, so there is not a way to see every state transition. "Transitions" to the same state are possible, because intermediate states may not have been observed. The API is only reliable in tracking the current state.

Note that the core library did not provide an implementation of this method until v1.6.1.

Parameters
source:ConnectivityState

the assumed current state, typically just returned by getState

callback:Runnable

the one-off callback

Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/4359
Exceptions
UnsupportedOperationException:
if not supported by implementation
Since
1.1.0
resetConnectBackoffback to summary
public void resetConnectBackoff()

For subchannels that are in TRANSIENT_FAILURE state, short-circuit the backoff timer and make them reconnect immediately. May also attempt to invoke NameResolver#refresh.

This is primarily intended for Android users, where the network may experience frequent temporary drops. Rather than waiting for gRPC's name resolution and reconnect timers to elapse before reconnecting, the app may use this method as a mechanism to notify gRPC that the network is now available and a reconnection attempt may occur immediately.

No-op if not supported by the implementation.

Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/4056
Since
1.8.0
shutdownback to summary
public abstract ManagedChannel shutdown()

Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.

Returns:ManagedChannel

this

Since
1.0.0
shutdownNowback to summary
public abstract ManagedChannel shutdownNow()

Initiates a forceful shutdown in which preexisting and new calls are cancelled. Although forceful, the shutdown process is still not instantaneous; isTerminated() will likely return false immediately after this method returns.

Returns:ManagedChannel

this

Since
1.0.0