org.infinispan.distribution
Class TransactionLoggerImpl

java.lang.Object
  extended by org.infinispan.distribution.TransactionLoggerImpl
All Implemented Interfaces:
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()
           
 
Method Summary
 List<WriteCommand> drain()
          Drains the transaction log and returns a list of what has been drained.
 List<WriteCommand> drainAndLock()
          Similar to TransactionLogger.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 logIfNeeded(Collection<WriteCommand> commands)
          If logging is enabled, will log the commands and return true.
 void logIfNeeded(CommitCommand command)
          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.
 boolean shouldDrainWithoutLock()
          Tests whether the drain() method can be called without a lock.
 void unlockAndDisable()
          Unlocks and disables the transaction logger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionLoggerImpl

public TransactionLoggerImpl()
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: TransactionLogger
Drains the transaction log and returns a list of what has been drained.

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

drainAndLock

public List<WriteCommand> drainAndLock()
Description copied from interface: TransactionLogger
Similar to TransactionLogger.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 TransactionLogger
Returns:
list of drained commands

unlockAndDisable

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

Specified by:
unlockAndDisable in interface TransactionLogger

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

logIfNeeded

public void logIfNeeded(CommitCommand command)
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

logIfNeeded

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

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

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: TransactionLogger
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 TransactionLogger
Returns:
true if drain() should be called, false if drainAndLock() should be called.

getPendingPrepares

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

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

Google Analytics

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