Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-lawrey committed Sep 12, 2013
2 parents dbbac1d + 5570fed commit 99fc91e
Show file tree
Hide file tree
Showing 92 changed files with 941 additions and 459 deletions.
8 changes: 7 additions & 1 deletion chronicle-fix/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>chronicle-parent</artifactId>
<groupId>com.higherfrequencytrading</groupId>
<version>1.7.3-SNAPSHOT</version>
<version>1.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -33,6 +33,12 @@
<artifactId>chronicle</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.kohsuke.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>9.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@

import com.higherfrequencytrading.chronicle.Excerpt;
import com.higherfrequencytrading.chronicle.StopCharTesters;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

/**
* @author peter.lawrey
*/
public class FixDecoder {
@NotNull
private final FixSocketReader reader;
@NotNull
private final Excerpt excerpt;

public FixDecoder(FixSocketReader reader) {
public FixDecoder(@NotNull FixSocketReader reader) {
this.reader = reader;
excerpt = reader.excerpt().chronicle().createExcerpt();
}

public boolean readMessages(FixDecodeListener listener) throws IOException {
public boolean readMessages(@NotNull FixDecodeListener listener) throws IOException {
boolean more = false;
if (!reader.readMessages())
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.higherfrequencytrading.chronicle.math.MutableDecimal;
import com.higherfrequencytrading.chronicle.tools.IOTools;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -47,6 +49,7 @@ public static void main(String... args) throws IOException, ParserConfigurationE
static class MyHandler extends DefaultHandler {
private final Map<String, FixFieldMeta> fieldMapByNumber = new LinkedHashMap<String, FixFieldMeta>();
private final Map<String, FixFieldMeta> fieldMapByName = new LinkedHashMap<String, FixFieldMeta>();
@Nullable
private MessageMeta messageMeta = null;
private final Deque<FieldAddable> fieldAddables = new LinkedList<FieldAddable>();

Expand All @@ -55,10 +58,11 @@ enum Mode {ROOT, HEADER, TRAILER, MESSAGES, MESSAGE, FIELDS}
final List<FixField> headerFields = new ArrayList<FixField>();
final List<FixField> trailerFields = new ArrayList<FixField>();
final Map<String, MessageMeta> messageMap = new LinkedHashMap<String, MessageMeta>();
@NotNull
Mode mode = Mode.ROOT;

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
public void startElement(String uri, String localName, @NotNull String qName, @NotNull Attributes attributes) throws SAXException {
if (qName.equals("header")) {
mode = Mode.HEADER;
return;
Expand Down Expand Up @@ -137,7 +141,7 @@ public void startElement(String uri, String localName, String qName, Attributes
}

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
public void endElement(String uri, String localName, @NotNull String qName) throws SAXException {
if (qName.equals("message")) {
mode = Mode.MESSAGES;
} else if (qName.equals("group")) {
Expand All @@ -164,7 +168,8 @@ public void endDocument() throws SAXException {
}
}

private String toCamelCase(String name) {
@NotNull
private String toCamelCase(@NotNull String name) {
return Character.toLowerCase(name.charAt(0)) + name.substring(1);
}

Expand All @@ -189,11 +194,13 @@ enum FieldType {
}

static class FixFieldMeta {
@NotNull
private final String number;
@NotNull
private final String name;
private final FieldType type;

public FixFieldMeta(String number, String name, String type) {
public FixFieldMeta(@NotNull String number, @NotNull String name, @NotNull String type) {
assert number != null;
assert name != null;
assert type != null;
Expand All @@ -202,6 +209,7 @@ public FixFieldMeta(String number, String name, String type) {
this.type = FieldType.valueOf(type);
}

@NotNull
@Override
public String toString() {
return "FixFieldMeta{" +
Expand Down Expand Up @@ -230,6 +238,7 @@ public void add(FixField ff) {
fields.add(ff);
}

@NotNull
@Override
public String toString() {
return "FF{" +
Expand All @@ -254,6 +263,7 @@ public void add(FixField ff) {
fields.add(ff);
}

@NotNull
@Override
public String toString() {
return "MessageMeta{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.higherfrequencytrading.chronicle.StopCharTesters;
import com.higherfrequencytrading.chronicle.impl.IndexedChronicle;
import com.higherfrequencytrading.chronicle.tools.ChronicleTools;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void testReadMessages() throws Exception {
int start = 0;

@Override
protected void readMoreData(ByteBuffer buffer) throws IOException {
protected void readMoreData(@NotNull ByteBuffer buffer) throws IOException {
int end = Math.min(bytes.length, start + 256);
buffer.put(bytes, start, end - start);
start = end;
Expand All @@ -129,7 +130,7 @@ protected void readMoreData(ByteBuffer buffer) throws IOException {
FixDecoder fd = new FixDecoder(fsr);
FixDecodeListener listener = new FixDecodeListener() {
@Override
public void onField(int fid, Excerpt value) {
public void onField(int fid, @NotNull Excerpt value) {
String text = value.parseUTF(StopCharTesters.FIX_TEXT);
System.out.println("\t" + fid + "=" + text);
}
Expand Down Expand Up @@ -175,7 +176,7 @@ public void testReadMessagesPerf() throws Exception {
int start = 0;

@Override
protected void readMoreData(ByteBuffer buffer) throws IOException {
protected void readMoreData(@NotNull ByteBuffer buffer) throws IOException {
int end = Math.min(bytes.length, start + 256);
buffer.put(bytes, start, end - start);
start = end;
Expand Down
6 changes: 6 additions & 0 deletions chronicle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
</properties>

<dependencies>
<dependency>
<groupId>org.kohsuke.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>9.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.higherfrequencytrading.chronicle;

import com.higherfrequencytrading.chronicle.math.MutableDecimal;
import org.jetbrains.annotations.NotNull;

/**
* @author peter.lawrey
Expand All @@ -26,28 +27,40 @@ public interface ByteStringAppender extends Appendable {

int capacity();

ByteStringAppender append(CharSequence s);
@NotNull
ByteStringAppender append(@NotNull CharSequence s);

ByteStringAppender append(CharSequence s, int start, int end);
@NotNull
ByteStringAppender append(@NotNull CharSequence s, int start, int end);

ByteStringAppender append(byte[] str);
@NotNull
ByteStringAppender append(@NotNull byte[] str);

ByteStringAppender append(byte[] str, int offset, int len);
@NotNull
ByteStringAppender append(@NotNull byte[] str, int offset, int len);

@NotNull
ByteStringAppender append(boolean b);

@NotNull
ByteStringAppender append(char c);

@NotNull
ByteStringAppender append(Enum value);

@NotNull
ByteStringAppender append(int i);

@NotNull
ByteStringAppender append(long l);

@NotNull
ByteStringAppender appendTime(long timeInMS);

@NotNull
ByteStringAppender appendDate(long timeInMS);

@NotNull
ByteStringAppender appendDateTime(long timeInMS);

// TODO
Expand All @@ -56,9 +69,12 @@ public interface ByteStringAppender extends Appendable {
// TODO
// ByteStringAppender append(float f, int precision);

@NotNull
ByteStringAppender append(double d);

@NotNull
ByteStringAppender append(double d, int precision);

ByteStringAppender append(MutableDecimal md);
@NotNull
ByteStringAppender append(@NotNull MutableDecimal md);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@
package com.higherfrequencytrading.chronicle;

import com.higherfrequencytrading.chronicle.math.MutableDecimal;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author peter.lawrey
*/
public interface ByteStringParser {
public void parseUTF(Appendable builder, StopCharTester tester);
public void parseUTF(@NotNull Appendable builder, @NotNull StopCharTester tester);

public String parseUTF(StopCharTester tester);
@NotNull
public String parseUTF(@NotNull StopCharTester tester);

public <E> E parseEnum(Class<E> eClass, StopCharTester tester);
@Nullable
public <E> E parseEnum(@NotNull Class<E> eClass, @NotNull StopCharTester tester);

public MutableDecimal parseDecimal(MutableDecimal decimal);
@NotNull
public MutableDecimal parseDecimal(@NotNull MutableDecimal decimal);

public long parseLong();

Expand All @@ -40,13 +45,13 @@ public interface ByteStringParser {
* @param tester to stop at
* @return true if we stopped at a stop character, false if we ran out of data.
*/
public boolean stepBackAndSkipTo(StopCharTester tester);
public boolean stepBackAndSkipTo(@NotNull StopCharTester tester);

/**
* Wind from this position to the end of the field
*
* @param tester to stop at
* @return true if we stopped at a stop character, false if we ran out of data.
*/
public boolean skipTo(StopCharTester tester);
public boolean skipTo(@NotNull StopCharTester tester);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.higherfrequencytrading.chronicle;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.Closeable;
import java.nio.ByteOrder;

Expand All @@ -28,11 +31,13 @@ public interface Chronicle extends Closeable {
/**
* @return A name for logging purposes for this Chronicle.
*/
@NotNull
String name();

/**
* @return a new Excerpt of this Chronicle
*/
@NotNull
Excerpt createExcerpt();

/**
Expand Down Expand Up @@ -69,12 +74,13 @@ public interface Chronicle extends Closeable {
* @param marshaller to add for marshaled types.
* @param <E> type marshaled.
*/
<E> void setEnumeratedMarshaller(EnumeratedMarshaller<E> marshaller);
<E> void setEnumeratedMarshaller(@NotNull EnumeratedMarshaller<E> marshaller);

/**
* Get the marshaller for a class
*
* @return the marshaller or null for there is not already.
*/
<E> EnumeratedMarshaller<E> getMarshaller(Class<E> eClass);
@Nullable
<E> EnumeratedMarshaller<E> getMarshaller(@NotNull Class<E> eClass);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@

package com.higherfrequencytrading.chronicle;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author peter.lawrey
*/
public interface EnumeratedMarshaller<E> {
@NotNull
public Class<E> classMarshaled();

public void write(Excerpt excerpt, E e);
public void write(@NotNull Excerpt excerpt, E e);

public E read(Excerpt excerpt);
@Nullable
public E read(@NotNull Excerpt excerpt);

public E parse(Excerpt excerpt, StopCharTester tester);
@Nullable
public E parse(@NotNull Excerpt excerpt, @NotNull StopCharTester tester);
}
Loading

0 comments on commit 99fc91e

Please sign in to comment.