本文整理汇总了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");
}
}));
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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");
}
}
示例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");
}
}
示例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();
}