QJCC homepage

biz.chitec.quarterback.gjsa
Class TransactionLogger

java.lang.Object
  extended bybiz.chitec.quarterback.util.Logger
      extended bybiz.chitec.quarterback.gjsa.TransactionLogger

public class TransactionLogger
extends Logger

Logger with history. TransactionLogger stores its logged objects. Receivers get the objects together with a counter and can therefore store themselves which objects have been received and which not.

With this information, a TransactionLoggingReceiver can connect with its last received number. The transaction logger then retransmits all objects that have been logged between that last object and now. It takes care for right order and that no object is missed.

TransactionLogger needs a database to store the logged objects in. To do this, it needs JDBC and the GJSA object parsers.

The logger needs a database and a table in it which looks like this (MySQL syntax):

CREATE TABLE translogtable (
nr int NOT NULL default '0',
inserted timestamp NOT NULL,
content blob NOT NULL,
PRIMARY KEY (nr)
);
Each TransactionLogger used in a program needs its own table!

Version:
$Id: 2bde6d3ec9e0b55d32a3c6fcff934e5acdaeb652 $
Author:
Dirk Hillbrecht 1997-1999, chitec/Dirk Hillbrecht 2000,2001,2002. Distributed under the terms of the GNU LGPL.

Nested Class Summary
 
Nested classes inherited from class biz.chitec.quarterback.util.Logger
Logger.ChainElem
 
Field Summary
private  java.sql.Connection conn
           
private  java.sql.Statement htstmt
          Statement used in handling thread
private  java.lang.String lockname
          The name of the rowlock variable
private  java.lang.String name
          name of the table in the database and of the sequence counter in the sequencertable
 
Fields inherited from class biz.chitec.quarterback.util.Logger
first, handleloophandler, receiverexpr, receivers, sleeping, worked
 
Constructor Summary
TransactionLogger()
          Open without table name and without database connection.
TransactionLogger(java.sql.Connection connx, java.lang.String namex)
          Init with a database connection and a table name.
TransactionLogger(java.lang.String namex)
          Open without database connection (but with the table name).
 
Method Summary
 boolean addReceiver(LoggingReceiver lr, int oldnum)
          Adds a receiver together with its stored last logged-object-counter-value.
protected  void handleLogObject(java.lang.Object o, LoggingReceiver sender, long ts, boolean tosenderonly)
          logging handler.
protected  void handleNewReceiver(LoggingReceiver lr, int oldnum)
          Internally used method for sending older data to new receiver.
 boolean removeReceiver(LoggingReceiver lr, java.lang.Object reference)
          Override super implementation to ignore given reference.
protected  int sendNewToReceiver(java.sql.Statement dbstmt, LoggingReceiver lr, int oldnum)
          sends old data to new receiver.
 void setDBConnection(java.sql.Connection connx)
          Sets or resets the database connection.
 
Methods inherited from class biz.chitec.quarterback.util.Logger
addReceiver, addReceiver, containsReceiver, continueHandleLogObject, doSendInHandleLoop, doSendToReceiver, emergencyRemoveReceiver, handleloop, logObject, logObject, logObject, logObjectToSenderOnly, nothingToHandle, removeReceiver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conn

private java.sql.Connection conn

htstmt

private java.sql.Statement htstmt
Statement used in handling thread


name

private java.lang.String name
name of the table in the database and of the sequence counter in the sequencertable


lockname

private java.lang.String lockname
The name of the rowlock variable

Constructor Detail

TransactionLogger

public TransactionLogger(java.sql.Connection connx,
                         java.lang.String namex)
Init with a database connection and a table name. TransactionLogger opens its own Statement on the Connection object.

Parameters:
connx - Description of the Parameter
namex - Description of the Parameter

TransactionLogger

public TransactionLogger(java.lang.String namex)
Open without database connection (but with the table name). While no database connection is set, logging cannot take place.

Parameters:
namex - Description of the Parameter

TransactionLogger

public TransactionLogger()
Open without table name and without database connection.

Method Detail

setDBConnection

public void setDBConnection(java.sql.Connection connx)
Sets or resets the database connection.

Parameters:
connx - The new dBConnection value

addReceiver

public boolean addReceiver(LoggingReceiver lr,
                           int oldnum)
Adds a receiver together with its stored last logged-object-counter-value. This method does not insert the new receiver immideately in the receivers list. Before this, any older logged objects are sent to it (using the standard sending mechanisms).

Parameters:
lr - The feature to be added to the Receiver attribute
oldnum - The feature to be added to the Receiver attribute

handleNewReceiver

protected void handleNewReceiver(LoggingReceiver lr,
                                 int oldnum)
Internally used method for sending older data to new receiver. This method is always executed in its own thread. It passes the old logged objects to the given client using sendNewToReceiver(). As that method does not cope with newly inserted new logged objects while it is scanning for the old objects, handleNewReceiver operates in two steps: Assuming that new objects are added with lower frequency than sendNewToReceiver() sends its objects, this method neither blocks the whole logger for too long when synchronizing the new receiver with the log, nor does it miss any objects while bringing the new receiver up-to-date.

Parameters:
lr - Description of the Parameter
oldnum - Description of the Parameter

sendNewToReceiver

protected int sendNewToReceiver(java.sql.Statement dbstmt,
                                LoggingReceiver lr,
                                int oldnum)
                         throws java.sql.SQLException
sends old data to new receiver. Called by handleNewReceiver(). Doesn't care about objects that are inserted into the log while it is sending older ones.

Parameters:
dbstmt - Description of the Parameter
lr - Description of the Parameter
oldnum - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.sql.SQLException - Description of the Exception

removeReceiver

public boolean removeReceiver(LoggingReceiver lr,
                              java.lang.Object reference)
Override super implementation to ignore given reference. As TransactionLogger does not know about logical expressions and references, removeReceiver will bail out otherwise as it assumes that conditional and unconditional receiver handling is mixed.

Overrides:
removeReceiver in class Logger
Parameters:
lr -
reference -
Returns:

handleLogObject

protected void handleLogObject(java.lang.Object o,
                               LoggingReceiver sender,
                               long ts,
                               boolean tosenderonly)
logging handler. While passing most of the work to the inherited methods for logging objects, this one has to insert the object into the database table.

Overrides:
handleLogObject in class Logger
Parameters:
o - Description of the Parameter
sender - Description of the Parameter
ts - Description of the Parameter
tosenderonly - Description of the Parameter

QJCC homepage