public static class Caches.WeakSoftRef extends EngineWrapper implements Engine
SoftReference
or WeakReference
Items can be removed from cache by Garbage Collector ifModifier and Type | Class and Description |
---|---|
protected static interface |
Caches.WeakSoftRef.CacheItem |
protected static class |
Caches.WeakSoftRef.CacheSoftItem<A> |
protected static class |
Caches.WeakSoftRef.CacheWeakItem<A> |
EngineWrapper.CloseOnJVMShutdown, EngineWrapper.ImmutabilityCheckEngine, EngineWrapper.ReadOnlyEngine, EngineWrapper.SerializerCheckEngineWrapper, EngineWrapper.SynchronizedEngineWrapper
Modifier and Type | Field and Description |
---|---|
protected LongConcurrentHashMap<Caches.WeakSoftRef.CacheItem> |
items |
protected ReentrantLock[] |
locks |
protected ReferenceQueue<Object> |
queue |
protected Thread |
queueThread |
protected boolean |
useWeakRef |
CLOSED
CATALOG_RECID, CHECK_RECORD, CLASS_INFO_RECID, LAST_RESERVED_RECID
Constructor and Description |
---|
WeakSoftRef(Engine engine,
boolean useWeakRef,
boolean disableLocks) |
Modifier and Type | Method and Description |
---|---|
void |
clearCache()
clears any underlying cache
|
void |
close()
Close store/cache.
|
<A> boolean |
compareAndSwap(long recid,
A expectedOldValue,
A newValue,
Serializer<A> serializer)
Updates existing record in atomic (Compare And Swap) manner.
|
<A> void |
delete(long recid,
Serializer<A> serializer)
Remove existing record from store/cache
Recid must be a number returned by 'put' method.
|
<A> A |
get(long recid,
Serializer<A> serializer)
Get existing record.
|
<A> long |
put(A value,
Serializer<A> serializer)
Insert new record.
|
void |
rollback()
Undoes all changes made in the current transaction.
|
protected void |
runRefQueue()
Collects items from GC and removes them from cache
|
<A> void |
update(long recid,
A value,
Serializer<A> serializer)
Update existing record with new value.
|
canRollback, canSnapshot, checkClosed, closeListenerRegister, closeListenerUnregister, commit, compact, getSerializerPojo, getWrappedEngine, isClosed, isReadOnly, preallocate, preallocate, snapshot
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canRollback, canSnapshot, closeListenerRegister, closeListenerUnregister, commit, compact, getSerializerPojo, isClosed, isReadOnly, preallocate, preallocate, snapshot
protected final ReentrantLock[] locks
protected ReferenceQueue<Object> queue
protected Thread queueThread
protected LongConcurrentHashMap<Caches.WeakSoftRef.CacheItem> items
protected final boolean useWeakRef
public WeakSoftRef(Engine engine, boolean useWeakRef, boolean disableLocks)
protected void runRefQueue()
public <A> long put(A value, Serializer<A> serializer)
Engine
put
in interface Engine
put
in class EngineWrapper
value
- records to be addedserializer
- used to convert record into/from binary formpublic <A> A get(long recid, Serializer<A> serializer)
Engine
get
in interface Engine
get
in class EngineWrapper
recid
- (record identifier) under which record was persistedserializer
- used to deserialize record from binary formpublic <A> void update(long recid, A value, Serializer<A> serializer)
Engine
update
in interface Engine
update
in class EngineWrapper
recid
- (record identifier) under which record was persisted.value
- new record value to be storedserializer
- used to serialize record into binary formpublic <A> void delete(long recid, Serializer<A> serializer)
Engine
delete
in interface Engine
delete
in class EngineWrapper
recid
- (record identifier) under which was record persistedserializer
- which may be used in some circumstances to deserialize and store old objectpublic <A> boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer)
Engine
oldValue==expectedOldValue
when old value is found in instance cacheoldValue
using serializer
and checking oldValue.equals(expectedOldValue)
expectedOldValue
using serializer
and comparing binary array with already serialized oldValue
compareAndSwap
in interface Engine
compareAndSwap
in class EngineWrapper
recid
- (record identifier) under which record was persisted.expectedOldValue
- old value to be compared with existing recordnewValue
- to be written if values are matchingserializer
- used to serialize record into binary formpublic void close()
Engine
NullPointerException
There is an configuration option DBMaker.closeOnJvmShutdown()
which uses shutdown hook to automatically
close Engine when JVM shutdowns.close
in interface Engine
close
in class EngineWrapper
public void rollback()
Engine
UnsupportedOperationException
.rollback
in interface Engine
rollback
in class EngineWrapper
public void clearCache()
Engine
clearCache
in interface Engine
clearCache
in class EngineWrapper
Copyright © 2016. All rights reserved.