connectionFactoryBuilder.setProtocol( protocolString == null ? DEFAULT_PROTOCOL : ConnectionFactoryBuilder.Protocol.valueOf(protocolString.toUpperCase()));
new PlainCallbackHandler(memcachedUser, memcachePassword)); ConnectionFactory cf = new ConnectionFactoryBuilder() .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setAuthDescriptor(ad) .build();
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; }
.setProtocol(ConnectionFactoryBuilder.Protocol.valueOf(StringUtils.toUpperCase(config.getProtocol()))) .setLocatorType(ConnectionFactoryBuilder.Locator.valueOf(StringUtils.toUpperCase(config.getLocator()))) .setDaemon(true)
new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH) .setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT)
new PlainCallbackHandler(user, pass)); connectionFactory = new ConnectionFactoryBuilder() .setProtocol(protocol) .setAuthDescriptor(authDescriptor) .build(); } else { connectionFactory = new ConnectionFactoryBuilder() .setProtocol(protocol) .build();
public void setProtocol(final Protocol prot) { connectionFactoryBuilder.setProtocol(prot); }
public void setProtocol(final Protocol prot) { connectionFactoryBuilder.setProtocol(prot); }
public void setProtocol(final Protocol prot) { connectionFactoryBuilder.setProtocol(prot); }
public void setProtocol(final Protocol prot) { connectionFactoryBuilder.setProtocol(prot); }
memcachedNodesManager.getSessionIdFormat(), statistics, operationTimeout, maxReconnectDelay, authDescriptor) : new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setAuthDescriptor(authDescriptor) .setOpTimeout(operationTimeout)
@Override protected ConnectionFactoryBuilder getConnectionFactoryBuilder() { ConnectionFactoryBuilder factoryBuilder = super.getConnectionFactoryBuilder(); return factoryBuilder.setProtocol(ConnectionFactoryBuilder.Protocol.BINARY); } }
@Override public MemcachedClient call() throws Exception { return new MemcachedClient( new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setAuthDescriptor(ad) .build(), AddrUtil.getAddresses(proxy + ":" + port)); } }, 9, 1000L, true);
private MemcachedClient memcachedClient() throws IOException { final List<InetSocketAddress> servers = properties.getServers(); final ClientMode mode = properties.getMode(); final MemcachedCacheProperties.Protocol protocol = properties.getProtocol(); final ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder() .setClientMode(mode) .setProtocol(protocol.value()); return new MemcachedClient(connectionFactoryBuilder.build(), servers); } }
public void initClient() throws IOException { System.setProperty("net.spy.log.LoggerImpl", "org.osgl.cache.impl.SpyMemcachedLogger"); List<InetSocketAddress> addrs = MemcachedClientConfigurator.getHosts(); if (addrs.isEmpty()) { throw new ConfigurationException("Bad configuration for memcached: missing host(s)"); } String username = MemcachedClientConfigurator.getUsername(); if (S.notBlank(username)) { String password = MemcachedClientConfigurator.getPassword(); if (null == password) { throw new ConfigurationException("Bad configuration for memcached: missing password"); } // Use plain SASL to connect to memcached AuthDescriptor ad = new AuthDescriptor(new String[]{"PLAIN"}, new PlainCallbackHandler(username, password)); ConnectionFactory cf = new ConnectionFactoryBuilder() .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setAuthDescriptor(ad) .build(); client = new MemcachedClient(cf, addrs); } else { client = new MemcachedClient(addrs); } }
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; }
builder.setProtocol(conf.isUseBinaryProtocol() ? Protocol.BINARY : Protocol.TEXT); if (conf.getOperationTimeout() != null) { builder.setOpTimeout(conf.getOperationTimeout());
@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)); }
public MemcachedClientWrapper() { configuration = MemcachedConfigurationBuilder.getInstance().parseConfiguration(); try { if (configuration.isUsingSASL()) { AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" }, new PlainCallbackHandler(configuration.getUsername(), configuration.getPassword())); client = new MemcachedClient(new ConnectionFactoryBuilder() .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).setAuthDescriptor(ad).build(), configuration.getAddresses()); } else { client = new MemcachedClient(configuration.getConnectionFactory(), configuration.getAddresses()); } } catch (IOException e) { String message = "Impossible to instantiate a new memecached client instance, see nested exceptions"; LOG.error(message, e); throw new RuntimeException(message, e); } if (LOG.isDebugEnabled()) { LOG.debug("Running new Memcached client using " + configuration); } }
@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 ) ); }