net.spy.memcached.MemcachedClient.getAvailableServers()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中net.spy.memcached.MemcachedClient.getAvailableServers()方法的一些代码示例,展示了MemcachedClient.getAvailableServers()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MemcachedClient.getAvailableServers()方法的具体详情如下:
包路径:net.spy.memcached.MemcachedClient
类名称:MemcachedClient
方法名:getAvailableServers

MemcachedClient.getAvailableServers介绍

[英]Get the addresses of available servers.

This is based on a snapshot in time so shouldn't be considered completely accurate, but is a useful for getting a feel for what's working and what's not working.
[中]获取可用服务器的地址。
这是基于时间快照的,所以不应该被认为是完全准确的,但对于了解什么是有效的,什么是无效的非常有用。

代码示例

代码示例来源:origin: magro/memcached-session-manager

public static void waitForReconnect( final MemcachedClient client, final int expectedNumServers, final long timeToWait )
    throws InterruptedException, RuntimeException {
  final long start = System.currentTimeMillis();
  while( System.currentTimeMillis() < start + timeToWait ) {
    if ( client.getAvailableServers().size() >= expectedNumServers ) {
      return;
    }
    Thread.sleep( 20 );
  }
  throw new RuntimeException( "MemcachedClient did not reconnect after " + timeToWait + " millis." );
}

代码示例来源:origin: magro/memcached-session-manager

private void waitForReconnect( final MemcachedClient client, final int expectedServers, final long timeToWait )
    throws InterruptedException, RuntimeException {
  final long start = System.currentTimeMillis();
  while( System.currentTimeMillis() < start + timeToWait ) {
    if(client.getAvailableServers().size() == expectedServers) {
      return;
    }
    Thread.sleep( 20 );
  }
  throw new RuntimeException( "MemcachedClient did not reconnect after " + timeToWait + " millis." );
}

代码示例来源:origin: magro/memcached-session-manager

public void waitForReconnect( final MemcachedClient client, final InetSocketAddress serverAddressToCheck, final long timeToWait )
    throws InterruptedException, RuntimeException {
  final long start = System.currentTimeMillis();
  while( System.currentTimeMillis() < start + timeToWait ) {
    for( final SocketAddress address : client.getAvailableServers() ) {
      if ( address.equals( serverAddressToCheck ) ) {
        return;
      }
    }
    Thread.sleep( 100 );
  }
  throw new RuntimeException( "MemcachedClient did not reconnect after " + timeToWait + " millis." );
}

代码示例来源:origin: com.m3/memcached-client-facade

private boolean hasNoAvailableServer() {
  boolean unavailable = memcached.getAvailableServers().isEmpty();
  if (unavailable && log.isDebugEnabled()) {
    log.debug("No available memcached servers now.");
  }
  return unavailable;
}

代码示例来源:origin: aurorafeint/jruby-memcached

@JRubyMethod
public IRubyObject servers(ThreadContext context) {
  Ruby ruby = context.getRuntime();
  List<IRubyObject> addresses = new ArrayList<IRubyObject>();
  for (SocketAddress address : client.getAvailableServers()) {
    String addressStr = address.toString();
    if (addressStr.indexOf("/") == 0) {
      addressStr = addressStr.replace("/", "");
    }
    addresses.add(ruby.newString(addressStr));
  }
  return ruby.newArray(addresses);
}

代码示例来源:origin: OneBusAway/onebusaway-application-modules

public boolean containsKey(K key) {
 if (_disabled)
  return false;
 Cache<K, V> cache = getCache();
 if (useMemcached) {
  try {
   return memcache.get(key.toString()) != null;
  } catch (Exception e) {
   toggleCache(false);
  }
 }
 if (!cache.asMap().containsKey(key)){
  // only attempt to switch to memcached if there is a miss in local cache
  // to minimize memcached connection attempts, saving time per local cache usage
  if (memcache != null && !memcache.getAvailableServers().isEmpty()){
   toggleCache(true);
  }
  return false;
 }
 return true;
}

代码示例来源:origin: ECNU-1X/DataX-Masking

/**
 * 检查ocs服务器网络是否可达
 */
private static void hostReachableCheck(Configuration config) {
  String proxy = config.getString(Key.PROXY);
  String port = config.getString(Key.PORT);
  String username = config.getString(Key.USER);
  String password = config.getString(Key.PASSWORD);
  AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" },
      new PlainCallbackHandler(username, password));
  try {
    MemcachedClient client = new MemcachedClient(
        new ConnectionFactoryBuilder()
            .setProtocol(
                ConnectionFactoryBuilder.Protocol.BINARY)
            .setAuthDescriptor(ad).build(),
        AddrUtil.getAddresses(proxy + ":" + port));
    client.get("for_check_connectivity");
    client.getVersions();
    if (client.getAvailableServers().isEmpty()) {
      throw new RuntimeException(
          "没有可用的Servers: getAvailableServers() -> is empty");
    }
    client.shutdown();
  } catch (Exception e) {
    throw DataXException.asDataXException(
        OcsWriterErrorCode.HOST_UNREACHABLE,
        String.format("OCS[%s]服务不可用", proxy), e);
  }
}

相关文章