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

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

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

MemcachedClient.<init>介绍

[英]Get a memcache client over the specified memcached locations.
[中]通过指定的memcached位置获取memcache客户端。

代码示例

代码示例来源:origin: apache/incubator-druid

@Override
 public MemcachedClientIF get()
 {
  try {
   return new MemcachedClient(connectionFactory, hosts);
  }
  catch (IOException e) {
   log.error(e, "Unable to create memcached client");
   throw Throwables.propagate(e);
  }
 }
}

代码示例来源:origin: ityouknow/spring-boot-examples

@Override
public void run(String... args) throws Exception {
  try {
    client = new MemcachedClient(new InetSocketAddress(memcacheSource.getIp(),memcacheSource.getPort()));
  } catch (IOException e) {
    logger.error("inint MemcachedClient failed ",e);
  }
}

代码示例来源:origin: aol/micro-server

@Bean(name = "memcachedClient")
  public MemcachedClient createMemcachedClient() throws IOException {
    try {
      log.info("Starting an instance of memcache client towards elasticache cluster");
      return new MemcachedClient(new InetSocketAddress(hostname, port));
    } catch (IOException e) {
      log.error("Could not initilise connection to elasticache cluster", e);
      return null;
    }

  }
}

代码示例来源:origin: Netflix/EVCache

public Map<SocketAddress, Map<String, String>> getStats(String cmd) {
  if(config.isRendInstance()) {
    List<InetSocketAddress> udsproxyInetSocketAddress = new ArrayList<InetSocketAddress>(memcachedNodesInZone.size());
    for(InetSocketAddress address : memcachedNodesInZone) {
      udsproxyInetSocketAddress.add(new InetSocketAddress(address.getHostName(), config.getUdsproxyMemcachedPort()));
    }
    
    MemcachedClient mc = null;
    try {
      mc = new MemcachedClient(connectionFactory, udsproxyInetSocketAddress);
      return mc.getStats(cmd);
    } catch(Exception ex) {
      
    } finally {
      if(mc != null) mc.shutdown();
    }
    return Collections.<SocketAddress, Map<String, String>>emptyMap();
  } else {
    return evcacheMemcachedClient.getStats(cmd);
  }
}

代码示例来源:origin: jooby-project/jooby

@Override
public MemcachedClient get() {
 client = throwingSupplier(() -> {
  ConnectionFactory connectionFactory = builder.build();
  this.builder = null;
  return new MemcachedClient(connectionFactory, servers);
 }).get();
 return client;
}

代码示例来源:origin: brianfrankcooper/YCSB

return new net.spy.memcached.MemcachedClient(
  connectionFactoryBuilder.build(), addresses);

代码示例来源:origin: apache/hbase

public MemcachedBlockCache(Configuration c) throws IOException {
 LOG.info("Creating MemcachedBlockCache");
 long opTimeout = c.getLong(MEMCACHED_OPTIMEOUT_KEY, MEMCACHED_DEFAULT_TIMEOUT);
 long queueTimeout = c.getLong(MEMCACHED_TIMEOUT_KEY, opTimeout + MEMCACHED_DEFAULT_TIMEOUT);
 boolean optimize = c.getBoolean(MEMCACHED_OPTIMIZE_KEY, MEMCACHED_OPTIMIZE_DEFAULT);
 ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder()
   .setOpTimeout(opTimeout)
   .setOpQueueMaxBlockTime(queueTimeout) // Cap the max time before anything times out
   .setFailureMode(FailureMode.Redistribute)
   .setShouldOptimize(optimize)
   .setDaemon(true)                      // Don't keep threads around past the end of days.
   .setUseNagleAlgorithm(false)          // Ain't nobody got time for that
   .setReadBufferSize(HConstants.DEFAULT_BLOCKSIZE * 4 * 1024); // Much larger just in case
 // Assume only the localhost is serving memecached.
 // A la mcrouter or co-locating memcached with split regionservers.
 //
 // If this config is a pool of memecached servers they will all be used according to the
 // default hashing scheme defined by the memcache client. Spy Memecache client in this
 // case.
 String serverListString = c.get(MEMCACHED_CONFIG_KEY,"localhost:11211");
 String[] servers = serverListString.split(",");
 List<InetSocketAddress> serverAddresses = new ArrayList<>(servers.length);
 for (String s:servers) {
  serverAddresses.add(Addressing.createInetSocketAddressFromHostAndPortStr(s));
 }
 client = new MemcachedClient(builder.build(), serverAddresses);
}

代码示例来源:origin: apache/ignite

/**
 * @return Memcache client.
 * @throws Exception If start failed.
 */
private MemcachedClientIF startClient() throws Exception {
  int port = customPort != null ? customPort : IgniteConfiguration.DFLT_TCP_PORT;
  return new MemcachedClient(new BinaryConnectionFactory(),
    F.asList(new InetSocketAddress(LOC_HOST, port)));
}

代码示例来源:origin: ninjaframework/ninja

.build();
client = new MemcachedClient(cf, addrs);
client = new MemcachedClient(addrs);

代码示例来源:origin: apache/httpcomponents-client

/**
 * Create a storage backend talking to a <i>memcached</i> instance
 * listening on the specified host and port. This is useful if you
 * just have a single local memcached instance running on the same
 * machine as your application, for example.
 * @param address where the <i>memcached</i> daemon is running
 * @throws IOException in case of an error
 */
public MemcachedHttpCacheStorage(final InetSocketAddress address) throws IOException {
  this(new MemcachedClient(address));
}

代码示例来源:origin: apache/httpcomponents-client

/**
 * Create a storage backend talking to a <i>memcached</i> instance
 * listening on the specified host and port. This is useful if you
 * just have a single local memcached instance running on the same
 * machine as your application, for example.
 * @param address where the <i>memcached</i> daemon is running
 * @throws IOException in case of an error
 */
public MemcachedHttpAsyncCacheStorage(final InetSocketAddress address) throws IOException {
  this(new MemcachedClient(address));
}

代码示例来源:origin: apache/incubator-druid

return new MemcachedClient(connectionFactory, hosts);
} else {
 clientSupplier = Suppliers.ofInstance(
   StupidResourceHolder.create(new MemcachedClient(connectionFactory, hosts))
 );

代码示例来源:origin: apache/kylin

public static MemcachedCache create(final MemcachedCacheConfig config, String memcachedPrefix, int timeToLive) {
  try {
    SerializingTranscoder transcoder = new SerializingTranscoder(config.getMaxObjectSize());
    // always no compression inside, we compress/decompress outside
    transcoder.setCompressionThreshold(Integer.MAX_VALUE);
    OperationQueueFactory opQueueFactory;
    int maxQueueSize = config.getMaxOperationQueueSize();
    if (maxQueueSize > 0) {
      opQueueFactory = new ArrayOperationQueueFactory(maxQueueSize);
    } else {
      opQueueFactory = new LinkedOperationQueueFactory();
    }
    String hostsStr = config.getHosts();
    ConnectionFactory connectionFactory = new MemcachedConnectionFactoryBuilder()
        .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY)
        .setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH)
        .setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT).setDaemon(true)
        .setFailureMode(FailureMode.Redistribute).setTranscoder(transcoder).setShouldOptimize(true)
        .setOpQueueMaxBlockTime(config.getTimeout()).setOpTimeout(config.getTimeout())
        .setReadBufferSize(config.getReadBufferSize()).setOpQueueFactory(opQueueFactory).build();
    return new MemcachedCache(new MemcachedClient(new MemcachedConnectionFactory(connectionFactory),
        AddrUtil.getAddresses(hostsStr)), config, memcachedPrefix, timeToLive);
  } catch (IOException e) {
    logger.error("Unable to create MemcachedCache instance.", e);
    throw Throwables.propagate(e);
  }
}

代码示例来源:origin: apache/incubator-druid

client = new MemcachedClient(
  new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY)
                 .setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH)

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

protected StorageClient createStorageClient(final MemcachedNodesManager memcachedNodesManager,
                      final String memcachedProtocol, final String username, final String password, final long operationTimeout,
                      final long maxReconnectDelay, final Statistics statistics ) {
  try {
    if (memcachedNodesManager.isRedisConfig()) {
      return new RedisStorageClient(memcachedNodesManager.getMemcachedNodes(), operationTimeout);
    }
    final ConnectionType connectionType = ConnectionType.valueOf(memcachedNodesManager.isCouchbaseBucketConfig(), username, password);
    if (connectionType.isCouchbaseBucketConfig()) {
      return new MemcachedStorageClient(MemcachedHelper.createCouchbaseClient(memcachedNodesManager, memcachedProtocol, username, password,
          operationTimeout, maxReconnectDelay, statistics));
    }
    final ConnectionFactory connectionFactory = MemcachedHelper.createConnectionFactory(memcachedNodesManager, connectionType, memcachedProtocol,
        username, password, operationTimeout, maxReconnectDelay, statistics);
    return new MemcachedStorageClient(new MemcachedClient(connectionFactory, memcachedNodesManager.getAllMemcachedAddresses()));
  } catch (final Exception e) {
    throw new RuntimeException("Could not create memcached client", e);
  }
}

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

private MemcachedClient createMemcachedClient( final String memcachedNodes, final InetSocketAddress address ) throws IOException, InterruptedException {
  final MemcachedNodesManager nodesManager = MemcachedNodesManager.createFor(memcachedNodes, null, null, _storageClientCallback);
  final ConnectionFactory cf = nodesManager.isEncodeNodeIdInSessionId()
    ? new SuffixLocatorConnectionFactory( nodesManager, nodesManager.getSessionIdFormat(), Statistics.create(), 1000, 1000 )
    : new DefaultConnectionFactory();
  final MemcachedClient result = new MemcachedClient( cf, Arrays.asList( address ) );
  // Wait a little bit, so that the memcached client can connect and is ready when test starts
  Thread.sleep( 100 );
  return result;
}

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

@BeforeMethod
public void setUp(final Method testMethod) throws Throwable {
  final InetSocketAddress address = new InetSocketAddress( "localhost", MEMCACHED_PORT );
  _daemon = createDaemon( address );
  _daemon.start();
  final String[] testGroups = testMethod.getAnnotation(Test.class).groups();
  final String nodePrefix = testGroups.length == 0 || !GROUP_WITHOUT_NODE_ID.equals(testGroups[0]) ? NODE_ID + ":" : "";
  _memcachedNodes = nodePrefix + "localhost:" + MEMCACHED_PORT;
  try {
    _tomcat1 = startTomcat( TC_PORT_1, JVM_ROUTE_1 );
    _tomcat2 = startTomcat( TC_PORT_2, JVM_ROUTE_2 );
  } catch ( final Throwable e ) {
    LOG.error( "could not start tomcat.", e );
    throw e;
  }
  final MemcachedNodesManager nodesManager = MemcachedNodesManager.createFor(_memcachedNodes, null, null, _storageClientCallback);
  final ConnectionFactory cf = nodesManager.isEncodeNodeIdInSessionId()
    ? new SuffixLocatorConnectionFactory( nodesManager, nodesManager.getSessionIdFormat(), Statistics.create(), 1000, 1000 )
    : new DefaultConnectionFactory();
  _client = new MemcachedClient( cf, Arrays.asList( address ) );
  _httpClient = new DefaultHttpClient();
}

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

@BeforeMethod
public void setUp() throws Throwable {
  final InetSocketAddress address1 = new InetSocketAddress( "localhost", MEMCACHED_PORT_1 );
  _daemon1 = createDaemon( address1 );
  _daemon1.start();
  final InetSocketAddress address2 = new InetSocketAddress( "localhost", MEMCACHED_PORT_2 );
  _daemon2 = createDaemon( address2 );
  _daemon2.start();
  try {
    _tomcat1 = startTomcat( TC_PORT_1 );
    _tomcat2 = startTomcat( TC_PORT_2 );
  } catch ( final Throwable e ) {
    LOG.error( "could not start tomcat.", e );
    throw e;
  }
  final MemcachedNodesManager nodesManager = MemcachedNodesManager.createFor(MEMCACHED_NODES, null, null, _storageClientCallback);
  _client =
      new MemcachedClient( new SuffixLocatorConnectionFactory( nodesManager, nodesManager.getSessionIdFormat(), Statistics.create(), 1000, 1000 ),
          Arrays.asList( address1, address2 ) );
  final SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(
      new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
  _httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(schemeRegistry));
  _executor = Executors.newCachedThreadPool();
}

代码示例来源:origin: pippo-java/pippo

.build();
  client = new MemcachedClient(connectionFactory, AddrUtil.getAddresses(hosts));
} catch (IOException ex) {
  log.error("An error occurred when creating the MemcachedClient.", ex);

代码示例来源:origin: de.flapdoodle.embed/de.flapdoodle.embed.memcached

/**
 * Creates a new Memcache connection.
 * 
 * @throws IOException
 */
public MemcachedClient newMemcachedClient() throws IOException {
  return new MemcachedClient(new InetSocketAddress(memcachedProcess
      .getConfig().net().getServerAddress()
      .getCanonicalHostName(), memcachedProcess.getConfig()
      .net().getPort()));
}

相关文章