I’m cc’ing the silkjs google group. Lots of info here might be of interest to all.
You don’t need to write Java. You CAN, but you don’t have to. For SilkJS, any library you’d want to have had to be C++ wrappers around the library functions and linked into SilkJS binary. With decaf, you can call anything in any Java .jar file on your path. Decaf does some magic to assure things for modules are on your classpath. However, I’ve written pure JS modules that wrap around the Java functions and provide you with pure JS callable API with little or no hint of Java to your app. The one exception is Java Byte Arrays are used for binary data. Java has ‘em, why not use ‘em? :)
Your code should be quite similar to your SilkJS code. However, you will be able to spawn threads now, and your HTTP children can share variables across requests. This is one of the driving factors for me to work on decaf in the first place. Threads, semaphores, and shared variables.
Performance? Rhino is notoriously slower than V8. But it really depends on what you’re doing. Reading from files and querying databases? You won’t see much of a difference. Calculating images pixel by pixel? Rhino will be 10x slower. In terms of the http server, decaf is about 1.5x faster than SilkJS at returning a “hello, world” response programatically, and well over 10x faster than a single threaded NodeJS.
Rhino is not going to have some radical changes to its API. Neither is Nashorn, the JS interpreter for Java 8.
I am not a Java guy!
Decaf uses bower:
Not NPM..
Bower installs from github repositories into a bower_components/ directory in your project. Any require() you do searches bower_components automatically. Thus, we can break up Decaf into lots of smaller bower components and use just what you want in your project. Like, no need for mongodb drivers if you’re using MySQL. Many NodeJS modules can be installed with bower and decaf does support them - like HoganJS, MomentJS, etc. Ones that rely on nodejs’ async methods are not going to port easily, though I think it’s very possible.
Your project’s bower.json might look like:
{
…
dependencies: [
“jquery” : “2.x”,
“moment”: “2.x”,
…
]
…
}
So you’re actually using bower to install decaf and the decaf-jolt module along with jQuery and moment. In your decaf main.js/app.js/boostrap.js/whatever, you can:
var Application = require(‘decaf-jolt’).Application,
SjsServer = require(‘decaf-jolt’).SjsServer,
app = new Application();
app.verb(‘/‘, new SjsFile(‘/some/path/to/my/root.sjs’));
// when URL / is fetched, /some/path/to/my/root.sjs is executed, sjs works like in SilkJS.
Note decaf-jolt is in bower_components/decaf-jolt directory. Decaf finds it for require().
Please take time to read the wiki page about decaf’s require() implementation. I think it might be the best implementation anywhere. It supports pure commonJS modules, NodeJS style modules (module.exports), and for directories: package.json or bower.json or index.js.
You can also:
var moment = require(‘moment’);
This loads the moment date library/API for use in your decaf app.
You would put this shell script in your project root to be able to run decaf:
#!/bin/sh
# chmod this script 700
./bower_components/decaf/bin/decaf $@
If you then run:
% ./decaf.sh your_app.js
It runs your app
If you provide no app.js parameter, it does REPL mode like SilkJS.
If you run:
%./decaf.sh debug your_app.js
You get a windowed debugger, something like developer tools for chrome, but server-side.
To answer another one of your questions, can you switch on req.host like you are now in SilkJS? Yep!
See the example Web server? You get called with a req and res object for every request. You can examine req.host and do whatever you like.
This example WWW server happens to be 100% compatible with the example on the
nodejs.org home page.
The http module (comes with decaf) is documented here:
I provided decaf-jolt. Please look at this URL. I just now moved over the current (pretty good!) documentation for Jolt.
It is a WWW application framework something along the lines of expressjs (inspired by it but not a clone). If you don’t like it, you can trivially roll your own.
I will work on breaking out decaf-mysql tomorrow.
I am always looking for collaborators, even if it’s just to write test/example programs or documentation :)
Mike,
Trying to wrap my head around decafJS;
1. Do I need to write Java? (Ugh)
2. Does it integrate with ExtJS like SilkJS does?
3. What is performance like compared to SilkJS?
4. Is there more of a 'NPM' like infrastructure leveraged by decafJS?
5. Can I use one decafJS server to serve multiple apps like I am with SilkJS? (Using HttpChild.requestHandler)
I am months away from the 'Phase 2' part of my project, and migrating now would be pretty easy. I didn't realize that Google could 'force your hand' so easily.
Thanks!
Eric
On 07/08/2014 09:24 PM, Mike Schwartz wrote:
Note I’m not dropping SilkJS support. Google may force my hand, though, as the API is a radically moving target and at some point, editing many thousands of lines of code just to fix it to call their latest API may not be feasible without many hours. That’s why SilkJS is a snapshot of an earlier version of V8.
Code written for SilkJS shouldn’t be a huge porting project. For example, I’ve implemented a MySQL module with Schema class that’s identical to the SilkJS one. I haven’t exactly been making it public that decafJS exists. It has been in a private repo with a similar kitchen sink set of modules/API as SilkJS. I’ve been breaking out those modules into bower installable modules.
DecafJS itself is installable via bower. I’ll put together a demo project using bower to install everything soon.
One of the huge benefits of DecafJS is that it is threaded instead of process oriented. This means all your child “processes” become threads and can share variables.
If you all have any questions about it, let me know.