本文整理汇总了Java中net.spy.memcached.ConnectionFactoryBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactoryBuilder类的具体用法?Java ConnectionFactoryBuilder怎么用?Java ConnectionFactoryBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionFactoryBuilder类属于net.spy.memcached包,在下文中一共展示了ConnectionFactoryBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: ExceptionSwallowingMemcachedClient
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
@Autowired
public ExceptionSwallowingMemcachedClient(GlobalConfigHandler globalConfigHandler, ZkCuratorHandler zkCuratorHandler) throws Exception {
logger.info("Initializing...");
Stat stat = zkCuratorHandler.getCurator().checkExists().forPath(ZK_CONFIG_KEY_MEMCACHED_SERVERS_FPATH);
if (stat != null)
{
ObjectMapper mapper = new ObjectMapper();
byte[] bytes = zkCuratorHandler.getCurator().getData().forPath(ZK_CONFIG_KEY_MEMCACHED_SERVERS_FPATH);
MemcacheConfig config = mapper.readValue(bytes,MemcacheConfig.class);
logger.info(config.toString());
memcachedClient = new MemcachedClient(new ConnectionFactoryBuilder(new DefaultConnectionFactory()).setOpTimeout(MEMCACHE_OP_TIMEOUT).build(),
AddrUtil.getAddresses(config.servers));
logger.info(String.format("MemcachedClient initialized using %s[%s]", ZK_CONFIG_KEY_MEMCACHED_SERVERS, config.servers));
MemCachePeer.initialise(config.servers,config.numClients);
}
if (memcachedClient == null) {
throw new Exception("*Warning* Memcached NOT initialized!");
}
globalConfigHandler.addSubscriber(ZK_CONFIG_KEY_MEMCACHED_SERVERS, this);
}
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:23,代码来源:ExceptionSwallowingMemcachedClient.java
示例2: 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
示例3: getObject
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
@Override
public ArcusClientPool getObject() throws Exception {
ConnectionFactoryBuilder cfb = new ConnectionFactoryBuilder();
cfb.setFrontCacheExpireTime(frontCacheExpireTime);
cfb.setTimeoutExceptionThreshold(timeoutExceptionThreshold);
cfb.setFrontCacheCopyOnRead(frontCacheCopyOnRead);
cfb.setFrontCacheCopyOnWrite(frontCacheCopyOnWrite);
cfb.setMaxReconnectDelay(maxReconnectDelay);
if (maxFrontCacheElements > 0) {
cfb.setMaxFrontCacheElements(maxFrontCacheElements);
}
if (globalTranscoder != null) {
cfb.setTranscoder(globalTranscoder);
}
client = ArcusClient.createArcusClientPool(url, serviceCode, cfb,
poolSize);
return client;
}
开发者ID:naver,项目名称:arcus-spring,代码行数:19,代码来源:ArcusClientFactoryBean.java
示例4: SASLConnectReconnect
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
SASLConnectReconnect(String username, String password, String host) {
AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" },
new PlainCallbackHandler(username, password));
try {
List<InetSocketAddress> addresses = AddrUtil.getAddresses(host);
mc = new MemcachedClient(
new ConnectionFactoryBuilder().setProtocol(Protocol.BINARY)
.setAuthDescriptor(ad).build(), addresses);
} catch (IOException ex) {
System.err
.println("Couldn't create a connection, bailing out: \nIOException "
+ ex.getMessage());
if (mc != null) {
mc.shutdown();
}
}
}
开发者ID:naver,项目名称:arcus-java-client,代码行数:20,代码来源:SASLConnectReconnect.java
示例5: getObject
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
@Override
public Object getObject() throws IOException {
List<URI> addresses = getAddresses(connectionURI);
long timeout = Math.max(readTimeout, writeTimeout);
//TODO make all the below properties configurable via properties file
ConnectionFactoryBuilder builder = new CouchbaseConnectionFactoryBuilder()
.setOpTimeout(timeout) // wait up to timeout seconds for an operation to succeed
.setOpQueueMaxBlockTime(enqueueTimeout) // wait up to 'enqueueTimeout' seconds when trying to enqueue an operation
.setDaemon(true)
.setProtocol(Protocol.BINARY)
.setHashAlg(DefaultHashAlgorithm.KETAMA_HASH)
.setFailureMode(FailureMode.Redistribute)
.setInitialObservers(Collections.singleton((ConnectionObserver) new CouchbaseAlerter()));
if(transcoder!=null) {
builder.setTranscoder(transcoder);
}
//assuming there isn't any password set for Couchbase
CouchbaseConnectionFactory connectionFactory
= ((CouchbaseConnectionFactoryBuilder)builder).buildCouchbaseConnection(addresses, "default", "", "");
return new CouchbaseClient(connectionFactory);
}
开发者ID:parekhparth,项目名称:SimpleJavaWS,代码行数:24,代码来源:CouchbaseFactory.java
示例6: memcachedClient
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
@Lazy
@Bean
public MemcachedClientFactoryBean memcachedClient() {
try {
final MemcachedClientFactoryBean bean = new MemcachedClientFactoryBean();
bean.setServers(casProperties.getTicket().getRegistry().getMemcached().getServers());
bean.setLocatorType(ConnectionFactoryBuilder.Locator.valueOf(casProperties.getTicket().getRegistry().getMemcached().getLocatorType()));
bean.setTranscoder(kryoTranscoder());
bean.setFailureMode(FailureMode.valueOf(casProperties.getTicket().getRegistry().getMemcached().getFailureMode()));
bean.setHashAlg(DefaultHashAlgorithm.valueOf(casProperties.getTicket().getRegistry().getMemcached().getHashAlgorithm()));
return bean;
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:16,代码来源:MemcachedTicketRegistryConfiguration.java
示例7: 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
示例8: 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
示例9: 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
示例10: MemcacheConnect
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
public MemcacheConnect(String ip, int port) {
super(ip, port);
try {
client = new MemcachedClient(new ConnectionFactoryBuilder().setDaemon(true).setFailureMode(FailureMode.Retry).build(),AddrUtil.getAddresses(ip + ":" + port));
} catch (IOException ex) {
Logger.getLogger(MemcacheConnect.class.getName()).log(Level.SEVERE, null, ex);
}
}
开发者ID:eternalthinker,项目名称:finagle-java-example-master-slave,代码行数:9,代码来源:MemcacheConnect.java
示例11: create
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
public static MemcachedCache create(final MemcachedCacheConfig config) {
if (INSTANCE == null) {
try {
LZ4Transcoder transcoder = new LZ4Transcoder(config.getMaxObjectSize());
// always use compression
transcoder.setCompressionThreshold(0);
OperationQueueFactory opQueueFactory;
long maxQueueBytes = config.getMaxOperationQueueSize();
if (maxQueueBytes > 0) {
opQueueFactory = new MemcachedOperationQueueFactory(maxQueueBytes);
} else {
opQueueFactory = new LinkedOperationQueueFactory();
}
String hosts2Str = config.getHosts().toString();
String hostsList = hosts2Str.substring(1, hosts2Str.length() - 1);
synchronized (MemcachedCache.class) {
if (INSTANCE == null) {
INSTANCE = new MemcachedCache(new MemcachedClient(new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH).setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT).setDaemon(true).setFailureMode(FailureMode.Cancel).setTranscoder(transcoder).setShouldOptimize(true).setOpQueueMaxBlockTime(config.getTimeout()).setOpTimeout(config.getTimeout()).setReadBufferSize(config.getReadBufferSize())
.setOpQueueFactory(opQueueFactory).build(), AddrUtil.getAddresses(hostsList)), config);
}
}
} catch (IOException e) {
logger.error("Unable to create MemcachedCache instance: " + e.getMessage());
throw Throwables.propagate(e);
}
}
return INSTANCE;
}
开发者ID:pulsarIO,项目名称:pulsar-reporting-api,代码行数:32,代码来源:MemcachedCache.java
示例12: 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
示例13: 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
示例14: setupBeforeClass
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
@BeforeClass
public static void setupBeforeClass() throws IOException {
final ConnectionFactory cf = new ConnectionFactoryBuilder()
.setProtocol(ConnectionFactoryBuilder.Protocol.TEXT)
.setTranscoder(new WhalinTranscoder())
.setOpTimeout(1000)
.build();
spyClient = new MemcachedClient(cf, Collections.singletonList(new InetSocketAddress("localhost", MEMCACHED_PORT)));
}
开发者ID:outbrain,项目名称:ob1k,代码行数:11,代码来源:MemcacheClientTest.java
示例15: testCreate_5args
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
/**
* Test of create method, of class SpymemcachedUtil.
*/
@Test
public void testCreate_5args() {
System.out.println("create");
ConnectionFactoryBuilder.Protocol protocol = ConnectionFactoryBuilder.Protocol.BINARY;
String user = "";
String pass = "";
String[] authMechanisms = new String[]{"PLAIN"};
MemcachedClient result = SpymemcachedFactory.create(HOST, protocol, user, pass, authMechanisms);
assertNotNull(result);
result.shutdown();
}
开发者ID:decebals,项目名称:pippo,代码行数:15,代码来源:SpymemcachedFactoryTest.java
示例16: ReconnectJob
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
public ReconnectJob(String hostPort, String serviceCode,
ConnectionFactoryBuilder cfb, ArcusClient[] client) {
super();
this.hostPort = hostPort;
this.serviceCode = serviceCode;
this.cfb = cfb;
this.client = client;
}
开发者ID:naver,项目名称:arcus-java-client,代码行数:9,代码来源:ReconnectJob.java
示例17: ExcessivelyLargeGetTest
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
public ExcessivelyLargeGetTest() throws Exception {
client = new MemcachedClient(new ConnectionFactoryBuilder()
.setProtocol(Protocol.BINARY).setOpTimeout(15000).build(),
AddrUtil.getAddresses("127.0.0.1:11211"));
keys = new ArrayList<String>(N);
new Random().nextBytes(value);
}
开发者ID:naver,项目名称:arcus-java-client,代码行数:8,代码来源:ExcessivelyLargeGetTest.java
示例18: configure
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
Config $memcached = conf.getConfig("memcached")
.withFallback(conf.getConfig("memcached"));
ConnectionFactoryBuilder builder = newConnectionFactoryBuilder($memcached);
if (configurer != null) {
configurer.accept(builder, conf);
}
List<String> servers = new ArrayList<>();
Object $servers = conf.getAnyRef("memcached.server");
if ($servers instanceof List) {
servers.addAll((Collection<? extends String>) $servers);
} else {
servers.add($servers.toString());
}
MemcachedClientProvider provider = new MemcachedClientProvider(
builder,
AddrUtil.getAddresses(servers),
$memcached.getDuration("shutdownTimeout", TimeUnit.MILLISECONDS));
env.onStop(provider::destroy);
binder
.bind(MemcachedClient.class)
.toProvider(provider)
.asEagerSingleton();
}
开发者ID:jooby-project,项目名称:jooby,代码行数:33,代码来源:SpyMemcached.java
示例19: newConnectionFactoryBuilder
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
private ConnectionFactoryBuilder newConnectionFactoryBuilder(final Config conf) {
ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();
ifset(conf, "authWaitTime", path -> builder
.setAuthWaitTime(conf.getDuration(path, TimeUnit.MILLISECONDS)));
ifset(conf, "daemon", path -> builder.setDaemon(conf.getBoolean(path)));
ifset(conf, "enableMetrics", path -> builder
.setEnableMetrics(enumFor(conf.getString(path), MetricType.values())));
ifset(conf, "failureMode", path -> builder
.setFailureMode(enumFor(conf.getString(path), FailureMode.values())));
ifset(conf, "locator", path -> builder
.setLocatorType(enumFor(conf.getString(path), Locator.values())));
ifset(conf, "maxReconnectDelay", path -> builder
.setMaxReconnectDelay(conf.getDuration(path, TimeUnit.SECONDS)));
ifset(conf, "opQueueMaxBlockTime", path -> builder
.setOpQueueMaxBlockTime(conf.getDuration(path, TimeUnit.MILLISECONDS)));
ifset(conf, "opTimeout", path -> builder
.setOpTimeout(conf.getDuration(path, TimeUnit.MILLISECONDS)));
ifset(conf, "protocol", path -> builder
.setProtocol(enumFor(conf.getString(path), Protocol.values())));
ifset(conf, "readBufferSize", path -> builder
.setReadBufferSize(conf.getInt(path)));
ifset(conf, "shouldOptimize", path -> builder
.setShouldOptimize(conf.getBoolean(path)));
ifset(conf, "timeoutExceptionThreshold", path -> builder
.setTimeoutExceptionThreshold(conf.getInt(path)));
ifset(conf, "useNagleAlgorithm", path -> builder
.setUseNagleAlgorithm(conf.getBoolean(path)));
return builder;
}
开发者ID:jooby-project,项目名称:jooby,代码行数:31,代码来源:SpyMemcached.java
示例20: defaults
import net.spy.memcached.ConnectionFactoryBuilder; //导入依赖的package包/类
@Test
public void defaults() throws Exception {
List<InetSocketAddress> servers = AddrUtil.getAddresses("localhost:11211");
long timeout = -1;
new MockUnit(ConnectionFactoryBuilder.class)
.run(unit -> {
new MemcachedClientProvider(unit.get(ConnectionFactoryBuilder.class), servers, timeout);
});
}
开发者ID:jooby-project,项目名称:jooby,代码行数:10,代码来源:MemcachedClientProviderTest.java
注:本文中的net.spy.memcached.ConnectionFactoryBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论