com.binaryfantasy.murq
Class MurqSource

java.lang.Object
  extended by com.binaryfantasy.murq.MurqSource
All Implemented Interfaces:
ISource

public final class MurqSource
extends Object
implements ISource

An ISource wrapper that manages the raw interaction with the persistance layer. Functions performed by this class include:

FOR INTERNAL USE ONLY.

Author:
Bill Weiss

Method Summary
 void add(ISource src)
           
 void add(ISource src, String password)
           
 void addSourceListener(ISourceListener listener)
          Adds a listener to be notified of SourceEvents.
 void addSourceListener(ISourceListener listener, Executor executor)
          Adds a listener to be notified of SourceEvents using the specified Executor.
 void close()
          Called when a source is no longer to be used and provides a chance for clean up and release of resources.
 IContent get(SourceKey key)
          Returns the content associated with the specified key, or null if no content is found.
 ContentDirectory getDirectory()
           
 String getId()
          Returns the unique identifier for the raw ISource.
 ContentIndex getIndex()
           
 InputStream getInputStream(String key)
          Returns a stream to read the content specified by the key, or null if no content is associated with the key.
static MurqSource getInstance(ISource source)
          Returns a MurqSource used to interact with the unencrypted source.
static MurqSource getInstance(ISource src, String password)
          Returns a MurqSource used to interact with the source.
 Set<String> getKeys()
          Returns a Set of all current keys in this source, or an empty Set if there are none.
 com.binaryfantasy.murq.Links getLinks()
          Returns the Links used to manage content links for the ISource.
 ReentrantReadWriteLock getLock()
           
 OutputStream getOutputStream(String key)
          Returns a stream to write the content associated with the key.
 ISourceIO getSourceIO()
           
 void put(IContent content, boolean force, boolean index)
          Persists the specified content, ignoring any possible concurrent modification issues if force is true.
 int read(SourceKey key, OutputStream out)
          Reads the default binary data associated with the key and writes it to the specified out.
 boolean remove(SourceKey key)
          Removes the content specified by the key.
 boolean remove(String key)
          Returns true if the content mapped to the provided key was removed, false if no content is associated with the key.
 void removeSourceListener(ISourceListener listener)
          Removes a listener from being notified of SourceEvents.
 int write(IBinaryContent content, InputStream in, boolean force, boolean index)
          Persists the specified binary data from the in along with the metadata describing it in the content, ignoring any possible concurrent modification issues if force is true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static MurqSource getInstance(ISource source)
Returns a MurqSource used to interact with the unencrypted source. If source is an instance of MurqSource, it will simply be returned.

Parameters:
source - the raw ISource to be used.
Returns:
a MurqSource used to interact with the unencrypted source.
Throws:
InvalidPasswordException - if source is encrypted.

getInstance

public static MurqSource getInstance(ISource src,
                                     String password)
Returns a MurqSource used to interact with the source. If source is an instance of MurqSource, it will simply be returned.

Parameters:
src - the raw ISource to be used.
password - the password needed to decrypt the source, or null if the source is not encrypted.
Returns:
a MurqSource used to interact with the source.
Throws:
InvalidPasswordException - if password is not valid.

addSourceListener

public void addSourceListener(ISourceListener listener)
Adds a listener to be notified of SourceEvents.

Parameters:
listener - the listener to be notified of SourceEvents.

addSourceListener

public void addSourceListener(ISourceListener listener,
                              Executor executor)
Adds a listener to be notified of SourceEvents using the specified Executor.

Parameters:
listener - the listener to be notified of SourceEvents.
executor - the Executor used to fire events.

removeSourceListener

public void removeSourceListener(ISourceListener listener)
Removes a listener from being notified of SourceEvents.

Parameters:
listener - the listener to be removed from being notified of SourceEvents.

getId

public String getId()
Returns the unique identifier for the raw ISource.

Returns:
the unique identifier for the raw ISource.

getLinks

public com.binaryfantasy.murq.Links getLinks()
Returns the Links used to manage content links for the ISource.

Returns:
the Links used to manage content links for the ISource.

getSourceIO

public ISourceIO getSourceIO()

getIndex

public ContentIndex getIndex()

getDirectory

public ContentDirectory getDirectory()

getLock

public ReentrantReadWriteLock getLock()

getKeys

public Set<String> getKeys()
Description copied from interface: ISource
Returns a Set of all current keys in this source, or an empty Set if there are none.

Specified by:
getKeys in interface ISource
Returns:
a Set of all current keys in this source, or an empty Set if there are none.

remove

public boolean remove(SourceKey key)
Removes the content specified by the key.

Parameters:
key - key associated with the content to be removed.
Returns:
true if successful, false otherwise.

remove

public boolean remove(String key)
Description copied from interface: ISource
Returns true if the content mapped to the provided key was removed, false if no content is associated with the key.

Specified by:
remove in interface ISource
Parameters:
key - unique value associated with the content.
Returns:
true if the content mapped to the provided key was removed, false if no content is associated with the key.

get

public IContent get(SourceKey key)
Returns the content associated with the specified key, or null if no content is found.

Parameters:
key - key associated with the content to be returned.
Returns:
the content associated with the specified key, or null if no content is found.

read

public int read(SourceKey key,
                OutputStream out)
Reads the default binary data associated with the key and writes it to the specified out.

Parameters:
key - the key associated with the binary data to be read.
out - destination of the read binary data.
Returns:
number of bytes read, or -1 if none.

getInputStream

public InputStream getInputStream(String key)
Description copied from interface: ISource
Returns a stream to read the content specified by the key, or null if no content is associated with the key.

Specified by:
getInputStream in interface ISource
Parameters:
key - unique value associated with the content.
Returns:
a stream to read the content specified by the key, or null if no content is associated with the key.

put

public void put(IContent content,
                boolean force,
                boolean index)
Persists the specified content, ignoring any possible concurrent modification issues if force is true.

Content is considered to be new if IContent.getContentId() returns null. In this case, a unique id will be set, both in the persisted copy and the content passed in. New content also has it's creationDate set.

All content, new or updated, has it's lastModified date updated.

Parameters:
content - the content to be persisted.
force - set to true to ignore concurent modification checks.
index - set to false if object should not be indexed, true otherwise.
Throws:
ConcurrentModificationException - if force is false and content already exists and is an older version than the one already persisted.

write

public int write(IBinaryContent content,
                 InputStream in,
                 boolean force,
                 boolean index)
Persists the specified binary data from the in along with the metadata describing it in the content, ignoring any possible concurrent modification issues if force is true.

Parameters:
content - the metadata content describing the binary data.
in - binary data to read and persist.
force - set to true to ignore concurent modification checks.
index - set to false if metadata should not be indexed.
Throws:
ConcurrentModificationException - if force is false and content already exists and is an older version than the one already persisted.

getOutputStream

public OutputStream getOutputStream(String key)
Description copied from interface: ISource
Returns a stream to write the content associated with the key.

Specified by:
getOutputStream in interface ISource
Parameters:
key - unique value associated with the content.
Returns:
a stream to write the content associated with the key.

close

public void close()
Description copied from interface: ISource
Called when a source is no longer to be used and provides a chance for clean up and release of resources.

Specified by:
close in interface ISource

add

public void add(ISource src)

add

public void add(ISource src,
                String password)


Copyright (c) 2000-2006, BinaryFantasy.com