use of net.spy.memcached.ConnectionFactoryBuilder 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