当前位置: 首页>>代码示例>>Java>>正文


Java ConnectivityState类代码示例

本文整理汇总了Java中io.grpc.ConnectivityState的典型用法代码示例。如果您正苦于以下问题:Java ConnectivityState类的具体用法?Java ConnectivityState怎么用?Java ConnectivityState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConnectivityState类属于io.grpc包,在下文中一共展示了ConnectivityState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAggregatedState

import io.grpc.ConnectivityState; //导入依赖的package包/类
private ConnectivityState getAggregatedState() {
  Set<ConnectivityState> states = EnumSet.noneOf(ConnectivityState.class);
  for (Subchannel subchannel : getSubchannels()) {
    states.add(getSubchannelStateInfoRef(subchannel).get().getState());
  }
  if (states.contains(READY)) {
    return READY;
  }
  if (states.contains(CONNECTING)) {
    return CONNECTING;
  }
  if (states.contains(IDLE)) {
    return CONNECTING;
  }
  return TRANSIENT_FAILURE;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:17,代码来源:GrpcRouteRoundRobinLbFactory.java

示例2: delegatingPickFirstThenNameResolutionFails

import io.grpc.ConnectivityState; //导入依赖的package包/类
@Test
public void delegatingPickFirstThenNameResolutionFails() {
  List<EquivalentAddressGroup> resolvedServers = createResolvedServerAddresses(false);

  Attributes resolutionAttrs = Attributes.newBuilder().set(RESOLUTION_ATTR, "yeah").build();
  deliverResolvedAddresses(resolvedServers, resolutionAttrs);

  verify(pickFirstBalancerFactory).newLoadBalancer(helper);
  verify(pickFirstBalancer).handleResolvedAddressGroups(eq(resolvedServers), eq(resolutionAttrs));

  // Then let name resolution fail.  The error will be passed directly to the delegate.
  Status error = Status.NOT_FOUND.withDescription("www.google.com not found");
  deliverNameResolutionError(error);
  verify(pickFirstBalancer).handleNameResolutionError(error);
  verify(helper, never())
      .updateBalancingState(any(ConnectivityState.class), any(SubchannelPicker.class));
  verifyNoMoreInteractions(roundRobinBalancerFactory);
  verifyNoMoreInteractions(roundRobinBalancer);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:20,代码来源:GrpclbLoadBalancerTest.java

示例3: delegatingRoundRobinThenNameResolutionFails

import io.grpc.ConnectivityState; //导入依赖的package包/类
@Test
public void delegatingRoundRobinThenNameResolutionFails() {
  List<EquivalentAddressGroup> resolvedServers = createResolvedServerAddresses(false, false);

  Attributes resolutionAttrs = Attributes.newBuilder()
      .set(RESOLUTION_ATTR, "yeah")
      .set(GrpclbConstants.ATTR_LB_POLICY, LbPolicy.ROUND_ROBIN)
      .build();
  deliverResolvedAddresses(resolvedServers, resolutionAttrs);

  verify(roundRobinBalancerFactory).newLoadBalancer(helper);
  verify(roundRobinBalancer).handleResolvedAddressGroups(resolvedServers, resolutionAttrs);

  // Then let name resolution fail.  The error will be passed directly to the delegate.
  Status error = Status.NOT_FOUND.withDescription("www.google.com not found");
  deliverNameResolutionError(error);
  verify(roundRobinBalancer).handleNameResolutionError(error);
  verify(helper, never())
      .updateBalancingState(any(ConnectivityState.class), any(SubchannelPicker.class));
  verifyNoMoreInteractions(pickFirstBalancerFactory);
  verifyNoMoreInteractions(pickFirstBalancer);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:23,代码来源:GrpclbLoadBalancerTest.java

示例4: updateBalancingState

import io.grpc.ConnectivityState; //导入依赖的package包/类
@Override
public void updateBalancingState(
    final ConnectivityState newState, final SubchannelPicker newPicker) {
  checkNotNull(newState, "newState");
  checkNotNull(newPicker, "newPicker");

  runSerialized(
      new Runnable() {
        @Override
        public void run() {
          if (LbHelperImpl.this != lbHelper) {
            return;
          }
          subchannelPicker = newPicker;
          delayedTransport.reprocess(newPicker);
          // It's not appropriate to report SHUTDOWN state from lb.
          // Ignore the case of newState == SHUTDOWN for now.
          if (newState != SHUTDOWN) {
            channelStateManager.gotoState(newState);
          }
        }
      });
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:24,代码来源:ManagedChannelImpl.java

示例5: getAggregatedState

import io.grpc.ConnectivityState; //导入依赖的package包/类
private ConnectivityState getAggregatedState() {
  Set<ConnectivityState> states = EnumSet.noneOf(ConnectivityState.class);
  for (Subchannel subchannel : getSubchannels()) {
    states.add(getSubchannelStateInfoRef(subchannel).value.getState());
  }
  if (states.contains(READY)) {
    return READY;
  }
  if (states.contains(CONNECTING)) {
    return CONNECTING;
  }
  if (states.contains(IDLE)) {
    // This subchannel IDLE is not because of channel IDLE_TIMEOUT, in which case LB is already
    // shutdown.
    // RRLB will request connection immediately on subchannel IDLE.
    return CONNECTING;
  }
  return TRANSIENT_FAILURE;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:20,代码来源:RoundRobinLoadBalancerFactory.java

示例6: proxyTest

import io.grpc.ConnectivityState; //导入依赖的package包/类
@Test
public void proxyTest() {
  final SocketAddress addr1 = mock(SocketAddress.class);
  final ProxyParameters proxy = new ProxyParameters(
      InetSocketAddress.createUnresolved("proxy.example.com", 1000), "username", "password");
  ProxyDetector proxyDetector = new ProxyDetector() {
    @Nullable
    @Override
    public ProxyParameters proxyFor(SocketAddress targetServerAddress) {
      if (targetServerAddress == addr1) {
        return proxy;
      } else {
        return null;
      }
    }
  };
  createInternalSubChannelWithProxy(proxyDetector, addr1);
  assertEquals(ConnectivityState.IDLE, internalSubchannel.getState());
  assertNoCallbackInvoke();
  assertNull(internalSubchannel.obtainActiveTransport());
  assertExactCallbackInvokes("onStateChange:CONNECTING");
  assertEquals(ConnectivityState.CONNECTING, internalSubchannel.getState());
  verify(mockTransportFactory).newClientTransport(
      eq(addr1), eq(AUTHORITY), eq(USER_AGENT), eq(proxy));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:InternalSubchannelTest.java

示例7: nameResolutionErrorWithActiveChannels

import io.grpc.ConnectivityState; //导入依赖的package包/类
@Test
public void nameResolutionErrorWithActiveChannels() throws Exception {
  final Subchannel readySubchannel = subchannels.values().iterator().next();
  loadBalancer.handleResolvedAddressGroups(servers, affinity);
  loadBalancer.handleSubchannelState(readySubchannel, ConnectivityStateInfo.forNonError(READY));
  loadBalancer.handleNameResolutionError(Status.NOT_FOUND.withDescription("nameResolutionError"));

  verify(mockHelper, times(3)).createSubchannel(any(EquivalentAddressGroup.class),
      any(Attributes.class));
  verify(mockHelper, times(3))
      .updateBalancingState(stateCaptor.capture(), pickerCaptor.capture());

  Iterator<ConnectivityState> stateIterator = stateCaptor.getAllValues().iterator();
  assertEquals(CONNECTING, stateIterator.next());
  assertEquals(READY, stateIterator.next());
  assertEquals(TRANSIENT_FAILURE, stateIterator.next());

  LoadBalancer.PickResult pickResult = pickerCaptor.getValue().pickSubchannel(mockArgs);
  assertEquals(readySubchannel, pickResult.getSubchannel());
  assertEquals(Status.OK.getCode(), pickResult.getStatus().getCode());

  LoadBalancer.PickResult pickResult2 = pickerCaptor.getValue().pickSubchannel(mockArgs);
  assertEquals(readySubchannel, pickResult2.getSubchannel());
  verifyNoMoreInteractions(mockHelper);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:RoundRobinLoadBalancerTest.java

示例8: maybeUpdatePicker

import io.grpc.ConnectivityState; //导入依赖的package包/类
/**
 * Make and use a picker out of the current lists and the states of subchannels if they have
 * changed since the last picker created.
 */
private void maybeUpdatePicker() {
  List<RoundRobinEntry> pickList = new ArrayList<RoundRobinEntry>(backendList.size());
  Status error = null;
  boolean hasIdle = false;
  for (BackendEntry entry : backendList) {
    Subchannel subchannel = entry.result.getSubchannel();
    Attributes attrs = subchannel.getAttributes();
    ConnectivityStateInfo stateInfo = attrs.get(STATE_INFO).get();
    if (stateInfo.getState() == READY) {
      pickList.add(entry);
    } else if (stateInfo.getState() == TRANSIENT_FAILURE) {
      error = stateInfo.getStatus();
    } else if (stateInfo.getState() == IDLE) {
      hasIdle = true;
    }
  }
  ConnectivityState state;
  if (pickList.isEmpty()) {
    if (error != null && !hasIdle) {
      logger.log(Level.FINE, "[{0}] No ready Subchannel. Using error: {1}",
          new Object[] {logId, error});
      pickList.add(new ErrorEntry(error));
      state = TRANSIENT_FAILURE;
    } else {
      logger.log(Level.FINE, "[{0}] No ready Subchannel and still connecting", logId);
      pickList.add(BUFFER_ENTRY);
      state = CONNECTING;
    }
  } else {
    logger.log(
        Level.FINE, "[{0}] Using drop list {1} and pick list {2}",
        new Object[] {logId, dropList, pickList});
    state = READY;
  }
  maybeUpdatePicker(state, new RoundRobinPicker(dropList, pickList));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:41,代码来源:GrpclbState.java

示例9: getState

import io.grpc.ConnectivityState; //导入依赖的package包/类
@Override
public ConnectivityState getState(boolean requestConnection) {
  ConnectivityState savedChannelState = channelStateManager.getState();
  if (requestConnection && savedChannelState == IDLE) {
    channelExecutor.executeLater(
        new Runnable() {
          @Override
          public void run() {
            exitIdleMode();
          }
        }).drain();
  }
  return savedChannelState;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:15,代码来源:ManagedChannelImpl.java

示例10: notifyWhenStateChanged

import io.grpc.ConnectivityState; //导入依赖的package包/类
@Override
public void notifyWhenStateChanged(final ConnectivityState source, final Runnable callback) {
  channelExecutor.executeLater(
      new Runnable() {
        @Override
        public void run() {
          channelStateManager.notifyWhenStateChanged(callback, executor, source);
        }
      }).drain();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:11,代码来源:ManagedChannelImpl.java

示例11: getState

import io.grpc.ConnectivityState; //导入依赖的package包/类
@VisibleForTesting
ConnectivityState getState() {
  try {
    synchronized (lock) {
      return state.getState();
    }
  } finally {
    channelExecutor.drain();
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:11,代码来源:InternalSubchannel.java

示例12: ChannelStats

import io.grpc.ConnectivityState; //导入依赖的package包/类
/**
 * Creates an instance.
 */
public ChannelStats(
    String target,
    ConnectivityState state,
    long callsStarted,
    long callsSucceeded,
    long callsFailed,
    long lastCallStartedMillis) {
  this.target = target;
  this.state = state;
  this.callsStarted = callsStarted;
  this.callsSucceeded = callsSucceeded;
  this.callsFailed = callsFailed;
  this.lastCallStartedMillis = lastCallStartedMillis;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:18,代码来源:Channelz.java

示例13: notifyWhenStateChanged

import io.grpc.ConnectivityState; //导入依赖的package包/类
/**
 * Adds a listener for state change event.
 *
 * <p>The {@code executor} must be one that can run RPC call listeners.
 */
void notifyWhenStateChanged(Runnable callback, Executor executor, ConnectivityState source) {
  checkNotNull(callback, "callback");
  checkNotNull(executor, "executor");
  checkNotNull(source, "source");

  Listener stateChangeListener = new Listener(callback, executor);
  if (state != source) {
    stateChangeListener.runInExecutor();
  } else {
    listeners.add(stateChangeListener);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:18,代码来源:ConnectivityStateManager.java

示例14: gotoNullableState

import io.grpc.ConnectivityState; //导入依赖的package包/类
private void gotoNullableState(@Nullable ConnectivityState newState) {
  if (state != newState && state != ConnectivityState.SHUTDOWN) {
    state = newState;
    if (listeners.isEmpty()) {
      return;
    }
    // Swap out callback list before calling them, because a callback may register new callbacks,
    // if run in direct executor, can cause ConcurrentModificationException.
    ArrayList<Listener> savedListeners = listeners;
    listeners = new ArrayList<Listener>();
    for (Listener listener : savedListeners) {
      listener.runInExecutor();
    }
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:16,代码来源:ConnectivityStateManager.java

示例15: getState

import io.grpc.ConnectivityState; //导入依赖的package包/类
/**
 * Gets the current connectivity state of the channel. This method is threadsafe.
 */
ConnectivityState getState() {
  ConnectivityState stateCopy = state;
  if (stateCopy == null) {
    throw new UnsupportedOperationException("Channel state API is not implemented");
  }
  return stateCopy;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:11,代码来源:ConnectivityStateManager.java


注:本文中的io.grpc.ConnectivityState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。