mirror of https://github.com/grpc/grpc-java.git
core: ConnectivityStateManager is always enabled
There have been no callers of disable() since commit 1c7421be7.
This commit is contained in:
parent
35665af72c
commit
3480a08e70
|
|
@ -17,14 +17,12 @@
|
||||||
package io.grpc.internal;
|
package io.grpc.internal;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
|
||||||
|
|
||||||
import io.grpc.ConnectivityState;
|
import io.grpc.ConnectivityState;
|
||||||
import io.grpc.ManagedChannel;
|
import io.grpc.ManagedChannel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -63,11 +61,6 @@ final class ConnectivityStateManager {
|
||||||
*/
|
*/
|
||||||
void gotoState(@Nonnull ConnectivityState newState) {
|
void gotoState(@Nonnull ConnectivityState newState) {
|
||||||
checkNotNull(newState, "newState");
|
checkNotNull(newState, "newState");
|
||||||
checkState(!isDisabled(), "ConnectivityStateManager is already disabled");
|
|
||||||
gotoNullableState(newState);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void gotoNullableState(@Nullable ConnectivityState newState) {
|
|
||||||
if (state != newState && state != ConnectivityState.SHUTDOWN) {
|
if (state != newState && state != ConnectivityState.SHUTDOWN) {
|
||||||
state = newState;
|
state = newState;
|
||||||
if (listeners.isEmpty()) {
|
if (listeners.isEmpty()) {
|
||||||
|
|
@ -94,21 +87,6 @@ final class ConnectivityStateManager {
|
||||||
return stateCopy;
|
return stateCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this method when the channel learns from the load balancer that channel state API is not
|
|
||||||
* supported.
|
|
||||||
*/
|
|
||||||
void disable() {
|
|
||||||
gotoNullableState(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is threadsafe.
|
|
||||||
*/
|
|
||||||
boolean isDisabled() {
|
|
||||||
return state == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class Listener {
|
private static final class Listener {
|
||||||
final Runnable callback;
|
final Runnable callback;
|
||||||
final Executor executor;
|
final Executor executor;
|
||||||
|
|
|
||||||
|
|
@ -369,9 +369,7 @@ public final class ManagedChannelImpl extends ManagedChannel implements Instrume
|
||||||
lbHelper.lb.shutdown();
|
lbHelper.lb.shutdown();
|
||||||
lbHelper = null;
|
lbHelper = null;
|
||||||
subchannelPicker = null;
|
subchannelPicker = null;
|
||||||
if (!channelStateManager.isDisabled()) {
|
channelStateManager.gotoState(IDLE);
|
||||||
channelStateManager.gotoState(IDLE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must be run from channelExecutor
|
// Must be run from channelExecutor
|
||||||
|
|
@ -596,9 +594,7 @@ public final class ManagedChannelImpl extends ManagedChannel implements Instrume
|
||||||
channelExecutor.executeLater(new Runnable() {
|
channelExecutor.executeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!channelStateManager.isDisabled()) {
|
channelStateManager.gotoState(SHUTDOWN);
|
||||||
channelStateManager.gotoState(SHUTDOWN);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import static io.grpc.ConnectivityState.READY;
|
||||||
import static io.grpc.ConnectivityState.SHUTDOWN;
|
import static io.grpc.ConnectivityState.SHUTDOWN;
|
||||||
import static io.grpc.ConnectivityState.TRANSIENT_FAILURE;
|
import static io.grpc.ConnectivityState.TRANSIENT_FAILURE;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
import io.grpc.ConnectivityState;
|
import io.grpc.ConnectivityState;
|
||||||
|
|
@ -234,36 +233,6 @@ public class ConnectivityStateManagerTest {
|
||||||
assertEquals(READY, sink.poll());
|
assertEquals(READY, sink.poll());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disable() {
|
|
||||||
state.disable();
|
|
||||||
assertTrue(state.isDisabled());
|
|
||||||
|
|
||||||
thrown.expect(UnsupportedOperationException.class);
|
|
||||||
thrown.expectMessage("Channel state API is not implemented");
|
|
||||||
state.getState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disableThenDisable() {
|
|
||||||
state.disable();
|
|
||||||
state.disable();
|
|
||||||
assertTrue(state.isDisabled());
|
|
||||||
|
|
||||||
thrown.expect(UnsupportedOperationException.class);
|
|
||||||
thrown.expectMessage("Channel state API is not implemented");
|
|
||||||
state.getState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disableThenGotoReady() {
|
|
||||||
state.disable();
|
|
||||||
|
|
||||||
thrown.expect(IllegalStateException.class);
|
|
||||||
thrown.expectMessage("ConnectivityStateManager is already disabled");
|
|
||||||
state.gotoState(READY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shutdownThenReady() {
|
public void shutdownThenReady() {
|
||||||
state.gotoState(SHUTDOWN);
|
state.gotoState(SHUTDOWN);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue