本文整理汇总了Java中org.iq80.leveldb.Options类的典型用法代码示例。如果您正苦于以下问题:Java Options类的具体用法?Java Options怎么用?Java Options使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Options类属于org.iq80.leveldb包,在下文中一共展示了Options类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startInternal
import org.iq80.leveldb.Options; //导入依赖的package包/类
@Override
protected void startInternal() throws Exception {
Path storeRoot = createStorageDir();
Options options = new Options();
options.createIfMissing(false);
options.logger(new LeveldbLogger());
LOG.info("Using state database at " + storeRoot + " for recovery");
File dbfile = new File(storeRoot.toString());
try {
db = JniDBFactory.factory.open(dbfile, options);
} catch (NativeDB.DBException e) {
if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
LOG.info("Creating state database at " + dbfile);
options.createIfMissing(true);
try {
db = JniDBFactory.factory.open(dbfile, options);
// store version
storeVersion();
} catch (DBException dbErr) {
throw new IOException(dbErr.getMessage(), dbErr);
}
} else {
throw e;
}
}
}
示例2: createCachePool
import org.iq80.leveldb.Options; //导入依赖的package包/类
@Override
public CachePool createCachePool(String poolName, int cacheSize,
int expireSeconds) {
Options options = new Options();
options.cacheSize(cacheSize * 1048576);//cacheSize M 大小
options.createIfMissing(true);
DB db =null;
try {
db=factory.open(new File("leveldb\\"+poolName), options);
// Use the db in here....
} catch (Exception e) {
// Make sure you close the db to shutdown the
// database and avoid resource leaks.
// db.close();
}
return new LevelDBPool(poolName,db,cacheSize);
}
示例3: startStore
import org.iq80.leveldb.Options; //导入依赖的package包/类
private void startStore(Path recoveryRoot) throws IOException {
Options options = new Options();
options.createIfMissing(false);
options.logger(new LevelDBLogger());
Path dbPath = new Path(recoveryRoot, STATE_DB_NAME);
LOG.info("Using state database at " + dbPath + " for recovery");
File dbfile = new File(dbPath.toString());
try {
stateDb = JniDBFactory.factory.open(dbfile, options);
} catch (NativeDB.DBException e) {
if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
LOG.info("Creating state database at " + dbfile);
options.createIfMissing(true);
try {
stateDb = JniDBFactory.factory.open(dbfile, options);
storeVersion();
} catch (DBException dbExc) {
throw new IOException("Unable to create state store", dbExc);
}
} else {
throw e;
}
}
checkVersion();
}
示例4: createCachePool
import org.iq80.leveldb.Options; //导入依赖的package包/类
@Override
public CachePool createCachePool(String poolName, int cacheSize,
int expireSeconds) {
Options options = new Options();
options.cacheSize(1048576L * cacheSize); //cacheSize M
options.createIfMissing(true);
DB db = null;
String filePath = "leveldb\\" + poolName;
try {
db = factory.open(new File(filePath), options);
// Use the db in here....
} catch (IOException e) {
LOGGER.info("factory try to open file " + filePath + " failed ");
// Make sure you close the db to shutdown the
// database and avoid resource leaks.
// db.close();
}
return new LevelDBPool(poolName, db, cacheSize);
}
示例5: LevelDBWorldAdapter
import org.iq80.leveldb.Options; //导入依赖的package包/类
/**
* Construct and init a new levedb based World
*
* @param server which has requested to load this world
* @param worldDir the folder where the world should be in
*/
private LevelDBWorldAdapter( GoMintServer server, File worldDir ) {
super( server, worldDir );
this.chunkCache = new ChunkCache( this );
// CHECKSTYLE:OFF
try {
this.loadLevelDat();
// We only support storage version 3 and up (MC:PE >= 1.0)
if ( this.worldVersion < 3 ) {
throw new WorldLoadException( "Version of the world is too old. Please update your MC:PE and import this world. After that you can use the exported version again." );
}
this.db = Iq80DBFactory.factory.open( new File( this.worldDir, "db" ), new Options().createIfMissing( true ) );
this.prepareSpawnRegion();
} catch ( Exception e ) {
e.printStackTrace();
}
// CHECKSTYLE:ON
}
示例6: start
import org.iq80.leveldb.Options; //导入依赖的package包/类
private void start() throws IOException {
persister = Executors.newFixedThreadPool(config.getInt("persisterThreads"));
Options levelDbOptions = new Options();
levelDbOptions.createIfMissing(true);
levelDbOptions.cacheSize(config.getInt("levelDbCache"));
avatarDb = factory.open(new File("./db/chatAvatars"), levelDbOptions);
chatRoomDb = factory.open(new File("./db/chatRooms"), levelDbOptions);
if(config.getBoolean("compressMails"))
levelDbOptions.compressionType(CompressionType.SNAPPY);
mailDb = factory.open(new File("./db/mails"), levelDbOptions);
getHighestAvatarIdFromDatabase();
registrar = new ChatApiTcpListener(config.getInt("registrarPort"));
gateway = new ChatApiTcpListener(config.getInt("gatewayPort"));
registrar.start();
gateway.start();
}
示例7: main
import org.iq80.leveldb.Options; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
String path = args[0];
Options options = new Options();
options.createIfMissing(true);
options.verifyChecksums(true);
options.paranoidChecks(true);
DB db = null;
try {
db = JniDBFactory.factory.open(new File(path), options);
} catch (UnsatisfiedLinkError ule) {
db = Iq80DBFactory.factory.open(new File(path), options);
}
db.close();
}
示例8: open
import org.iq80.leveldb.Options; //导入依赖的package包/类
@Override
public void open() {
Options options = new Options();
options.createIfMissing(true);
options.cacheSize(cacheSize);
options.compressionType(CompressionType.SNAPPY);
try {
File file = new File(database);
logger.info("Opening LevelDB: " + file.getAbsolutePath());
db = JniDBFactory.factory.open(new File(database), options);
logger.debug(db.getProperty("leveldb.stats"));
} catch (IOException e) {
logger.error("Error opening LevelDB ", e);
}
}
示例9: onOK
import org.iq80.leveldb.Options; //导入依赖的package包/类
private void onOK() {
Options options = new Options();
options.createIfMissing(this.createBox.isSelected());
options.compressionType((CompressionType) this.compressType.getSelectedItem());
try{
options.maxOpenFiles(Integer.parseInt(this.maxOpenFiles.getValue().toString()));
}catch (NumberFormatException e){
options.maxOpenFiles(1000);
}
options.verifyChecksums(this.verifyChecksumsCheckBox.isSelected());
options.paranoidChecks(this.paranoidChecksCheckBox.isSelected());
this.viewer.setOptions(options);
dispose();
}
示例10: openDatabase
import org.iq80.leveldb.Options; //导入依赖的package包/类
protected DB openDatabase() throws Exception {
Path storeRoot = createStorageDir();
Options options = new Options();
options.createIfMissing(false);
options.logger(new LeveldbLogger());
LOG.info("Using state database at " + storeRoot + " for recovery");
File dbfile = new File(storeRoot.toString());
try {
db = JniDBFactory.factory.open(dbfile, options);
} catch (NativeDB.DBException e) {
if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
LOG.info("Creating state database at " + dbfile);
options.createIfMissing(true);
try {
db = JniDBFactory.factory.open(dbfile, options);
// store version
storeVersion();
} catch (DBException dbErr) {
throw new IOException(dbErr.getMessage(), dbErr);
}
} else {
throw e;
}
}
return db;
}
示例11: submitScore
import org.iq80.leveldb.Options; //导入依赖的package包/类
public static boolean submitScore(String username, String score) throws IOException {
Options options = new Options();
options.createIfMissing(true);
DB db = factory.open(new File("database"), options);
String value = asString(db.get(bytes("scores")));
org.json.JSONObject scoreJSON;
if (!value.isEmpty()) { //user score
scoreJSON = new org.json.JSONObject(value);
} else {
scoreJSON = new org.json.JSONObject();
}
scoreJSON.put(username, score);
System.out.println("All Scores: \n" + scoreJSON.toString());
db.put(bytes("scores"), bytes(scoreJSON.toString()));
db.close();
return true;
}
示例12: getAllScoreAsJsonString
import org.iq80.leveldb.Options; //导入依赖的package包/类
public static String getAllScoreAsJsonString() throws IOException {
Options options = new Options();
options.createIfMissing(true);
DB db = factory.open(new File("database"), options);
String value = asString(db.get(bytes("scores")));
db.close();
org.json.JSONObject scoreJSON;
if (!value.isEmpty()) { //user score
scoreJSON = new org.json.JSONObject(value);
} else {
scoreJSON = new org.json.JSONObject();
}
System.out.println("All Scores: \n" + scoreJSON.toString());
return scoreJSON.toString();
}
示例13: DainLevelDBStorageSystem
import org.iq80.leveldb.Options; //导入依赖的package包/类
/** Constructor. */
public DainLevelDBStorageSystem(File dir, int cacheSizeMB)
throws StorageException {
ensureStorageDirectory(dir);
Options options = new Options();
options.createIfMissing(true);
// we disable compression, as the storage framework has own support for
// selective compression of sub-stores
options.compressionType(CompressionType.NONE);
options.cacheSize(cacheSizeMB * 1024 * 1024);
try {
database = Iq80DBFactory.factory.open(dir, options);
} catch (IOException e) {
throw new StorageException(e);
}
}
示例14: LevelDBJNI
import org.iq80.leveldb.Options; //导入依赖的package包/类
/**
* @param config
* @throws IOException
*/
public LevelDBJNI(Config config) throws IOException {
super(config);
this.dbPath = config.getString("leveldb.path");
this.cacheSize = config.getBytes("leveldb.cache");
File dbDir = new File(dbPath);
if (!dbDir.exists()) {
if (!dbDir.mkdirs()) {
throw new IOException("Unable to create DB directory");
}
}
Options options = new Options();
options.createIfMissing(true);
options.cacheSize(cacheSize);
options.compressionType(CompressionType.NONE); // No compression
db = JniDBFactory.factory.open(dbDir, options);
}
示例15: EzLevelDbTable
import org.iq80.leveldb.Options; //导入依赖的package包/类
public EzLevelDbTable(File path, EzLevelDbFactory factory,
Serde<H> hashKeySerde, Serde<R> rangeKeySerde, Serde<V> valueSerde,
Comparator<byte[]> hashKeyComparator,
Comparator<byte[]> rangeKeyComparator) {
this.hashKeySerde = hashKeySerde;
this.rangeKeySerde = rangeKeySerde;
this.valueSerde = valueSerde;
this.hashKeyComparator = hashKeyComparator;
this.rangeKeyComparator = rangeKeyComparator;
Options options = new Options();
options.createIfMissing(true);
options.comparator(new EzLevelDbComparator(hashKeyComparator,
rangeKeyComparator));
try {
this.db = factory.open(path, options);
} catch (IOException e) {
throw new DbException(e);
}
}