static TxFilter parseTxFilter( String txFilter ) { if ( txFilter == null ) { return null; } String[] tokens = txFilter.split( "," ); long[][] filters = new long[tokens.length][]; for ( int i = 0; i < tokens.length; i++ ) { String token = tokens[i]; int index = token.lastIndexOf( '-' ); long low, high; if ( index == -1 ) { low = high = Long.parseLong( token ); } else { low = Long.parseLong( token.substring( 0, index ) ); high = Long.parseLong( token.substring( index + 1 ) ); } filters[i] = new long[]{low, high}; } return new TxFilter( filters ); }
if ( txFilter != null ) txFilter.clear();
if ( txFilter != null ) txFilter.clear();
static TxFilter parseTxFilter( String txFilter ) { if ( txFilter == null ) { return null; } String[] tokens = txFilter.split( "," ); long[][] filters = new long[tokens.length][]; for ( int i = 0; i < tokens.length; i++ ) { String token = tokens[i]; int index = token.lastIndexOf( '-' ); long low, high; if ( index == -1 ) { low = high = Long.parseLong( token ); } else { low = Long.parseLong( token.substring( 0, index ) ); high = Long.parseLong( token.substring( index + 1 ) ); } filters[i] = new long[]{low, high}; } return new TxFilter( filters ); }
private static void dumpMerge( Dumper dumper, byte type, ReadableChannel channel, long range, int labelId, TxFilter txFilter, long session, long flush ) throws IOException { long existingBits = channel.getLong(); long newBits = channel.getLong(); if ( txFilter == null || txFilter.contains() ) { dumper.merge( type == TYPE_MERGE_ADD, session, flush, range, labelId, existingBits, newBits ); } }
private static void dumpPrepare( Dumper dumper, byte type, ReadableChannel channel, long range, int labelId, TxFilter txFilter, long session, long flush ) throws IOException { long txId = channel.getLong(); int offset = channel.get(); long nodeId = range * 64 + offset; if ( txFilter == null || txFilter.contains( txId ) ) { // I.e. if the txId this update comes from is within the txFilter dumper.prepare( type == TYPE_PREPARE_ADD, session, flush, txId, nodeId, labelId ); } }
@Test public void shouldParseRangedMultipleTxFilters() { // given LabelScanWriteMonitor.TxFilter txFilter = LabelScanWriteMonitor.parseTxFilter( "123-125,345-567" ); // when/then assertFalse( txFilter.contains( 122 ) ); assertTrue( txFilter.contains( 123 ) ); assertTrue( txFilter.contains( 124 ) ); assertTrue( txFilter.contains( 125 ) ); assertFalse( txFilter.contains( 201 ) ); assertTrue( txFilter.contains( 345 ) ); assertTrue( txFilter.contains( 405 ) ); assertTrue( txFilter.contains( 567 ) ); assertFalse( txFilter.contains( 568 ) ); }
@Test public void shouldParseRangedSingleTxFilter() { // given LabelScanWriteMonitor.TxFilter txFilter = LabelScanWriteMonitor.parseTxFilter( "123-126" ); // when/then assertFalse( txFilter.contains( 122 ) ); assertTrue( txFilter.contains( 123 ) ); assertTrue( txFilter.contains( 124 ) ); assertTrue( txFilter.contains( 125 ) ); assertTrue( txFilter.contains( 126 ) ); assertFalse( txFilter.contains( 127 ) ); }
private static void dumpPrepare( Dumper dumper, byte type, ReadableChannel channel, long range, int labelId, TxFilter txFilter, long session, long flush ) throws IOException { long txId = channel.getLong(); int offset = channel.get(); long nodeId = range * 64 + offset; if ( txFilter == null || txFilter.contains( txId ) ) { // I.e. if the txId this update comes from is within the txFilter dumper.prepare( type == TYPE_PREPARE_ADD, session, flush, txId, nodeId, labelId ); } }
@Test public void shouldParseSimpleMultipleTxFilters() { // given LabelScanWriteMonitor.TxFilter txFilter = LabelScanWriteMonitor.parseTxFilter( "123,146,123456" ); // when/then assertFalse( txFilter.contains( 122 ) ); assertTrue( txFilter.contains( 123 ) ); assertTrue( txFilter.contains( 146 ) ); assertTrue( txFilter.contains( 123456 ) ); assertFalse( txFilter.contains( 147 ) ); }
private static void dumpMerge( Dumper dumper, byte type, ReadableChannel channel, long range, int labelId, TxFilter txFilter, long session, long flush ) throws IOException { long existingBits = channel.getLong(); long newBits = channel.getLong(); if ( txFilter == null || txFilter.contains() ) { dumper.merge( type == TYPE_MERGE_ADD, session, flush, range, labelId, existingBits, newBits ); } }