public class MongodbBinaryStore extends AbstractBinaryStore
BinaryStore
implementation that uses a MongoDB for persisting binary values.Modifier and Type | Field and Description |
---|---|
protected int |
chunkSize |
protected static com.mongodb.BasicDBObject |
DATA_CHUNK |
protected static com.mongodb.BasicDBObject |
HEADER |
logger, MEDIUM_BUFFER_SIZE
Constructor and Description |
---|
MongodbBinaryStore(String host,
int port,
String database)
Creates a new instance of the store, using a single MongoDB.
|
MongodbBinaryStore(String host,
int port,
String database,
String username,
String password,
Set<String> replicaSet)
Creates a new mongo binary store instance using the supplied params.
|
Modifier and Type | Method and Description |
---|---|
Iterable<BinaryKey> |
getAllBinaryKeys()
Obtain an iterable implementation containing all of the store's binary keys of those binaries that are in use.
|
int |
getChunkSize()
Gets the size of the chunk used to store content.
|
String |
getExtractedText(BinaryValue source)
Returns the extracted text of a binary value, or
null if such text hasn't been stored previously (but the binary
value can be found in the store) |
InputStream |
getInputStream(BinaryKey key)
Get an
InputStream to the binary content with the supplied key. |
protected String |
getStoredMimeType(BinaryValue source)
Returns the stored mime-type of a binary value.
|
void |
markAsUnused(Iterable<BinaryKey> keys)
Mark the supplied binary keys as unused, but keep them in quarantine until needed again (at which point they're removed from
quarantine) or until
BinaryStore.removeValuesUnusedLongerThan(long, TimeUnit) is called. |
void |
markAsUsed(Iterable<BinaryKey> keys)
Marks the binary with supplied keys as used.
|
void |
removeValuesUnusedLongerThan(long minimumAge,
TimeUnit unit)
Remove binary values that have been
unused for at least the specified amount of time. |
void |
setChunkSize(int chunkSize)
Modifies chunk size used to store content.
|
void |
start()
Initialize the store and get ready for use.
|
void |
storeExtractedText(BinaryValue source,
String extractedText)
Stores the extracted text of a binary value into this store.
|
protected void |
storeMimeType(BinaryValue source,
String mimeType)
Stores the given mime-type for a binary value.
|
BinaryValue |
storeValue(InputStream stream,
boolean markAsUnused)
Store the binary value and return the JCR representation.
|
bestBufferSize, detector, extractors, getMimeType, getMinimumBinarySizeInBytes, getText, hasBinary, setMimeTypeDetector, setMinimumBinarySizeInBytes, setTextExtractors, shutdown, storeValue
protected static final com.mongodb.BasicDBObject HEADER
protected static final com.mongodb.BasicDBObject DATA_CHUNK
protected int chunkSize
public MongodbBinaryStore(String host, int port, String database)
host
- port
- database
- public MongodbBinaryStore(String host, int port, String database, String username, String password, Set<String> replicaSet)
host
- the mongo host; may not be nullport
- the portdatabase
- the name of the database; may be null in which case a default will be usedusername
- the username; may be nullpassword
- the password; may be nullreplicaSet
- a Set
of (host:port) pairs representing multiple server addresses; may be nullpublic int getChunkSize()
public void setChunkSize(int chunkSize)
chunkSize
- chunk size in bytes.public BinaryValue storeValue(InputStream stream, boolean markAsUnused) throws BinaryStoreException
BinaryStore
stream
- the stream containing the binary content to be stored; may not be nullmarkAsUnused
- a boolean
which indicates if the binary will be stored as unused or not. Binaries used from
normal sessions (via properties) will normally be stored as unused and they will be marked as used only on tx commit.BinaryStoreException
- if there any unexpected problempublic InputStream getInputStream(BinaryKey key) throws BinaryStoreException
BinaryStore
InputStream
to the binary content with the supplied key. The input stream will be returned as long as
the binary value has not been removed, so expired binary values should be included here as well.key
- the key to the binary content; never nullnever null
BinaryStoreException
- if there is a problem reading the content from the store or if a valid, non-null
InputStream
cannot be returned for the given key.public void markAsUsed(Iterable<BinaryKey> keys)
BinaryStore
public void markAsUnused(Iterable<BinaryKey> keys)
BinaryStore
BinaryStore.removeValuesUnusedLongerThan(long, TimeUnit)
is called. This method ignores any keys for
values not stored within this store.keys
- the keys for the binary values that are no longer neededpublic void removeValuesUnusedLongerThan(long minimumAge, TimeUnit unit)
BinaryStore
unused
for at least the specified amount of time.minimumAge
- the minimum time that a binary value has been unused
before it can be
removed; must be non-negativeunit
- the time unit for the minimum age; may not be nullprotected void storeMimeType(BinaryValue source, String mimeType) throws BinaryStoreException
AbstractBinaryStore
storeMimeType
in class AbstractBinaryStore
source
- a non-null
BinaryValue
mimeType
- a non-empty String
BinaryStoreException
- if there's a problem accessing the binary storeprotected String getStoredMimeType(BinaryValue source) throws BinaryStoreException
AbstractBinaryStore
getStoredMimeType
in class AbstractBinaryStore
source
- a non-null
BinaryValue
String
if a stored mimetype exists, or null
if such a value doesn't exist yet.BinaryStoreException
- if there's a problem accessing the binary store or if the binary value cannot be found in the
storepublic void storeExtractedText(BinaryValue source, String extractedText) throws BinaryStoreException
AbstractBinaryStore
storeExtractedText
in class AbstractBinaryStore
source
- a non-null
BinaryValue
instance from which the text was extractedextractedText
- a non-null
and non-blank
string representing the extracted textBinaryStoreException
- if the operation fails or if the extracted text cannot be stored for the given binary value
(regardless of the reason)public String getExtractedText(BinaryValue source) throws BinaryStoreException
AbstractBinaryStore
null
if such text hasn't been stored previously (but the binary
value can be found in the store)getExtractedText
in class AbstractBinaryStore
source
- a non-null
BinaryValue
instance from which the text was extractedString
representing the extracted text, or null
if such text hasn't been stored in this store
previously.BinaryStoreException
- if the binary value cannot be found in the store.public Iterable<BinaryKey> getAllBinaryKeys()
BinaryStore
BinaryKey
s only as the iterator is used.public void start()
BinaryStore
start
in interface BinaryStore
start
in class AbstractBinaryStore
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.