org.infinispan.distribution
Interface TransactionLogger

All Known Implementing Classes:
TransactionLoggerImpl

public interface TransactionLogger

Typically adding a command, the following pattern would be used:

if (txLogger.logIfNeeded(cmd)) { // do NOT proceed with executing this command! } else { // proceed with executing this command as per normal! }

When draining, the following pattern should be used:

List<WriteCommand> c = null; while (txLogger.shouldDrainWithoutLock()) { c = txLogger.drain(); applyCommands(c); } c = txLogger.drainAndLock(); applyCommands(c); applyPendingPrepares(txLogger.getPendingPrepares()); txLogger.unlockAndDisable();

Since:
4.0
Author:
Manik Surtani

Method Summary
 List<WriteCommand> drain()
          Drains the transaction log and returns a list of what has been drained.
 List<WriteCommand> drainAndLock()
          Similar to 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.
 

Method Detail

enable

void enable()
Enables transaction logging


drain

List<WriteCommand> drain()
Drains the transaction log and returns a list of what has been drained.

Returns:
a list of drained commands

drainAndLock

List<WriteCommand> drainAndLock()
Similar to 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.

Returns:
list of drained commands

unlockAndDisable

void unlockAndDisable()
Unlocks and disables the transaction logger. Should only be called after drainAndLock().


logIfNeeded

boolean logIfNeeded(WriteCommand command)
If logging is enabled, will log the command and return true. Otherwise, will just return false.

Parameters:
command - command to log
Returns:
true if logged, false otherwise

logIfNeeded

void logIfNeeded(PrepareCommand command)
Logs a PrepareCommand if needed.

Parameters:
command - PrepoareCommand to log

logIfNeeded

void logIfNeeded(CommitCommand command)
Logs a CommitCommand if needed.

Parameters:
command - CommitCommand to log

logIfNeeded

void logIfNeeded(RollbackCommand command)
Logs a RollbackCommand if needed.

Parameters:
command - RollbackCommand to log

logIfNeeded

boolean logIfNeeded(Collection<WriteCommand> commands)
If logging is enabled, will log the commands and return true. Otherwise, will just return false.

Parameters:
commands - commands to log
Returns:
true if logged, false otherwise

isEnabled

boolean isEnabled()
Checks whether transaction logging is enabled

Returns:
true if enabled, false otherwise.

shouldDrainWithoutLock

boolean shouldDrainWithoutLock()
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.

Returns:
true if drain() should be called, false if drainAndLock() should be called.

getPendingPrepares

Collection<PrepareCommand> getPendingPrepares()
Drains pending prepares. Note that this should *only* be done after calling drainAndLock() to prevent race conditions

Returns:
a list of prepares pending commit or rollback

Google Analytics

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