-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from getyourguide/feat/dump-to-file
Feat/dump to file
- Loading branch information
Showing
8 changed files
with
251 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.getyourguide.models; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class Lsn { | ||
private final long value; | ||
|
||
public Lsn(long lsn) { | ||
this.value = lsn; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%s, [hex:%s]", value, asHexString()); | ||
} | ||
|
||
private String asHexString() { | ||
final ByteBuffer buf = ByteBuffer.allocate(8); | ||
buf.putLong(value); | ||
buf.position(0); | ||
|
||
final int logicalXlog = buf.getInt(); | ||
final int segment = buf.getInt(); | ||
return String.format("%X/%X", logicalXlog, segment); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/getyourguide/source/FileStreamSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.getyourguide.source; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
|
||
public class FileStreamSource implements Source { | ||
|
||
private int count = 0; | ||
private final DataInputStream dataInputStream; | ||
|
||
public FileStreamSource(String fileName) { | ||
try { | ||
dataInputStream = new DataInputStream(new FileInputStream(fileName)); | ||
} catch (FileNotFoundException e) { | ||
throw new RuntimeException("File not found: " + fileName); | ||
} | ||
} | ||
|
||
@Override | ||
public ByteBuffer readPending() throws Exception { | ||
count++; | ||
if (dataInputStream.available() == 0) { | ||
System.out.printf("End of File: %s events read\n", count); | ||
throw new RuntimeException("End of File"); | ||
} | ||
|
||
// Read the size of the message | ||
var size = dataInputStream.readInt(); | ||
System.out.printf("Reading %s bytes\n", size); | ||
|
||
// Read the message | ||
var data = dataInputStream.readNBytes(size); | ||
return ByteBuffer.wrap(data); | ||
} | ||
|
||
@Override | ||
public long getLastReceiveLSN() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
dataInputStream.close(); | ||
} | ||
} |
Oops, something went wrong.