Bt is a modern Java 8 BitTorrent library. It offers good performance, reliability and is highly customizable.
© 2016-2021
Andrei Tomashpolskiy
Release 1.5 was published to Maven Central on September 26th, 2017. There are several cool features in this release.
The new centralized mechanism for publishing/receiving events is represented by two DI services: bt.event.EventSink
for publishing and bt.event.EventSource
for subscriptions. Library users have an easy access to the EventSource
instance via bt.runtime.BtRuntime#getEventSource()
.
Currently there are the following types of events:
This is mostly an internal enhancement, but it brings two useful features for library users:
1) Ability to stop torrent processing as soon as the metadata has been fetched. It can be convenient, when one is using magnet links and doesn’t want to download the actual data, but just the info dictionary. See bt.TorrentClientBuilder#afterTorrentFetched
.
2) Ability to stop torrent processing as soon as the data has been downloaded. It is supposed to replace the custom listeners, that periodically perform state.getPiecesRemaining() == 0
checks and then invoke client.stop()
. The new alternative is much more efficient, because it does not use a separate thread. See bt.TorrentClientBuilder#stopWhenDownloaded
.
Leveraging OS I/O multiplexing allowed to significantly reduce the number of system calls and slightly cut down on the CPU usage in message dispatching loop.
This feature is borrowed from Bootique project (which I strongly recommend to anyone, who is interested in runnable Java applications). It replaces contribution methods with a clearer and more concise API for contributing custom extensions into the core. Instead of invoking individual contributions methods, downstream modules should now call bt.module.ServiceModule#extend(Binder)
or bt.module.ProtocolModule#extend(Binder)
and use methods in the returned builder instance, e.g.:
import com.google.inject.Binder;
import com.google.inject.Module;
import bt.module.ProtocolModule;
public class MyModule implements Module {
@Override
public void configure(Binder binder) {
ProtocolModule.extend(binder)
.addMessageHandler(20, ExtendedProtocol.class)
.addExtendedMessageHandler("ut_metadata", UtMetadataMessageHandler.class);
}
}
As usual, here’s the complete list of what has been done: