Search in sources :

Example 1 with WriteOptions

use of org.iq80.leveldb.WriteOptions in project camel by apache.

the class LevelDBFile method getWriteOptions.

public WriteOptions getWriteOptions() {
    WriteOptions options = new WriteOptions();
    options.sync(sync);
    return options;
}
Also used : WriteOptions(org.iq80.leveldb.WriteOptions)

Example 2 with WriteOptions

use of org.iq80.leveldb.WriteOptions in project jesos by groupon.

the class JLevelDBState method expunge.

@Override
public Future<Boolean> expunge(final Variable variable) {
    checkNotNull(variable, "variable is null");
    checkState(!closed.get(), "already closed");
    checkState(variable instanceof JVariable, "can not process native variable, use JVariable");
    final JVariable v = (JVariable) variable;
    return executor.submit(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            final WriteOptions writeOptions = new WriteOptions();
            writeOptions.sync(true);
            final String internedName = v.getName().intern();
            synchronized (internedName) {
                final JVariable current = load(internedName);
                if (current != null && current.getUuid().equals(v.getUuid())) {
                    db.delete(bytes(internedName));
                    return Boolean.TRUE;
                } else {
                    return Boolean.FALSE;
                }
            }
        }
    });
}
Also used : WriteOptions(org.iq80.leveldb.WriteOptions) Iq80DBFactory.asString(org.iq80.leveldb.impl.Iq80DBFactory.asString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException)

Example 3 with WriteOptions

use of org.iq80.leveldb.WriteOptions in project jesos by groupon.

the class JLevelDBState method store.

@Override
public Future<Variable> store(final Variable variable) {
    checkNotNull(variable, "variable is null");
    checkState(!closed.get(), "already closed");
    checkState(variable instanceof JVariable, "can not process native variable, use JVariable");
    final JVariable v = (JVariable) variable;
    return executor.submit(new Callable<Variable>() {

        @Override
        public Variable call() throws Exception {
            final WriteOptions writeOptions = new WriteOptions();
            writeOptions.sync(true);
            final String internedName = v.getName().intern();
            synchronized (internedName) {
                final JVariable current = load(internedName);
                if (current == null || current.getUuid().equals(v.getUuid())) {
                    final JVariable update = new JVariable(internedName, v.value());
                    final WriteBatch writeBatch = db.createWriteBatch();
                    writeBatch.delete(bytes(internedName));
                    writeBatch.put(bytes(internedName), update.getEntry().toByteArray());
                    db.write(writeBatch, writeOptions);
                    return update;
                } else {
                    return null;
                }
            }
        }
    });
}
Also used : WriteOptions(org.iq80.leveldb.WriteOptions) Variable(org.apache.mesos.state.Variable) Iq80DBFactory.asString(org.iq80.leveldb.impl.Iq80DBFactory.asString) WriteBatch(org.iq80.leveldb.WriteBatch) IOException(java.io.IOException)

Aggregations

WriteOptions (org.iq80.leveldb.WriteOptions)3 IOException (java.io.IOException)2 Iq80DBFactory.asString (org.iq80.leveldb.impl.Iq80DBFactory.asString)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Variable (org.apache.mesos.state.Variable)1 WriteBatch (org.iq80.leveldb.WriteBatch)1