gzz.mediaserver
Class SimpleMediaserver

java.lang.Object
  |
  +--gzz.mediaserver.SimpleMediaserver
All Implemented Interfaces:
Mediaserver

public class SimpleMediaserver
extends java.lang.Object
implements Mediaserver

A mediaserver capable of retrieving and adding data. This is a combination of a Storer and an IDSpace. Unlike a Storer, a Mediaserver does not allow storing data under arbitrary IDs; rather, when adding a new datum, a new ID is assigned to it.


Nested Class Summary
 
Nested classes inherited from class gzz.mediaserver.Mediaserver
Mediaserver.Id, Mediaserver.InvalidID
 
Field Summary
static boolean dbg
           
 
Constructor Summary
SimpleMediaserver(Storer store)
           
SimpleMediaserver(Storer store, IDSpace idspace, long flags)
           
 
Method Summary
 Mediaserver.Id addDatum(byte[] data, java.util.Collection headerLines, Mediaserver.Id assocId, boolean addDefaultHeaders)
          Add a new datum, explicitly giving a collection of header lines.
 Mediaserver.Id addDatum(byte[] data, java.lang.String contentType)
          Add a new datum, creating a new ID for it.
 Mediaserver.Id addDatum(byte[] data, java.lang.String contentType, Mediaserver.Id assocId)
          Add a new datum, creating a new ID for it.
protected  void blockAdded(Mediaserver.Id id)
          Called when a new block is added; checks if it's a pointer changing a pointer set.
 void cache(MediaserverBlock b)
          Cache a mediaserver block.
 void expungeDatum(Mediaserver.Id id)
          Permanently remove a block.
 MediaserverBlock getDatum(Mediaserver.Id id)
          Get the datum corresponding to the given id.
 java.util.Set getDiffsFrom(Mediaserver.Id id)
           
 java.util.Set getDiffsTo(Mediaserver.Id id)
           
 java.util.Set getIDs()
          Get a set of the IDs of all entries in the Mediaserver database.
 Mediaserver.Id getPointer(java.lang.String s)
          (Kludge) Get a String-identified pointer local to this mediaserver.
 java.util.Set getPointers()
          (Kludge) Get the names of all String-identified pointers local to this mediaserver.
 PointerSet getPointerSet(java.lang.String s)
          Get the pointer set for a specific pointer.
 java.lang.String getPoolName()
          Get the name of the pool this mediaserver stores.
protected  java.util.Set readIdSet(java.lang.String key)
           
 void setPointer(java.lang.String s, Mediaserver.Id id)
          (Kludge) Set a String-identified pointer local to this mediaserver.
 void setPointer(java.lang.String s, Mediaserver.Id id, Mediaserver.Id obsolete)
           
 void setPointer(java.lang.String s, Mediaserver.Id id, java.util.Set obsoletes)
           
 void setPoolName(java.lang.String name)
          Set the name of the pool this mediaserver stores.
 void storeDatum(Mediaserver.Id id, byte[] data)
          Store an existing datum under a given ID.
 void uncache(MediaserverBlock b)
          Uncache a mediaserver block.
protected  void writeIdSet(java.lang.String key, java.util.Set s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbg

public static boolean dbg
Constructor Detail

SimpleMediaserver

public SimpleMediaserver(Storer store,
                         IDSpace idspace,
                         long flags)

SimpleMediaserver

public SimpleMediaserver(Storer store)
Method Detail

getIDs

public java.util.Set getIDs()
                     throws java.io.IOException
Description copied from interface: Mediaserver
Get a set of the IDs of all entries in the Mediaserver database. Used in synchronization and pointer tracking.

Specified by:
getIDs in interface Mediaserver
java.io.IOException

getDatum

public MediaserverBlock getDatum(Mediaserver.Id id)
                          throws java.io.IOException
Description copied from interface: Mediaserver
Get the datum corresponding to the given id.

Specified by:
getDatum in interface Mediaserver
java.io.IOException

addDatum

public Mediaserver.Id addDatum(byte[] data,
                               java.lang.String contentType,
                               Mediaserver.Id assocId)
                        throws java.io.IOException
Description copied from interface: Mediaserver
Add a new datum, creating a new ID for it. The new datum is associated with an existing id. (For example, the existing Id might be the previous version of the datum; the effect is that the new datum is stored in the same pool as assocId.)

Specified by:
addDatum in interface Mediaserver
Returns:
The key of the new datum.
java.io.IOException

addDatum

public Mediaserver.Id addDatum(byte[] data,
                               java.lang.String contentType)
                        throws java.io.IOException
Description copied from interface: Mediaserver
Add a new datum, creating a new ID for it.

Specified by:
addDatum in interface Mediaserver
Returns:
The key of the new datum.
java.io.IOException

addDatum

public Mediaserver.Id addDatum(byte[] data,
                               java.util.Collection headerLines,
                               Mediaserver.Id assocId,
                               boolean addDefaultHeaders)
                        throws java.io.IOException
Description copied from interface: Mediaserver
Add a new datum, explicitly giving a collection of header lines.

Specified by:
addDatum in interface Mediaserver
Parameters:
assocId - May be null.
addDefaultHeaders - Whether to also add the default header lines: "Content-Transfer-Encoding: binary", "X-Injector: ...", and "Date: ...".
java.io.IOException

storeDatum

public void storeDatum(Mediaserver.Id id,
                       byte[] data)
                throws java.io.IOException
Description copied from interface: Mediaserver
Store an existing datum under a given ID.

Specified by:
storeDatum in interface Mediaserver
Parameters:
data - the pure data block obtained from another mediaserver, containing all header information etc.
java.io.IOException

expungeDatum

public void expungeDatum(Mediaserver.Id id)
                  throws java.io.IOException
Description copied from interface: Mediaserver
Permanently remove a block.

Specified by:
expungeDatum in interface Mediaserver
java.io.IOException

getPointerSet

public PointerSet getPointerSet(java.lang.String s)
                         throws java.io.IOException
Get the pointer set for a specific pointer. XXX performance

Specified by:
getPointerSet in interface Mediaserver
Parameters:
s - The ID of the pointer whose pointer set we want to retrieve.
java.io.IOException

cache

public void cache(MediaserverBlock b)
Description copied from interface: Mediaserver
Cache a mediaserver block. The block must be from this mediaserver. This operation doesn't need to do anything, if this mediaserver does not support caching.

Specified by:
cache in interface Mediaserver

uncache

public void uncache(MediaserverBlock b)
Description copied from interface: Mediaserver
Uncache a mediaserver block. The block must be from this mediaserver. This operation doesn't need to do anything, if this mediaserver does not support caching. If the block wasn't in the cache, this should not issue an error message.

Specified by:
uncache in interface Mediaserver

setPointer

public void setPointer(java.lang.String s,
                       Mediaserver.Id id)
                throws java.io.IOException
Description copied from interface: Mediaserver
(Kludge) Set a String-identified pointer local to this mediaserver. A pointer points to an ID. That way, the mediaserver can be used somewhat like a file system, in that there are references that can be updated. The system isn't very powerful, though, and needs to be rethought sometime soon.

XXX THIS EXPLANATION IS OUTDATED! Explain the new pointer system!

Specified by:
setPointer in interface Mediaserver
java.io.IOException

setPointer

public void setPointer(java.lang.String s,
                       Mediaserver.Id id,
                       Mediaserver.Id obsolete)
                throws java.io.IOException
Specified by:
setPointer in interface Mediaserver
java.io.IOException

setPointer

public void setPointer(java.lang.String s,
                       Mediaserver.Id id,
                       java.util.Set obsoletes)
                throws java.io.IOException
java.io.IOException

getPointer

public Mediaserver.Id getPointer(java.lang.String s)
                          throws java.io.IOException
Description copied from interface: Mediaserver
(Kludge) Get a String-identified pointer local to this mediaserver. null if the pointer is not yet set.

Specified by:
getPointer in interface Mediaserver
java.io.IOException
See Also:
setPointer

getPointers

public java.util.Set getPointers()
                          throws java.io.IOException
Description copied from interface: Mediaserver
(Kludge) Get the names of all String-identified pointers local to this mediaserver. Needed for synching.

Specified by:
getPointers in interface Mediaserver
java.io.IOException
See Also:

blockAdded

protected void blockAdded(Mediaserver.Id id)
                   throws java.io.IOException
Called when a new block is added; checks if it's a pointer changing a pointer set. XXX performance

java.io.IOException

readIdSet

protected java.util.Set readIdSet(java.lang.String key)
                           throws java.io.IOException
java.io.IOException

writeIdSet

protected void writeIdSet(java.lang.String key,
                          java.util.Set s)
                   throws java.io.IOException
java.io.IOException

getDiffsFrom

public java.util.Set getDiffsFrom(Mediaserver.Id id)
                           throws java.io.IOException
Specified by:
getDiffsFrom in interface Mediaserver
java.io.IOException

getDiffsTo

public java.util.Set getDiffsTo(Mediaserver.Id id)
                         throws java.io.IOException
Specified by:
getDiffsTo in interface Mediaserver
java.io.IOException

getPoolName

public java.lang.String getPoolName()
                             throws java.io.IOException
Description copied from interface: Mediaserver
Get the name of the pool this mediaserver stores.

Specified by:
getPoolName in interface Mediaserver
java.io.IOException

setPoolName

public void setPoolName(java.lang.String name)
                 throws java.io.IOException
Description copied from interface: Mediaserver
Set the name of the pool this mediaserver stores.

Specified by:
setPoolName in interface Mediaserver
java.io.IOException