本文整理汇总了Java中net.spy.memcached.FailureMode类的典型用法代码示例。如果您正苦于以下问题:Java FailureMode类的具体用法?Java FailureMode怎么用?Java FailureMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FailureMode类属于net.spy.memcached包,在下文中一共展示了FailureMode类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createWithSpecificConf
import net.spy.memcached.FailureMode; //导入依赖的package包/类
@Test
public void createWithSpecificConf() throws IOException {
SpymemcachedConfiguration conf = new SpymemcachedConfiguration();
conf.setConsistentHashing(true);
conf.setOperationTimeout(1000);
conf.setUseBinaryProtocol(false);
conf.setFailureMode(FailureMode.Cancel);
conf.setShouldOptimize(true);
conf.setMaxReconnectDelay(1000L);
conf.setTimeoutExceptionThreshold(100);
conf.setUseNagleAlgorithm(false);
conf.setMetricCollector(new NoopMetricCollector());
conf.setMetricType(MetricType.PERFORMANCE);
CacheClient client = factory.create(addrs, conf);
assertNotNull(client);
client.shutdown();
}
示例2: createWithSpecificConf
import net.spy.memcached.FailureMode; //导入依赖的package包/类
@Test
public void createWithSpecificConf() throws IOException {
ElastiCacheConfiguration conf = new ElastiCacheConfiguration();
conf.setConsistentHashing(true);
conf.setOperationTimeout(100);
conf.setUseBinaryProtocol(false);
conf.setFailureMode(FailureMode.Retry);
conf.setShouldOptimize(true);
conf.setMaxReconnectDelay(1000L);
conf.setTimeoutExceptionThreshold(100);
conf.setUseNagleAlgorithm(false);
CacheClient client = factory.create(addrs, conf);
assertNotNull(client);
client.shutdown();
}
示例3: getObject
import net.spy.memcached.FailureMode; //导入依赖的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);
}
示例4: memcachedClient
import net.spy.memcached.FailureMode; //导入依赖的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);
}
}
示例5: MemcachedBlockCache
import net.spy.memcached.FailureMode; //导入依赖的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);
}
示例6: doStart
import net.spy.memcached.FailureMode; //导入依赖的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();
}
示例7: MemcacheConnect
import net.spy.memcached.FailureMode; //导入依赖的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);
}
}
示例8: create
import net.spy.memcached.FailureMode; //导入依赖的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;
}
示例9: MemcachedBlockCache
import net.spy.memcached.FailureMode; //导入依赖的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);
}
示例10: newConnectionFactoryBuilder
import net.spy.memcached.FailureMode; //导入依赖的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;
}
示例11: ApiMemcached
import net.spy.memcached.FailureMode; //导入依赖的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);
}
}
示例12: getFailureMode
import net.spy.memcached.FailureMode; //导入依赖的package包/类
public FailureMode getFailureMode() {
try {
return FailureMode.valueOf(failureMode.get());
} catch (IllegalArgumentException ex) {
return FailureMode.Cancel;
}
}
示例13: init
import net.spy.memcached.FailureMode; //导入依赖的package包/类
protected void init() throws Exception {
if (BucketConfig.instance == null){
new BucketConfig().afterPropertiesSet();
}
this.config = BucketConfig.instance;
initMetrics();
this.buckets = new HashMap<String, CouchbaseClient>();
this.entityBuckets = new HashMap<String, String>();
List<Map> items = (List<Map>) this.config.getBuckets();
CouchbaseConnectionFactoryBuilder builder = new CouchbaseConnectionFactoryBuilder();
builder.setDaemon(true);
builder.setEnableMetrics(MetricType.PERFORMANCE);
builder.setFailureMode(FailureMode.Redistribute);
for (Map item : items) {
String name = Objects.toString(item.get("bucket"), "").trim();
String user = Objects.toString(item.get("user"), "");
String pwd = Objects.toString(item.get("pwd"), "");
String urls = Objects.toString(item.get("urls"), "");
String[] ents = Objects.toString(item.get("ents"), "").split(",");
logger.info("@Couchbase connecting to bucket: {}, urls: {}", name, urls);
CouchbaseConnectionFactory ccf = null;
if(StringUtils.isNotBlank(user)){
ccf = builder.buildCouchbaseConnection(this.wrapBaseList(urls), name, user, pwd);
}else{
ccf = builder.buildCouchbaseConnection(this.wrapBaseList(urls), name, pwd);
}
this.buckets.put(name, new CouchbaseClient(ccf));
this.defaultBucket = name;
for(String str : ents){
this.entityBuckets.put(str.toLowerCase().trim(), name);
}
logger.info("@Couchbase init, bucket:{}, urls:{}", name, urls);
}
}
示例14: setFailureMode
import net.spy.memcached.FailureMode; //导入依赖的package包/类
public void setFailureMode(final FailureMode fm) {
connectionFactoryBuilder.setFailureMode(fm);
}