Skip to content
Tim Olson edited this page Feb 7, 2015 · 5 revisions

Esper

Esper is a Complex Event Processing system which allows you to write SQL-like statements that can select time series. For example: select avg(priceAsDouble) from Trade.win:time(30 sec) gives the average price over all Trades occuring within the last 30 seconds.

Esper Tutorial

Esper Reference

EPL Language Introduction

Coin Trader relies heavily on Esper as the hub of the architecture. The Context class manages Esper Engine configuration and supports module loading.

WARNING: any object which has been published to Esper MUST NOT BE CHANGED after being published. All events are "in the past" and should not be touched after creation. For example, if a business object changes state, publish a state-change notification rather than publishing the mutable business object.

Guice

The Context manages dependency injection with a wrapped implementation of Guice along with the JSR-330 annotations @Inject and @Singleton. Simply use the @Inject annotation on fields and constructors, then context.attach(My.class). The Context will use its Guice injector to instantiate your attached class and populate the @Injected fields with other attached members of the Context.

Guice powers the dependency injection performed by the Context, but Coin Trader mostly abuses the Guice model. The Guice Injector is wrapped by org.cryptocoinpartners.util.Injector, but in Coin Trader, the Context is really the main actor. The Context acts like a dependency scope and manages the underlying injections dynamically, so you don't have to worry much about Guice. In your module classes, you might want to access the Injector like this:

@Inject org.cryptocoinpartners.util.Injector injector;
private void myFoo() {
  MyClass instance = injector.getInstance(MyClass.class);
}

Any module classes attached to a Context have bindings created for them (see Services) so that subsequently attached classes may access that module by injection.

Configuration

We use Apache Commons Configuration to load system properties, cointrader.properties, and module’s config.properties files.

Logging

We log using the slf4j api. For any class attached to a Context or otherwise instantiated by injection, you can use this pattern:

@Inject private Logger log;
private void doLog() { log.debug("log is not null because it was injected by the Context."); }

Otherwise the standard SLF4J idiom looks like this:

Logger log = LoggerFactory.getLogger(MyClass.class);
log.debug("it works");

The underlying log implementation is logback, and the config file is at src/main/resources/logback.xml

Log Levels

  • trace: spammy debug
  • debug: regular debug
  • info: for notable infrequent events like connected to DB or data source
  • warn: problems which can be recovered from. notify human administrator
  • error: problems which have no recovery. notify human administrator immediately

Joda Time

The date and time classes of JodaTime are the basis for a new standard in Java. Coin Trader primarily uses Instants to record event times at millisecond resolution locally, but second resolution from most of the markets.

Clone this wiki locally