org.iq80.leveldb.Options Maven / Gradle / Ivy
/*
* Copyright (C) 2011 the original author or authors.
* See the notice.md file distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.iq80.leveldb;
public class Options
{
private boolean createIfMissing = true;
private boolean errorIfExists;
private int writeBufferSize = 4 << 20;
private int maxOpenFiles = 1000;
private int blockRestartInterval = 16;
private int maxFileSize = 2 << 20;
private int blockSize = 4 * 1024;
private CompressionType compressionType = CompressionType.SNAPPY;
private boolean paranoidChecks;
private DBComparator comparator;
private Logger logger;
private long cacheSize = 8 << 20;
private XFilterPolicy filterPolicy;
private boolean reuseLogs = false;
public static Options fromOptions(Options options)
{
checkArgNotNull(options, "Options can't be null");
final Options options1 = new Options();
options1.createIfMissing = options.createIfMissing;
options1.errorIfExists = options.errorIfExists;
options1.writeBufferSize = options.writeBufferSize;
options1.maxOpenFiles = options.maxOpenFiles;
options1.blockRestartInterval = options.blockRestartInterval;
options1.maxFileSize = options.maxFileSize;
options1.blockSize = options.blockSize;
options1.compressionType = options.compressionType;
options1.paranoidChecks = options.paranoidChecks;
options1.comparator = options.comparator;
options1.logger = options.logger;
options1.cacheSize = options.cacheSize;
options1.filterPolicy = options.filterPolicy;
options1.reuseLogs = options.reuseLogs;
return options1;
}
static void checkArgNotNull(Object value, String name)
{
if (value == null) {
throw new IllegalArgumentException("The " + name + " argument cannot be null");
}
}
public boolean createIfMissing()
{
return createIfMissing;
}
public Options createIfMissing(boolean createIfMissing)
{
this.createIfMissing = createIfMissing;
return this;
}
public boolean errorIfExists()
{
return errorIfExists;
}
public Options errorIfExists(boolean errorIfExists)
{
this.errorIfExists = errorIfExists;
return this;
}
public int writeBufferSize()
{
return writeBufferSize;
}
public Options writeBufferSize(int writeBufferSize)
{
this.writeBufferSize = writeBufferSize;
return this;
}
public int maxOpenFiles()
{
return maxOpenFiles;
}
public Options maxOpenFiles(int maxOpenFiles)
{
this.maxOpenFiles = maxOpenFiles;
return this;
}
public int blockRestartInterval()
{
return blockRestartInterval;
}
public Options blockRestartInterval(int blockRestartInterval)
{
this.blockRestartInterval = blockRestartInterval;
return this;
}
public int maxFileSize()
{
return maxFileSize;
}
/**
* Leveldb will write up to this amount of bytes to a file before
* switching to a new one.
* Most clients should leave this parameter alone. However if your
* filesystem is more efficient with larger files, you could
* consider increasing the value. The downside will be longer
* compactions and hence longer latency/performance hiccups.
* Another reason to increase this parameter might be when you are
* initially populating a large database.
*
* Default: 2MB
*
* @param maxFileSize max file size int bytes
*/
public Options maxFileSize(int maxFileSize)
{
this.maxFileSize = maxFileSize;
return this;
}
public int blockSize()
{
return blockSize;
}
public Options blockSize(int blockSize)
{
this.blockSize = blockSize;
return this;
}
public CompressionType compressionType()
{
return compressionType;
}
public Options compressionType(CompressionType compressionType)
{
checkArgNotNull(compressionType, "compressionType");
this.compressionType = compressionType;
return this;
}
public long cacheSize()
{
return cacheSize;
}
public Options cacheSize(long cacheSize)
{
this.cacheSize = cacheSize;
return this;
}
public DBComparator comparator()
{
return comparator;
}
public Options comparator(DBComparator comparator)
{
this.comparator = comparator;
return this;
}
public Logger logger()
{
return logger;
}
public Options logger(Logger logger)
{
this.logger = logger;
return this;
}
public boolean paranoidChecks()
{
return paranoidChecks;
}
public Options paranoidChecks(boolean paranoidChecks)
{
this.paranoidChecks = paranoidChecks;
return this;
}
/**
* Set table filter policy
*
* @param filterPolicy new filter policy
* @return self
*/
public Options filterPolicy(XFilterPolicy filterPolicy)
{
this.filterPolicy = filterPolicy;
return this;
}
public XFilterPolicy filterPolicy()
{
return filterPolicy;
}
/**
* If true, append to existing MANIFEST and log files
* when a database is opened. This can significantly speed up open.
*/
public Options reuseLogs(boolean reuseLogs)
{
this.reuseLogs = reuseLogs;
return this;
}
public boolean reuseLogs()
{
return this.reuseLogs;
}
}