Skip to content

Commit

Permalink
Possible to use LogExtractor for doing other things than for nioneo
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Aug 27, 2012
1 parent 94c74a4 commit 37144d9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 58 deletions.
Expand Up @@ -348,51 +348,6 @@ private static interface LogEntryCollector
int getIdentifier();
}

private static class KnownIdentifierCollector implements LogEntryCollector
{
private final int identifier;
private LogEntry.Start startEntry;

KnownIdentifierCollector( int identifier )
{
this.identifier = identifier;
}

public int getIdentifier()
{
return identifier;
}

public LogEntry collect( LogEntry entry, LogBuffer target ) throws IOException
{
if ( entry.getIdentifier() == identifier )
{
if ( entry instanceof LogEntry.Start )
{
startEntry = (Start) entry;
}
if ( target != null )
{
LogIoUtils.writeLogEntry( entry, target );
}
return entry;
}
return null;
}

@Override
public boolean hasInFutureQueue()
{
return false;
}

@Override
public LogEntry.Start getLastStartEntry()
{
return startEntry;
}
}

private static class KnownTxIdCollector implements LogEntryCollector
{
private final Map<Integer,List<LogEntry>> transactions = new HashMap<Integer,List<LogEntry>>();
Expand Down Expand Up @@ -546,11 +501,22 @@ public String toString()

public static LogExtractor from( final String storeDir ) throws IOException
{
// 2 is a "magic" first tx :)
return from( storeDir, 2 );
return from( storeDir, NIONEO_COMMAND_FACTORY );
}

public static LogExtractor from( final String storeDir, long startTxId ) throws IOException
{
return from( storeDir, NIONEO_COMMAND_FACTORY, startTxId );
}

public static LogExtractor from( final String storeDir, XaCommandFactory commandFactory ) throws IOException
{
// 2 is a "magic" first tx :)
return from( storeDir, commandFactory, 2 );
}

public static LogExtractor from( final String storeDir, XaCommandFactory commandFactory,
long startTxId ) throws IOException
{
LogLoader loader = new LogLoader()
{
Expand Down Expand Up @@ -623,18 +589,24 @@ public long getLastCommittedTxId()
{
throw new UnsupportedOperationException();
}
};

XaCommandFactory commandFactory = new XaCommandFactory()
{

@Override
public XaCommand readCommand( ReadableByteChannel byteChannel,
ByteBuffer buffer ) throws IOException
public String toString()
{
return Command.readCommand( null, byteChannel, buffer );
return getClass().getSimpleName() + "[" + storeDir + "]";
}
};

return new LogExtractor( new LogPositionCache(), loader, commandFactory, startTxId, Long.MAX_VALUE );
}

public static final XaCommandFactory NIONEO_COMMAND_FACTORY = new XaCommandFactory()
{
@Override
public XaCommand readCommand( ReadableByteChannel byteChannel,
ByteBuffer buffer ) throws IOException
{
return Command.readCommand( null, byteChannel, buffer );
}
};
}
Expand Up @@ -28,12 +28,13 @@ public class CompareTxStreams
{
public static void main( String[] args ) throws IOException
{
LogExtractor extractor1 = null;
LogExtractor extractor2 = null;
compareLogStreams( LogExtractor.from( args[0] ), LogExtractor.from( args[1] ) );
}

protected static void compareLogStreams( LogExtractor extractor1, LogExtractor extractor2 ) throws IOException
{
try
{
extractor1 = LogExtractor.from( args[0] );
extractor2 = LogExtractor.from( args[1] );
boolean branchingDetected = false;
long lastTx = 1;
while ( true )
Expand Down

0 comments on commit 37144d9

Please sign in to comment.