Search in sources :

Example 11 with ConnectionFactoryBuilder

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);
        }
    }
}
Also used : PlainCallbackHandler(net.spy.memcached.auth.PlainCallbackHandler) ConnectionFactoryBuilder(net.spy.memcached.ConnectionFactoryBuilder) AuthDescriptor(net.spy.memcached.auth.AuthDescriptor) MemcachedClient(net.spy.memcached.MemcachedClient) JsonObject(com.bluenimble.platform.json.JsonObject) IOException(java.io.IOException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException)

Aggregations

ConnectionFactoryBuilder (net.spy.memcached.ConnectionFactoryBuilder)11 MemcachedClient (net.spy.memcached.MemcachedClient)8 InetSocketAddress (java.net.InetSocketAddress)5 ConnectionFactory (net.spy.memcached.ConnectionFactory)3 AuthDescriptor (net.spy.memcached.auth.AuthDescriptor)3 PlainCallbackHandler (net.spy.memcached.auth.PlainCallbackHandler)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 SerializingTranscoder (net.spy.memcached.transcoders.SerializingTranscoder)2 DataXException (com.alibaba.datax.common.exception.DataXException)1 JsonObject (com.bluenimble.platform.json.JsonObject)1 PluginRegistryException (com.bluenimble.platform.plugins.PluginRegistryException)1 Config (com.hazelcast.config.Config)1 RestServerEndpointConfig (com.hazelcast.config.RestServerEndpointConfig)1 ServerSocketEndpointConfig (com.hazelcast.config.ServerSocketEndpointConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1 ResourceHolder (io.druid.collections.ResourceHolder)1 StupidResourceHolder (io.druid.collections.StupidResourceHolder)1 IOException (java.io.IOException)1