Long Tail Treasure Trove Slides!
Gianugo has posted the slides from our JavaOne presentation, on Slideshare and in pdf form. The talk was awesome to give, we had a killer audience. A huge thank you to all who attended!
2 writebacks [/src/java] permanent link
Wed, 23 Apr 2008
The Shape of Async Callback APIs
When we have async callbacks in a Java API, the idiommatic way of writing the interface to register the callback looks like:
Future<Foo> f = asyncEventThing.addListener(new Listener<Foo>() {
public Foo onEvent(Event e) {
return new Foo(e.getSomethingNifty());
}
})
I'd like to propose that we adopt a new idiom, which is to pass an
Executor along with the listener:
Executor myExecutor = Executors.newSingleThreadExecutor();
// ...
Future<Foo> f = asyncEventThing.addListener(new Listener<Foo>() {
public Foo onEvent(Event e) {
return new Foo(e.getSomethingNifty());
}
}, myExecutor);
The main benefit is that you give the caller control over the threading model for the callback. Right now, most libraries either have a separate thread pool for callbacks, or make the callback on the event generator thread. Usually there is nothing but an obscure reference on a wiki to indicate the behavior.
0 writebacks [/src/java] permanent link
Thu, 17 Apr 2008As I got hit with a meme about command line stuff, I figured I'd share an update to my favorite bash completion:
SSH_COMPLETE=( $(cut -f1 -d' ' ~/.ssh/known_hosts |\
tr ',' '\n' |\
sort -u |\
grep -e '[:alpha:]') )
complete -o default -W "${SSH_COMPLETE[*]}" ssh
If you ssh directly to IP addresses very often, you might want to leave
off the last grep -e.
Not going to tag anyone, but if you have a favorite completion, please share! (I suggest not in a comment on this post as my comment system does not preserve any formatting).
4 writebacks [/stuff] permanent link
bakert tagged me, so:
brianm@binky:~$ history | awk {'print $2'} | sort | uniq -c | sort -k1 -rn | head
164 svn
52 cd
42 ssh
32 sudo
22 git
16 ls
16 for
14 echo
13 man
10 curl
brianm@binky:~$
Sadly, I only seem to keep a 500 line .history -- need to fix that.
0 writebacks [/stuff] permanent link
Tue, 15 Apr 2008So, thought experiment. If we, as an industry, had to drop Java, the language and the virtual machine, for some reason, what could really move into its niche?
Some points to consider:
Putting aside the "damn I want to use coolness X," what out there provides something that could do it?
4 writebacks [/src] permanent link
Sun, 16 Mar 2008Nathan wrote up a great blog post about thoughts for working on mod_wombat (Lua in Apache) for this coming Google Summer of Code. I'd be extremely excited (along with Nathan and Matthew, I suspect) to mentor someone on it if it sounds exciting to folks out there :-)
0 writebacks [/src/wombat] permanent link
Sat, 01 Mar 2008I haven't actually used Groovy much since, oh, egads, umh, 2004. It was at 1.0b6 and was taking a direction which I both disagreed with and found kind of boring. It was throwing away large chunks of dynamicity for some performance gains as it decided it really wanted to be compiled, after all. Large chunks of the new syntax I also disagreed with so... I wandered away, wishing everyone luck.
Well, funny things can happen in, er, three and a half years, so when a coworker suggested we look at Groovy for solving a problem my initial reaction was "erk, umh, I kind of like our use of JRuby for that" but Groovy wasn't even at 1.0 when last I used it, so it was a pretty unfair reaction. Looking again, it is at 1.5.4! Time to revisit!
After noting that none of my old code parsed, I worked through the tutorial. This isn't the same language I last used. It smells like Perl or PHP more than Ruby, which it rather resembled back then. Overall, my second "first" impression: totally practical, rather ornery. Will dig into it more.
0 writebacks [/src/groovy] permanent link
Wed, 27 Feb 2008A coworker commented to me today "what's up with all these libraries that encourage method chaining? ;-)" when we were talking about FEST. To stay in context, we are talking about this kind of thing:
assertThat(yoda).isInstanceOf(Jedi.class)
.isEqualTo(foundJedi)
.isNotEqualTo(foundSith);
This, of course, has also been called nice things like "train wreck" and is frequently seen to be a brittleness inducer in code. On the other hand, I encourage the heck out of it in libraries I write, from jDBI for example:
handle.prepareBatch("insert into something (id, name) values (:id, :name)")
.add(1, "Brian")
.add(2, "Keith")
.add(3, "Eric")
.execute();
On yet another hand, I pointed out that it was a bad practice to someone in a code review just last week. So, when is it a good fluent interface, and when is it a train wreck? Good question. My first reaction is "I know it when I see it" but that isn't very useful. So, to take a stab at a description...
Method chaining makes a good interface when the chained methods all
come from the same module, are part of the published API, and when taken
together represent a single logical action. In the first example, they are
all on the published interface of FEST-Assert and are asserting that
yoda is correct. In the second, they all come from the
published interfaces of jDBI and form one batch statement.
For a negative example, let's take data access traversal:
yoda.getMidiclorians().getForce().getDarkSide().getLightningFromFingers();
Here, even if the interfaces for all the intervening classes are in the same module, and are very stable, it sure as heck isn't a single logical unit.
Anyway, gotta run, lunch is done. If I think of a better way to describe it will do so this evening!
5 writebacks [/src] permanent link
Sun, 24 Feb 2008A happy coincidence of The Praggies and O'Reilly both doing bookamajigs focused on general, programmery, learning. O'Reilly's is an interesting take in that it is a collaborative, wiki-based venture. Andy Hunt's is triply interesting to me as I did my graduate work on the stuff he is writing about, if in a very different context (formal education).
Refactoring Your Wetware starts out with a nice review of the Dreyfus model (I grabbed the beta book) but is still mostly not-yet-written, so Andy's approach to progressing through the stages isn't clear, yet. I'm very much looking forward to seeing how he approaches and presents the long view of learning.
The O'Reilly approach hits close to home for me as I spent a lot of time experimenting with material from the Portland Pattern Repository when I transitioned back into programmering from teaching and realized I didn't actually remember much! Anything that helps self-taught folks get better is teh win.
0 writebacks [/src] permanent link
Sat, 02 Feb 2008So AtomPub is a reasonable way to publish things, etc. Would be nice to push an AtomPub endpoint to a service as a callback for events. An awfully large number of things can accept HTTP now, and there is a reasonable basic-operation system available, so why not take advantage for callback APIs? Instead of polling a site for updates, post a subscription with an AtomPub endpoint as the entry and let the service push to you. AtomSub :-)
3 writebacks [/src] permanent link
Sat, 26 Jan 2008
an interesting milestone: mod_slow
Crossed some kind of threshold today, I am sure. I needed a quick'n'dirty web server hack so broke out C for an apache module! What is happening to me?!
Basically, I needed something to put behind a proxy to do some load and capacity testing of the proxy. As I wanted to have things like the size of the response and time of the response be easily configurable on the load generator I needed to hack something up...
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
#include "apr_time.h"
#include "apr_strings.h"
static int handler(request_rec *r)
{
if (r->args)
apr_sleep(apr_atoi64(r->args) * 1000);
return DECLINED;
}
static void register_hooks(apr_pool_t *p)
{
ap_hook_handler(handler, NULL, NULL, APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA slow_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
register_hooks
};
This very nicely lets me drop artificial slowdowns in front of the the
default handler (serve up files) so I can control "processing time" and
file size (pick the file with the size I want):
http://binky/big.html?2000
Sweet! Am kind of floored that the first solution which leapt to mind for
me was an apache module in C, though!
For some reason, putting the sleep in fixups doubled the
sleep time, so I made it a declined handler and things worked fine. Need
to figure out why.... someday.
2 writebacks [/src/apache] permanent link
Mon, 21 Jan 2008
A recent thread on the Apache HTTPD development mailing list reminded me of something funny. Orthodox Server Programmerism states that events are better than threads. Funny thing is that at the same time this meme has finally broken into the mainstream (the last several years) it has become largely irrelevant. Even better, it is only going to become more and more irrelevant as time passes.
OS kernels, even ones that love events and hate threads now do threads very efficiently. On top of that, many-processor, multi-core computers are the norm (heck, my laptop is dual-core) and this trend is going to increase very quickly.
I suspect events vs. threads is going to go the way of Assembly vs. C (or C vs. Java (or Java vs. The P(+R) gang)). Sure you can theoretically optimize the former better, but the theoretically will be operative in the vast majority of cases. Heck, I hope thread schedulers use events when a thread blocks on IO. Presuming they do, the penalty for a thread vs an event listener should be the thread stack and restoring registers. The thread stack is a specific solution to storing the context for handling the event, and I don't know close to enough to dive any deeper :-)
Heck, anyone designing a new system for embarassingly concurrent stuff today would probably be better off solving this in the compiler and then exposing linear programming to the programmer via explicit happens-before semantics rather than a thread model.
2 writebacks [/src] permanent link
Thu, 17 Jan 2008Nick and I had a good IM discussion last night about the social graph, data portability, etc. Timely in light of
0 writebacks [/tech] permanent link
Mon, 14 Jan 2008It came up in a different context, so thought I would post :-) If you trim a tiny smidge from the butt end of a uni-ball Signo 207 refill it fits very nicely into the Pilot G2 Pro body. The G2 Pro body is my favorite everyday pen body, but the G2 cartridges (what do you call them when they include the ball, anyway?) tend to be uneven and even blotchy on me compared to the 207s. So, a couple seconds with a pocketknife and I have the best of both worlds!
1 writebacks [/stuff] permanent link
Ran across Nu today in a reference from Brandon Warner. Nu is an interpreted lisp dialect with close ties to ruby and objective-c. Really :-)
The best way to illustrate this is probably to look at a snippet, in this case from the nuke tool bundled with Nu:
(unless @prefix
(set @prefix
"#{((((NSProcessInfo processInfo) arguments) 0) dirName)}.."))
(unless @icon_files
(set @icon_files
(array "#{@prefix}/share/nu/resources/nu.icns")))
I won't point out the objc and ruby bits therein, as if you know one or both, you see them. It looks weird in places, but if you want to hack around on cocoa stuff, wowzers, it rocks. Check the converted form of ye olde currency converter (the first bit of cocoa programming for a lot of folks, myself included).
0 writebacks [/src] permanent link
Thu, 03 Jan 2008Right now I am functional enough in emacs to do basic things, like write this blog post, but I use too many OS X-isms, like splat-z for undo, and I need to turn those off and learn emacs properly :-)
6 writebacks [/stuff] permanent link
Sat, 29 Dec 2007Sadly, mod_wombat is stalled because I cannot figure out autotools, nor can I find anyone who understands autotools. Apparently everything is built by copying the macros from something else and tweaking them.. and praying.
I am coming around to building it with SCons, or if Jan finishes it, his Lua based autotools replacement. I am pretty sure waiting for him to build it, them learning it, will be faster than making autotools do what I want (ie, work).
4 writebacks [/src] permanent link
Wed, 26 Dec 2007
Shindig, Ning, OpenSocial, and, er.. ME!
Dion posted an interview he did with me on OpenSocial, Shindig, and Ning.
He says way too many nice things about me, but Shindig is pretty cool :-) We need a website for it pretty badly...
1 writebacks [/ning] permanent link
Fri, 21 Dec 2007So, I generally have two classes of scripting needs: systemy/unixy stuff and systemy/application stuff. Most of the applications I work with in $dayjob are Java. Over the last year or two that means I use Ruby (MRI or JRuby) as the case may be. Tonight, prodded by the new book I broke out Scala for doing a bunch of in-REPL statistics crunching using the wonderful commons-math library.
I love it. Don't know if I love it enough to replace JRuby for typical Java-interaction hackery, but enough that I am going to switch back and forth for a while so I can decide.
Hadn't actually used scala in a few years, so is great to break it out again!
6 writebacks [/src/scala] permanent link
Wed, 12 Dec 2007
Shindig: An OpenSocial Container
So a bunch of folks are contributing to set of open source implementations of OpenSocial at Apache, called Shindig. There isn't much of a site yet but there is a pile of working code! Much more information over on Google's OpenSocial Blog.