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


Java LocalCacheElement类代码示例

本文整理汇总了Java中com.thimbleware.jmemcached.LocalCacheElement的典型用法代码示例。如果您正苦于以下问题:Java LocalCacheElement类的具体用法?Java LocalCacheElement怎么用?Java LocalCacheElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: newQueueInstance

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
public static void newQueueInstance(int port) {
    InetSocketAddress addr = new InetSocketAddress("0.0.0.0", port);
    int idle = -1;
    boolean verbose = false;
    MemCacheDaemon.memcachedVersion = "0.1";
    final MemCacheDaemon<LocalCacheElement> daemon = new MemCacheDaemon<LocalCacheElement>();
    CacheStorage<String, LocalCacheElement> storage = new FSStorage();
    CacheImpl cacheImpl = new CacheImpl(storage);
    daemon.setCache(cacheImpl);
    daemon.setAddr(addr);
    daemon.setBinary(false);
    daemon.setIdleTime(idle);
    daemon.setVerbose(verbose);
    daemon.start();
    log.info("\r\n\t         FQueue instance started,port:" + port
            + " [version 0.1] \r\n\t\t\t Copyright (C) 2011 sunli");
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        public void run() {
            if (daemon != null && daemon.isRunning())
                daemon.stop();
            log.info("shutdown server");
        }
    }));
}
 
开发者ID:sunli1223,项目名称:fqueue,代码行数:25,代码来源:StartNewQueue.java

示例2: startServer

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
public static int startServer() {
    if (daemon == null) {
        System.setProperty("net.spy.log.LoggerImpl", SLF4JLogger.class.getName());

        // Get next free port for the test server
        portForInstance = SocketUtils.findAvailableTcpPort();

        //noinspection NonThreadSafeLazyInitialization
        daemon = new MemCacheDaemon<>();
        CacheStorage<Key, LocalCacheElement> storage = ConcurrentLinkedHashMap.create(ConcurrentLinkedHashMap.EvictionPolicy.FIFO, 1024 * 1024, 1024 * 1024 * 1024);
        daemon.setCache(new CacheImpl(storage));
        daemon.setAddr(new InetSocketAddress(portForInstance));
        daemon.setVerbose(true);
        daemon.start();
    }
    return portForInstance;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:18,代码来源:TestMemcacheServer.java

示例3: remove

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
public final LocalCacheElement remove(Object key) {
    if (!(key instanceof Key)) return null;
    StoredValue val = index.get(key);
    if (val != null) {
        LocalCacheElement el = val.toElement((Key) key);
        lockWrite(val);
        val.free();
        unlockWrite(val);
        el.setData(val.getData());

        index.remove(key);

        return el;
    } else
        return null;
}
 
开发者ID:callan,项目名称:jmemcached,代码行数:17,代码来源:BlockStorageCacheStorage.java

示例4: main

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
public static void main(String[] args) {
       // create daemon and start it
	Logger log = LogManager.getLogger("QuickTest");
	
       MemCacheDaemon daemon = new MemCacheDaemon<LocalCacheElement>();
       CacheStorage<Key, LocalCacheElement> map = ConcurrentLinkedHashMap.create(
       						ConcurrentLinkedHashMap.EvictionPolicy.FIFO, MAX_SIZE, MAX_BYTES);
       
       daemon.setCache(new CacheImpl(map));
       daemon.setBinary(false);
       
       daemon.setAddr(new InetSocketAddress(11211));
       daemon.setVerbose(false);
       
       try {
       	daemon.start();
       } catch (Exception e) {
       	e.printStackTrace();
       	return;
       }

       Cache cache = daemon.getCache();
}
 
开发者ID:callan,项目名称:jmemcached,代码行数:24,代码来源:QuickTest.java

示例5: start

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
public void start(final String host, final int port) {
    logger.debug("Starting memcache...");

    final CountDownLatch startupLatch = new CountDownLatch(1);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.execute(new Runnable() {
        @Override
        public void run() {
            CacheStorage<Key, LocalCacheElement> storage = ConcurrentLinkedHashMap.create(ConcurrentLinkedHashMap
                    .EvictionPolicy.FIFO, DEFAULT_STORAGE_CAPACITY, DEFAULT_STORAGE_MEMORY_CAPACITY);
            memcacheDaemon = new MemCacheDaemon<>();
            memcacheDaemon.setCache(new CacheImpl(storage));
            memcacheDaemon.setAddr(new InetSocketAddress(host, port));
            memcacheDaemon.start();
            startupLatch.countDown();
        }
    });
    try {
        if (!startupLatch.await(DEFAULT_STARTUP_TIMEOUT, MILLISECONDS)) {
            logger.error("Memcache daemon did not start after {}ms. Consider increasing the timeout", MILLISECONDS);
            throw new AssertionError("Memcache daemon did not start within timeout");
        }
    } catch (InterruptedException e) {
        logger.error("Interrupted waiting for Memcache daemon to start:", e);
        throw new AssertionError(e);
    }
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:28,代码来源:JMemcachedServer.java

示例6: putIfAbsent

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
public final LocalCacheElement putIfAbsent(Key key, LocalCacheElement item) {
    Partition partition = pickPartition(key);

    partition.storageLock.readLock().lock();
    try {
        Region region = partition.find(key);

        // not there? add it
        if (region == null) {
            partition.storageLock.readLock().unlock();
            partition.storageLock.writeLock().lock();
            try {
                numberItems++;
                partition.add(key, item);
            } finally {
                partition.storageLock.readLock().lock();
                partition.storageLock.writeLock().unlock();
            }

            return null;
        } else {
            // there? return its value
            return region.toValue();
        }
    } finally {
        partition.storageLock.readLock().unlock();
    }
}
 
开发者ID:rdaum,项目名称:jmemcache-daemon,代码行数:29,代码来源:BlockStorageCacheStorage.java

示例7: remove

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public final boolean remove(Object okey, Object value) {
    if (!(okey instanceof Key) || (!(value instanceof LocalCacheElement))) return false;

    Key key = (Key) okey;
    Partition partition = pickPartition(key);


    try {
        partition.storageLock.readLock().lock();
        Region region = partition.find(key);
        if (region == null) return false;
        else {
            partition.storageLock.readLock().unlock();
            partition.storageLock.writeLock().lock();
            try {
                partition.blockStore.free(region);
                partition.remove(key, region);
                numberItems++;
                return true;
            } finally {
                partition.storageLock.readLock().lock();
                partition.storageLock.writeLock().unlock();
            }

        }
    } finally {
        partition.storageLock.readLock().unlock();
    }
}
 
开发者ID:rdaum,项目名称:jmemcache-daemon,代码行数:33,代码来源:BlockStorageCacheStorage.java

示例8: get

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
public final LocalCacheElement get(Object okey) {
    if (!(okey instanceof Key)) return null;

    Key key = (Key) okey;
    Partition partition = pickPartition(key);

    try {
        partition.storageLock.readLock().lock();
        Region region = partition.find(key);
        if (region == null) return null;
        return region.toValue();
    } finally {
        partition.storageLock.readLock().unlock();
    }
}
 
开发者ID:rdaum,项目名称:jmemcache-daemon,代码行数:16,代码来源:BlockStorageCacheStorage.java

示例9: put

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
public final LocalCacheElement put(final Key key, final LocalCacheElement item) {
    Partition partition = pickPartition(key);

    partition.storageLock.readLock().lock();
    try {
        Region region = partition.find(key);

        partition.storageLock.readLock().unlock();
        partition.storageLock.writeLock().lock();
        try {
            LocalCacheElement old = null;
            if (region != null) {
                old = region.toValue();
            }
            if (region != null) partition.remove(key, region);
            partition.add(key, item);
            numberItems++;
            return old;
        } finally {
            partition.storageLock.readLock().lock();
            partition.storageLock.writeLock().unlock();
        }


    } finally {
        partition.storageLock.readLock().unlock();
    }
}
 
开发者ID:rdaum,项目名称:jmemcache-daemon,代码行数:29,代码来源:BlockStorageCacheStorage.java

示例10: putAll

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
public final void putAll(Map<? extends Key, ? extends LocalCacheElement> map) {
    // absent, lock the store and put the new value in
    for (Entry<? extends Key, ? extends LocalCacheElement> entry : map.entrySet()) {
        Key key = entry.getKey();
        LocalCacheElement item;
        item = entry.getValue();
        put(key, item);
    }
}
 
开发者ID:rdaum,项目名称:jmemcache-daemon,代码行数:10,代码来源:BlockStorageCacheStorage.java

示例11: add

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
public Region add(Key key, LocalCacheElement e) {
    Region region = blockStore.alloc(e.bufferSize(), e.getExpire(), System.currentTimeMillis());
    e.writeToBuffer(region.slice);
    int bucket = findBucketNum(key);

    ChannelBuffer outbuf = ChannelBuffers.directBuffer(32 + key.bytes.capacity());
    outbuf.writeInt(region.size);
    outbuf.writeInt(region.usedBlocks);
    outbuf.writeInt(region.startBlock);
    outbuf.writeLong(region.expiry);
    outbuf.writeLong(region.timestamp);
    outbuf.writeInt(key.bytes.capacity());
    key.bytes.readerIndex(0);
    outbuf.writeBytes(key.bytes);

    ChannelBuffer regions = buckets[bucket];
    if (regions == null) {
        regions = ChannelBuffers.dynamicBuffer(128);
        buckets[bucket] = regions;
    }

    regions.writeInt(outbuf.capacity());
    regions.writeBytes(outbuf);

    numberItems++;

    return region;
}
 
开发者ID:rdaum,项目名称:jmemcache-daemon,代码行数:29,代码来源:Partition.java

示例12: get

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
@Override
public LocalCacheElement get(String keystring) {
    try {
        if (keystring.indexOf("_") == -1) {
            return getProtocol(keystring);
        }
        String[] clientInfo = QueueClient.parseWithCache(keystring);
        if (valid(clientInfo[0], clientInfo[1])) {
            byte[] data;
            data = getClientQueue(clientInfo[0]).poll();
            if (data != null) {
                LocalCacheElement element = new LocalCacheElement(keystring, 0, 0, 0);
                element.setData(data);
                return element;
            } else {
                log.info("queue empty");
            }
        } else {
            log.error("unvalid " + keystring);
            throw new ClientException("Authorization error");
        }
    } catch (Exception e) {
        log.error("get queue " + keystring + " error", e);
        return null;
    }
    return null;
}
 
开发者ID:sunli1223,项目名称:fqueue,代码行数:28,代码来源:FSStorage.java

示例13: put

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
@Override
public LocalCacheElement put(String keystring, LocalCacheElement e) throws DatabaseException, Exception {
    String[] clientInfo = QueueClient.parseWithCache(keystring);
    if (valid(clientInfo[0], clientInfo[1])) {// 先进行密码验证
        getClientQueue(clientInfo[0]).add(e.getData());
        return null;
    } else {
        throw new ClientException("Authorization error");
    }
}
 
开发者ID:sunli1223,项目名称:fqueue,代码行数:11,代码来源:FSStorage.java

示例14: putIfAbsent

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
@Override
public LocalCacheElement putIfAbsent(String keystring, LocalCacheElement e) throws DatabaseException, Exception {
    String[] clientInfo = QueueClient.parseWithCache(keystring);
    if (valid(clientInfo[0], clientInfo[1])) {// 先进行密码验证
        getClientQueue(clientInfo[0]).add(e.getData());
        return null;
    } else {
        throw new ClientException("Authorization error");
    }

}
 
开发者ID:sunli1223,项目名称:fqueue,代码行数:12,代码来源:FSStorage.java

示例15: setup

import com.thimbleware.jmemcached.LocalCacheElement; //导入依赖的package包/类
@Before
public void setup() throws InterruptedException {

    // create daemon and start it
    final CacheStorage<Key, LocalCacheElement> storage = ConcurrentLinkedHashMap
            .create(ConcurrentLinkedHashMap.EvictionPolicy.FIFO, 10000,
                    10000);
    daemon.setCache(new CacheImpl(storage));
    daemon.setBinary(true);
    daemon.setAddr(new InetSocketAddress(11242));
    daemon.setIdleTime(1000);
    daemon.setVerbose(true);
    daemon.start();
}
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:15,代码来源:MemcacheRestCacheTest.java


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