org.infinispan.distribution
Class TransactionLoggerImpl

java.lang.Object
  extended by org.infinispan.distribution.TransactionLoggerImpl
All Implemented Interfaces:
RemoteTransactionLogger, TransactionLogger

public class TransactionLoggerImpl
extends Object
implements TransactionLogger

A transaction logger to log ongoing transactions in an efficient and thread-safe manner while a rehash is going on.

Transaction logs can then be replayed after the state transferred during a rehash has been written.

Since:
4.0
Author:
Manik Surtani, Dan Berindei

Constructor Summary
TransactionLoggerImpl(CommandsFactory cf)
           
 
Method Summary
 void afterCommand(CommitCommand command, TxInvocationContext context)
          Logs a CommitCommand if needed.
 void afterCommand(PrepareCommand command)
          Logs a PrepareCommand if needed.
 void afterCommand(RollbackCommand command)
          Logs a RollbackCommand if needed.
 void afterCommand(WriteCommand command)
          Logs a write command (if needed).
 void beforeCommand(CommitCommand command, TxInvocationContext context)
          Notify the transaction logger before a commit command, potentially blocking.
 void beforeCommand(PrepareCommand command)
          Notify the transaction logger before a prepare command, potentially blocking.
 void beforeCommand(RollbackCommand command)
          Notify the transaction logger before a rollback command, potentially blocking.
 void beforeCommand(WriteCommand command)
          Notify the transaction logger before a write command, potentially blocking.
 void blockNewTransactions()
          Causes new transactions to block when calling beforeCommand().
 List<WriteCommand> drain()
          Drains the transaction log and returns a list of what has been drained.
 List<WriteCommand> drainAndLock()
          Similar to RemoteTransactionLogger.drain() except that relevant locks are acquired so that no more commands are added to the transaction log during this process, and transaction logging is disabled after draining.
 void enable()
          Enables transaction logging
 Collection<PrepareCommand> getPendingPrepares()
          Drains pending prepares.
 boolean isEnabled()
          Checks whether transaction logging is enabled
 boolean shouldDrainWithoutLock()
          Tests whether the drain() method can be called without a lock.
 String toString()
           
 void unblockNewTransactions()
          Unblocks anything blocking on beforeCommand().
 void unlockAndDisable()
          Unlocks and disables the transaction logger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TransactionLoggerImpl

public TransactionLoggerImpl(CommandsFactory cf)
Method Detail

enable

public void enable()
Description copied from interface: TransactionLogger
Enables transaction logging

Specified by:
enable in interface TransactionLogger

drain

public List<WriteCommand> drain()
Description copied from interface: RemoteTransactionLogger
Drains the transaction log and returns a list of what has been drained.

Specified by:
drain in interface RemoteTransactionLogger
Returns:
a list of drained commands

drainAndLock

public List<WriteCommand> drainAndLock()
                                throws InterruptedException
Description copied from interface: RemoteTransactionLogger
Similar to RemoteTransactionLogger.drain() except that relevant locks are acquired so that no more commands are added to the transaction log during this process, and transaction logging is disabled after draining.

Specified by:
drainAndLock in interface RemoteTransactionLogger
Returns:
list of drained commands
Throws:
InterruptedException

unlockAndDisable

public void unlockAndDisable()
Description copied from interface: RemoteTransactionLogger
Unlocks and disables the transaction logger. Should only be called after RemoteTransactionLogger.drainAndLock().

Specified by:
unlockAndDisable in interface RemoteTransactionLogger

afterCommand

public void afterCommand(WriteCommand command)
                  throws InterruptedException
Description copied from interface: TransactionLogger
Logs a write command (if needed).

Specified by:
afterCommand in interface TransactionLogger
Parameters:
command - command to log
Throws:
InterruptedException

afterCommand

public void afterCommand(PrepareCommand command)
                  throws InterruptedException
Description copied from interface: TransactionLogger
Logs a PrepareCommand if needed.

Specified by:
afterCommand in interface TransactionLogger
Parameters:
command - PrepoareCommand to log
Throws:
InterruptedException

afterCommand

public void afterCommand(CommitCommand command,
                         TxInvocationContext context)
                  throws InterruptedException
Description copied from interface: TransactionLogger
Logs a CommitCommand if needed.

Specified by:
afterCommand in interface TransactionLogger
Parameters:
command - CommitCommand to log
Throws:
InterruptedException

afterCommand

public void afterCommand(RollbackCommand command)
Description copied from interface: TransactionLogger
Logs a RollbackCommand if needed.

Specified by:
afterCommand in interface TransactionLogger
Parameters:
command - RollbackCommand to log

beforeCommand

public void beforeCommand(WriteCommand command)
                   throws InterruptedException
Description copied from interface: TransactionLogger
Notify the transaction logger before a write command, potentially blocking.

Specified by:
beforeCommand in interface TransactionLogger
Throws:
InterruptedException

beforeCommand

public void beforeCommand(PrepareCommand command)
                   throws InterruptedException
Description copied from interface: TransactionLogger
Notify the transaction logger before a prepare command, potentially blocking.

Specified by:
beforeCommand in interface TransactionLogger
Throws:
InterruptedException

beforeCommand

public void beforeCommand(CommitCommand command,
                          TxInvocationContext context)
                   throws InterruptedException
Description copied from interface: TransactionLogger
Notify the transaction logger before a commit command, potentially blocking. If transaction logging was not enabled during the prepare command, use the context to extract the list of modifications.

Specified by:
beforeCommand in interface TransactionLogger
Throws:
InterruptedException

beforeCommand

public void beforeCommand(RollbackCommand command)
                   throws InterruptedException
Description copied from interface: TransactionLogger
Notify the transaction logger before a rollback command, potentially blocking.

Specified by:
beforeCommand in interface TransactionLogger
Throws:
InterruptedException

isEnabled

public boolean isEnabled()
Description copied from interface: TransactionLogger
Checks whether transaction logging is enabled

Specified by:
isEnabled in interface TransactionLogger
Returns:
true if enabled, false otherwise.

shouldDrainWithoutLock

public boolean shouldDrainWithoutLock()
Description copied from interface: RemoteTransactionLogger
Tests whether the drain() method can be called without a lock. This is usually true if there is a lot of stuff to drain. After a certain threshold (once there are relatively few entries in the tx log) this will return false after which you should call drainAndLock() to clear the final parts of the log.

Specified by:
shouldDrainWithoutLock in interface RemoteTransactionLogger
Returns:
true if drain() should be called, false if drainAndLock() should be called.

getPendingPrepares

public Collection<PrepareCommand> getPendingPrepares()
Description copied from interface: RemoteTransactionLogger
Drains pending prepares. Note that this should *only* be done after calling drainAndLock() to prevent race conditions

Specified by:
getPendingPrepares in interface RemoteTransactionLogger
Returns:
a list of prepares pending commit or rollback

blockNewTransactions

public void blockNewTransactions()
                          throws InterruptedException
Description copied from interface: TransactionLogger
Causes new transactions to block when calling beforeCommand().

Specified by:
blockNewTransactions in interface TransactionLogger
Throws:
InterruptedException

unblockNewTransactions

public void unblockNewTransactions()
Description copied from interface: TransactionLogger
Unblocks anything blocking on beforeCommand().

Specified by:
unblockNewTransactions in interface TransactionLogger

toString

public String toString()
Overrides:
toString in class Object

-->

Copyright © 2011 JBoss, a division of Red Hat. All Rights Reserved.