org.apache.flume.channel
Class BasicTransactionSemantics

java.lang.Object
  extended by org.apache.flume.channel.BasicTransactionSemantics
All Implemented Interfaces:
Transaction

public abstract class BasicTransactionSemantics
extends Object
implements Transaction

An implementation of basic Transaction semantics designed to work in concert with BasicChannelSemantics to simplify creation of robust Channel implementations. This class ensures that each transaction implementation method is called only while the transaction is in the correct state for that method, and only by the thread that created the transaction. Nested calls to begin() and close() are supported as long as they are balanced.

Subclasses need only implement doPut, doTake, doCommit, and doRollback, and the developer can rest assured that those methods are called only after transaction state preconditions have been properly met. doBegin and doClose may also be implemented if there is work to be done at those points.

All InterruptedException exceptions thrown from the implementations of the doXXX methods are automatically wrapped to become ChannelExceptions, but only after restoring the interrupted status of the thread so that any subsequent blocking method calls will themselves throw InterruptedException rather than blocking. The exception to this rule is doTake, which simply returns null instead of wrapping and propagating the InterruptedException, though it still first restores the interrupted status of the thread.


Nested Class Summary
protected static class BasicTransactionSemantics.State
           The state of the Transaction to which it belongs.
 
Nested classes/interfaces inherited from interface org.apache.flume.Transaction
Transaction.TransactionState
 
Constructor Summary
protected BasicTransactionSemantics()
           
 
Method Summary
 void begin()
          Starts a transaction boundary for the current channel operation.
 void close()
          Ends a transaction boundary for the current channel operation.
 void commit()
          Indicates that the transaction can be successfully committed.
protected  void doBegin()
           
protected  void doClose()
           
protected abstract  void doCommit()
           
protected abstract  void doPut(Event event)
           
protected abstract  void doRollback()
           
protected abstract  Event doTake()
           
protected  BasicTransactionSemantics.State getState()
           
protected  void put(Event event)
           The method to which BasicChannelSemantics delegates calls to put.
 void rollback()
          Indicates that the transaction can must be aborted.
protected  Event take()
           The method to which BasicChannelSemantics delegates calls to take.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicTransactionSemantics

protected BasicTransactionSemantics()
Method Detail

doBegin

protected void doBegin()
                throws InterruptedException
Throws:
InterruptedException

doPut

protected abstract void doPut(Event event)
                       throws InterruptedException
Throws:
InterruptedException

doTake

protected abstract Event doTake()
                         throws InterruptedException
Throws:
InterruptedException

doCommit

protected abstract void doCommit()
                          throws InterruptedException
Throws:
InterruptedException

doRollback

protected abstract void doRollback()
                            throws InterruptedException
Throws:
InterruptedException

doClose

protected void doClose()

put

protected void put(Event event)

The method to which BasicChannelSemantics delegates calls to put.


take

protected Event take()

The method to which BasicChannelSemantics delegates calls to take.


getState

protected BasicTransactionSemantics.State getState()
Returns:
the current state of the transaction

begin

public void begin()
Description copied from interface: Transaction

Starts a transaction boundary for the current channel operation. If a transaction is already in progress, this method will join that transaction using reference counting.

Note: For every invocation of this method there must be a corresponding invocation of Transaction.close() method. Failure to ensure this can lead to dangling transactions and unpredictable results.

Specified by:
begin in interface Transaction

commit

public void commit()
Description copied from interface: Transaction
Indicates that the transaction can be successfully committed. It is required that a transaction be in progress when this method is invoked.

Specified by:
commit in interface Transaction

rollback

public void rollback()
Description copied from interface: Transaction
Indicates that the transaction can must be aborted. It is required that a transaction be in progress when this method is invoked.

Specified by:
rollback in interface Transaction

close

public void close()
Description copied from interface: Transaction

Ends a transaction boundary for the current channel operation. If a transaction is already in progress, this method will join that transaction using reference counting. The transaction is completed only if there are no more references left for this transaction.

Note: For every invocation of this method there must be a corresponding invocation of Transaction.begin() method. Failure to ensure this can lead to dangling transactions and unpredictable results.

Specified by:
close in interface Transaction

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009-2013 Apache Software Foundation. All Rights Reserved.