edu.washington.biostr.sig.brainj3d.data
Class Data

java.lang.Object
  extended by java.util.Observable
      extended by edu.washington.biostr.sig.brainj3d.data.Data
Direct Known Subclasses:
DataWrapper, ImageData, LabelData, LibraryData, Model3DData, PlainTextData, VolumeData

public abstract class Data
extends Observable

The Data object contains information that is shared between all loaded instances of the data. This acts as the logical place where the single file is available.
When data changes in a way that makes it out of sync with the disk, then it must send an message to its Observers. This is done automatically by setSaved(boolean). It is also important to note that if Data that changes does not setSaved(false), then the system will likely not save the Data. In order to properly cache and manage data, the data expects to be told when it is in use (addReference() and removeReference()). If you are using the DataHandler, you do not need to worry about these calls, but if you use data outside of a DataHandler, then it is important to properly call these methods.

Version:
1.0
Author:
not attributable

Field Summary
protected  AtomicReference<FileGroup> file
           
static String SAVE_STATE_CHANGED
          Send this Object when the state of saved changes.
protected  AtomicBoolean saved
           
 
Constructor Summary
Data()
           
Data(FileGroup file)
           
 
Method Summary
protected  boolean cacheTo(File f)
          Write this Data object out to disk.
abstract  boolean canDiskCache()
          Return true if we can cache this Data or part of it to disk.
protected  void finalize()
           
 Map<String,Object> getDefaultParameters(Set<Tag> metadata)
          Get the default parameters for this Data.
 FileGroup getFile()
           
 Object getLock()
          Get the lock that this data uses to synchronize itself.
abstract  FileType getType()
          Every piece of data has a type.
 boolean hasTime()
          return true if this data varies with time
 boolean isImmutable()
          Find out if this data is immutable.
 boolean isSaved()
           
 boolean isSerialized()
          If the data was cached, return true if it was serialized.
protected  Data readFrom(File f)
          Read the object from the given file using the same format as cacheTo(File).
 void setFile(FileGroup file)
          Set the name for this component.
 void setSaved(boolean save)
          Set the saved state and send a message if it changes.
 boolean sharable()
          If we can put the data in a central cache and reuse it for different users, return true.
 String toString()
           
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SAVE_STATE_CHANGED

public static final String SAVE_STATE_CHANGED
Send this Object when the state of saved changes.

See Also:
Constant Field Values

saved

protected AtomicBoolean saved

file

protected AtomicReference<FileGroup> file
Constructor Detail

Data

public Data()

Data

public Data(FileGroup file)
Method Detail

getType

public abstract FileType getType()
Every piece of data has a type. The type is used to filter out file names, get the decoders and the encoders.

Returns:

getLock

public Object getLock()
Get the lock that this data uses to synchronize itself. It may return null if the data is immutable.

Returns:
by default this.

isSaved

public boolean isSaved()

setSaved

public void setSaved(boolean save)
Set the saved state and send a message if it changes.

Parameters:
save -

isImmutable

public boolean isImmutable()
Find out if this data is immutable.

Returns:
false by default

sharable

public boolean sharable()
If we can put the data in a central cache and reuse it for different users, return true. If it cannot (because it might change) return false.

Returns:
true by default;

canDiskCache

public abstract boolean canDiskCache()
Return true if we can cache this Data or part of it to disk.

Returns:

cacheTo

protected boolean cacheTo(File f)
                   throws IOException
Write this Data object out to disk. The format chosen should take the following things into consideration (most important to least important):
  1. Read speed: it needs to be read and usable ASAP.
  2. Write speed: it should write quickly
  3. Disk size: it should be compact, but not at the expense of read speed
The following things should be considered of no importance to choosing the format (unless they don't impact the above and it is simpler):
It is completely acceptable to just serialize or externalize (preferable) the object. And if you haven't noticed, binary is the way to go (parsing isn't terribly fast and encoding text from binary is also slow).
The default implementation assumes serializability and only works if canDiskCache returns true and this implements Serializable.

Parameters:
f -
Returns:
true if the cache was successful.
Throws:
IOException

readFrom

protected Data readFrom(File f)
                 throws IOException,
                        ClassNotFoundException
Read the object from the given file using the same format as cacheTo(File).

Parameters:
f -
Returns:
this
Throws:
IOException
ClassNotFoundException

isSerialized

public boolean isSerialized()
If the data was cached, return true if it was serialized. This implementation returns true if this object implements serializable

Returns:

getFile

public FileGroup getFile()

setFile

public void setFile(FileGroup file)
Set the name for this component.

Parameters:
name -

toString

public String toString()
Overrides:
toString in class Object

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

getDefaultParameters

public Map<String,Object> getDefaultParameters(Set<Tag> metadata)
Get the default parameters for this Data.

Returns:

hasTime

public boolean hasTime()
return true if this data varies with time

Returns:
false by default


Copyright © 2006 University of Washington. All Rights Reserved.