From 3b7f89a13ecedee932ef5899d6cc41ca2518c101 Mon Sep 17 00:00:00 2001 From: canmogol Date: Mon, 21 Nov 2016 11:04:41 +0200 Subject: [PATCH] memcache initializer moved under memcache class --- .../implementations/cache/MemCache.java | 42 +++++++++++++++++ .../cache/MemCacheInitializer.java | 46 ------------------- 2 files changed, 42 insertions(+), 46 deletions(-) delete mode 100644 src/main/java/fatjar/implementations/cache/MemCacheInitializer.java diff --git a/src/main/java/fatjar/implementations/cache/MemCache.java b/src/main/java/fatjar/implementations/cache/MemCache.java index 7185780..02c4988 100644 --- a/src/main/java/fatjar/implementations/cache/MemCache.java +++ b/src/main/java/fatjar/implementations/cache/MemCache.java @@ -1,9 +1,13 @@ package fatjar.implementations.cache; import com.whalin.MemCached.MemCachedClient; +import com.whalin.MemCached.SockIOPool; import fatjar.Cache; +import java.io.IOException; +import java.io.InputStream; import java.util.Map; +import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -102,4 +106,42 @@ public void clear() { throw new UnsupportedOperationException(); } + public static class MemCacheInitializer { + private static final String PROP_NAME = "memcache.properties"; + + public void initializeSockIOPool(String name) { + + Properties memcacheProp = new Properties(); + InputStream input = null; + SockIOPool pool = SockIOPool.getInstance(name); + input = this.getClass().getClassLoader().getResourceAsStream(PROP_NAME); + try { + memcacheProp.load(input); + input.close(); + pool.setServers(memcacheProp.getProperty("serversList").split(",")); + pool.setFailover(Boolean.parseBoolean(memcacheProp.getProperty("failover"))); + pool.setInitConn(Integer.parseInt(memcacheProp.getProperty("initConn"))); + pool.setMinConn(Integer.parseInt(memcacheProp.getProperty("minConn"))); + pool.setMaxConn(Integer.parseInt(memcacheProp.getProperty("maxConn"))); + pool.setMaintSleep(Long.parseLong(memcacheProp.getProperty("maintSleep"))); + pool.setNagle(Boolean.parseBoolean(memcacheProp.getProperty("nagle"))); + pool.setSocketTO(Integer.parseInt(memcacheProp.getProperty("docketTO"))); + pool.setAliveCheck(Boolean.parseBoolean(memcacheProp.getProperty("aliveCheck"))); + } catch (IOException e) { + e.printStackTrace(); + String[] servers = { "localhost:11211" }; + pool.setServers(servers); + pool.setFailover(true); + pool.setInitConn(10); + pool.setMinConn(5); + pool.setMaxConn(250); + pool.setMaintSleep(30); + pool.setNagle(false); + pool.setSocketTO(3000); + pool.setAliveCheck(true); + } + + pool.initialize(); + } + } } diff --git a/src/main/java/fatjar/implementations/cache/MemCacheInitializer.java b/src/main/java/fatjar/implementations/cache/MemCacheInitializer.java deleted file mode 100644 index b1cc1cc..0000000 --- a/src/main/java/fatjar/implementations/cache/MemCacheInitializer.java +++ /dev/null @@ -1,46 +0,0 @@ -package fatjar.implementations.cache; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import com.whalin.MemCached.SockIOPool; - -public class MemCacheInitializer { - private static final String PROP_NAME = "memcache.properties"; - - public void initializeSockIOPool(String name) { - - Properties memcacheProp = new Properties(); - InputStream input = null; - SockIOPool pool = SockIOPool.getInstance(name); - input = this.getClass().getClassLoader().getResourceAsStream(PROP_NAME); - try { - memcacheProp.load(input); - input.close(); - pool.setServers(memcacheProp.getProperty("serversList").split(",")); - pool.setFailover(Boolean.parseBoolean(memcacheProp.getProperty("failover"))); - pool.setInitConn(Integer.parseInt(memcacheProp.getProperty("initConn"))); - pool.setMinConn(Integer.parseInt(memcacheProp.getProperty("minConn"))); - pool.setMaxConn(Integer.parseInt(memcacheProp.getProperty("maxConn"))); - pool.setMaintSleep(Long.parseLong(memcacheProp.getProperty("maintSleep"))); - pool.setNagle(Boolean.parseBoolean(memcacheProp.getProperty("nagle"))); - pool.setSocketTO(Integer.parseInt(memcacheProp.getProperty("docketTO"))); - pool.setAliveCheck(Boolean.parseBoolean(memcacheProp.getProperty("aliveCheck"))); - } catch (IOException e) { - e.printStackTrace(); - String[] servers = { "localhost:11211" }; - pool.setServers(servers); - pool.setFailover(true); - pool.setInitConn(10); - pool.setMinConn(5); - pool.setMaxConn(250); - pool.setMaintSleep(30); - pool.setNagle(false); - pool.setSocketTO(3000); - pool.setAliveCheck(true); - } - - pool.initialize(); - } -}