use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class ConcurrentTests3 method get.
private void get(String key) {
Pointer p = map.get(key);
read.incrementAndGet();
if (p != null) {
got.incrementAndGet();
byte[] payload = MemoryManager.retrieve(p);
if ((new String(payload)).startsWith(key))
good.incrementAndGet();
else
bad.incrementAndGet();
} else {
missed.incrementAndGet();
}
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class MemoryManagerTests method fillupTest.
@Test
public void fillupTest() {
MemoryManager.clear();
logger.info("payload size=" + Ram.inKb(payload.length));
long howMany = (MemoryManager.capacity() / payload.length);
howMany = (howMany * 90) / 100;
for (int i = 0; i < howMany; i++) {
Pointer p = MemoryManager.store(payload);
assertNotNull(p);
}
logger.info("" + howMany + " items stored");
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class Cache method put.
public static Pointer put(String key, Object object, int expiresIn) {
try {
byte[] payload = serializer.serialize(object, object.getClass());
Pointer ptr = putByteArray(key, payload);
ptr.clazz = object.getClass();
return ptr;
} catch (IOException e) {
logger.error(e.getMessage());
return null;
}
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class Cache method update.
public static Pointer update(String key, Object object) {
Pointer p = map.get(key);
try {
p = MemoryManager.update(p, serializer.serialize(object, object.getClass()));
p.clazz = object.getClass();
return p;
} catch (IOException e) {
logger.error(e.getMessage());
return null;
}
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class BaseTests method smokeTest.
@Test
public void smokeTest() {
OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(1 * 1024 * 1024);
logger.info("buffer size=" + mem.capacity());
assertNotNull(mem);
Random rnd = new Random();
int size = rnd.nextInt(10) * mem.capacity() / 100;
logger.info("size=" + size);
Pointer p = mem.store(new byte[size]);
assertNotNull(p);
assertEquals(size, p.end);
assertEquals(size, mem.used());
mem.free(p);
assertEquals(0, mem.used());
}
Aggregations