From 98567bdc63badd953af8228549e659e6a0fddc7b Mon Sep 17 00:00:00 2001 From: lyr90329 Date: Sun, 10 Aug 2014 11:39:03 +0800 Subject: [PATCH] client manager --- .../src/r_memcached/MemcachedMgr.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 MemcachedClient/src/r_memcached/MemcachedMgr.java diff --git a/MemcachedClient/src/r_memcached/MemcachedMgr.java b/MemcachedClient/src/r_memcached/MemcachedMgr.java new file mode 100644 index 0000000..43d79f1 --- /dev/null +++ b/MemcachedClient/src/r_memcached/MemcachedMgr.java @@ -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 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 hm) + { + m_mapLocalClients = new HashMap(); + + 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"); + } + } + } + +}