|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ccs.beetree.BeeObject
public abstract class BeeObject
A BeeObject is an object that is marshalled and stored in a BeeTree database file. This includes stored blobs, and the other entities required to index them; these count as BeeTree internals and are not documented.
Every BeeObject contains a nestable (ie. re-entrant) mutex. This is used to guard accesses to that part of the BeeObject's state which is package- protected; this state is documented below, and for the most part is either set exactly once when the object is created, or is reserved for the use of the BeeTree.
Experience has shown that BeeObjects are rarely shared among threads. However, where this happens, it is often better to use the BeeObject's mutex explicitly rather than relying on synchronized methods. In particular, relying on synchronized methods is error-prone where a BeeObject calculates its own length; the state may change between the call to obtain the length and that which marshals the (new) state, and if the length of the new state is different from the old then the marshal will fail and mark the BeeTree as corrupt.
BeeTree
Field Summary | |
---|---|
protected Cipher |
cipher
The Cipher object which should be used to encrypt this object. |
protected long |
encodedLength
The encoded length of the object, for informational purposes. |
protected boolean |
isBodiless
Whether this object has no body. |
protected boolean |
isForceDirectDecrypt
Whether the object should always be decrypted directly. |
protected boolean |
isZip
Whether this object should be compressed. |
protected int |
slack
The minimum amount of slack space that should be made available if the object has to be moved. |
Constructor Summary | |
---|---|
BeeObject()
creates a BeeObject, with an invalidated set of attributes. |
Method Summary | |
---|---|
java.lang.String |
getKey()
Return the key for this object - the String used to find
this object within the BeeTree. |
long |
getMarshalledLength()
Returns the marshalled length. |
void |
lock()
Acquire one hold on the BeeObject's nestable mutex. |
abstract void |
marshal(java.io.DataOutputStream dest)
Implement this function to marshal - write as a succession of fields - your object's data onto the supplied stream. |
void |
preMarshal()
Prepare to marshal. |
void |
preUnmarshal()
Prepare to unmarshal. |
void |
setKey(java.lang.String key)
sets the key for this object. |
void |
unlock()
Release one hold on the the mutex obtained by lock . |
abstract void |
unmarshal(java.io.DataInputStream src)
Implement this function to de-serialise your object's properties from the supplied input stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int slack
protected boolean isZip
protected boolean isBodiless
protected Cipher cipher
Cipher
object which should be used to encrypt this object.
Set to null (the default) to have the BeeTree use its own Cipher. Some schemes
require individual objects to have their own Cipher
s, but this
causes significant problems so don't do it unless you really mean it. In
particular:
Cipher
s cannot be updated.
Instead the object must be deleted and re-inserted.
protected transient long encodedLength
protected boolean isForceDirectDecrypt
Cipher
, the BeeTree will usually decrypt it first
and only attempt to unmarshal after the decrypt has succeeded. This means that
a failed decrypt (due to eg. wrong password) will be reported as such,
rather than manifesting as wierd unmarshalling errors whose cause is
far from obvious. If you want to override this in the interests of
efficiency (and risk frightening your users), set this flag to true.
All of this only applies to objects which have their own Cipher
s.
Most don't.
Constructor Detail |
---|
public BeeObject()
Method Detail |
---|
public void lock() throws DeadlockException
BeeTree
, any code which affects the BeeObject's state MUST
gain this lock first. This uses the optional deadlock timeout specified by
BeeTree.setDeadlockTimeoutMillis
.
DeadlockException
public void unlock()
lock
. The
current thread must own the lock.
public void preMarshal() throws java.io.IOException
java.io.IOException
- if the object isn't ready.public void preUnmarshal() throws java.io.IOException
find
the key on entry to the BeeTree routine
would be partial, for next
the key would be null or irrelevant).
Throw either IOException or a suitable RuntimeException if
it isn't ready. The default implementation does nothing.
java.io.IOException
- if the object isn't ready.public java.lang.String getKey()
String
used to find
this object within the BeeTree. The default implementation returns null,
and you must override it.
public void setKey(java.lang.String key)
find / next / prev / match
to furnish the (non-unmarshalled) object with its own key. Called before
unmarshalling. The default implementation does nothing. The key may be set
(to provisional values) several times during searching so this routine should
be fast - do any associated processing during unmarshal instead.
key
- The full, but possibly provisional, key to this object.public abstract void marshal(java.io.DataOutputStream dest) throws java.io.IOException
If you have given a marshalled length, then the stream will throw an IOException if you exceed it, or do not use all of it. If the key is a basic field of your object, rather than being some function of your object's state, then you don't have to marshal it. Do not close the stream. Don't marshal the data members of BeeObject - the BeeTree engine will do that for you; just marshal the members of your subclass. You should synchronize this method when you override it.
dest
- The stream to write onto.
java.io.IOException
- if an error occurs.public abstract void unmarshal(java.io.DataInputStream src) throws java.io.IOException
marshal
either use Java
serialisation or write your own. The data members of BeeObject itself will
have been correctly set up before this function is called. You should
synchronize this method when you override it.
src
- the stream to read from.
java.io.IOException
- if an error occurs.public long getMarshalledLength()
isZip
is true, since the compressed length of
an object depends on its content and cannot be precomputed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |