Search in sources :

Example 1 with Exchange

use of com.persistit.Exchange in project sonarqube by SonarSource.

the class Storage method keySet.

/**
   * Returns the set of keys associated with this cache.
   *
   * @return The set containing the keys for this cache.
   */
public Set<Object> keySet() {
    try {
        Set<Object> keys = Sets.newLinkedHashSet();
        exchange.clear();
        Exchange iteratorExchange = new Exchange(exchange);
        iteratorExchange.append(Key.BEFORE);
        while (iteratorExchange.next(false)) {
            keys.add(iteratorExchange.getKey().indexTo(-1).decode());
        }
        return keys;
    } catch (Exception e) {
        throw new IllegalStateException("Fail to get keys from cache " + name, e);
    }
}
Also used : Exchange(com.persistit.Exchange) PersistitException(com.persistit.exception.PersistitException) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with Exchange

use of com.persistit.Exchange in project sonarqube by SonarSource.

the class Storages method createCache.

public <V> Storage<V> createCache(String cacheName) {
    Preconditions.checkState(volume != null && volume.isOpened(), "Caches are not initialized");
    Preconditions.checkState(!cacheMap.containsKey(cacheName), "Cache is already created: %s", cacheName);
    try {
        Exchange exchange = persistit.getExchange(volume, cacheName, true);
        exchange.setMaximumValueSize(Value.MAXIMUM_SIZE);
        Storage<V> cache = new Storage<>(cacheName, exchange);
        cacheMap.put(cacheName, exchange);
        return cache;
    } catch (Exception e) {
        throw new IllegalStateException("Fail to create cache: " + cacheName, e);
    }
}
Also used : Exchange(com.persistit.Exchange) PersistitException(com.persistit.exception.PersistitException)

Example 3 with Exchange

use of com.persistit.Exchange in project xodus by JetBrains.

the class JMHPersistItTokyoCabinetWriteBenchmark method randomWrite.

@Benchmark
@BenchmarkMode(Mode.SingleShotTime)
@Warmup(iterations = WARMUP_ITERATIONS)
@Measurement(iterations = MEASUREMENT_ITERATIONS)
@Fork(FORKS)
public void randomWrite() throws PersistitException {
    final Exchange exchange = createTestStore();
    for (final ByteIterable key : randomKeys) {
        exchange.clear();
        for (int i = 0; i < key.getLength(); i++) {
            exchange.append(key.getBytesUnsafe()[i]);
        }
        exchange.getValue().put(key.getBytesUnsafe());
        exchange.store();
    }
    persistit.flush();
}
Also used : Exchange(com.persistit.Exchange) ByteIterable(jetbrains.exodus.ByteIterable) TokyoCabinetBenchmark(jetbrains.exodus.benchmark.TokyoCabinetBenchmark)

Example 4 with Exchange

use of com.persistit.Exchange in project titan by thinkaurelius.

the class PersistitTransaction method getExchange.

public Exchange getExchange(String treeName, Boolean create) throws StorageException {
    synchronized (this) {
        Exchange exchange;
        try {
            assign();
            exchange = db.getExchange(VOLUME_NAME, treeName, create);
            return exchange;
        } catch (PersistitException ex) {
            throw new PermanentStorageException(ex);
        }
    }
}
Also used : Exchange(com.persistit.Exchange) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) PersistitException(com.persistit.exception.PersistitException)

Example 5 with Exchange

use of com.persistit.Exchange in project sonarqube by SonarSource.

the class Storage method keySet.

/**
   * Returns the set of cache keys associated with this group.
   * TODO implement a lazy-loading equivalent with Iterator/Iterable
   *
   * @param group The group.
   * @return The set of cache keys for this group.
   */
@SuppressWarnings("rawtypes")
public Set keySet(Object key) {
    try {
        Set<Object> keys = Sets.newLinkedHashSet();
        exchange.clear();
        Exchange iteratorExchange = new Exchange(exchange);
        iteratorExchange.append(key);
        iteratorExchange.append(Key.BEFORE);
        while (iteratorExchange.next(false)) {
            keys.add(iteratorExchange.getKey().indexTo(-1).decode());
        }
        return keys;
    } catch (Exception e) {
        throw new IllegalStateException("Fail to get keys from cache " + name, e);
    }
}
Also used : Exchange(com.persistit.Exchange) PersistitException(com.persistit.exception.PersistitException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Exchange (com.persistit.Exchange)8 PersistitException (com.persistit.exception.PersistitException)5 TokyoCabinetBenchmark (jetbrains.exodus.benchmark.TokyoCabinetBenchmark)3 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)2 NoSuchElementException (java.util.NoSuchElementException)2 ByteIterable (jetbrains.exodus.ByteIterable)2 Volume (com.persistit.Volume)1