com.sun.sgs.impl.kernel.logging
Class TransactionalHandler

java.lang.Object
  extended by java.util.logging.Handler
      extended by com.sun.sgs.impl.kernel.logging.TransactionalHandler
All Implemented Interfaces:
NonDurableTransactionParticipant, TransactionParticipant

public class TransactionalHandler
extends Handler
implements NonDurableTransactionParticipant

A Handler implementation that given a backing Handler, provides transactional semantics for the #publish(LogRecord) method. This class is used by the TransactionAwareLogManager to wrap existing handlers as specificed by the application.

See Also:
TransactionAwareLogManager

Constructor Summary
TransactionalHandler(TransactionProxy proxy, Handler backingHandler)
          Constructs a new TransactionalHandler with the provided proxy for joining transactions a the backing handler for performing the actual logging.
 
Method Summary
 void abort(Transaction txn)
          Removes any buffered records for this transaction and performs no logging.
 void close()
          
 void commit(Transaction txn)
          Removes any buffered records for this transaction and logs all buffered records using the backing Handler.
 void flush()
          
 Handler getBackingHandler()
          Returns the Handler used to publish all buffered LogRecords when a transaction commmits.
 String getEncoding()
          
 ErrorManager getErrorManager()
          
 Filter getFilter()
          
 Formatter getFormatter()
          
 Level getLevel()
          
 String getTypeName()
          Returns the class name of the Handler that this instance wraps.
 boolean isLoggable(LogRecord record)
          
 boolean prepare(Transaction txn)
          Tells the participant to prepare for commiting its state associated with the given transaction.
 void prepareAndCommit(Transaction txn)
          Removes any buffered records for this transaction and logs all buffered records using the backing Handler.
 void publish(LogRecord record)
          Joins the current transaction and buffers the provided record for later publication until transaction commit time.
 void reportError(String msg, Exception ex, int code)
          
 void setEncoding(String encoding)
          
 void setErrorManager(ErrorManager em)
          
 void setFilter(Filter newFilter)
          
 void setFormatter(Formatter newFormatter)
          
 void setLevel(Level newLevel)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionalHandler

TransactionalHandler(TransactionProxy proxy,
                     Handler backingHandler)
Constructs a new TransactionalHandler with the provided proxy for joining transactions a the backing handler for performing the actual logging.

Parameters:
proxy - the proxy used to join transactions
backingHandler - the handler used to perform the actual logging at commit time
Throws:
NullPointerException - if the backingHandler or proxy is null.
Method Detail

abort

public void abort(Transaction txn)
Removes any buffered records for this transaction and performs no logging.

Specified by:
abort in interface TransactionParticipant
Parameters:
txn - the failed transaction that in the past performed some logging operation

close

public void close()

Specified by:
close in class Handler

commit

public void commit(Transaction txn)
Removes any buffered records for this transaction and logs all buffered records using the backing Handler.

Specified by:
commit in interface TransactionParticipant
Parameters:
txn - the successful transaction that in the past performed some logging operation

flush

public void flush()

Specified by:
flush in class Handler

getBackingHandler

public Handler getBackingHandler()
Returns the Handler used to publish all buffered LogRecords when a transaction commmits.

Returns:
the backing handler used for actual record publication

getEncoding

public String getEncoding()

Overrides:
getEncoding in class Handler

getErrorManager

public ErrorManager getErrorManager()

Overrides:
getErrorManager in class Handler

getFilter

public Filter getFilter()

Overrides:
getFilter in class Handler

getFormatter

public Formatter getFormatter()

Overrides:
getFormatter in class Handler

getLevel

public Level getLevel()

Overrides:
getLevel in class Handler

getTypeName

public String getTypeName()
Returns the class name of the Handler that this instance wraps.

Specified by:
getTypeName in interface TransactionParticipant
Returns:
the class name of the wrapped Handler

isLoggable

public boolean isLoggable(LogRecord record)

Overrides:
isLoggable in class Handler

prepare

public boolean prepare(Transaction txn)
Tells the participant to prepare for commiting its state associated with the given transaction. This method returns a boolean flag stating whether the prepared state is read-only, meaning that no external state is modified by this participant. If this method returns true, then neither commit nor abort will be called.

If this method throws an exception, then the preparation failed, and the transaction will be aborted. If this method completes successfully, then the participant is required to be able to commit the transaction without failure. This participant always returns false.

Specified by:
prepare in interface TransactionParticipant
Parameters:
txn - the Transaction object
Returns:
false

prepareAndCommit

public void prepareAndCommit(Transaction txn)
Removes any buffered records for this transaction and logs all buffered records using the backing Handler.

Specified by:
prepareAndCommit in interface TransactionParticipant
Parameters:
txn - the successful transaction that in the past performed some logging operation

publish

public void publish(LogRecord record)
Joins the current transaction and buffers the provided record for later publication until transaction commit time.

Specified by:
publish in class Handler
Parameters:
record - the record to be buffer and later publication upon transaction success.

reportError

public void reportError(String msg,
                        Exception ex,
                        int code)

Overrides:
reportError in class Handler

setEncoding

public void setEncoding(String encoding)
                 throws UnsupportedEncodingException

Overrides:
setEncoding in class Handler
Throws:
UnsupportedEncodingException

setErrorManager

public void setErrorManager(ErrorManager em)

Overrides:
setErrorManager in class Handler

setFilter

public void setFilter(Filter newFilter)

Overrides:
setFilter in class Handler

setFormatter

public void setFormatter(Formatter newFormatter)

Overrides:
setFormatter in class Handler

setLevel

public void setLevel(Level newLevel)

Overrides:
setLevel in class Handler

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved