public class AsynchronousDataStore extends Object implements IDataStore
IDataStore
that does the actual saving in worker thread.
Creates an Entry
for each triple (sessionId, pageId, data) and puts it in
entries
queue if there is room. Acts as producer.
Later PageSavingRunnable
reads in blocking manner from entries
and saves each
entry. Acts as consumer.
PageSavingRunnable
because all we need is to make the page
storing asynchronous. We don't want to write concurrently in the wrapped IDataStore
,
though it may happen in the extreme case when the queue is full. These cases should be avoided.Constructor and Description |
---|
AsynchronousDataStore(IDataStore dataStore,
int capacity)
Construct.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canBeAsynchronous() |
void |
destroy()
Properly close the data store and possibly open resource handles
|
byte[] |
getData(String sessionId,
int id)
Get data associated with the session id and page id.
|
boolean |
isReplicated() |
void |
removeData(String sessionId)
Remove all page data for the session id
|
void |
removeData(String sessionId,
int id)
Remove all persisted data related to the session id and page id
|
void |
storeData(String sessionId,
int id,
byte[] data)
Save the entry in the queue if there is a room or directly pass it to the wrapped
IDataStore if there is no such |
public AsynchronousDataStore(IDataStore dataStore, int capacity)
dataStore
- the wrapped IDataStore
that actually saved the datacapacity
- the capacity of the queue that delays the savingpublic void destroy()
IDataStore
destroy
in interface IDataStore
public byte[] getData(String sessionId, int id)
IDataStore
getData
in interface IDataStore
sessionId
- Session IDid
- Page IDpublic boolean isReplicated()
isReplicated
in interface IDataStore
public void removeData(String sessionId, int id)
IDataStore
removeData
in interface IDataStore
sessionId
- Session IDid
- Page IDpublic void removeData(String sessionId)
IDataStore
removeData
in interface IDataStore
sessionId
- Session IDpublic void storeData(String sessionId, int id, byte[] data)
IDataStore
if there is no suchstoreData
in interface IDataStore
sessionId
- Session IDid
- Page IDdata
- Page dataIDataStore.storeData(java.lang.String, int, byte[])
public final boolean canBeAsynchronous()
canBeAsynchronous
in interface IDataStore
AsynchronousDataStore
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.