-
Notifications
You must be signed in to change notification settings - Fork 166
Dev Libs
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 Trade
s occuring within the last 30 seconds.
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.
See Injection
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.
We use Apache Commons Configuration to load system properties, cointrader.properties
, and module’s config.properties
files.
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
-
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
The date and time classes of JodaTime are the basis for a new standard in Java. Coin Trader primarily uses Instant
s to record event times at millisecond resolution locally, but second resolution from most of the markets.