Skip to content

Commit

Permalink
memcache initializer moved under memcache class
Browse files Browse the repository at this point in the history
  • Loading branch information
canmogol committed Nov 21, 2016
1 parent f882d65 commit 3b7f89a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 46 deletions.
42 changes: 42 additions & 0 deletions src/main/java/fatjar/implementations/cache/MemCache.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
}
}
}

This file was deleted.

0 comments on commit 3b7f89a

Please sign in to comment.