use of net.spy.memcached.auth.PlainCallbackHandler 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.auth.PlainCallbackHandler 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);
}
}
Aggregations