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

Constructor Summary
TransactionLoggerImpl(CommandsFactory cf)
           
 
Method Summary
 void blockNewTransactions()
          Causes new transactions to block when testing isEnabled().
 List<WriteCommand> drain()
          Drains the transaction log and returns a list of what has been drained.
 List<WriteCommand> drainAndLock(Address lockedFor)
          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
 void logIfNeeded(CommitCommand command, TxInvocationContext context)
          Logs a CommitCommand if needed.
 void logIfNeeded(PrepareCommand command)
          Logs a PrepareCommand if needed.
 void logIfNeeded(RollbackCommand command)
          Logs a RollbackCommand if needed.
 boolean logIfNeeded(WriteCommand command)
          If logging is enabled, will log the command and return true.
 void logModificationsIfNeeded(CommitCommand commit, TxInvocationContext context)
          A mechanism for commit commands to register modifications instead of a prepare.
 boolean shouldDrainWithoutLock()
          Tests whether the drain() method can be called without a lock.
 String toString()
           
 void unblockNewTransactions()
          Unblocks anything blocking on isEnabled().
 void unlockAndDisable(Address lockedFor)
          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(Address lockedFor)
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

unlockAndDisable

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

Specified by:
unlockAndDisable in interface RemoteTransactionLogger

logIfNeeded

public boolean logIfNeeded(WriteCommand command)
Description copied from interface: TransactionLogger
If logging is enabled, will log the command and return true. Otherwise, will just return false.

Specified by:
logIfNeeded in interface TransactionLogger
Parameters:
command - command to log
Returns:
true if logged, false otherwise

logIfNeeded

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

Specified by:
logIfNeeded in interface TransactionLogger
Parameters:
command - PrepoareCommand to log

logModificationsIfNeeded

public void logModificationsIfNeeded(CommitCommand commit,
                                     TxInvocationContext context)
Description copied from interface: TransactionLogger
A mechanism for commit commands to register modifications instead of a prepare. Used for when transaction logging was disabled during prepare, but was enabled before commit.

Specified by:
logModificationsIfNeeded in interface TransactionLogger
Parameters:
commit - commit command
context - context from which to extract modification list

logIfNeeded

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

Specified by:
logIfNeeded in interface TransactionLogger
Parameters:
command - CommitCommand to log

logIfNeeded

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

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

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()
Description copied from interface: TransactionLogger
Causes new transactions to block when testing isEnabled().

Specified by:
blockNewTransactions in interface TransactionLogger

unblockNewTransactions

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

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.