org.tranche.logs.activity
Class Activity

java.lang.Object
  extended by org.tranche.logs.activity.Activity
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Activity>

public class Activity
extends java.lang.Object
implements java.lang.Comparable<Activity>, java.io.Serializable

Entry in activity log, which is used to log all requests that impact data held by Tranche server.

Author:
Bryan Smith - bryanesmith@gmail.com, James "Augie" Hill - augman85@gmail.com
See Also:
Serialized Form

Field Summary
static byte ACTION_ANY
          We reserved the four high-order bits for action types so can expand (up to 128 values)
static byte ACTION_DELETE
           
static byte ACTION_REPLACE
           
static byte ACTION_SET
           
static byte ANY
          Mask for all activities, regardless of chunk type (data, meta, etc?) and action.
static byte CHUNK_ANY
          We reserved the four low-order bits for chunk types so can expand (up to 128 values)
static byte CHUNK_DATA
           
static byte CHUNK_META_DATA
           
static byte DELETE_DATA
          Action byte representing a data chunk being deleted.
static byte DELETE_META_DATA
          Action byte representing a meta data chunk being deleted.
static byte REPLACE_META_DATA
          Action byte representing a meta data chunk being replaced.
static byte SET_DATA
          Action byte representing a data chunk being set.
static byte SET_META_DATA
          Action byte representing a meta data chunk being set.
static long UNSET_TIMESTAMP
          The value used when a timestamp is not known.
 
Constructor Summary
Activity(byte[] bytes)
           
Activity(byte action, Signature signature, BigHash hash)
          Used to create an Activity object that will be written to ActivityLog.
Activity(java.io.InputStream in)
           
Activity(long timestamp, byte action, Signature signature, BigHash hash)
          Used to create an Activity object that was read from the ActivityLog.
 
Method Summary
 int compareTo(Activity a)
           
protected  void deserialize(java.io.InputStream in)
           
 boolean equals(java.lang.Object o)
           
 byte getAction()
           
 BigHash getHash()
           
 Signature getSignature()
           
 long getTimestamp()
           
 int hashCode()
           
 boolean isData()
           
static boolean isData(byte actionByte)
           
 boolean isMetaData()
           
static boolean isMetaData(byte actionByte)
           
 boolean isTimestampSet()
           
protected  void serialize(java.io.OutputStream out)
           
 void setTimestamp(long timestamp)
           
 byte[] toByteArray()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNSET_TIMESTAMP

public static final long UNSET_TIMESTAMP

The value used when a timestamp is not known.

A timestamp is not known until it is written. This is because all entries must be in chronological order, so timestamp is recordered when thread is writing.

See Also:
Constant Field Values

CHUNK_ANY

public static final byte CHUNK_ANY
We reserved the four low-order bits for chunk types so can expand (up to 128 values)

See Also:
Constant Field Values

CHUNK_DATA

public static final byte CHUNK_DATA
See Also:
Constant Field Values

CHUNK_META_DATA

public static final byte CHUNK_META_DATA
See Also:
Constant Field Values

ACTION_ANY

public static final byte ACTION_ANY
We reserved the four high-order bits for action types so can expand (up to 128 values)

See Also:
Constant Field Values

ACTION_SET

public static final byte ACTION_SET
See Also:
Constant Field Values

ACTION_DELETE

public static final byte ACTION_DELETE
See Also:
Constant Field Values

ACTION_REPLACE

public static final byte ACTION_REPLACE
See Also:
Constant Field Values

ANY

public static final byte ANY

Mask for all activities, regardless of chunk type (data, meta, etc?) and action.

See Also:
Constant Field Values

SET_DATA

public static final byte SET_DATA

Action byte representing a data chunk being set.

See Also:
Constant Field Values

SET_META_DATA

public static final byte SET_META_DATA

Action byte representing a meta data chunk being set.

See Also:
Constant Field Values

DELETE_DATA

public static final byte DELETE_DATA

Action byte representing a data chunk being deleted.

See Also:
Constant Field Values

DELETE_META_DATA

public static final byte DELETE_META_DATA

Action byte representing a meta data chunk being deleted.

See Also:
Constant Field Values

REPLACE_META_DATA

public static final byte REPLACE_META_DATA

Action byte representing a meta data chunk being replaced.

See Also:
Constant Field Values
Constructor Detail

Activity

public Activity(byte action,
                Signature signature,
                BigHash hash)
         throws java.lang.Exception

Used to create an Activity object that will be written to ActivityLog.

Note that there is no timestamp parameter. When an Activity is written to the activity log, the timestamp will be recorded.

Parameters:
action -
signature -
hash -
Throws:
java.lang.Exception

Activity

public Activity(long timestamp,
                byte action,
                Signature signature,
                BigHash hash)
         throws java.lang.Exception

Used to create an Activity object that was read from the ActivityLog.

In the other constructor, there is no timestamp parameter since the timestamp is unknown until the Activity is recorded. Here, the timestamp is known and must be supplied as a parameter.

Parameters:
timestamp -
action -
signature -
hash -
Throws:
java.lang.Exception

Activity

public Activity(java.io.InputStream in)
         throws java.io.IOException,
                java.security.GeneralSecurityException
Parameters:
in -
Throws:
java.io.IOException
java.security.GeneralSecurityException

Activity

public Activity(byte[] bytes)
         throws java.io.IOException,
                java.security.GeneralSecurityException
Parameters:
bytes -
Throws:
java.io.IOException
java.security.GeneralSecurityException
Method Detail

getTimestamp

public long getTimestamp()
Returns:

setTimestamp

public void setTimestamp(long timestamp)
Parameters:
timestamp -

getAction

public byte getAction()
Returns:

getSignature

public Signature getSignature()
Returns:

getHash

public BigHash getHash()
Returns:

isTimestampSet

public boolean isTimestampSet()
Returns:

isMetaData

public boolean isMetaData()
Returns:

isData

public boolean isData()
Returns:

isMetaData

public static boolean isMetaData(byte actionByte)
Parameters:
actionByte -
Returns:

isData

public static boolean isData(byte actionByte)
Parameters:
actionByte -
Returns:

toByteArray

public byte[] toByteArray()
                   throws java.io.IOException,
                          java.security.cert.CertificateEncodingException
Returns:
Throws:
java.io.IOException
java.security.cert.CertificateEncodingException

serialize

protected void serialize(java.io.OutputStream out)
                  throws java.io.IOException,
                         java.security.cert.CertificateEncodingException
Parameters:
out -
Throws:
java.io.IOException
java.security.cert.CertificateEncodingException

deserialize

protected void deserialize(java.io.InputStream in)
                    throws java.io.IOException,
                           java.security.GeneralSecurityException
Parameters:
in -
Throws:
java.io.IOException
java.security.GeneralSecurityException

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
Returns:

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object
Parameters:
o -
Returns:

compareTo

public int compareTo(Activity a)
Specified by:
compareTo in interface java.lang.Comparable<Activity>
Parameters:
a -
Returns:

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:


This code is free for use both commercially and non-commercially as stated in the project's license