public ObjectObjectPersistentMultiMaplet(final File file, final KeyDescriptor<K> keyExternalizer, final DataExternalizer<V> valueExternalizer, final CollectionFactory<V> collectionFactory) throws IOException { myValueExternalizer = valueExternalizer; myMap = new PersistentHashMap<K, Collection<V>>(file, keyExternalizer, new CollectionDataExternalizer<V>(valueExternalizer, collectionFactory)); myCache = new SLRUCache<K, Collection>(CACHE_SIZE, CACHE_SIZE, keyExternalizer) { @NotNull @Override public Collection createValue(K key) { try { final Collection<V> collection = myMap.get(key); return collection == null? NULL_COLLECTION : collection; } catch (IOException e) { throw new BuildDataCorruptedException(e); } } }; }
public IntIntPersistentMultiMaplet(final File file, final KeyDescriptor<Integer> keyExternalizer) throws IOException { myMap = new PersistentHashMap<Integer, TIntHashSet>(file, keyExternalizer, new IntSetExternalizer()); myCache = new SLRUCache<Integer, TIntHashSet>(CACHE_SIZE, CACHE_SIZE) { @NotNull @Override public TIntHashSet createValue(Integer key) { try { final TIntHashSet collection = myMap.get(key); return collection == null? NULL_COLLECTION : collection; } catch (IOException e) { throw new BuildDataCorruptedException(e); } } }; }
public IntObjectPersistentMultiMaplet(final File file, final KeyDescriptor<Integer> keyExternalizer, final DataExternalizer<V> valueExternalizer, final CollectionFactory<V> collectionFactory) throws IOException { myValueExternalizer = valueExternalizer; myMap = new PersistentHashMap<Integer, Collection<V>>(file, keyExternalizer, new CollectionDataExternalizer<V>(valueExternalizer, collectionFactory)); myCache = new SLRUCache<Integer, Collection>(CACHE_SIZE, CACHE_SIZE) { @NotNull @Override public Collection createValue(Integer key) { try { final Collection<V> collection = myMap.get(key); return collection == null? NULL_COLLECTION : collection; } catch (IOException e) { throw new BuildDataCorruptedException(e); } } }; }
public FileAccessorCache(int protectedQueueSize, int probationalQueueSize) { myCache = new SLRUCache<K, Handle<T>>(protectedQueueSize, probationalQueueSize, this) { @NotNull @Override public final Handle<T> createValue(K path) { try { return new Handle<T>(createAccessor(path), FileAccessorCache.this); } catch (IOException ex) { throw new RuntimeException(ex); } } @Override protected final void onDropFromCache(K key, Handle<T> value) { value.release(); } }; }
public ObjectObjectPersistentMultiMaplet(final File file, final KeyDescriptor<K> keyExternalizer, final DataExternalizer<V> valueExternalizer, final CollectionFactory<V> collectionFactory) throws IOException { myValueExternalizer = valueExternalizer; myMap = new PersistentHashMap<K, Collection<V>>(file, keyExternalizer, new CollectionDataExternalizer<V>(valueExternalizer, collectionFactory)); myCache = new SLRUCache<K, Collection>(CACHE_SIZE, CACHE_SIZE) { @NotNull @Override public Collection createValue(K key) { try { final Collection<V> collection = myMap.get(key); return collection == null? NULL_COLLECTION : collection; } catch (IOException e) { throw new RuntimeException(e); } } }; }
public IntObjectPersistentMaplet(final File file, final DataExternalizer<V> externalizer) { try { myMap = new PersistentHashMap<Integer, V>(file, new IntInlineKeyDescriptor(), externalizer); myCache = new SLRUCache<Integer, Object>(CACHE_SIZE, CACHE_SIZE) { @NotNull @Override public Object createValue(Integer key) { try { final V v1 = myMap.get(key); return v1 == null? NULL_OBJ : v1; } catch (IOException e) { throw new RuntimeException(e); } } }; } catch (IOException e) { throw new RuntimeException(e); } }
public IntIntPersistentMultiMaplet(final File file, final KeyDescriptor<Integer> keyExternalizer) throws IOException { myMap = new PersistentHashMap<Integer, TIntHashSet>(file, keyExternalizer, new IntSetExternalizer()); myCache = new SLRUCache<Integer, TIntHashSet>(CACHE_SIZE, CACHE_SIZE) { @NotNull @Override public TIntHashSet createValue(Integer key) { try { final TIntHashSet collection = myMap.get(key); return collection == null? NULL_COLLECTION : collection; } catch (IOException e) { throw new RuntimeException(e); } } }; }
public IntObjectPersistentMultiMaplet(final File file, final KeyDescriptor<Integer> keyExternalizer, final DataExternalizer<V> valueExternalizer, final CollectionFactory<V> collectionFactory) throws IOException { myValueExternalizer = valueExternalizer; myMap = new PersistentHashMap<Integer, Collection<V>>(file, keyExternalizer, new CollectionDataExternalizer<V>(valueExternalizer, collectionFactory)); myCache = new SLRUCache<Integer, Collection>(CACHE_SIZE, CACHE_SIZE) { @NotNull @Override public Collection createValue(Integer key) { try { final Collection<V> collection = myMap.get(key); return collection == null? NULL_COLLECTION : collection; } catch (IOException e) { throw new RuntimeException(e); } } }; }
private void initialize() throws IOException { myMap = new PersistentHashMap<K, CompiledDataValueContainer<V>>(myIndexFile, myKeyDescriptor, createValueContainerExternalizer(myValueExternalizer), INITIAL_INDEX_SIZE); myCache = new SLRUCache<K, CompiledDataValueContainer<V>>(CACHE_QUEUES_SIZE, CACHE_QUEUES_SIZE) { @NotNull @Override public CompiledDataValueContainer<V> createValue(final K key) { try { final CompiledDataValueContainer<V> valueContainer = myMap.get(key); if (valueContainer != null) { return valueContainer; } } catch (final IOException e) { throw new RuntimeException(e); } return new CompiledDataValueContainer<V>(); } @Override protected void onDropFromCache(final K key, final CompiledDataValueContainer<V> value) { try { myMap.put(key, value); } catch (final IOException e) { throw new RuntimeException(e); } } }; }
public IntIntPersistentMaplet(final File file, final KeyDescriptor<Integer> k) { try { myMap = new PersistentHashMap<Integer, Integer>(file, k, new DataExternalizer<Integer>() { @Override public void save(DataOutput out, Integer value) throws IOException { out.writeInt(value); } @Override public Integer read(DataInput in) throws IOException { return in.readInt(); } }); myCache = new SLRUCache<Integer, Object>(CACHE_SIZE, CACHE_SIZE) { @NotNull @Override public Object createValue(Integer key) { try { final Integer v1 = myMap.get(key); return v1 == null? NULL_OBJ : v1; } catch (IOException e) { throw new RuntimeException(e); } } }; } catch (IOException e) { throw new RuntimeException(e); } }
private void initMapAndCache() throws IOException { final ValueContainerMap<Key, Value> map; PersistentHashMapValueStorage.CreationTimeOptions.EXCEPTIONAL_IO_CANCELLATION.set(ourProgressManagerCheckCancelledIOCanceller); try { map = new ValueContainerMap<Key, Value>(myStorageFile, myKeyDescriptor, myDataExternalizer, myKeyIsUniqueForIndexedFile); } finally { PersistentHashMapValueStorage.CreationTimeOptions.EXCEPTIONAL_IO_CANCELLATION.set(null); } myCache = new SLRUCache<Key, ChangeTrackingValueContainer<Value>>(myCacheSize, (int)(Math.ceil(myCacheSize * 0.25)) /* 25% from the main cache size*/) { @Override @NotNull public ChangeTrackingValueContainer<Value> createValue(final Key key) { return new ChangeTrackingValueContainer<Value>(new ChangeTrackingValueContainer.Initializer<Value>() { @NotNull @Override public Object getLock() { return map.getDataAccessLock(); } @Nullable @Override public ValueContainer<Value> compute() { ValueContainer<Value> value; try { value = map.get(key); if (value == null) { value = new ValueContainerImpl<Value>(); } } catch (IOException e) { throw new RuntimeException(e); } return value; } }); } @Override protected void onDropFromCache(final Key key, @NotNull final ChangeTrackingValueContainer<Value> valueContainer) { if (valueContainer.isDirty()) { try { map.put(key, valueContainer); } catch (IOException e) { throw new RuntimeException(e); } } } }; myMap = map; myKeyHashToVirtualFileMapping = myBuildKeyHashToVirtualFileMapping ? new KeyHash2VirtualFileEnumerator(getProjectFile()) : null; }
public CompilerDependencyStorage(File file, KeyDescriptor<Key> keyDescriptor, final int cacheSize) throws IOException { myMap = new PersistentHashMap<Key, int[]>(file, keyDescriptor, new DataExternalizer<int[]>() { public void save(DataOutput out, int[] array) throws IOException { out.writeInt(array.length); for (int value : array) { out.writeInt(value); } } public int[] read(DataInput in) throws IOException { final TIntHashSet set = new TIntHashSet(); DataInputStream stream = (DataInputStream)in; while(stream.available() > 0) { final int size = stream.readInt(); final int _size = Math.abs(size); for (int idx = 0; idx < _size; idx++) { if (size > 0) { set.add(stream.readInt()); } else { set.remove(stream.readInt()); } } } return set.toArray(); } }); myCache = new SLRUCache<Key, IntSet>(cacheSize * 2, cacheSize) { @NotNull public IntSet createValue(Key key) { return new IntSet(key); } protected void onDropFromCache(Key key, final IntSet set) { if (key == myKeyToRemove || !set.isDirty()) { return; } try { if (set.needsCompacting()) { myMap.put(key, set.getValues()); } else { myMap.appendData(key, new PersistentHashMap.ValueDataAppender() { public void append(final DataOutput out) throws IOException { final Ref<IOException> exception = new Ref<IOException>(null); final TIntProcedure saveProc = new TIntProcedure() { public boolean execute(int value) { try { out.writeInt(value); return true; } catch (IOException e) { exception.set(e); return false; } } }; out.writeInt(-set.getRemovedCount()); set.processRemovedValues(saveProc); if (exception.get() != null) { throw exception.get(); } out.writeInt(set.getAddedCount()); set.processAddedValues(saveProc); if (exception.get() != null) { throw exception.get(); } } }); } } catch (IOException e) { LOG.error(e); } } }; }
public BackwardDependenciesStorage(File file, final int cacheSize) throws IOException { myMap = new PersistentHashMap<Integer, DependenciesSet>(file, EnumeratorIntegerDescriptor.INSTANCE, new MyDataExternalizer()); myCache = new SLRUCache<Integer, ReferencerSetHolder>(cacheSize * 2, cacheSize) { @NotNull public ReferencerSetHolder createValue(Integer key) { return new ReferencerSetHolder(key); } protected void onDropFromCache(Integer key, final ReferencerSetHolder holder) { if (key.equals(myKeyToRemove) || !holder.isDirty()) { return; } try { if (holder.isDataLoaded() || !myMap.containsMapping(key)) { myMap.put(key, new DependenciesSet(holder.getData())); } else { myMap.appendData(key, new PersistentHashMap.ValueDataAppender() { public void append(final DataOutput out) throws IOException { final Ref<IOException> exception = new Ref<IOException>(null); // process removed holder.myRemoveRequested.forEach(new TIntProcedure() { public boolean execute(int qName) { try { out.writeInt(-qName); return true; } catch (IOException e) { exception.set(e); } return false; } }); final IOException _ex = exception.get(); if (_ex != null) { throw _ex; } // process added members for (ReferencerItem item : holder.myAdded) { item.save(out); } } }); } } catch (IOException e) { LOG.error(e); } } }; }
private void initMapAndCache() throws IOException { final ValueContainerMap<Key, Value> map = new ValueContainerMap<Key, Value>(myStorageFile, myKeyDescriptor, myDataExternalizer); myCache = new SLRUCache<Key, ChangeTrackingValueContainer<Value>>(myCacheSize, (int)(Math.ceil(myCacheSize * 0.25)) /* 25% from the main cache size*/) { @Override @NotNull public ChangeTrackingValueContainer<Value> createValue(final Key key) { return new ChangeTrackingValueContainer<Value>(new ChangeTrackingValueContainer.Initializer<Value>() { @NotNull @Override public Object getLock() { return map.getDataAccessLock(); } @Nullable @Override public ValueContainer<Value> compute() { ValueContainer<Value> value; try { value = map.get(key); if (value == null) { value = new ValueContainerImpl<Value>(); } } catch (IOException e) { throw new RuntimeException(e); } return value; } }); } @Override protected void onDropFromCache(final Key key, @NotNull final ChangeTrackingValueContainer<Value> valueContainer) { if (valueContainer.isDirty()) { try { map.put(key, valueContainer); } catch (IOException e) { throw new RuntimeException(e); } } } }; myMap = map; }
protected void initMapAndCache() throws IOException { final ValueContainerMap<Key, Value> map; PersistentHashMapValueStorage.CreationTimeOptions.EXCEPTIONAL_IO_CANCELLATION.set(new PersistentHashMapValueStorage.ExceptionalIOCancellationCallback() { @Override public void checkCancellation() { checkCanceled(); } }); PersistentHashMapValueStorage.CreationTimeOptions.COMPACT_CHUNKS_WITH_VALUE_DESERIALIZATION.set(Boolean.TRUE); try { map = new ValueContainerMap<Key, Value>(getStorageFile(), myKeyDescriptor, myDataExternalizer, myKeyIsUniqueForIndexedFile); } finally { PersistentHashMapValueStorage.CreationTimeOptions.EXCEPTIONAL_IO_CANCELLATION.set(null); PersistentHashMapValueStorage.CreationTimeOptions.COMPACT_CHUNKS_WITH_VALUE_DESERIALIZATION.set(null); } myCache = new SLRUCache<Key, ChangeTrackingValueContainer<Value>>(myCacheSize, (int)(Math.ceil(myCacheSize * 0.25)) /* 25% from the main cache size*/) { @Override @Nonnull public ChangeTrackingValueContainer<Value> createValue(final Key key) { return new ChangeTrackingValueContainer<Value>(new ChangeTrackingValueContainer.Initializer<Value>() { @Nonnull @Override public Object getLock() { return map.getDataAccessLock(); } @Nullable @Override public ValueContainer<Value> compute() { ValueContainer<Value> value; try { value = map.get(key); if (value == null) { value = new ValueContainerImpl<Value>(); } } catch (IOException e) { throw new RuntimeException(e); } return value; } }); } @Override protected void onDropFromCache(final Key key, @Nonnull final ChangeTrackingValueContainer<Value> valueContainer) { if (valueContainer.isDirty()) { try { map.put(key, valueContainer); } catch (IOException e) { throw new RuntimeException(e); } } } }; myMap = map; }