com.continuent.tungsten.replicator.thl.log
Class LogCursorManager

java.lang.Object
  extended by com.continuent.tungsten.replicator.thl.log.LogCursorManager

public class LogCursorManager
extends java.lang.Object

Encapsulates management of connections and their log cursors. Log cursors are a position in a particular log file and can only move in a forward direction. If clients move backward in the log we need to allocated a new cursor.

Author:
Robert Hodges

Constructor Summary
LogCursorManager()
          Create a new log cursor manager.
 
Method Summary
 LogCursor createAndGetLogCursor(LogConnection client, LogFile logFile, long lastSeqno)
          Sets the log file and last accessed sequence number for this thread.
 LogCursor getLogCursor(LogConnection client, long nextSeqno)
          Return a cursor to the log file belonging to this client.
 int getSize()
          Returns the number of cursors currently managed.
 int getTimeoutMillis()
          Returns the timeout for idle cursors.
 void release()
          Releases all cursors.
 void releaseConnection(LogConnection client)
          Releases log cursor for specific thread ID.
 void returnLogCursor(LogCursor logCursor)
          Returns a loaned log cursor.
 void setTimeoutMillis(int timeoutMillis)
          Sets the timeout for idle cursors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LogCursorManager

public LogCursorManager()
                 throws ReplicatorException
Create a new log cursor manager.

Throws:
ReplicatorException
Method Detail

getSize

public int getSize()
Returns the number of cursors currently managed.


getTimeoutMillis

public int getTimeoutMillis()
Returns the timeout for idle cursors.


setTimeoutMillis

public void setTimeoutMillis(int timeoutMillis)
Sets the timeout for idle cursors. This recomputes the timeout.


getLogCursor

public LogCursor getLogCursor(LogConnection client,
                              long nextSeqno)
                       throws ReplicatorException
Return a cursor to the log file belonging to this client. If the next seqno is before the current position, we release the existing file and return null.

Returns:
A cursor. This must be returned using returnLogConnection().
Throws:
ReplicatorException

createAndGetLogCursor

public LogCursor createAndGetLogCursor(LogConnection client,
                                       LogFile logFile,
                                       long lastSeqno)
                                throws ReplicatorException
Sets the log file and last accessed sequence number for this thread. This allows clients to roll over the log cursor and receive it back as a new loaned cursor.

Returns:
A cursor. This must be returned using returnLogConnection().
Throws:
ReplicatorException

returnLogCursor

public void returnLogCursor(LogCursor logCursor)
Returns a loaned log cursor. This must be called on any cursor before asking for it again.

Parameters:
logCursor -

release

public void release()
Releases all cursors. This must be called when terminating to ensure file descriptors are released.


releaseConnection

public void releaseConnection(LogConnection client)
Releases log cursor for specific thread ID.