Package org.iq80.leveldb

Examples of org.iq80.leveldb.DBFactory


    try {
      return iter.prev();
    } catch (DBException e) {
      throw e;
    } catch (RuntimeException e) {
      throw new DBException(e.getMessage(), e);
    }
  }
View Full Code Here


    try {
      return iter.peekPrev();
    } catch (DBException e) {
      throw e;
    } catch (RuntimeException e) {
      throw new DBException(e.getMessage(), e);
    }
  }
View Full Code Here

    try {
      iter.remove();
    } catch (DBException e) {
      throw e;
    } catch (RuntimeException e) {
      throw new DBException(e.getMessage(), e);
    }
  }
View Full Code Here

        configuration.refresh();
        LevelDBEntityStoreConfiguration config = configuration.get();

        // Choose flavour
        String flavour = config.flavour().get();
        DBFactory factory;
        if( "jni".equalsIgnoreCase( flavour ) )
        {
            factory = newJniDBFactory();
        }
        else if( "java".equalsIgnoreCase( flavour ) )
        {
            factory = newJavaDBFactory();
        }
        else
        {
            factory = newDBFactory();
        }

        // Apply configuration
        Options options = new Options();
        options.createIfMissing( true );
        if( config.blockRestartInterval().get() != null )
        {
            options.blockRestartInterval( config.blockRestartInterval().get() );
        }
        if( config.blockSize().get() != null )
        {
            options.blockSize( config.blockSize().get() );
        }
        if( config.cacheSize().get() != null )
        {
            options.cacheSize( config.cacheSize().get() );
        }
        if( config.compression().get() != null )
        {
            options.compressionType( config.compression().get()
                                     ? CompressionType.SNAPPY
                                     : CompressionType.NONE );
        }
        if( config.maxOpenFiles().get() != null )
        {
            options.maxOpenFiles( config.maxOpenFiles().get() );
        }
        if( config.paranoidChecks().get() != null )
        {
            options.paranoidChecks( config.paranoidChecks().get() );
        }
        if( config.verifyChecksums().get() != null )
        {
            options.verifyChecksums( config.verifyChecksums().get() );
        }
        if( config.writeBufferSize().get() != null )
        {
            options.writeBufferSize( config.writeBufferSize().get() );
        }

        // Open/Create the database
        File dbFile = new File( fileConfig.dataDirectory(), descriptor.identity() );
        db = factory.open( dbFile, options );
    }
View Full Code Here

    }

    private DB openDatabase(String aDirectoryPath) {

        try {
            DBFactory factory = new Iq80DBFactory();

            Options options = new Options();

            options.createIfMissing(true);

            DB db = factory.open(new File(aDirectoryPath), options);

            return db;

        } catch (Throwable t) {
            throw new IllegalStateException(
View Full Code Here

    private void openDatabase(String aDirectoryPath) {

        try {
            this.setDatabasePath(aDirectoryPath);

            DBFactory factory = new Iq80DBFactory();

            Options options = new Options();

            options.createIfMissing(true);

            this.setDatabase(factory.open(new File(aDirectoryPath), options));

            if (!this.cacheJournalSequence()) {
                this.repair();
            }
View Full Code Here

    private final DBFactory iq80factory = Iq80DBFactory.factory;
    private final DBFactory jnifactory;

    public NativeInteropTest()
    {
        DBFactory jnifactory = Iq80DBFactory.factory;
        try {
            ClassLoader cl = NativeInteropTest.class.getClassLoader();
            jnifactory = (DBFactory) cl.loadClass("org.fusesource.leveldbjni.JniDBFactory").newInstance();
        }
        catch (Throwable e) {
View Full Code Here

      }
      try {
         if (stopped) {
            throw new PersistenceException("LevelDB is stopped");
         }
         DBIterator it = db.iterator(new ReadOptions().fillCache(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

      }
      try {
         if (stopped) {
            throw new PersistenceException("LevelDB is stopped");
         }
         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, loadValues, loadMetadata);
               }
            }
            if (!entries.isEmpty()) {
               submitProcessTask(cacheLoaderTask, keyFilter, eacs, taskContext, entries, loadValues, loadMetadata);
            }

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

            }
         }

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

               Long time = (Long) unmarshall(entry.getKey());
               if (time > now)
                  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;
            for (Object key : keys) {
               byte[] keyBytes = marshall(key);

               byte[] b = db.get(keyBytes);
               if (b == null)
                  continue;
               MarshalledEntry me = (MarshalledEntry) ctx.getMarshaller().objectFromByteBuffer(b);
               // TODO race condition: the entry could be updated between the get and delete!
               if (me.getMetadata() != null && me.getMetadata().isExpired(now)) {
                  // somewhat inefficient to FIND then REMOVE...
                  db.delete(keyBytes);
                  purgeListener.entryPurged(key);
                  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

TOP

Related Classes of org.iq80.leveldb.DBFactory

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.