Skip to content

Commit

Permalink
added recovery indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
mappedbuf committed May 10, 2015
1 parent 16cfc13 commit 531ebfa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
MappedBus
</description>
<!-- set global properties for this build -->
<property name="version" value="0.1.1"/>
<property name="ant.project.name" value="mappedbus"/>
<property name="main_class_name" value="changeme"/>
<property name="jarname" value="${ant.project.name}"/>
Expand Down Expand Up @@ -34,6 +35,8 @@
<javac debug="true"
srcdir="${src}"
destdir="${build}"
source="1.7"
target="1.7"
classpathref="project.classpath"/>
<!-- Copy files from ${src} into ${build} -->
<copy todir="${build}">
Expand Down Expand Up @@ -67,13 +70,13 @@
<!-- Create the distribution directory -->

<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/${jarname}-${DSTAMP}.jar" basedir="${build}">
<jar jarfile="${dist}/${jarname}-${version}.jar" basedir="${build}">
<manifest>
<attribute name="Main-Class"
value="${main_class_name}"/>
</manifest>
</jar>
<copy file="${dist}/${jarname}-${DSTAMP}.jar" tofile="./${jarname}.jar" overwrite="true"/>
<copy file="${dist}/${jarname}-${version}.jar" tofile="./${jarname}.jar" overwrite="true"/>
</target>

<target name="clean"
Expand Down
9 changes: 8 additions & 1 deletion src/se/caplogic/mappedbus/MappedBusReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ public class MappedBusReader {

private long limit = Layout.Data;

private long initialLimit;

private boolean typeRead;

public MappedBusReader(String file, long size) {
this.size = size;
try {
mem = new MemoryMappedFile(file, size);
mem = new MemoryMappedFile(file, size);
initialLimit = mem.getLongVolatile(Layout.Limit);
} catch(Exception e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -80,4 +83,8 @@ public Message readMessage(Message message) {
limit += message.size();
return message;
}

public boolean hasRecovered() {
return limit >= initialLimit;
}
}
5 changes: 3 additions & 2 deletions src/se/caplogic/mappedbus/sample/message/MessageReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void run() {

while (true) {
if (reader.hasNext()) {
boolean recovered = reader.hasRecovered();
int type = reader.readType();
switch (type) {
case PriceUpdate.TYPE:
Expand All @@ -27,8 +28,8 @@ public void run() {
default:
throw new RuntimeException("Unknown type: " + type);
}
reader.readMessage(message);
System.out.println("Read: " + message);
reader.readMessage(message);
System.out.println("Read: " + message + ", hasRecovered=" + recovered);
}
}
} catch(Exception e) {
Expand Down

0 comments on commit 531ebfa

Please sign in to comment.