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

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

本文整理了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

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

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

  1. private void waitForReconnect( final MemcachedClient client, final int expectedServers, final long timeToWait )
  2. throws InterruptedException, RuntimeException {
  3. final long start = System.currentTimeMillis();
  4. while( System.currentTimeMillis() < start + timeToWait ) {
  5. if(client.getAvailableServers().size() == expectedServers) {
  6. return;
  7. }
  8. Thread.sleep( 20 );
  9. }
  10. throw new RuntimeException( "MemcachedClient did not reconnect after " + timeToWait + " millis." );
  11. }

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

  1. public void waitForReconnect( final MemcachedClient client, final InetSocketAddress serverAddressToCheck, final long timeToWait )
  2. throws InterruptedException, RuntimeException {
  3. final long start = System.currentTimeMillis();
  4. while( System.currentTimeMillis() < start + timeToWait ) {
  5. for( final SocketAddress address : client.getAvailableServers() ) {
  6. if ( address.equals( serverAddressToCheck ) ) {
  7. return;
  8. }
  9. }
  10. Thread.sleep( 100 );
  11. }
  12. throw new RuntimeException( "MemcachedClient did not reconnect after " + timeToWait + " millis." );
  13. }

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

  1. private boolean hasNoAvailableServer() {
  2. boolean unavailable = memcached.getAvailableServers().isEmpty();
  3. if (unavailable && log.isDebugEnabled()) {
  4. log.debug("No available memcached servers now.");
  5. }
  6. return unavailable;
  7. }

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

  1. @JRubyMethod
  2. public IRubyObject servers(ThreadContext context) {
  3. Ruby ruby = context.getRuntime();
  4. List<IRubyObject> addresses = new ArrayList<IRubyObject>();
  5. for (SocketAddress address : client.getAvailableServers()) {
  6. String addressStr = address.toString();
  7. if (addressStr.indexOf("/") == 0) {
  8. addressStr = addressStr.replace("/", "");
  9. }
  10. addresses.add(ruby.newString(addressStr));
  11. }
  12. return ruby.newArray(addresses);
  13. }

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

  1. public boolean containsKey(K key) {
  2. if (_disabled)
  3. return false;
  4. Cache<K, V> cache = getCache();
  5. if (useMemcached) {
  6. try {
  7. return memcache.get(key.toString()) != null;
  8. } catch (Exception e) {
  9. toggleCache(false);
  10. }
  11. }
  12. if (!cache.asMap().containsKey(key)){
  13. // only attempt to switch to memcached if there is a miss in local cache
  14. // to minimize memcached connection attempts, saving time per local cache usage
  15. if (memcache != null && !memcache.getAvailableServers().isEmpty()){
  16. toggleCache(true);
  17. }
  18. return false;
  19. }
  20. return true;
  21. }

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

  1. /**
  2. * 检查ocs服务器网络是否可达
  3. */
  4. private static void hostReachableCheck(Configuration config) {
  5. String proxy = config.getString(Key.PROXY);
  6. String port = config.getString(Key.PORT);
  7. String username = config.getString(Key.USER);
  8. String password = config.getString(Key.PASSWORD);
  9. AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" },
  10. new PlainCallbackHandler(username, password));
  11. try {
  12. MemcachedClient client = new MemcachedClient(
  13. new ConnectionFactoryBuilder()
  14. .setProtocol(
  15. ConnectionFactoryBuilder.Protocol.BINARY)
  16. .setAuthDescriptor(ad).build(),
  17. AddrUtil.getAddresses(proxy + ":" + port));
  18. client.get("for_check_connectivity");
  19. client.getVersions();
  20. if (client.getAvailableServers().isEmpty()) {
  21. throw new RuntimeException(
  22. "没有可用的Servers: getAvailableServers() -> is empty");
  23. }
  24. client.shutdown();
  25. } catch (Exception e) {
  26. throw DataXException.asDataXException(
  27. OcsWriterErrorCode.HOST_UNREACHABLE,
  28. String.format("OCS[%s]服务不可用", proxy), e);
  29. }
  30. }

相关文章