Show HN: Bt – BitTorrent library in Java 8
github.com
github.com
I also have a simple shell script locally, that wraps the java command, so I have to just type `btmagnet AF0D9AA01A9AE123A73802CFA58CCAF355EB19F8` to download to a pre-determined location (hardcoded in the script). I wonder if I should share it on the CLI README page
function bt() { java -jar /path/to/bt-launcher.jar -m "magnet:xt=urn:btih:$1" -d /$HOME/Downloads }
Or don't use the Oracle proprietary distribution but the OpenJDK of your operating system which normally doesn't exclude proper crypto algorithms.
(be aware that the JDKs downgrade silently if certain libraries are missing in your host)
Benchmarks (like in libtorrent) is something I'm looking forward to, but the project is still in the early stage -- there's a lot to be done with regards to optimization, i.e. switching to using NIO selectors, adding a caching layer, etc. That's a lot of work, and that's why I'm looking for collaborators, before investing more time into performance-tuning.
note that mapped buffers are not necessarily backed by RAM, they act more like swap space, except it goes straight to the original file instead of a swap partition. the downside is that anything reading from the buffer can unpredictably incur IO overhead if there's memory pressure and the OS decides to not back them with memory. java doesn't have an api to check residency of buffers. a possible workaround is to first queue them up on a separate thread and forcing them in before using. if they're already there it should have low latency. if they aren't then only the victim thread eats the IO penalty.
Too late to edit now, but I misremembered that part. I think the issue was that isLoaded was not entirely reliable.
Will look forward to reading through the code later!
$ time java HelloWorld
Hello, World
real 0m0.088s
user 0m0.088s
sys 0m0.016sSure it is loading libraries, everything that System.out.println() depends on.
There are plenty of JDKs that support it, and even Oracle is finally adding support for it with Java 9, initially only for Linux x64.
By Java 10 timeframe no one that only knows about OpenJDK and not the several other JDKs can state that Java starts slow vs C, because both will be AOT compiled to native code, loading native .so files.
Nevertheless it is quite useful for improving startup for tools like Gradle or server applications. But sure, I also don't expect Java startup performance to be a problem in the mid- to long-run.
This is only relevant to Oracle's implementation though.
Other JDKs do support static linking, as long as you restrain yourself from features that could require dynamic compilation.
There was a talk at JVM Languages Summit about the current state of AOT compilation regarding Java 10.
https://www.youtube.com/watch?v=n5DCg6M2MDM&index=11&list=PL...
Besides this comparison looks like a total bikeshedding unless you plan on downloading torrents with vim.
By the way the project looks fantastic. I'll be giving it a try.
The alternative for just command line torrent on a *nix is aria2 [0]. Works exactly as advertised.
But then you need to provide different app packages for different OSes.
On top of that, if lucky enough to be on an Linux x64 system, you can AOT compile to native code.
I definitely like the idea. My question was more aimed to understand if Java has some desirable features for writing a torrent client maybe as part of the SDK or other 3rd party libs. I didn't even look at your source code yet :P
Java stood out to me because I don't think I've seen other CLIs written in Java.
I guess nothing to do with this but was triggered by two combined words: Torrent and Java
On my context it is useful for downloading large files without depending on a single point of failure or fixed location.
Have a question in regards to the example syntax:
client.startAsync(state -> { if (state.getPiecesRemaining() == 0) { client.stop(); } }, 1000).join();
This is a feature from newer Java syntax that I'm not yet familiar enough with lambdas to understand in full what is happening.
Perhaps I can ask for an example that replaces the "->" into the older Java syntax? I know this would likely come at the cost of a few extra lines, it would certainly ease a lot for many developers looking at the example. Many thanks.
client.startAsync(new Consumer<TorrentSessionState> {
void accept(TorrentSessionState state) {
if (state.getPiecesRemaining() == 0) {
client.stop();
}
}
}, 1000).join();I can only thank those who wrote such obfuscated code in previous years, that eventually forced everyone else afterwards to write code as simple and clear as reasonably possible. That's the reason why I've asked for the simplified code, Might as well save the time for other developers on similar situation.
Of course you can choose to shoot yourself in the foot and just stick with Java 6, but don't try to force others to make the same mistake.
Seems you prefer to put everyone on the same bag and speak for them too.