net.spy.memcached.ConnectionFactoryBuilder.Protocol Java Examples
The following examples show how to use
net.spy.memcached.ConnectionFactoryBuilder.Protocol.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MemcacheClientFactoryImpl.java From simple-spring-memcached with MIT License | 6 votes |
@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)); }
Example #2
Source File: MemcachePoolMixin.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@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 ) ); }
Example #3
Source File: MemcacheClientFactoryImpl.java From simple-spring-memcached with MIT License | 5 votes |
@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)); }
Example #4
Source File: SpymemcachedFactory.java From pippo with Apache License 2.0 | 5 votes |
/** * Create a memcached client with pippo settings. * * @param settings pippo settings * @return memcached client */ public static final MemcachedClient create(final PippoSettings settings) { String host = settings.getString(HOST, "localhost:11211"); String prot = settings.getString(PROT, "BINARY"); Protocol protocol = Protocol.valueOf(prot); String user = settings.getString(USER, ""); String pass = settings.getString(PASS, ""); List<String> autM = settings.getStrings(AUTM); String[] mechanisms = autM.toArray(new String[autM.size()]); return create(host, protocol, user, pass, mechanisms); }
Example #5
Source File: ApiMemcached.java From iaf with Apache License 2.0 | 5 votes |
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.add(log, "Unable to connect to one or more memcached servers."); } }
Example #6
Source File: ConnectFactoryBuilderTestFile.java From KodeBeagle with Apache License 2.0 | 4 votes |
public void testProtocolSetterBinary() { assertTrue(b.setProtocol(Protocol.BINARY).build().getOperationFactory() instanceof BinaryOperationFactory); }
Example #7
Source File: ConnectFactoryBuilderTestFile.java From KodeBeagle with Apache License 2.0 | 4 votes |
public void testProtocolSetterText() { assertTrue(b.setProtocol(Protocol.TEXT).build().getOperationFactory() instanceof AsciiOperationFactory); }