Package org.iq80.leveldb

Examples of org.iq80.leveldb.DBIterator


  @Override
  protected Set<Object> loadAllKeysLockSafe(Set<Object> keysToExclude)
      throws CacheLoaderException {
    Set<Object> keys = new HashSet<Object>();

    DBIterator it = db.iterator(new ReadOptions().fillCache(false));
    try {
      for (it.seekToFirst(); it.hasNext();) {
        Map.Entry<byte[], byte[]> entry = it.next();
        Object key = unmarshall(entry.getKey());
        if (keysToExclude == null || keysToExclude.isEmpty()
            || !keysToExclude.contains(key))
          keys.add(key);
      }

      return keys;
    } catch (Exception e) {
      throw new CacheLoaderException(e);
    } finally {
      try {
            it.close();
         } catch (IOException e) {
            log.warnUnableToCloseDbIterator(e);
         }
    }
  }
View Full Code Here


  }

  @Override
  protected void toStreamLockSafe(ObjectOutput oos)
      throws CacheLoaderException {
    DBIterator it = db.iterator(new ReadOptions().fillCache(false));
    try {

      for (it.seekToFirst(); it.hasNext();) {
        Map.Entry<byte[], byte[]> entry = it.next();
        InternalCacheEntry ice = unmarshall(entry);
        getMarshaller().objectToObjectStream(ice, oos);
      }
      getMarshaller().objectToObjectStream(null, oos);
    } catch (Exception e) {
      throw new CacheLoaderException(e);
    } finally {
      try {
            it.close();
         } catch (IOException e) {
            log.warnUnableToCloseDbIterator(e);
         }
    }
  }
View Full Code Here

        }
      }

      List<Long> times = new ArrayList<Long>();
      List<Object> keys = new ArrayList<Object>();
      DBIterator it = expiredDb.iterator(new ReadOptions()
          .fillCache(false));
      try {
        for (it.seekToFirst(); it.hasNext();) {
          Map.Entry<byte[], byte[]> entry = it.next();

          Long time = (Long) unmarshall(entry.getKey());
          if (time > System.currentTimeMillis())
            break;
          times.add(time);
          Object key = unmarshall(entry.getValue());
          if (key instanceof List)
            keys.addAll((List<?>) key);
          else
            keys.add(key);
        }

        for (Long time : times) {
          expiredDb.delete(marshall(time));
        }

        if (!keys.isEmpty())
          log.debugf("purge (up to) %d entries", keys.size());
        int count = 0;
        long currentTimeMillis = System.currentTimeMillis();
        for (Object key : keys) {
          byte[] keyBytes = marshall(key);
         
          byte[] b = db.get(keyBytes);
          if (b == null)
            continue;
          InternalCacheValue ice = (InternalCacheValue) getMarshaller()
              .objectFromByteBuffer(b);
          if (ice.isExpired(currentTimeMillis)) {
            // somewhat inefficient to FIND then REMOVE...
            db.delete(keyBytes);
            count++;
          }
        }
        if (count != 0)
          log.debugf("purged %d entries", count);
      } catch (Exception e) {
        throw new CacheLoaderException(e);
      } finally {
         try {
            it.close();
         } catch (IOException e) {
            log.warnUnableToCloseDbIterator(e);
         }
      }
    } catch (Exception e) {
View Full Code Here

   }

   @Override
   public void clear() {
      long count = 0;
      DBIterator it = db.iterator(new ReadOptions().fillCache(false));
      boolean destroyDatabase = false;

      if (configuration.clearThreshold() <= 0) {
         try {
            for (it.seekToFirst(); it.hasNext();) {
               Map.Entry<byte[], byte[]> entry = it.next();
               db.delete(entry.getKey());
               count++;

               if (count > configuration.clearThreshold()) {
                  destroyDatabase = true;
                  break;
               }
            }
         } finally {
            try {
               it.close();
            } catch (IOException e) {
               log.warnUnableToCloseDbIterator(e);
            }
         }
      } else {
View Full Code Here

      ExecutorCompletionService ecs = new ExecutorCompletionService(executor);
      int tasks = 0;
      final TaskContext taskContext = new TaskContextImpl();

      List<Map.Entry<byte[], byte[]>> entries = new ArrayList<Map.Entry<byte[], byte[]>>(batchSize);
      DBIterator it = db.iterator(new ReadOptions().fillCache(false));
      try {
         for (it.seekToFirst(); it.hasNext();) {
            Map.Entry<byte[], byte[]> entry = it.next();
            entries.add(entry);
            if (entries.size() == batchSize) {
               final List<Map.Entry<byte[], byte[]>> batch = entries;
               entries = new ArrayList<Map.Entry<byte[], byte[]>>(batchSize);
               submitProcessTask(cacheLoaderTask, keyFilter,ecs, taskContext, batch);
               tasks++;
            }
         }
         if (!entries.isEmpty()) {
            submitProcessTask(cacheLoaderTask, keyFilter,ecs, taskContext, entries);
            tasks++;
         }

         PersistenceUtil.waitForAllTasksToComplete(ecs, tasks);
      } catch (Exception e) {
         throw new CacheLoaderException(e);
      } finally {
         try {
            it.close();
         } catch (IOException e) {
            log.warnUnableToCloseDbIterator(e);
         }
      }
   }
View Full Code Here

            }
         }

         List<Long> times = new ArrayList<Long>();
         List<Object> keys = new ArrayList<Object>();
         DBIterator it = expiredDb.iterator(new ReadOptions().fillCache(false));
         try {
            for (it.seekToFirst(); it.hasNext();) {
               Map.Entry<byte[], byte[]> entry = it.next();

               Long time = (Long) unmarshall(entry.getKey());
               if (time > System.currentTimeMillis())
                  break;
               times.add(time);
               Object key = unmarshall(entry.getValue());
               if (key instanceof List)
                  keys.addAll((List<?>) key);
               else
                  keys.add(key);
            }

            for (Long time : times) {
               expiredDb.delete(marshall(time));
            }

            if (!keys.isEmpty())
               log.debugf("purge (up to) %d entries", keys.size());
            int count = 0;
            long currentTimeMillis = System.currentTimeMillis();
            for (Object key : keys) {
               byte[] keyBytes = marshall(key);

               byte[] b = db.get(keyBytes);
               if (b == null)
                  continue;
               MarshalledEntry me = (MarshalledEntry) ctx.getMarshaller().objectFromByteBuffer(b);
               if (me.getMetadata() != null && me.getMetadata().isExpired(ctx.getTimeService().wallClockTime())) {
                  // somewhat inefficient to FIND then REMOVE...
                  db.delete(keyBytes);
                  count++;
               }
            }
            if (count != 0)
               log.debugf("purged %d entries", count);
         } catch (Exception e) {
            throw new CacheLoaderException(e);
         } finally {
            try {
               it.close();
            } catch (IOException e) {
               log.warnUnableToCloseDbIterator(e);
            }
         }
      } catch (CacheLoaderException e) {
View Full Code Here

   }

   @Override
   public void clear() {
      long count = 0;
      DBIterator it = db.iterator(new ReadOptions().fillCache(false));
      boolean destroyDatabase = false;

      if (configuration.clearThreshold() <= 0) {
         try {
            for (it.seekToFirst(); it.hasNext();) {
               Map.Entry<byte[], byte[]> entry = it.next();
               db.delete(entry.getKey());
               count++;

               if (count > configuration.clearThreshold()) {
                  destroyDatabase = true;
                  break;
               }
            }
         } finally {
            try {
               it.close();
            } catch (IOException e) {
               log.warnUnableToCloseDbIterator(e);
            }
         }
      } else {
View Full Code Here

      int batchSize = 100;
      ExecutorAllCompletionService eacs = new ExecutorAllCompletionService(executor);
      final TaskContext taskContext = new TaskContextImpl();

      List<Map.Entry<byte[], byte[]>> entries = new ArrayList<Map.Entry<byte[], byte[]>>(batchSize);
      DBIterator it = db.iterator(new ReadOptions().fillCache(false));
      try {
         for (it.seekToFirst(); it.hasNext();) {
            Map.Entry<byte[], byte[]> entry = it.next();
            entries.add(entry);
            if (entries.size() == batchSize) {
               final List<Map.Entry<byte[], byte[]>> batch = entries;
               entries = new ArrayList<Map.Entry<byte[], byte[]>>(batchSize);
               submitProcessTask(cacheLoaderTask, keyFilter,eacs, taskContext, batch);
            }
         }
         if (!entries.isEmpty()) {
            submitProcessTask(cacheLoaderTask, keyFilter,eacs, taskContext, entries);
         }

         eacs.waitUntilAllCompleted();
         if (eacs.isExceptionThrown()) {
            throw new PersistenceException("Execution exception!", eacs.getFirstException());
         }
      } catch (Exception e) {
         throw new PersistenceException(e);
      } finally {
         try {
            it.close();
         } catch (IOException e) {
            log.warnUnableToCloseDbIterator(e);
         }
      }
   }
View Full Code Here

            }
         }

         List<Long> times = new ArrayList<Long>();
         List<Object> keys = new ArrayList<Object>();
         DBIterator it = expiredDb.iterator(new ReadOptions().fillCache(false));
         try {
            for (it.seekToFirst(); it.hasNext();) {
               Map.Entry<byte[], byte[]> entry = it.next();

               Long time = (Long) unmarshall(entry.getKey());
               if (time > System.currentTimeMillis())
                  break;
               times.add(time);
               Object key = unmarshall(entry.getValue());
               if (key instanceof List)
                  keys.addAll((List<?>) key);
               else
                  keys.add(key);
            }

            for (Long time : times) {
               expiredDb.delete(marshall(time));
            }

            if (!keys.isEmpty())
               log.debugf("purge (up to) %d entries", keys.size());
            int count = 0;
            long currentTimeMillis = System.currentTimeMillis();
            for (Object key : keys) {
               byte[] keyBytes = marshall(key);

               byte[] b = db.get(keyBytes);
               if (b == null)
                  continue;
               MarshalledEntry me = (MarshalledEntry) ctx.getMarshaller().objectFromByteBuffer(b);
               if (me.getMetadata() != null && me.getMetadata().isExpired(ctx.getTimeService().wallClockTime())) {
                  // somewhat inefficient to FIND then REMOVE...
                  db.delete(keyBytes);
                  count++;
               }
            }
            if (count != 0)
               log.debugf("purged %d entries", count);
         } catch (Exception e) {
            throw new PersistenceException(e);
         } finally {
            try {
               it.close();
            } catch (IOException e) {
               log.warnUnableToCloseDbIterator(e);
            }
         }
      } catch (PersistenceException e) {
View Full Code Here

    new Thread(){
     
      @Override
      public void run(){
                Repository repository = UIEthereumManager.ethereum.getRepository();
        DBIterator i = repository.getAccountsIterator();
        while(i.hasNext()) {
          DataClass dc = new DataClass();
          dc.address = i.next().getKey();
         
          AccountState state = repository.getAccountState(dc.address);
          dc.accountState = state;
         
          adapter.addDataPiece(dc);
View Full Code Here

TOP

Related Classes of org.iq80.leveldb.DBIterator

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.