Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tool to replay (uncompressed) journal files. #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Fri Mar 22 2019 Dave Benson <david.benson> 2.2.2
- add ReplayJournal program mostly to use in testing emitters

* Fri Jan 11 2019 Dave Benson <david.benson> 2.2.1
- support for registration of new EmitterGroup to support
plugins that render to alternate targets (which aren't necessarily
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>org.lwes</groupId>
<artifactId>lwes-java</artifactId>
<packaging>jar</packaging>
<version>2.2.1</version>
<version>2.2.2</version>
<name>lwes-java</name>
<description>Lightweight event system, java implementation</description>
<url>http://lwes.org</url>
Expand Down Expand Up @@ -161,8 +161,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/org/lwes/emitter/ReplayJournal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.lwes.emitter;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.lwes.Event;
import org.lwes.EventFactory;
import org.lwes.emitter.EmitterGroupBuilder;
import org.lwes.emitter.EmitterGroup;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.util.Properties;


public class ReplayJournal {

@Option(name = "-i", usage = "journal file", required = true, metaVar = "FILE")
String inputFilename;

@Option(name = "-n", usage = "repeat count", metaVar = "COUNT")
int repeatCount = 1;

@Option(name = "-sleep", usage = "milliseconds to sleep between events", metaVar = "MILLISECONDS")
int sleepMillis = 0;

@Option(name = "-group", usage = "event emitter group name", required = true)
String groupName;

@Option(name = "-properties", usage = "properties file", required = true)
String propertiesFilename;

public static EventFactory factory = new EventFactory();

private void run() throws Exception {
Properties props = new Properties();
props.load(new FileReader(propertiesFilename));
EmitterGroup group = EmitterGroupBuilder.createGroup(props, groupName, factory);
byte[] header = new byte[22];
for (int i = 0; repeatCount < 0 || i < repeatCount; i++) {
FileInputStream file = new FileInputStream(inputFilename);
BufferedInputStream input = new BufferedInputStream(file);
while (input.read(header) == 22) {
int size = (((int)header[0] << 8) & 0xff00)
| (((int)header[1] << 0) & 0x00ff);
byte[] eventData = new byte[size];
if (input.read(eventData) != eventData.length) {
throw new RuntimeException("bad journal");
}
Event event = factory.createEvent(eventData, false);
group.emitToGroup(event);
if (sleepMillis != 0)
Thread.sleep(sleepMillis);
}
}
System.err.println("no more data: returning");
}

public static void main(String[] args) throws Exception {
ReplayJournal replayer = new ReplayJournal();
CmdLineParser parser = new CmdLineParser(replayer);
parser.parseArgument(args);
replayer.run();
}
}