当前位置: 首页>>代码示例>>Java>>正文


Java UtilCache.removeListener方法代码示例

本文整理汇总了Java中org.ofbiz.base.util.cache.UtilCache.removeListener方法的典型用法代码示例。如果您正苦于以下问题:Java UtilCache.removeListener方法的具体用法?Java UtilCache.removeListener怎么用?Java UtilCache.removeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ofbiz.base.util.cache.UtilCache的用法示例。


在下文中一共展示了UtilCache.removeListener方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPutIfAbsentAndGet

import org.ofbiz.base.util.cache.UtilCache; //导入方法依赖的package包/类
public void testPutIfAbsentAndGet() throws Exception {
    UtilCache<String, String> cache = createUtilCache(5, 5, 2000, false, false);
    Listener<String, String> gotListener = createListener(cache);
    Listener<String, String> wantedListener = new Listener<String, String>();
    wantedListener.noteKeyAddition(cache, "key", "value");
    wantedListener.noteKeyAddition(cache, "anotherKey", "anotherValue");
    assertNull("no-get", cache.get("key"));
    assertEquals("putIfAbsentAndGet", "value", cache.putIfAbsentAndGet("key", "value"));
    assertHasSingleKey(cache, "key", "value");
    assertEquals("putIfAbsentAndGet", "value", cache.putIfAbsentAndGet("key", "newValue"));
    assertHasSingleKey(cache, "key", "value");
    String anotherValueAddedToCache = new String("anotherValue");
    String anotherValueNotAddedToCache = new String("anotherValue");
    assertEquals(anotherValueAddedToCache, anotherValueNotAddedToCache);
    assertNotSame(anotherValueAddedToCache, anotherValueNotAddedToCache);
    String cachedValue = cache.putIfAbsentAndGet("anotherKey", anotherValueAddedToCache);
    assertSame(cachedValue, anotherValueAddedToCache);
    cachedValue = cache.putIfAbsentAndGet("anotherKey", anotherValueNotAddedToCache);
    assertNotSame(cachedValue, anotherValueNotAddedToCache);
    assertSame(cachedValue, anotherValueAddedToCache);
    cache.removeListener(gotListener);
    assertEquals("listener", wantedListener, gotListener);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:24,代码来源:UtilCacheTests.java

示例2: testPutIfAbsent

import org.ofbiz.base.util.cache.UtilCache; //导入方法依赖的package包/类
public void testPutIfAbsent() throws Exception {
    UtilCache<String, String> cache = createUtilCache(5, 5, 2000, false, false);
    Listener<String, String> gotListener = createListener(cache);
    Listener<String, String> wantedListener = new Listener<String, String>();
    wantedListener.noteKeyAddition(cache, "two", "dos");
    assertNull("putIfAbsent", cache.putIfAbsent("two", "dos"));
    assertHasSingleKey(cache, "two", "dos");
    assertEquals("putIfAbsent", "dos", cache.putIfAbsent("two", "double"));
    assertHasSingleKey(cache, "two", "dos");
    cache.removeListener(gotListener);
    assertEquals("listener", wantedListener, gotListener);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:13,代码来源:UtilCacheTests.java

示例3: basicTest

import org.ofbiz.base.util.cache.UtilCache; //导入方法依赖的package包/类
private static void basicTest(UtilCache<String, String> cache) throws Exception {
    Listener<String, String> gotListener = createListener(cache);
    Listener<String, String> wantedListener = new Listener<String, String>();
    for (int i = 0; i < 2; i++) {
        assertTrue("UtilCacheTable.keySet", UtilCache.getUtilCacheTableKeySet().contains(cache.getName()));
        assertSame("UtilCache.findCache", cache, UtilCache.findCache(cache.getName()));
        assertSame("UtilCache.getOrCreateUtilCache", cache, UtilCache.getOrCreateUtilCache(cache.getName(), cache.getSizeLimit(), cache.getMaxInMemory(), cache.getExpireTime(), cache.getUseSoftReference(), cache.getUseFileSystemStore()));

        assertNoSingleKey(cache, "one");
        long origByteSize = cache.getSizeInBytes();

        wantedListener.noteKeyAddition(cache, null, "null");
        assertNull("put", cache.put(null, "null"));
        assertHasSingleKey(cache, null, "null");
        long nullByteSize = cache.getSizeInBytes();
        assertThat(nullByteSize, greaterThan(origByteSize));

        wantedListener.noteKeyRemoval(cache, null, "null");
        assertEquals("remove", "null", cache.remove(null));
        assertNoSingleKey(cache, null);

        wantedListener.noteKeyAddition(cache, "one", "uno");
        assertNull("put", cache.put("one", "uno"));
        assertHasSingleKey(cache, "one", "uno");
        long unoByteSize = cache.getSizeInBytes();
        assertThat(unoByteSize, greaterThan(origByteSize));

        wantedListener.noteKeyUpdate(cache, "one", "single", "uno");
        assertEquals("replace", "uno", cache.put("one", "single"));
        assertHasSingleKey(cache, "one", "single");
        long singleByteSize = cache.getSizeInBytes();
        assertThat(singleByteSize, greaterThan(origByteSize));
        assertThat(singleByteSize, greaterThan(unoByteSize));

        wantedListener.noteKeyRemoval(cache, "one", "single");
        assertEquals("remove", "single", cache.remove("one"));
        assertNoSingleKey(cache, "one");
        assertEquals("byteSize", origByteSize, cache.getSizeInBytes());

        wantedListener.noteKeyAddition(cache, "one", "uno");
        assertNull("put", cache.put("one", "uno"));
        assertHasSingleKey(cache, "one", "uno");

        wantedListener.noteKeyUpdate(cache, "one", "only", "uno");
        assertEquals("replace", "uno", cache.put("one", "only"));
        assertHasSingleKey(cache, "one", "only");

        wantedListener.noteKeyRemoval(cache, "one", "only");
        cache.erase();
        assertNoSingleKey(cache, "one");
        assertEquals("byteSize", origByteSize, cache.getSizeInBytes());

        cache.setExpireTime(100);
        wantedListener.noteKeyAddition(cache, "one", "uno");
        assertNull("put", cache.put("one", "uno"));
        assertHasSingleKey(cache, "one", "uno");

        wantedListener.noteKeyRemoval(cache, "one", "uno");
        Thread.sleep(200);
        assertNoSingleKey(cache, "one");
    }

    assertEquals("get-miss", 10, cache.getMissCountNotFound());
    assertEquals("get-miss-total", 10, cache.getMissCountTotal());
    assertEquals("get-hit", 12, cache.getHitCount());
    assertEquals("remove-hit", 6, cache.getRemoveHitCount());
    assertEquals("remove-miss", 10, cache.getRemoveMissCount());
    cache.removeListener(gotListener);
    assertEquals("listener", wantedListener, gotListener);
    UtilCache.clearCache(cache.getName());
    UtilCache.clearCache(":::" + cache.getName());
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:73,代码来源:UtilCacheTests.java


注:本文中的org.ofbiz.base.util.cache.UtilCache.removeListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。