Search in sources :

Example 1 with Protocol

use of net.spy.memcached.ConnectionFactoryBuilder.Protocol 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));
    }
}
Also used : ConnectionFactoryBuilder(net.spy.memcached.ConnectionFactoryBuilder) PlainCallbackHandler(net.spy.memcached.auth.PlainCallbackHandler) AuthDescriptor(net.spy.memcached.auth.AuthDescriptor) MemcachedClient(net.spy.memcached.MemcachedClient) Protocol(net.spy.memcached.ConnectionFactoryBuilder.Protocol)

Aggregations

ConnectionFactoryBuilder (net.spy.memcached.ConnectionFactoryBuilder)1 Protocol (net.spy.memcached.ConnectionFactoryBuilder.Protocol)1 MemcachedClient (net.spy.memcached.MemcachedClient)1 AuthDescriptor (net.spy.memcached.auth.AuthDescriptor)1 PlainCallbackHandler (net.spy.memcached.auth.PlainCallbackHandler)1