org.tranche.server.logs
Class LogEntry

java.lang.Object
  extended by org.tranche.server.logs.LogEntry

public class LogEntry
extends java.lang.Object

Handles the complicated work of translating to and from bytes for transmission using a checksum.

Author:
Bryan E. Smith - bryanesmith@gmail.com

Constructor Summary
LogEntry()
           
 
Method Summary
static LogEntry createFromBytes(byte[] data)
          Create a log entry.
 byte getAction()
           
 java.lang.String getClientIP()
          Retrieve the client's IP address as a string.
 BigHash getHash()
          Retrieve BigHash.
 byte[] getSignatureMD5()
          Retrieve MD5 signature.
 long getTimestamp()
          Retrieve log entry timestamp.
 long length()
          Return the length, in bytes, of the entry, including the checksum.
static LogEntry logGetConfiguration(long timestamp, java.lang.String ip)
          Return a new log entry with the current log entry's configuration data.
static LogEntry logGetData(long timestamp, java.lang.String ip, BigHash hash)
          Return a new log entry of the current log entry's data.
static LogEntry logGetMetaData(long timestamp, java.lang.String ip, BigHash hash)
          Return a new log entry of the current log entry's meta data.
static LogEntry logGetNonce(long timestamp, java.lang.String ip)
          Return a new log entry with the current log enty's nonce data.
static LogEntry logSetConfiguration(long timestamp, java.lang.String ip, Signature sig)
          Create a log entry with configuration data.
static LogEntry logSetData(long timestamp, java.lang.String ip, BigHash hash, Signature sig)
          Create a log entry with set data.
static LogEntry logSetMetaData(long timestamp, java.lang.String ip, BigHash hash, Signature sig)
          Create a log entry with meta data.
 byte[] toByteArray()
          Serialized byte array representation of a log entry.
 java.lang.String toString()
          Return simple string representation of log entry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LogEntry

public LogEntry()
Method Detail

createFromBytes

public static LogEntry createFromBytes(byte[] data)
                                throws java.lang.Exception
Create a log entry.

Parameters:
data - An array of bytes without the first long value, number of bytes, attached.
Throws:
java.lang.Exception

length

public long length()
Return the length, in bytes, of the entry, including the checksum.

Returns:

logSetData

public static LogEntry logSetData(long timestamp,
                                  java.lang.String ip,
                                  BigHash hash,
                                  Signature sig)
                           throws java.lang.Exception
Create a log entry with set data.

Parameters:
timestamp -
ip -
hash -
sig -
Returns:
Throws:
java.lang.Exception

logSetMetaData

public static LogEntry logSetMetaData(long timestamp,
                                      java.lang.String ip,
                                      BigHash hash,
                                      Signature sig)
                               throws java.lang.Exception
Create a log entry with meta data.

Parameters:
timestamp -
ip -
hash -
sig -
Returns:
Throws:
java.lang.Exception

logSetConfiguration

public static LogEntry logSetConfiguration(long timestamp,
                                           java.lang.String ip,
                                           Signature sig)
                                    throws java.lang.Exception
Create a log entry with configuration data.

Parameters:
timestamp -
ip -
sig -
Returns:
Throws:
java.lang.Exception

logGetData

public static LogEntry logGetData(long timestamp,
                                  java.lang.String ip,
                                  BigHash hash)
                           throws java.lang.Exception
Return a new log entry of the current log entry's data.

Parameters:
timestamp -
ip -
hash -
Returns:
Throws:
java.lang.Exception

logGetMetaData

public static LogEntry logGetMetaData(long timestamp,
                                      java.lang.String ip,
                                      BigHash hash)
                               throws java.lang.Exception
Return a new log entry of the current log entry's meta data.

Parameters:
timestamp -
ip -
hash -
Returns:
Throws:
java.lang.Exception

logGetConfiguration

public static LogEntry logGetConfiguration(long timestamp,
                                           java.lang.String ip)
                                    throws java.lang.Exception
Return a new log entry with the current log entry's configuration data.

Parameters:
timestamp -
ip -
Returns:
Throws:
java.lang.Exception

logGetNonce

public static LogEntry logGetNonce(long timestamp,
                                   java.lang.String ip)
                            throws java.lang.Exception
Return a new log entry with the current log enty's nonce data.

Parameters:
timestamp -
ip -
Returns:
Throws:
java.lang.Exception

toByteArray

public byte[] toByteArray()
                   throws java.lang.Exception
Serialized byte array representation of a log entry.

Returns:
Throws:
java.lang.Exception

toString

public java.lang.String toString()
Return simple string representation of log entry.

Overrides:
toString in class java.lang.Object
Returns:

getAction

public byte getAction()

getTimestamp

public long getTimestamp()
                  throws java.lang.Exception
Retrieve log entry timestamp.

Returns:
Throws:
java.lang.Exception

getClientIP

public java.lang.String getClientIP()
                             throws java.lang.Exception
Retrieve the client's IP address as a string.

Returns:
Throws:
java.lang.Exception

getHash

public BigHash getHash()
                throws java.lang.Exception
Retrieve BigHash.

Returns:
Throws:
java.lang.Exception

getSignatureMD5

public byte[] getSignatureMD5()
                       throws java.lang.Exception
Retrieve MD5 signature.

Returns:
Throws:
java.lang.Exception


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