Search in sources :

Example 1 with MemcachedClientFactoryBean

use of net.spy.memcached.spring.MemcachedClientFactoryBean in project cas by apereo.

the class MemcachedTicketRegistryConfiguration method memcachedClient.

@Lazy
@Bean
public MemcachedClientFactoryBean memcachedClient() {
    try {
        final MemcachedClientFactoryBean bean = new MemcachedClientFactoryBean();
        bean.setServers(casProperties.getTicket().getRegistry().getMemcached().getServers());
        bean.setLocatorType(ConnectionFactoryBuilder.Locator.valueOf(casProperties.getTicket().getRegistry().getMemcached().getLocatorType()));
        bean.setTranscoder(kryoTranscoder());
        bean.setFailureMode(FailureMode.valueOf(casProperties.getTicket().getRegistry().getMemcached().getFailureMode()));
        bean.setHashAlg(DefaultHashAlgorithm.valueOf(casProperties.getTicket().getRegistry().getMemcached().getHashAlgorithm()));
        return bean;
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : MemcachedClientFactoryBean(net.spy.memcached.spring.MemcachedClientFactoryBean) Lazy(org.springframework.context.annotation.Lazy) MemcachedClientFactoryBean(net.spy.memcached.spring.MemcachedClientFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with MemcachedClientFactoryBean

use of net.spy.memcached.spring.MemcachedClientFactoryBean in project cas by apereo.

the class MemcachedPooledClientConnectionFactory method create.

@Override
@SneakyThrows
public MemcachedClientIF create() {
    val factoryBean = new MemcachedClientFactoryBean();
    factoryBean.setServers(memcachedProperties.getServers());
    factoryBean.setTranscoder(this.transcoder);
    if (StringUtils.isNotBlank(memcachedProperties.getLocatorType())) {
        factoryBean.setLocatorType(ConnectionFactoryBuilder.Locator.valueOf(memcachedProperties.getLocatorType()));
    }
    if (StringUtils.isNotBlank(memcachedProperties.getFailureMode())) {
        factoryBean.setFailureMode(FailureMode.valueOf(memcachedProperties.getFailureMode()));
    }
    if (StringUtils.isNotBlank(memcachedProperties.getHashAlgorithm())) {
        factoryBean.setHashAlg(DefaultHashAlgorithm.valueOf(memcachedProperties.getHashAlgorithm()));
    }
    if (StringUtils.isNotBlank(memcachedProperties.getProtocol())) {
        factoryBean.setProtocol(ConnectionFactoryBuilder.Protocol.valueOf(memcachedProperties.getProtocol()));
    }
    factoryBean.setDaemon(memcachedProperties.isDaemon());
    factoryBean.setShouldOptimize(memcachedProperties.isShouldOptimize());
    factoryBean.setUseNagleAlgorithm(memcachedProperties.isUseNagleAlgorithm());
    if (memcachedProperties.getOpTimeout() > 0) {
        factoryBean.setOpTimeout(memcachedProperties.getOpTimeout());
    }
    if (memcachedProperties.getMaxReconnectDelay() > 0) {
        factoryBean.setMaxReconnectDelay(memcachedProperties.getMaxReconnectDelay());
    }
    if (memcachedProperties.getShutdownTimeoutSeconds() > 0) {
        factoryBean.setShutdownTimeoutSeconds(memcachedProperties.getShutdownTimeoutSeconds());
    }
    if (memcachedProperties.getTimeoutExceptionThreshold() > 0) {
        factoryBean.setTimeoutExceptionThreshold(memcachedProperties.getTimeoutExceptionThreshold());
    }
    factoryBean.afterPropertiesSet();
    return (MemcachedClientIF) factoryBean.getObject();
}
Also used : lombok.val(lombok.val) MemcachedClientIF(net.spy.memcached.MemcachedClientIF) MemcachedClientFactoryBean(net.spy.memcached.spring.MemcachedClientFactoryBean) SneakyThrows(lombok.SneakyThrows)

Aggregations

MemcachedClientFactoryBean (net.spy.memcached.spring.MemcachedClientFactoryBean)2 SneakyThrows (lombok.SneakyThrows)1 lombok.val (lombok.val)1 MemcachedClientIF (net.spy.memcached.MemcachedClientIF)1 Bean (org.springframework.context.annotation.Bean)1 Lazy (org.springframework.context.annotation.Lazy)1