Skip to content

Instantly share code, notes, and snippets.

@pablomoretti
Created November 7, 2011 13:57
Show Gist options
  • Save pablomoretti/1345067 to your computer and use it in GitHub Desktop.
Save pablomoretti/1345067 to your computer and use it in GitHub Desktop.
package net.spy.memcached.utils;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import net.spy.memcached.MemcachedClient;
import org.springframework.beans.factory.FactoryBean;
public class MemcachedClientFactoryBean implements FactoryBean<MemcachedClient> {
private String hosts;
@Override
public MemcachedClient getObject() throws Exception {
ArrayList<InetSocketAddress> inetAddressList = new ArrayList<InetSocketAddress>();
String[] splitHost = null;
for (String host : hosts.split(" ")) {
splitHost = host.split(":");
inetAddressList.add(new InetSocketAddress(splitHost[0], Integer.parseInt(splitHost[1])));
}
return new MemcachedClient(inetAddressList);
}
@Override
public Class<?> getObjectType() {
return MemcachedClient.class;
}
@Override
public boolean isSingleton() {
return true;
}
public String getHosts() {
return hosts;
}
/**
* Example localhost:11211 otherHost:11211
*
* @param host
*/
public void setHosts(String hosts) {
this.hosts = hosts;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment