use of net.spy.memcached.auth.AuthDescriptor 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.AuthDescriptor 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.auth.AuthDescriptor in project serverless by bluenimble.
the class MemCachedPlugin method createClients.
private void createClients(ApiSpace space) throws PluginRegistryException {
// create sessions
JsonObject msgFeature = Json.getObject(space.getFeatures(), feature);
if (msgFeature == null || msgFeature.isEmpty()) {
return;
}
Iterator<String> keys = msgFeature.keys();
while (keys.hasNext()) {
String key = keys.next();
JsonObject feature = Json.getObject(msgFeature, key);
if (!this.getName().equalsIgnoreCase(Json.getString(feature, ApiSpace.Features.Provider))) {
continue;
}
String sessionKey = createKey(key);
if (space.containsRecyclable(sessionKey)) {
continue;
}
JsonObject spec = Json.getObject(feature, ApiSpace.Features.Spec);
String[] nodes = Lang.split(Json.getString(spec, Spec.Cluster), Lang.COMMA);
if (nodes == null) {
continue;
}
final JsonObject oAuth = Json.getObject(spec, Spec.Auth);
if (oAuth == null || oAuth.isEmpty()) {
continue;
}
final String user = Json.getString(oAuth, Spec.User);
final String password = Json.getString(oAuth, Spec.Password);
AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" }, new PlainCallbackHandler(user, password));
try {
MemcachedClient client = new MemcachedClient(new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).setAuthDescriptor(ad).build(), AddrUtil.getAddresses(Arrays.asList(nodes)));
space.addRecyclable(sessionKey, new RecyclableCacheClient(client));
} catch (IOException e) {
throw new PluginRegistryException(e.getMessage(), e);
}
}
}
Aggregations