org.tranche.logs.activity
Class ActivityLog

java.lang.Object
  extended by org.tranche.commons.Debuggable
      extended by org.tranche.logs.activity.ActivityLog

public class ActivityLog
extends org.tranche.commons.Debuggable

Activity log used to log all requests that impact data held by Tranche server.

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

Field Summary
static java.lang.String BACKUP_SUFFIX
           
static java.lang.String DEFAULT_FILE_NAME_ACTIVITIES
           
static java.lang.String DEFAULT_FILE_NAME_SIGNATURES_ENTRIES
           
static java.lang.String DEFAULT_FILE_NAME_SIGNATURES_INDEX
           
 
Constructor Summary
ActivityLog()
          Instantiate an activity log used to log all requests that impact data held by Tranche server.
ActivityLog(java.io.File directoryForLogs)
          Instantiate an activity log used to log all requests that impact data held by Tranche server.
ActivityLog(java.io.File activitiesLogFile, java.io.File signaturesIndexFile, java.io.File signaturesFile)
          Instantiate an activity log used to log all requests that impact data held by Tranche server.
 
Method Summary
 void close()
          Close down the activity log.
 boolean contains(long timestamp, byte action, BigHash hash)
          Performs search to find whether contains an entry representing parameters.
 java.io.File getActivitiesLogFile()
           
 int getActivityCount(long fromTimestamp, long toTimestamp, byte mask)
          Returns count of all activities between timestamps that match mask.
 long getActivityLogEntriesCount()
           
 long getAvgReadTimeInMillis()
          Average time per entry (in milliseconds) spent reading in data.
 long getAvgWriteTimeInMillis()
          Average time per entry(in milliseconds) spent writing out data.
 java.io.File getBackupActivitiesLogFile()
           
 java.io.File getBackupSignaturesFile()
           
 java.io.File getBackupSignaturesIndexFile()
           
 long getLastRecordedTimestamp()
          Returns the last recorded timestamp for activity log.
 java.io.File getSignaturesFile()
           
 java.io.File getSignaturesIndexFile()
           
static void main(java.lang.String[] args)
           
 java.util.List<Activity> read(long fromTimestamp, long toTimestamp, int limit, byte mask)
          Returns all activities between timestamps up until a specified limit that match the supplied mask.
 void write(Activity activity)
          Writes activity to various files.
 
Methods inherited from class org.tranche.commons.Debuggable
debugErr, debugErr, debugOut, isDebug, setDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FILE_NAME_ACTIVITIES

public static final java.lang.String DEFAULT_FILE_NAME_ACTIVITIES
See Also:
Constant Field Values

DEFAULT_FILE_NAME_SIGNATURES_INDEX

public static final java.lang.String DEFAULT_FILE_NAME_SIGNATURES_INDEX
See Also:
Constant Field Values

DEFAULT_FILE_NAME_SIGNATURES_ENTRIES

public static final java.lang.String DEFAULT_FILE_NAME_SIGNATURES_ENTRIES
See Also:
Constant Field Values

BACKUP_SUFFIX

public static final java.lang.String BACKUP_SUFFIX
See Also:
Constant Field Values
Constructor Detail

ActivityLog

public ActivityLog()
            throws java.io.IOException,
                   java.lang.Exception

Instantiate an activity log used to log all requests that impact data held by Tranche server.

This constructor will create log files in the persistent directory using the default file names.

Throws:
java.io.IOException - If log files do not exist and cannot be created or other I/O exception
java.lang.Exception
See Also:
PersistentFileUtil#getPersistentDirectory()

ActivityLog

public ActivityLog(java.io.File directoryForLogs)
            throws java.io.IOException,
                   java.lang.Exception

Instantiate an activity log used to log all requests that impact data held by Tranche server.

This contrustor will create log files in the specified directory using the default file names.

Parameters:
directoryForLogs - Directory
Throws:
java.io.IOException - If log files do not exist and cannot be created or other I/O exception
java.lang.Exception

ActivityLog

public ActivityLog(java.io.File activitiesLogFile,
                   java.io.File signaturesIndexFile,
                   java.io.File signaturesFile)
            throws java.io.IOException,
                   java.lang.Exception

Instantiate an activity log used to log all requests that impact data held by Tranche server.

This constructor uses specified log file locations.

Parameters:
activitiesLogFile -
signaturesIndexFile -
signaturesFile -
Throws:
java.io.IOException - If log files do not exist and cannot be created or other I/O exception
java.lang.Exception
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

write

public void write(Activity activity)
           throws java.io.IOException,
                  java.security.cert.CertificateEncodingException

Writes activity to various files.

Thread safe.

Parameters:
activity -
Throws:
java.io.IOException
java.security.cert.CertificateEncodingException

contains

public boolean contains(long timestamp,
                        byte action,
                        BigHash hash)
                 throws java.io.IOException,
                        java.lang.Exception

Performs search to find whether contains an entry representing parameters.

Parameters:
timestamp -
action -
hash -
Returns:
True if found; false otherwise
Throws:
java.io.IOException
java.lang.Exception

read

public java.util.List<Activity> read(long fromTimestamp,
                                     long toTimestamp,
                                     int limit,
                                     byte mask)
                              throws java.lang.Exception

Returns all activities between timestamps up until a specified limit that match the supplied mask.

Parameters:
fromTimestamp - Starting timestamp (inclusive)
toTimestamp - Ending timestamp (inclusive)
limit - Limit to number of entries to return. Should use Integer.MAX_VALUE if want all entries
mask - Used to match activity bytes. If all the bits in the mask are included in the activity byte, then the activity will be included. For example, if the mask is Activity.ACTION_TYPE_SET, then all logs that have this bit set (set data and set meta data) will be included. However, if Activity.SET_DATA is the mask, then only set data actions will match (since there are two bits set in the mask, making it more restrictive). 0 is least restrictive (restricts nothing) and 0xFF is most restrictive (restricts everything but itself).
Returns:
Throws:
java.lang.Exception

getActivityCount

public int getActivityCount(long fromTimestamp,
                            long toTimestamp,
                            byte mask)
                     throws java.io.IOException,
                            java.lang.Exception

Returns count of all activities between timestamps that match mask.

Parameters:
fromTimestamp - Starting timestamp (inclusive)
toTimestamp - Ending timestamp (inclusive)
mask - Used to match activity bytes. If all the bits in the mask are included in the activity byte, then the activity will be included. For example, if the mask is Activity.ACTION_TYPE_SET, then all logs that have this bit set (set data and set meta data) will be included. However, if Activity.SET_DATA is the mask, then only set data actions will match (since there are two bits set in the mask, making it more restrictive). 0 is least restrictive (restricts nothing) and 0xFF is most restrictive (restricts everything but itself).
Returns:
Throws:
java.io.IOException
java.lang.Exception

getAvgWriteTimeInMillis

public long getAvgWriteTimeInMillis()

Average time per entry(in milliseconds) spent writing out data.

Returns:

getAvgReadTimeInMillis

public long getAvgReadTimeInMillis()

Average time per entry (in milliseconds) spent reading in data.

Returns:

close

public void close()
           throws java.io.IOException

Close down the activity log. Once closed, cannot reopen.

Thread safe.

Throws:
java.io.IOException

getActivitiesLogFile

public java.io.File getActivitiesLogFile()

getSignaturesIndexFile

public java.io.File getSignaturesIndexFile()

getSignaturesFile

public java.io.File getSignaturesFile()

getBackupActivitiesLogFile

public java.io.File getBackupActivitiesLogFile()

getBackupSignaturesIndexFile

public java.io.File getBackupSignaturesIndexFile()

getBackupSignaturesFile

public java.io.File getBackupSignaturesFile()

getActivityLogEntriesCount

public long getActivityLogEntriesCount()

getLastRecordedTimestamp

public long getLastRecordedTimestamp()
                              throws java.io.IOException

Returns the last recorded timestamp for activity log. If not found, returns -1.

Returns:
-1 if no entries; last timestamp otherwise
Throws:
java.io.IOException


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