Bt is a modern Java 8 BitTorrent library. It offers good performance, reliability and is highly customizable.
© 2016-2020Andrei Tomashpolskiy
One of the primary goals of Bt design is to give the user the power to extend it and customize it to her own liking. It uses a popular IoC container Google Guice and follows a modular approach, in which different components are loosely coupled and interact via generic interfaces.
The idea is that an advanced user who is familiar with the concept of DI should be able to easily navigate the codebase (which is pretty well-documented with JavaDoc) and provide custom services by standard means that Guice provides.
However, reality is such that the need to explore library internals can be a daunting task for a new user. Hence, there is a number of “standard” extension points that will help you get started.
The idea of contribution methods is borrowed from Bootique project and is very well explained in this DZone article.
In short, contribution method is a static method in a Guice Module, that accepts a Binder - primary DI tool for wiring interface classes to their implementations - and returns a Multibinder or a MapBinder, which are then used to contribute custom classes into the core.
In Bt one notable example of such method is bt.module.ProtocolModule#contributeExtendedMessageHandler. By using this method you can utilize the official Extension Protocol to build custom messaging. There is a dedicated page about using Extension Protocol, where you’ll be able to find more information.
Other noteworthy contribution methods are: