Skip to content
Tim Olson edited this page Jun 23, 2014 · 5 revisions

Guice

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.

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