Created
November 7, 2011 13:57
-
-
Save pablomoretti/1345067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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