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

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

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

  1. @Override
  2. public MemcachedClientIF get()
  3. {
  4. try {
  5. return new MemcachedClient(connectionFactory, hosts);
  6. }
  7. catch (IOException e) {
  8. log.error(e, "Unable to create memcached client");
  9. throw Throwables.propagate(e);
  10. }
  11. }
  12. }

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

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

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

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

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

  1. public Map<SocketAddress, Map<String, String>> getStats(String cmd) {
  2. if(config.isRendInstance()) {
  3. List<InetSocketAddress> udsproxyInetSocketAddress = new ArrayList<InetSocketAddress>(memcachedNodesInZone.size());
  4. for(InetSocketAddress address : memcachedNodesInZone) {
  5. udsproxyInetSocketAddress.add(new InetSocketAddress(address.getHostName(), config.getUdsproxyMemcachedPort()));
  6. }
  7. MemcachedClient mc = null;
  8. try {
  9. mc = new MemcachedClient(connectionFactory, udsproxyInetSocketAddress);
  10. return mc.getStats(cmd);
  11. } catch(Exception ex) {
  12. } finally {
  13. if(mc != null) mc.shutdown();
  14. }
  15. return Collections.<SocketAddress, Map<String, String>>emptyMap();
  16. } else {
  17. return evcacheMemcachedClient.getStats(cmd);
  18. }
  19. }

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

  1. @Override
  2. public MemcachedClient get() {
  3. client = throwingSupplier(() -> {
  4. ConnectionFactory connectionFactory = builder.build();
  5. this.builder = null;
  6. return new MemcachedClient(connectionFactory, servers);
  7. }).get();
  8. return client;
  9. }

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. return new MemcachedClient(connectionFactory, hosts);
  2. } else {
  3. clientSupplier = Suppliers.ofInstance(
  4. StupidResourceHolder.create(new MemcachedClient(connectionFactory, hosts))
  5. );

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

  1. public static MemcachedCache create(final MemcachedCacheConfig config, String memcachedPrefix, int timeToLive) {
  2. try {
  3. SerializingTranscoder transcoder = new SerializingTranscoder(config.getMaxObjectSize());
  4. // always no compression inside, we compress/decompress outside
  5. transcoder.setCompressionThreshold(Integer.MAX_VALUE);
  6. OperationQueueFactory opQueueFactory;
  7. int maxQueueSize = config.getMaxOperationQueueSize();
  8. if (maxQueueSize > 0) {
  9. opQueueFactory = new ArrayOperationQueueFactory(maxQueueSize);
  10. } else {
  11. opQueueFactory = new LinkedOperationQueueFactory();
  12. }
  13. String hostsStr = config.getHosts();
  14. ConnectionFactory connectionFactory = new MemcachedConnectionFactoryBuilder()
  15. .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY)
  16. .setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH)
  17. .setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT).setDaemon(true)
  18. .setFailureMode(FailureMode.Redistribute).setTranscoder(transcoder).setShouldOptimize(true)
  19. .setOpQueueMaxBlockTime(config.getTimeout()).setOpTimeout(config.getTimeout())
  20. .setReadBufferSize(config.getReadBufferSize()).setOpQueueFactory(opQueueFactory).build();
  21. return new MemcachedCache(new MemcachedClient(new MemcachedConnectionFactory(connectionFactory),
  22. AddrUtil.getAddresses(hostsStr)), config, memcachedPrefix, timeToLive);
  23. } catch (IOException e) {
  24. logger.error("Unable to create MemcachedCache instance.", e);
  25. throw Throwables.propagate(e);
  26. }
  27. }

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

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

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

  1. protected StorageClient createStorageClient(final MemcachedNodesManager memcachedNodesManager,
  2. final String memcachedProtocol, final String username, final String password, final long operationTimeout,
  3. final long maxReconnectDelay, final Statistics statistics ) {
  4. try {
  5. if (memcachedNodesManager.isRedisConfig()) {
  6. return new RedisStorageClient(memcachedNodesManager.getMemcachedNodes(), operationTimeout);
  7. }
  8. final ConnectionType connectionType = ConnectionType.valueOf(memcachedNodesManager.isCouchbaseBucketConfig(), username, password);
  9. if (connectionType.isCouchbaseBucketConfig()) {
  10. return new MemcachedStorageClient(MemcachedHelper.createCouchbaseClient(memcachedNodesManager, memcachedProtocol, username, password,
  11. operationTimeout, maxReconnectDelay, statistics));
  12. }
  13. final ConnectionFactory connectionFactory = MemcachedHelper.createConnectionFactory(memcachedNodesManager, connectionType, memcachedProtocol,
  14. username, password, operationTimeout, maxReconnectDelay, statistics);
  15. return new MemcachedStorageClient(new MemcachedClient(connectionFactory, memcachedNodesManager.getAllMemcachedAddresses()));
  16. } catch (final Exception e) {
  17. throw new RuntimeException("Could not create memcached client", e);
  18. }
  19. }

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

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

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

  1. @BeforeMethod
  2. public void setUp(final Method testMethod) throws Throwable {
  3. final InetSocketAddress address = new InetSocketAddress( "localhost", MEMCACHED_PORT );
  4. _daemon = createDaemon( address );
  5. _daemon.start();
  6. final String[] testGroups = testMethod.getAnnotation(Test.class).groups();
  7. final String nodePrefix = testGroups.length == 0 || !GROUP_WITHOUT_NODE_ID.equals(testGroups[0]) ? NODE_ID + ":" : "";
  8. _memcachedNodes = nodePrefix + "localhost:" + MEMCACHED_PORT;
  9. try {
  10. _tomcat1 = startTomcat( TC_PORT_1, JVM_ROUTE_1 );
  11. _tomcat2 = startTomcat( TC_PORT_2, JVM_ROUTE_2 );
  12. } catch ( final Throwable e ) {
  13. LOG.error( "could not start tomcat.", e );
  14. throw e;
  15. }
  16. final MemcachedNodesManager nodesManager = MemcachedNodesManager.createFor(_memcachedNodes, null, null, _storageClientCallback);
  17. final ConnectionFactory cf = nodesManager.isEncodeNodeIdInSessionId()
  18. ? new SuffixLocatorConnectionFactory( nodesManager, nodesManager.getSessionIdFormat(), Statistics.create(), 1000, 1000 )
  19. : new DefaultConnectionFactory();
  20. _client = new MemcachedClient( cf, Arrays.asList( address ) );
  21. _httpClient = new DefaultHttpClient();
  22. }

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

  1. @BeforeMethod
  2. public void setUp() throws Throwable {
  3. final InetSocketAddress address1 = new InetSocketAddress( "localhost", MEMCACHED_PORT_1 );
  4. _daemon1 = createDaemon( address1 );
  5. _daemon1.start();
  6. final InetSocketAddress address2 = new InetSocketAddress( "localhost", MEMCACHED_PORT_2 );
  7. _daemon2 = createDaemon( address2 );
  8. _daemon2.start();
  9. try {
  10. _tomcat1 = startTomcat( TC_PORT_1 );
  11. _tomcat2 = startTomcat( TC_PORT_2 );
  12. } catch ( final Throwable e ) {
  13. LOG.error( "could not start tomcat.", e );
  14. throw e;
  15. }
  16. final MemcachedNodesManager nodesManager = MemcachedNodesManager.createFor(MEMCACHED_NODES, null, null, _storageClientCallback);
  17. _client =
  18. new MemcachedClient( new SuffixLocatorConnectionFactory( nodesManager, nodesManager.getSessionIdFormat(), Statistics.create(), 1000, 1000 ),
  19. Arrays.asList( address1, address2 ) );
  20. final SchemeRegistry schemeRegistry = new SchemeRegistry();
  21. schemeRegistry.register(
  22. new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
  23. _httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(schemeRegistry));
  24. _executor = Executors.newCachedThreadPool();
  25. }

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

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

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

  1. /**
  2. * Creates a new Memcache connection.
  3. *
  4. * @throws IOException
  5. */
  6. public MemcachedClient newMemcachedClient() throws IOException {
  7. return new MemcachedClient(new InetSocketAddress(memcachedProcess
  8. .getConfig().net().getServerAddress()
  9. .getCanonicalHostName(), memcachedProcess.getConfig()
  10. .net().getPort()));
  11. }

相关文章