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


Java ConnectionFactoryBuilder.build方法代码示例

本文整理汇总了Java中net.spy.memcached.ConnectionFactoryBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactoryBuilder.build方法的具体用法?Java ConnectionFactoryBuilder.build怎么用?Java ConnectionFactoryBuilder.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.spy.memcached.ConnectionFactoryBuilder的用法示例。


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

示例1: create

import net.spy.memcached.ConnectionFactoryBuilder; //导入方法依赖的package包/类
@Override
public CacheClient create(final List<InetSocketAddress> addrs, final CacheConfiguration conf) throws IOException {
    // currently its works because this factory creates clients with the same connection settings, only memcached
    // addresses can be changed
    if (connectionFactory == null) {
        ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();

        if (conf.isConsistentHashing()) {
            builder.setHashAlg(DefaultHashAlgorithm.KETAMA_HASH);
            builder.setLocatorType(Locator.CONSISTENT);
        }

        builder.setProtocol(conf.isUseBinaryProtocol() ? Protocol.BINARY : Protocol.TEXT);
        if (conf.getOperationTimeout() != null) {
            builder.setOpTimeout(conf.getOperationTimeout());
        }

        if (conf instanceof SpymemcachedConfiguration) {
            setProviderSpecificSettings(builder, (SpymemcachedConfiguration) conf);
        }

        connectionFactory = builder.build();
    }

    return new MemcacheClientWrapper(new MemcachedClient(connectionFactory, addrs));
}
 
开发者ID:ragnor,项目名称:simple-spring-memcached,代码行数:27,代码来源:MemcacheClientFactoryImpl.java

示例2: MemcachedBlockCache

import net.spy.memcached.ConnectionFactoryBuilder; //导入方法依赖的package包/类
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<InetSocketAddress>(servers.length);
  for (String s:servers) {
    serverAddresses.add(Addressing.createInetSocketAddressFromHostAndPortStr(s));
  }

  client = new MemcachedClient(builder.build(), serverAddresses);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:32,代码来源:MemcachedBlockCache.java

示例3: doStart

import net.spy.memcached.ConnectionFactoryBuilder; //导入方法依赖的package包/类
@Override
protected void doStart() throws Exception {
    super.doStart();

    ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();
    // VERY IMPORTANT! Otherwise, spymemcached optimizes away concurrent gets
    builder.setShouldOptimize(false);
    // We never want spymemcached to time out
    builder.setOpTimeout(9999999);
    // Retry upon failure
    builder.setFailureMode(FailureMode.Retry);
    memcachedConnectionFactory = builder.build();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:KestrelComponent.java

示例4: activateService

import net.spy.memcached.ConnectionFactoryBuilder; //导入方法依赖的package包/类
@Override
public void activateService()
    throws Exception
{
    MemcacheConfiguration config = configuration.get();
    expiration = ( config.expiration().get() == null )
                 ? 3600
                 : config.expiration().get();
    String addresses = ( config.addresses().get() == null )
                       ? "localhost:11211"
                       : config.addresses().get();
    Protocol protocol = ( config.protocol().get() == null )
                        ? Protocol.TEXT
                        : Protocol.valueOf( config.protocol().get().toUpperCase() );
    String username = config.username().get();
    String password = config.password().get();
    String authMech = config.authMechanism().get() == null
                      ? "PLAIN"
                      : config.authMechanism().get();

    ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();
    builder.setProtocol( protocol );
    if( username != null && !username.isEmpty() )
    {
        String[] authType = { authMech };
        AuthDescriptor to = new AuthDescriptor( authType, new PlainCallbackHandler( username, password ) );
        builder.setAuthDescriptor( to );
    }

    client = new MemcachedClient( builder.build(), AddrUtil.getAddresses( addresses ) );
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:32,代码来源:MemcachePoolMixin.java

示例5: MemcachedBlockCache

import net.spy.memcached.ConnectionFactoryBuilder; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:hbase,代码行数:32,代码来源:MemcachedBlockCache.java

示例6: create

import net.spy.memcached.ConnectionFactoryBuilder; //导入方法依赖的package包/类
@Override
public CacheClient create(final List<InetSocketAddress> addrs, final CacheConfiguration conf) throws IOException {
    // currently its works because this factory creates clients with the same connection settings, only memcached
    // addresses can be changed
    if (connectionFactory == null) {
        ElastiCacheConfiguration elasticacheConf = null;
        if (conf instanceof ElastiCacheConfiguration) {
            elasticacheConf = (ElastiCacheConfiguration) conf;
        }
        
        if (elasticacheConf != null && Boolean.TRUE.equals(elasticacheConf.getUseAutoDiscovery())) {
            // there is no way to use custom client settings and auto discovery together
            LOGGER.info("All cache settings will be ignored because useAutoDiscovery is true");
            return new MemcacheClientWrapper(new MemcachedClient(addrs));
        }
        
        
        ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();

        if (conf.isConsistentHashing()) {
            builder.setHashAlg(DefaultHashAlgorithm.KETAMA_HASH);
            builder.setLocatorType(Locator.CONSISTENT);
        }

        builder.setProtocol(conf.isUseBinaryProtocol() ? Protocol.BINARY : Protocol.TEXT);
        if (conf.getOperationTimeout() != null) {
            builder.setOpTimeout(conf.getOperationTimeout());
        }

        if (elasticacheConf != null) {
            setProviderSpecificSettings(builder, elasticacheConf);
        }

        connectionFactory = builder.build();
    }

    return new MemcacheClientWrapper(new MemcachedClient(connectionFactory, addrs));
}
 
开发者ID:ragnor,项目名称:simple-spring-memcached,代码行数:39,代码来源:MemcacheClientFactoryImpl.java

示例7: ApiMemcached

import net.spy.memcached.ConnectionFactoryBuilder; //导入方法依赖的package包/类
public ApiMemcached() {
	AppConstants ac = AppConstants.getInstance();
	String address = ac.getProperty("etag.cache.server", "localhost:11211");
	String username = ac.getProperty("etag.cache.username", "");
	String password = ac.getProperty("etag.cache.password", "");
	int timeout = ac.getInt("etag.cache.timeout", 10);

	List<InetSocketAddress> addresses = AddrUtil.getAddresses(address);

	ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder()
		.setProtocol(Protocol.BINARY)
		.setOpTimeout(timeout)
		.setInitialObservers(Collections.singleton(obs));

	if(addresses.size()  > 1)
		connectionFactoryBuilder.setFailureMode(FailureMode.Redistribute);
	else
		connectionFactoryBuilder.setFailureMode(FailureMode.Retry);

	if(!username.isEmpty())
		connectionFactoryBuilder.setAuthDescriptor(AuthDescriptor.typical(username, password));

	ConnectionFactory cf = connectionFactoryBuilder.build();

	try {
		client = new MemcachedClient(cf, addresses);
		//Fetching a none-existing key to test the connection
		Future<Object> future = client.asyncGet("test-connection");
		future.get(timeout, TimeUnit.MILLISECONDS);
	} catch (Exception e) {
		ConfigurationWarnings.getInstance().add(log, "Unable to connect to one or more memcached servers.", null, true);
	}
}
 
开发者ID:ibissource,项目名称:iaf,代码行数:34,代码来源:ApiMemcached.java

示例8: connectionFactory

import net.spy.memcached.ConnectionFactoryBuilder; //导入方法依赖的package包/类
private ConnectionFactory connectionFactory() {
    ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();
    builder.setOpTimeout(timeout);
    return builder.build();
}
 
开发者ID:mwarc,项目名称:embedded-memcached-spring,代码行数:6,代码来源:MemcachedConfiguration.java

示例9: onActivate

import net.spy.memcached.ConnectionFactoryBuilder; //导入方法依赖的package包/类
@Override
public void onActivate( Application application )
    throws ActivationException
{
    // Gather Configuration
    Config config = application.config().atKey( "memcache" );
    Protocol protocol = Protocol.valueOf( config.string( "protocol" ).toUpperCase( Locale.US ) );
    String addresses = config.string( "addresses" );
    String username = config.has( "username" ) ? config.string( "username" ) : null;
    String password = config.has( "password" ) ? config.string( "password" ) : null;
    String authMech = config.string( "authMechanism" );

    // Create Client
    try
    {
        ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();
        builder.setProtocol( protocol );
        if( !Strings.isEmpty( username ) )
        {
            builder.setAuthDescriptor(
                new AuthDescriptor(
                    new String[]
                    {
                        authMech
                    },
                    new PlainCallbackHandler( username, password )
                )
            );
        }
        client = new MemcachedClient( builder.build(), AddrUtil.getAddresses( addresses ) );
    }
    catch( IOException ex )
    {
        throw new ActivationException( "Unable to Activate MemcachePlugin: " + ex.getMessage(), ex );
    }

    // Create Cache Instance
    backingCache = config.bool( "metrics" )
                   ? new MemcacheCache( application.plugin( Metrics.class ), client )
                   : new MemcacheCache( client );
}
 
开发者ID:werval,项目名称:werval,代码行数:42,代码来源:MemcachePlugin.java


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