Package org.directmemory.memory

Examples of org.directmemory.memory.Pointer


  }
 
  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;
View Full Code Here


    logger.info("payload size=" + Ram.inKb(size));
    logger.info("entries=" + howMany);
    String test = "this is a nicely crafted test";
    byte[] payload = test.getBytes();
    for (int i = 0; i < howMany; i++) {
      Pointer p = mem.store(payload);
      byte[] check = mem.retrieve(p);
      assertNotNull(check);
      assertEquals(test, new String(check));
    }
   
View Full Code Here

      return null;
    }
  }
 
  public static Pointer updateByteArray(String key, byte[] payload) {
    Pointer p = map.get(key);
    p = MemoryManager.update(p, payload);
      return p;
  }
View Full Code Here

    p = MemoryManager.update(p, payload);
      return p;
  }
 
  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) {
View Full Code Here

      return null;
    }
  }
 
  public static byte[] retrieveByteArray(String key) {
    Pointer ptr = getPointer(key);
    if (ptr == null) return null;
    if (ptr.expired() || ptr.free) {
      map.remove(key);
      if (!ptr.free) {
        MemoryManager.free(ptr);
      }
      return null;
View Full Code Here

        return MemoryManager.retrieve(ptr);
    }
  }
 
  public static Object retrieve(String key) {
    Pointer ptr = getPointer(key);
    if (ptr == null) return null;
    if (ptr.expired() || ptr.free) {
      map.remove(key);
      if (!ptr.free) {
        MemoryManager.free(ptr);
      }
      return null;
View Full Code Here

  public static Pointer getPointer(String key) {
      return map.get(key);
  }
 
  public static void free(String key) {
    Pointer p = map.remove(key);
    if (p != null) {
      MemoryManager.free(p);
    }
  }
View Full Code Here

  public void LFUEviction() throws QueryParseException, QueryExecutionException {
    Cache.collectAll();
  }
 
  private void getAndRetrieve(String key) {
      Pointer p = Cache.getPointer(key);
      @SuppressWarnings("unused")
    byte [] check = Cache.retrieveByteArray(key);
    read.incrementAndGet();
      if (p != null) {
        got.incrementAndGet();
View Full Code Here

      String key = "test-" + (rndGen.nextInt(entries*2)+1);
      get(key);
    }
 
  private void get(String key) {
      Pointer p = Cache.getPointer(key);
      @SuppressWarnings("unused")
    byte [] check = Cache.retrieveByteArray(key);
    read.incrementAndGet();
      if (p != null) {
        got.incrementAndGet();
View Full Code Here

   
    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());   
View Full Code Here

TOP

Related Classes of org.directmemory.memory.Pointer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.