public void testRun() throws Exception { String wsName = "test"; DefaultCacheManager dcm = new DefaultCacheManager(); Cache<String, Metadata> metaCache = dcm.getCache("meta"); Cache<String, byte[]> dataCache = dcm.getCache("data"); GridFilesystem gfs = new GridFilesystem(dataCache, metaCache); BuildContext bcontext = DirectoryBuilder.newDirectoryInstance(metaCache, dataCache, metaCache, wsName); bcontext.chunkSize(1024 * 1024); Directory directory = bcontext.create(); Central central = CentralConfig.oldFromDir(directory).build(); central.newIndexer().index(IndexJobs.create("/bleujin", 10)); central.newSearcher().createRequest("").find().debugPrint(); OutputStream output = gfs.getOutput("/test.data"); IOUtil.copyNClose(new StringInputStream("hello bleujin"), output); Debug.line(IOUtil.toStringWithClose(gfs.getInput("/test.data"))); central.newSearcher().createRequest("").find().debugPrint(); File root = gfs.getFile("/"); viewFile(root); dcm.stop(); }
@Override public Object removeObject(Object key) { // TODO Auto-generated method stub Cache cache = cacheManager.getCache(this.id); return cache.remove((String) key.toString()); }
@BeforeClass public static void beforeEachClass() throws Exception { context = mock(ExecutionContext.class); final DefaultCacheManager container = new DefaultCacheManager("./src/test/resources/infinispan_persistent_config.xml", true); TradesCacheSource.loadCache(container.getCache(TradesCacheSource.TRADES_CACHE_NAME)); factory = new InfinispanManagedConnectionFactory() { /** */ private static final long serialVersionUID = 6241061876834919893L; @Override protected Object performJNDICacheLookup(String jnidName) throws Exception { return container; } }; factory.setCacheJndiName(JNDI_NAME); factory.setCacheTypeMap( RemoteInfinispanTestHelper.TRADE_CACHE_NAME + ":" + Trade.class.getName()); tfactory = new InfinispanCacheExecutionFactory(); tfactory.start(); }
public void testMemoryConsumption() throws InterruptedException { DefaultCacheManager cm = new DefaultCacheManager(true); Cache<Object, Object> cache = cm.getCache(); long freeMemBefore = freeMemKb(); System.out.println("freeMemBefore = " + freeMemBefore); for (int i = 0; i < 1024 * 300; i++) { cache.put(i, i); } System.out.println("Free meme after: " + freeMemKb()); System.out.println("Consumed memory: " + (freeMemBefore - freeMemKb())); cm.stop(); for (int i = 0; i < 10; i++) { System.gc(); if (isOkay(freeMemBefore)) { break; } else { Thread.sleep(1000); } } System.out.println("Free memory at the end:" + freeMemKb()); assert isOkay(freeMemBefore); }
@PostConstruct public void generateCache() { m = new DefaultCacheManager(); Configuration c = new Configuration(); m.defineConfiguration("defaultCache", c); cache = m.getCache("defaultCache"); }
private static ObjectConnection createConnection(DefaultCacheManager container) { TradesCacheSource.loadCache(container.getCache(TradesCacheSource.TRADES_CACHE_NAME)); CacheContainerWrapper wrapper = new TestInfinispanCacheWrapper(container); ObjectConnection conn = new TestInfinispanConnection(wrapper, container); return conn; }
@Override public int getSize() { // TODO Auto-generated method stub Cache<String, Object> cache = cacheManager.getCache(this.id); if (cache == null) { return 0; } return cache.size(); }
@Test public void testDummyTMGetCache() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.transaction() .use1PcForAutoCommitTransactions(true) .transactionManagerLookup(new DummyTransactionManagerLookup()); DefaultCacheManager cm = new DefaultCacheManager(cb.build()); cm.getCache(); }
public void add() { Cache<Long, Product> cache = cacheManager.getCache(); Product product = new Product(id, name, description, pieces, price); cache.put(id, product); message = "Product successfully added."; logger.info("Added product: " + product); }
@Test public void testGetAndPut() { // new configuration DefaultCacheManager cacheManager = new DefaultCacheManager(new ConfigurationBuilder().build()); Cache<String, String> cache = cacheManager.getCache(); cache.put("Foo", "2"); cache.put("Bar", "4"); Assert.assertEquals(cache.get("Foo"), "2"); Assert.assertEquals(cache.get("Bar"), "4"); }
public static void main(String[] args) throws IOException { DefaultCacheManager cacheManager = new DefaultCacheManager("config-samples/lucene-demo-cache-config.xml"); cacheManager.start(); try { Cache<?, ?> cache = cacheManager.getCache(); InfinispanDirectory directory = new InfinispanDirectory(cache); DemoDriver driver = new DemoDriver(directory, cache); driver.run(); } finally { cacheManager.stop(); } }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { log.info("putting hello"); Cache<String, String> c = m.getCache(); String x = (String) c.get("hello"); PrintWriter writer = resp.getWriter(); writer.println(PAGE_HEADER); writer.println("<h1>" + "Get Infinispan: " + x + "</h1>"); writer.println(PAGE_FOOTER); writer.close(); }
/** * 만료시간이 설정되어있을 때 Flag값을 주어 0.5초 전이라면 다시 cache에 put해줄 수 있도록 체크 * * @param map * @param key * @return true/false */ private boolean checkLt(Map<String, Object> map, String key) { if (null == map.get("lifeTime")) { return false; } Cache<String, Object> cache = cacheManager.getCache(this.id); Long lifeTime = (Long) map.get("lifeTime"); Long currTime = System.currentTimeMillis(); if (null != lifeTime && (lifeTime - 500) < currTime && currTime < lifeTime) { if ((Boolean) map.get("cacheFlag")) { // 캐시를 다시 put하는 동안 다른 Thread가 캐시에서 읽어가도록 flag를 false로 세팅 map.put("cacheFlag", false); // cache.put(key.toString(), map); // sonar에서 스트링객체에 toString을 호출하는 것이 불필요하다고 하여 다음과 같이 수정 cache.put(key, map); return true; } } return false; }
@Override public void putObject(Object key, Object value) { // Cache<String, Object> cache = cacheManager.getCache(this.id); // cache.put(key.toString(), value); Cache<String, Object> cache = cacheManager.getCache(this.id); Map<String, Object> map = new HashMap<String, Object>(); map.put("data", value); // 만료 시간을 설정한 경우 현재시간에 만료시간을 더한 값을 map에 put해준다. Long lifeTime = cache.getCacheConfiguration().expiration().lifespan(); if (-1 != lifeTime) { map.put("lifeTime", lifeTime + System.currentTimeMillis()); map.put("cacheFlag", true); } cache.put(key.toString(), map); if (LOG.isDebugEnabled()) { LOG.debug("Cache Key(putObject) : " + key); LOG.debug("Cache Key(size) : " + getSize()); } }
/** * Extract the BinaryStore out of Modeshape (infinspan, jdbc, file, transient, etc) * * @return */ @Override public Map<String, String> apply(final Repository input) { checkNotNull(input, "null cannot have a BinaryStore!"); final Map<String, String> result = new LinkedHashMap<>(); final BinaryStore store = getBinaryStore.apply(input); if (!(store instanceof InfinispanBinaryStore)) { return result; } final InfinispanBinaryStore ispnStore = (InfinispanBinaryStore) store; final List<Cache<?, ?>> caches = ispnStore.getCaches(); final DefaultCacheManager cm = (DefaultCacheManager) caches.get(0).getCacheManager(); if (cm == null) { LOGGER.debug("Could not get cluster configuration information"); return result; } final int nodeView; if (cm.getTransport() != null) { nodeView = cm.getTransport().getViewId() + 1; } else { nodeView = UNKNOWN_NODE_VIEW; } result.put(CLUSTER_NAME, cm.getClusterName()); result.put( CACHE_MODE, cm.getCache().getCacheConfiguration().clustering().cacheMode().toString()); result.put(NODE_ADDRESS, cm.getNodeAddress()); result.put(PHYSICAL_ADDRESS, cm.getPhysicalAddresses()); result.put(NODE_VIEW, nodeView == UNKNOWN_NODE_VIEW ? "Unknown" : String.valueOf(nodeView)); result.put(CLUSTER_SIZE, String.valueOf(cm.getClusterSize())); result.put(CLUSTER_MEMBERS, cm.getClusterMembers()); return result; }
@Override public Object getObject(Object key) { Cache<String, Object> cache = cacheManager.getCache(this.id); // Object result = cache.get(key.toString()); Map<String, Object> result = (Map<String, Object>) cache.get(key.toString()); Object value = cache.get(key.toString()); if (null != result) { value = result.get("data"); if (checkLt(result, key.toString())) { // 만료시간0.5초 전이라면 cache에 값을 put return null; } } if (LOG.isDebugEnabled()) { LOG.debug("Cache Key(getObject) : " + key); LOG.debug("Cache Key(size) : " + getSize()); // LOG.debug("Cache result : " + result); 결과 값 클 때 디버그 출력하다가 멈춤 } return value; }
@Override public BasicCache getCache(String cacheName) { return dcm.getCache(cacheName); }
@Override public void clear() { // TODO Auto-generated method stub Cache<String, Object> cache = cacheManager.getCache(this.id); cache.clear(); }
@Override protected long getSavedSessionsCount() { return cm.getCache("jbpm-configured-cache").size(); }