client manager

This commit is contained in:
lyr90329 2014-08-10 11:39:03 +08:00
parent 14a2bcf170
commit 98567bdc63
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
package r_memcached;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import server.ClientConfig;
public class MemcachedMgr
{
public HashMap<Integer, Client> m_mapLocalClients;
static MemcachedMgr memcachedMgr;
public static int nCopyNode;
public static MemcachedMgr getInstance()
{
if (memcachedMgr == null)
{
memcachedMgr = new MemcachedMgr();
}
return memcachedMgr;
}
public Integer getSize()
{
return m_mapLocalClients.size();
}
@SuppressWarnings("rawtypes")
public void init(HashMap<Integer, ClientConfig> hm)
{
m_mapLocalClients = new HashMap<Integer, Client>();
Iterator iter = hm.entrySet().iterator();
while (iter.hasNext())
{
Entry entry = (Entry) iter.next();
ClientConfig cc = (ClientConfig)entry.getValue();
Client lc = new Client();
lc.host = cc.host;
lc.port = cc.client_port;
lc.id = cc.id;
m_mapLocalClients.put(lc.id, lc);
if(lc.init(lc.host, lc.port))
{
System.out.println("client connected successful");
}
}
}
}