use of net.spy.memcached.ConnectionFactoryBuilder in project qi4j-sdk by Qi4j.
the class MemcachePoolMixin method activateService.
@Override
public void activateService() throws Exception {
if (configuration != null) {
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()) {
builder.setAuthDescriptor(new AuthDescriptor(new String[] { authMech }, new PlainCallbackHandler(username, password)));
}
client = new MemcachedClient(builder.build(), AddrUtil.getAddresses(addresses));
}
}
use of net.spy.memcached.ConnectionFactoryBuilder in project DataX by alibaba.
the class ConfigurationChecker method hostReachableCheck.
/**
* 检查ocs服务器网络是否可达
*/
private static void hostReachableCheck(Configuration config) {
String proxy = config.getString(Key.PROXY);
String port = config.getString(Key.PORT);
String username = config.getString(Key.USER);
String password = config.getString(Key.PASSWORD);
AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" }, new PlainCallbackHandler(username, password));
try {
MemcachedClient client = new MemcachedClient(new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).setAuthDescriptor(ad).build(), AddrUtil.getAddresses(proxy + ":" + port));
client.get("for_check_connectivity");
client.getVersions();
if (client.getAvailableServers().isEmpty()) {
throw new RuntimeException("没有可用的Servers: getAvailableServers() -> is empty");
}
client.shutdown();
} catch (Exception e) {
throw DataXException.asDataXException(OcsWriterErrorCode.HOST_UNREACHABLE, String.format("OCS[%s]服务不可用", proxy), e);
}
}
use of net.spy.memcached.ConnectionFactoryBuilder in project hazelcast by hazelcast.
the class InvalidEndpointTest method attemptMemcacheOnHttpEndpoint.
@Test
public void attemptMemcacheOnHttpEndpoint() throws IOException, InterruptedException {
Config config = createRestEndpointConfig();
HazelcastInstance instance = factory.newHazelcastInstance(config);
// Invalid endpoint - points to REST
InetSocketAddress address = instance.getCluster().getLocalMember().getSocketAddress(REST);
ConnectionFactory factory = new ConnectionFactoryBuilder().setOpTimeout(60 * 60 * 60).setDaemon(true).setFailureMode(FailureMode.Retry).build();
MemcachedClient client = new MemcachedClient(factory, Collections.singletonList(address));
try {
client.set("one", 0, "two").get();
fail("Should not be able to connect");
} catch (InterruptedException e) {
ignore(e);
} catch (ExecutionException e) {
ignore(e);
}
shutdownQuietly(client);
}
use of net.spy.memcached.ConnectionFactoryBuilder in project hazelcast by hazelcast.
the class AdvancedNetworkingCommunicationIntegrationTest method getMemcachedClient.
private MemcachedClient getMemcachedClient(HazelcastInstance instance, int port) throws Exception {
String hostName = instance.getCluster().getLocalMember().getSocketAddress().getHostName();
InetSocketAddress address = new InetSocketAddress(hostName, port);
ConnectionFactory factory = new ConnectionFactoryBuilder().setOpTimeout(3000).setDaemon(true).setFailureMode(FailureMode.Retry).build();
return new MemcachedClient(factory, Collections.singletonList(address));
}
use of net.spy.memcached.ConnectionFactoryBuilder in project druid by druid-io.
the class MemcachedCacheBenchmark method setUp.
@Override
protected void setUp() throws Exception {
SerializingTranscoder transcoder = new SerializingTranscoder(// 50 MB
50 * 1024 * 1024);
// disable compression
transcoder.setCompressionThreshold(Integer.MAX_VALUE);
client = new MemcachedClient(new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH).setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT).setDaemon(true).setFailureMode(FailureMode.Retry).setTranscoder(transcoder).setShouldOptimize(true).build(), AddrUtil.getAddresses(hosts));
cache = new MemcachedCache(Suppliers.<ResourceHolder<MemcachedClientIF>>ofInstance(StupidResourceHolder.create(client)), new MemcachedCacheConfig() {
@Override
public String getMemcachedPrefix() {
return "druid-memcached-benchmark";
}
@Override
public int getTimeout() {
return 30000;
}
@Override
public int getExpiration() {
return 3600;
}
}, MemcachedCacheTest.NOOP_MONITOR);
randBytes = new byte[objectSize * 1024];
new Random(0).nextBytes(randBytes);
}
Aggregations