﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="atom-style.css"?>
<!--
    Je suppose que ce commentaire empêche que Firefox considère ce document XML comme flux RSS parce que la balise ouvrante est plus loin que les 512
    premiers octets. C'est à mon avis trop simple (ça s'appelle du "content sniffing" mais si ça peut faire fonctionner mon site, je ne vais pas m'en
    priver. Allez, il en manque encore un tout petit peu, et on a les 512 octets qu'il faut pour que le flux RSS ne soit pas découvert.
    -->
<a:feed xmlns:a="http://www.w3.org/2005/Atom" xmlns="http://www.w3.org/1999/xhtml">
  <a:author>
    <a:name>Matthias Ernst</a:name>
    <a:email>blog@mernst.org</a:email>
  </a:author>
  <a:title>Matthias Ernst's Weblog</a:title>
  <a:id>http://mernst.org/blog/rss.xml</a:id>
  <a:link href="http://www.mernst.org/blog/rss.xml" rel="self"/>
  <a:link href="http://www.mernst.org/jess/resume.html" rel="wife"/>
  <a:subtitle>Mostly geeky stuff</a:subtitle>
  <a:updated>2007-10-05T19:18:00+02:00</a:updated>
  <a:entry>
    <a:title>Sidebar</a:title>
    <a:content type="xhtml">
      <div style="position: relative">
        <div style="width: 50%">
          <h3 style="display: inline">About</h3>
          I'm a passionate, paid tinkerer in all things Java.
          <h3 style="display: inline">Links</h3>
          <a href="#Get-the-Jist">jist</a>
          -
          <a href="https://sprong.dev.java.net/">sprong</a>
          -
          <a href="https://axt.dev.java.net/">axt</a>
          -
          <a href="http://ulc-community.canoo.com/snipsnap/space/Spring+Integration">ULC with Spring</a>
          -
          <a href="http://virtualmachine.de/">heapprofile</a>
          -
          <a href="http://www.mernst.org/ariadna/index.html">ariadna</a>
          <h3 style="display: inline">Syndicate</h3>
          <a href="rss.xml">Atom 1.0</a>
        </div>
        <br style="clear: both"/>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#sidebar</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#sidebar"/>
    <a:updated>2007-06-11T13:00:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Re: Budget Reservation Confirmation</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="re-budget-reservation-confirmation" href="#re-budget-reservation-confirmation"></a>
        <p>
          So it seems I'm exhibiting a huge amount of naivety about how car rental works at Budget Inc.
          Four strong indications:
        </p>
        <ol>
        <li>Assumption: the online reservation system "knows" about the number of
        cars available at a rental location. It will not let you make a reservation
          when no cars are available and it will not send you a "confirmation" mail
          saying "your rental car has been reserved".</li>
        <li>Assumption: Representatives at the rental location are aware of your reservation
        and are expecting you at the time indicated therein.</li>
        <li>Assumption: A representative that - after debunking assumptions 1 &amp; 2 - offers
          to transfer your reservation to
        another location nearby has a better overview of availability in her software and
        will make sure a car will be waiting for you there.</li>
        <li>Assumption: The map handed to you by the representative actually carries the correct
        address of that other location.</li>
        </ol>
        <p>
          Needless to say, all four assumptions have been proven wrong at Budget Embarcadero, San Francisco, and FWIW said
          representative had already closed shop by the time #3 came to pass. It wasted like
          2 hours of a precious Saturday that I had planned to spend on the road - boy am I pissed.
          And I just refuse to accept the idea of having to question every statement made by a representative
          and jotting down the name of every person I talk to. Get your shit together, Budget, before I rent
          with you again.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#re-budget-reservation-confirmation</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#re-budget-reservation-confirmation"/>
    <a:updated>2008-02-16T15:17:00-08:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>To Rephrase Reginald</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="to-rephrase-reginald" href="#to-rephrase-reginald"></a>
        <p>
          Reginald
          <a href="http://feeds.raganwald.com/~r/raganwald/~3/233276343/blodgetts-law.html">quotes</a>
          Blodgett's Law and points to verbos languages:
        </p>
        <blockquote>
          A development process that involves any amount of tedium will eventually be done poorly or not at all.
        </blockquote>
        <p>
          If I read him correctly, Reginald is trying to say: "Programming Languages that require a
          handwritten test suite to prove basic type correctness will eventually be abandoned."
          <i>Happily trolling away ...</i>
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#to-rephrase-reginald</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#to-rephrase-reginald"/>
    <a:updated>2008-02-14T20:47:00-08:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Děkuji Vám</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="a-big-thank-u" href="#a-big-thank-u"></a>
        <p>
          Yet another installment in that long list of pleasant surprises (example made up).
          Imagine I've written a method that takes a map and prints its entry set. Now I
          want to generalize this method to print any set and to make the caller pass in the
          entry set himself. Highlight <code>map.entrySet()</code> and press Apple-Alt-P:
        </p>
        <img src="removeparam.png" alt="Introduce Parameter refactoring"/>
        <p>
          Notice the last option "Remove parameter no longer used"? It makes
          my refactoring just one consistent operation, one I'm doing quite regularly and
          this is really just awesome. Steve Yegge
          <a href="http://steve-yegge.blogspot.com/2007/12/codes-worst-enemy.html">dismisses</a>
          it as "industry excitement about
          manipulating code as algebraic structures". He's happier pushing around compressed ASCII.
          Matter of taste.
        </p>
        <p>
          Anyway, making my employer buy IDEA licenses is already a form of positive
          feedback, but I think it's about time to extend a BIG thank you to the
          guys at JetBrains. You have fundamentally and continually improved my work
          experience over the last >5 years --- I can't even remember anymore when I retired
          emacs. Cranking out and massaging code is what I do and every friction removed helps
          keep me sane.
        </p>
        <p>
          &lt;/vendor-promotion>
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#a-big-thanks</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#a-big-thanks"/>
    <a:updated>2008-01-12T10:44:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Actually type inference has been here for a long time</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="ide-type-inference" href="#ide-type-inference"></a>
        <p>
          There are so many complaints that variable declarations in Java are written
          like so: <em>type var = new type();</em>.
        </p>
        <p>
          Not in my IDE. In my IDE, it's: <em>new type() CTRL-ALT-V/F/C var RETURN</em>. Or
          <em>type var = new SHIFT-CTRL-SPACE RETURN</em>. And should I want to change the type,
          I typically rinse and repeat.
        </p>
        <p>
          This is not to say that it doesn't inhibit readability and that a compiler shouldn't do the job.
          But people who actually type the type twice today simply don't use the right tool.
        </p>
        <p>
          [2008-01-06] Kevin writes: <em>You must be joking. That's not type inference.</em> Of course I'm joking and not.
          Type inference refers to the process performed by the programming environment
          that fills in -redundant- type declarations that have been omitted from the source code, typically in two
          cases: variable declarations (type is that of the initialization expression) and function calls (type
          parameters derived of value parameters' types). This process is hopefully defined by the language specification.
        </p>
        <p>
          However, we have to keep in mind that this definition is very focused on the textual input that is source
          code. The underlying assumption is that the programmer types and reads the source code as a sequence of
          characters --- so we need the source code to be as concise as possible. I'm saying that we need to factor
          programming environments in more. I'm saying I don't need type inference for locals as badly as other people
          seem to because my interface to Java is much more than the JLS and a text editor, my IDE helps me.
        </p>
        <p>
          There are more examples like this. No one argues against long variable names because they are so hard to type.
          Opponents of extension methods as recently proposed say that a reader of a call site can no longer figure out
          easily where the method is defined. Not in my world: CTRL-Hover over the symbol and I see the definition site.
          Smalltalkers don't ever bitch about the class definition syntax since they almost never see it. And why has
          no one ever proposed getting rid of the package declaration statement in Java although it is predetermined by
          the directory location? Exactly, no one writes these by hand anyway.
        </p>
        <p>
          In the end it's a language vs tool argument: what I say makes the IDE great, linguists say they wouldn't need
          if the language were better. Don't get me wrong, I'm all for local variable type inference. And I loathe
          code generation. I'm just getting pretty tired of endless my language vs your language when the comparison is
          based on the textual representations and not on the net programming effort.
        </p>
        <p>
          [2008-01-07] Rémi and Ben raise an important point below: some types cannot be
          written down in Java, especially of anonymous inner classes.
        </p>
        <h3>Comments</h3>
        <div class="comment">
          <p>
            Kevin: You must be joking. That's not type inference.
          </p>
        </div>
        <div class="comment">
          <p>
            <a href="http://weblogs.java.net/blog/forax/">Rémi Forax</a>: Matthias, yes IDE helps but
            it will bother me to have to use the mouse over every variables to understand
            a code.
            Reading codes is a part of my job
            (finding bugs in student codes)
            and i love Java because i am able to
            do that pretty fast.</p><p>
          Moreover, Java type system own types that
          are not writeable like the type of null,
          the intersection of interfaces, wildcard capture.
          By example, try to find with your IDE,  the type of foo in the code below:</p>
          <pre><![CDATA[List<?> list = null;
foo := null;   // inference here
list.add(foo);
]]></pre>
          Rémi
        </div>
        <div class="comment">
          <p>
            Ben: Rémi makes a good point.  What if you have an anonymous inner class with a method that you want to be
            able to call or a field you want to reference?
          </p>
          <pre><![CDATA[
Object o = new Object() {
 void doSomething() { }
 int aField;
};

// Won't compile
// o.doSomething();
// o.aField;

with type inference:

final o = new Object o = new Object() { void doSomething() { } };
o.doSomething();
o.aField;  ]]></pre>
          <p>
            AFAIK, this is the main reason local variable inference was added to C#3 - to allow anonymous types for LINQ expressions.
          </p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#ide-type-inference</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#ide-type-inference"/>
    <a:updated>2008-01-05T22:00:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Swimming with the stream</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="swimming-with-the-stream" href="#swimming-with-the-stream"></a>
        <p>
          JAXB is great. Not a doubt. Just as an academic exercise, in order to
          write a big document, can we avoid
          building the object graph in advance? Could we still profit from strongly
          typed binding? The best answer I found was this:
        </p>
        <p>
          Write an interface that corresponds to your complex type. Where JAXB expects
          a property to read from, have a method that accepts a closure that accepts
          an instance of the child element type. For elements of simple type, provide
          a simple setter:
        </p>
        <pre>
          public interface Artist {
          public Artist name(String name);
          }

          public interface Album {
          public Album artist({Artist=>Void} artist);
          public Album title(String title);
          }
        </pre>
        <p>
          In order to produce an Xml document with this, we need to bootstrap ourselves
          an Album instance and write through typed calls:
        </p>
        <pre>
          write("album", Album.class, {Album a =>
          a.title("mein leben")
          .artist({Artist a =>
          a.name("Charlotte Saenger")
          })
          });
        </pre>
        <p>
          Not pretty. The best I could think of. Seems like this
          won't have a great future... Just for the sake of completeness, an
          implementation _sketch_:
        </p>
        <pre>
          public class StreamBinder {
          Model m;
          ContentHandler out;


          &lt;T> void write(String uri, String element, Class&lt;T> c, {T=>void} t) {
          out.startElement(uri, element, "", new AttributesImpl());
          t.invoke(bind(c));
          out.end(uri, element, "");
          }

          &lt;T> T bind(final Class&lt;T> c) {
          return c.cast(Proxy.newProxyInstance(c.getClassLoader(), new Class[] {c}, new InvocationHandler() {
          public Object invoke(Object o, Method method, Object[] args) throws Throwable {
          String uri, element = model.lookup(c, method);
          Class elementType = model.lookup(c, method);

          // ##handle simple content
          write(uri, element, elementType, args[0]);
          return o;
          }
          }));
          }


          public static void main(String[] args) {
          model = reflectOver(Album.class);

          new StreamBinder(out, model)
          .write("album", Album.class, {Album a =>
          a.title("mein leben")
          .artist({Artist a =>
          a.name("Saenger")
          })
          });
          }
          }
        </pre>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#swimming-with-the-stream</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#swimming-with-the-stream"/>
    <a:updated>2007-12-22T00:20:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>S3ad</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="S3ad" href="#S3ad"></a>
        <p>
          So I tried Transmit, Forklift and S3cmd and _none_ allows me to set
          the content-type. Only s3cmd can make items world-readable in an easy
          way. I can't believe I just had to hack s3cmd to make '--mime-type' work.
        </p>
        <p>
          Also sad: this file as application/atom+xml would be spec compliant, but Camino only
          renders application/xml. So I'm going to stay with xml I guess...
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#S3ad</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#S3ad"/>
    <a:updated>2007-12-21T22:34:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>PUT to work</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="PUT-to-work" href="#PUT-to-work"></a>
        <p>
          I want to second
          <a href="http://devhawk.net/2007/12/05/Durable+And+RESTful.aspx">Harry</a>
          and Patrick's comment over at
          <a href="http://www.dehora.net/journal/2007/12/21/durable-and-restful/">Bill's blog</a>. I think
          all of Bill's concerns can be addressed:
        </p>
        <p>
          Trust: If you have multiple clients, you need to do access control anyway (they might PUT to each other's
          items, even if created by POST).
        </p>
        <p>
          Accidental overwriting: handled by 'If-None-Match'.
        </p>
        <p>
          Conflicts: with PUT, you can route requests according to URI and do efficient conflict
          resolution/avoidance on the local server shard.
        </p>
        <p>
          Apart from idempotency: let's remember that Atom is for syndication - that typically entails already existing
          items
          with client-specific ids. That an Atom server forces its own id space onto me that I need to map to mine is a
          nuisance,
          not a feature. And for the really stupid clients: serve an Atom feed of fresh, unused ids.
        </p>
        <p>
          On the same level, I've never been into the "primary keys must be database-generated" mantra.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#PUT-to-work</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#PUT-to-work"/>
    <a:updated>2007-12-21T20:46:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>mernst.org moved and outsourced</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="mernst-org-moved-and-outsourced" href="#mernst-org-moved-and-outsourced"></a>
        <p>
          As a consequence of my move to Zurich, I had to change providers for mernst.org. I was torn
          between two extremes: a "real" server where I could experiment and put Java services on the web
          and a minimalistic approach where http file delivery and mail run with the big guys. I have chosen
          the latter route - a mere domain registration with a german provider, http traffic is CNAMEd to my
          bucket www.mernst.org at Amazon S3, email lives on Google Apps.
        </p>
        <p>
          What I'm still looking for is a free/pay per usage service that would accept [captcha'd] [XHR]
          POST requests for my domain, store them and offer them as a feed that I could process at
          my discretion, i.e. when I'm online.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#mernst-org-moved-and-outsourced</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#mernst-org-moved-and-outsourced"/>
    <a:updated>2007-11-24T23:24:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Non-blocking IO Iterators</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="non-blocking-io-iterators" href="#non-blocking-io-iterators"></a>
        <p>
          When you deal with non-blocking IO your IO tasks turn from methods into state machines. You do some
          IO on every transition, each state representing what kind of IO you would like to do next. In combination
          with something like the<a href="http://chaoticjava.com/posts/category/code/java/frameworks/yielder/">yielder
          iterator byte rewriting framework</a>, we can turn these back into iterator methods that
          <em>yield</em>
          interest sets, making NIO a little easier again:
        </p>
        <pre>
          // this is sample code that neither implements proper error handling
          // nor a tunable buffer allocation policy or anything ...
          // it just demonstrate how an NBIO task looks as an iterator of InterestSets
          public class Copy extends Yielder&lt;InterestSet> {
          public final ReadableByteChannel source;
          public final WritableByteChannel target;

          public Copy(ReadableByteChannel source, WritableByteChannel target) {
          this.source = source;
          this.target = target;
          }

          protected void yieldNextCore() {
          try {
          ByteBuffer b = ByteBuffer.allocate(4096);
          while (true) {
          switch (source.read(b)) {
          case -1: // EOF
          yieldBreak(); return; // yieldBreak() actually necessary?
          case 0:
          yieldReturn(new InterestSet().read(source));
          break;
          default:
          b.flip();
          while (b.remaining() > 0)
          if(target.write(b) == 0) yieldReturn(new InterestSet().write(target));
          }
          }
          } catch (IOException e) {
          // hmm what about that
          }
          }
          }

          ... where:

          public class InterestSet {
          public final HashMap&lt;Channel, Integer> interestSet = new HashMap&lt;Channel, Integer>();
          public Long delay;

          public InterestSet withInterest(Channel c, int op) {
          interestSet.put(c, or(interestSet.get(c), op));
          return this;
          }

          public InterestSet waitFor(long delay, TimeUnit u) {
          this.delay = TimeUnit.MILLISECONDS.convert(delay, u);
          return this;
          }

          public InterestSet read(Channel c) {
          return withInterest(c, SelectionKey.OP_READ);
          }

          public InterestSet write(Channel c) {
          return withInterest(c, SelectionKey.OP_WRITE);
          }

          public InterestSet connect(Channel c) {
          return withInterest(c, SelectionKey.OP_CONNECT);
          }

          public InterestSet accept(Channel c) {
          return withInterest(c, SelectionKey.OP_ACCEPT);
          }

          private int or(Integer a, int b) {
          return a == null ? b : a|b;
          }
          }
        </pre>
        <p>
          <em>Disclaimer:</em>
          I haven't actually run this code yet - just to get an idea how it would look like.
        </p>
        <h3>Comments</h3>
        <div class="comment"><a href="http://chaoticjava.com/">Aviad Ben Dov</a>: Actually, yieldBreak() isn't really
          neccessary. Reaching the end of the yieldNextCore method is an implicit yieldBreak. So, you could either
          yieldBreak, or to break from the while loop - if that's the intention.
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#non-blocking-io-iterators</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#non-blocking-io-iterators"/>
    <a:updated>2007-10-05T19:18:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Extract Method Reloaded</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="extract-method-reloaded" href="#extract-method-reloaded"></a>
        <p>
          Three steps of refactoring I often perform: given a complex expression
          <em>exprA(exprB)</em>
        </p>
        <ul>
          <li>extract local "b" on exprB: b=exprB; exprA(b)</li>
          <li>extract method "a" on exprA: b=exprB; a(b)</li>
          <li>inline local "b": a(exprB)</li>
        </ul>
        <p>Wouldn't it be great if this were part of the extract method refactoring? I.e. you get to choose
          subtrees of the expression's AST to form the parameters?
        </p>
        <p>Example at hand: my expression is "interestSet.get(ch)|op" and I want to extract a method "or(Integer a, int
          b)" where
          "interestSet.get(ch)" would form the first parameter. In the next step I would change the method to return
          "a == null ? b : a|b".
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#extract-method-reloaded</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#extract-method-reloaded"/>
    <a:updated>2007-10-04T16:15:00+02:00</a:updated>
  </a:entry>

  <a:entry>
    <a:title>Definite Initialization?</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="definite-initialization" href="#definite-initialization"></a>
        <p>
          The Java language specification requires that a call to a super(...) be the first statement in a constructor.
          That rule has often felt overly restrictive to me. For example, it forbids code like the following:
        </p>
        <pre>
          Constructor() {
          T local = expr;
          super(local);
          }
        </pre>
        <p>
          However super(expr) is allowed although both versions are provably equivalent. What's the motivation behind
          that rule? It's twofold: one, it garantuees that we do call a superclass constructor. Two, it (kind of)
          garantuees
          that we do not access "this" before that. The second point is kind of moot because the compiler still has to
          prove that
          "expr" does not access "this" either.
        </p>
        <p>
          The whole situation reminds me very much of definite assignment: with JDK 1.1, the rules
          for initialization of local final variables were relaxed. You do not need to provide an initialization
          expression at the point of declaration but you can assign a value later, iff the compiler can prove that a)
          you only assign once and b) you do not access the variable before.
        </p>
        <p>
          I personally believe :-) that the same relaxed rule could be applied to super constructor invocations. Take
          <a href="http://java.sun.com/docs/books/jls/third_edition/html/defAssign.html">
            http://java.sun.com/docs/books/jls/third_edition/html/defAssign.html</a>,
          replace the variable by "this", "definetely assigned" by "definetely initialized" and "assignment expression"
          by "super constructor
          invocation". Then the following code could be legal:
        </p>
        <pre>
          Constructor(x) {
          if(x != null) {
          super(x);
          } else {
          super();
          }
          }
        </pre>
        <p>
          Am I missing something?
        </p>
        <h3>Comments</h3>
        <div class="comment">
          <p>
            Matt: AFAIK, the JRE 1.4+ verifier allows super() to be later in the constructor, but only the language
            forbids it.
          </p>
          <p>In fact, for anonymous subclasses, the compiler generates assignments to this.static before calling
            super()! You can see evidence of this if you read through Lower.java in the compiler sources.
          </p>
        </div>
        <div class="comment">
          <p>
            <a href="http://chaoticjava.com/">Aviad Ben Dov</a>: I totally agree. This obscure rule has made a lot of
            code into a mess.
          </p>
          <p>Currently, to avoid having crazy expressions at the constructor, I create static methods and call those.
            But still, this causes ridiculous code.
          </p>
        </div>
        <div class="comment">
          <pre class="normal"><![CDATA[Robert Konigsberg: I'd love to see this restriction if only for precondition attribute validation.

Here's a contrived example:

class Derived extends Range {
 public Derived(int min, int max) {
   if (min > max) { throw new IAE(...); }
   super(min, max);
 }
}

Typically validations are single, such as

class Derived extends Range {
 public Derived(int min, int max) {
   super(min, max);
   if (min < 0) { throw new IAE(...); }
   if (max < 0) { throw new IAE(...); }
 }
}

This you can get away with using a validation method, but it's ugly.

class Derived extends Range {
 public Derived(int min, int max) {
   super(isNonNegative(min),
       isNonNegative(max));
 }
 private static int isNonNegative(int val) {
   if (val < 0) { throw new IAE(...); }
   return val;
 }
}

I'm not a language designer, but I'll ask: how about getting multiple return values? Then we could have

class Derived extends Range {
 public Derived(int min, int max) {
   super(validate(min, max));
 }
 private static int validate(int min, int max) {
   if (min < 0) { throw new IAE(...); }
   if (max < 0) { throw new IAE(...); }
   if (max < min) { throw new IAE(...); }
   return (min, max);
 }
}        ]]></pre>
        </div>
        <div class="comment">
          <p><a href="http://blogs.sun.com/brk">Bharath R</a>: In addition to the motivations that you mentioned, this
            rule also ensures that (in cases where explicit calls to super() are used) the subclass does not access
            non-static elements (methods and fields) of the super class before the latter has been completely
            initialized. Again, if the compiler can prove that this isn't violated, there is no need to mandate that
            super() be the first statement in the constructor.
          </p>
        </div>
        <div class="comment">
          <p><a href="http://weblogs.java.net/blog/forax/">Rémi Forax</a>: A simple rule could be:
          </p>
          <p>1) before super() or this(), context of the constructor is static
            so no access to an instance variable is allowed and "this" doesn't exist.
          </p>
          <p>2) after super()/this() context is classical</p>
          <p>Futhermore, only one super() or this() is allowed for an execution path.</p>

          Rémi
        </div>


      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#definite-initialization</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#definite-initialization"/>
    <a:updated>2007-09-29T12:50:00+02:00</a:updated>
  </a:entry>

  <a:entry>
    <a:title>On the Luxury of Walking to Work</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="on-the-luxury" href="#on-the-luxury"></a>
        <p>
          I've always enjoyed walking to the office on good weather (in Hamburg that means no rain), a habit that
          I'm determined to continue in Zurich. Here's a rocky rendition of my round about 25 minute commute, shot from
          the hip every ten seconds, stitched together with iMovie:
        </p>
        <p>
          <object width="425" height="350">
            <param name="movie" value="http://www.youtube.com/v/p5gVJXNVoUk"></param>
            <embed src="http://www.youtube.com/v/p5gVJXNVoUk" type="application/x-shockwave-flash" width="425"
                   height="350"></embed>
          </object>
        </p>
        <p>
          On a side note, I'm amazed how, let's say old fashioned the Youtube upload form is. Empty required fields are
          flagged only after
          submit/reload, the categories combo and my location map are reset in that moment. Not to mention that I have
          to invent yet another user name, even if I log in with my Google account - the obvious ones have already been
          harvested, of course.
        </p>
        <h3>Comments</h3>
        <div class="comment">
          <p>
            <a href="http://www.elien.de">Björn</a>: I expected to see something from Zürich and was quite astouned to
            recognize Hamburg after the first few frames. Only then, I realized that you are probably not even started
            your career in switzerland :)
          </p>
          <p>I wish you all the best and good luck.</p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#on-the-luxury</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#on-the-luxury"/>
    <a:updated>2007-09-12T19:35:00+02:00</a:updated>
  </a:entry>

  <a:entry>
    <a:title>New Adventures</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="new-adventures" href="#new-adventures"></a>
        <p>
          Friday was my last day at<a href="http://www.coremedia.com">CoreMedia</a>, after a long long time. I've had
          a great time and got to work with a bunch of people I highly respect. Fare well!
        </p>
        <p>
          Later this year, come find me in Google Zurich.
        </p>
        <p>
          <em>Folks, thanks for all the good wishes!</em>
        </p>
        <h3>Comments</h3>
        <div class="comment">
          <p>
            Sebastian Sanitz: Glückwunsch - Viel Spaß in Zürich!
          </p>
        </div>
        <div class="comment">
          <p>
            <a href="http://blogbauer.net">Björn Bauer</a>: Not only as a supporter I will miss you! Hope you feel good
            with Google. Wish you all the best!
          </p>
        </div>
        <div class="comment">
          <p>
            <a href="http://gafter.blogspot.com/">Neal Gafter</a>: Yay! Please look me up when you're in Mountain View.
          </p>
        </div>
        <div class="comment">
          <p>
            <a href="http://jandiandme.blogspot.com">Eberhard</a>: Well, I wish you the very best for your next step in
            your career. Zürich is quite a nice place - so enjoy
            your time there!
          </p>
        </div>
        <div class="comment">
          <p>
            <a href="http://blogs.sun.com/jmxetc">Daniel</a>: Hey Matthias, congratulations! -- daniel
          </p>
        </div>
        <div class="comment">
          <p>
            <a href="http://blogs.sun.com/brk">Bharath R</a>: Congratulations Matthias. Hope you keep the Java
            engineering flag flying high at Google (and continue your excellent writings). All the best.
          </p>
        </div>
        <div class="comment">
          <p>
            Gino: I wish you a good time in Zurich, please post the walk to your new work.
          </p>
        </div>
        <div class="comment">
          <p>
            Joerg: Alles Gute und guten Start!
          </p>
        </div>
        <div class="comment">
          <p>
            Jochen T: Awesome, Google sounds like it would be fun. They're turning evil though, so watch out. But then
            again, look at me -- I'm working for Microsoft ;-)
          </p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#new-adventures</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#new-adventures"/>
    <a:updated>2007-09-09T10:40:00+02:00</a:updated>
  </a:entry>

  <a:entry>
    <a:title>R as in record</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="r-as-in-record" href="#r-as-in-record"></a>
        <p>
          Some interesting stuff I've been working on recently: the never ending story of object-relational mapping.
          Instead of breaking objects into relations, I've looked into mapping annotated classes directly onto
          <a href="http://download.oracle.com/docs/cd/B12037_01/appdev.101/b10807/10_objs.htm#CHDEFBEA">Oracle
            user-defined
            object types</a>, or basically records.
        </p>
        <p>
          What you get is: in combination with VARRAYS you get arbitrary nesting and can persist an object tree in a
          single
          column. It's about the same usage model as with XML serialization: if you can get used to non-cyclic,
          non-shared,
          trees of value objects you'll like it. Performance is great, on the order of several hundred items per second
          on
          a standard PC with Oracle/XE. In contrast to just serializing blobs, the database actually understands your
          schema and we can define indexes on simple properties or easily have the database server maintain
          index-organized
          tables for joining against property paths that may be array-valued. All important operations can be performed
          in single statements,
          no hidden roundtrips to maintain several tables or open/close lobs are necessary. (Actually not a 100% true,
          creating an instance of a struct requires to acquire a StructDescriptor first but that can be reused for all
          instances
          in the same batch).
        </p>
        <p>
          No object identity, no sessions to flush, no second-level cache: this is just about making the database
          understand
          structured complex values. I'm beginning to think of it as my JAXB for persistence.
        </p>
        <p>
          I would like to see this on other databases but the support for structs and arrays and their respective JDBC
          counterparts doesn't look great. On DB2, it seems like the path leads to their XML store anyway.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#r-as-in-record</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#r-as-in-record"/>
    <a:updated>2007-09-09T09:59:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Knee Jerk</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="knee-jerk" href="#knee-jerk"></a>
        <p>
          How simple-minded have I become? Patrick Logan holds a
          <a href="http://patricklogan.blogspot.com/2007/09/morse-codes-in-erlang.html">hammer</a>
          to my knee and my immediate jerk: "by no means does that pattern matching look particularly readable to me"
          and "I can do it just as well in Java". Although
          that is indeed the case, it isn't Patrick's point and I also thought I had long given up on contests like
          these.
          It must be some kind of allergy striking as soon as one topic becomes too popular. So just for your reference:
        </p>
        <pre><![CDATA[
  public static final Map<Character, String> codes = new HashMap<Character, String>() {
    {
      put('A', ".-"); put('B', "-..."); put('C', "-.-."); put('D', "-.."); put('E', ".");
      put('F', "..-."); put('G', "--."); put('H', "...."); put('I', ".."); put('J', ".---");
      put('K', "-.-"); put('L', ".-.."); put('M', "--"); put('N', "-."); put('O', "---");
      put('P', ".--."); put('Q', "--.-"); put('R', ".-."); put('S', "..."); put('T', "-");
      put('U', "..-"); put('V', "...-"); put('W', ".--"); put('X', "-..-"); put('Y', "-.--");
      put('Z', "--..");
    }
  };

  public static List<String> decode(String morse) {
    ArrayList<String> result = new ArrayList<String>();
    decode(morse, "", result);
    return result;
  }

  private static void decode(String morse, String partial, ArrayList<String> result) {
    if (morse.length() == 0) {
      result.add(partial);
    } else {
      for (Map.Entry<Character, String> entry : codes.entrySet())
        if (morse.startsWith(entry.getValue()))
          decode(morse.substring(entry.getValue().length()), partial + entry.getKey(), result);
    }
  }

  public static void main(String[] args) {
    System.out.println("decode(\".-\") = " + decode(".-"));
    System.out.println("decode(\"...---..-....-\").contains(\"SOFIA\") = " + decode("...---..-....-").contains("SOFIA"));
    System.out.println("decode(\"...---..-....-\").contains(\"SOPHIA\") = " + decode("...---..-....-").contains("SOPHIA"));
    System.out.println("decode(\"...---..-....-\").contains(\"EUGENIA\") = " + decode("...---..-....-").contains("EUGENIA"));
    System.out.println("decode(\"...---..-....-\").size() = " + decode("...---..-....-").size());
  }
]]></pre>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#knee-jerk</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#knee-jerk"/>
    <a:updated>2007-09-09T09:40:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Generics in Reflection</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="generic-reflection" href="#generic-reflection"></a>
        <p>
          Generics haven't really arrived in relective libraries yet. Most libraries reflect over class objects, not
          types. For example, while JAXB knows how to marshal a List&lt;X>, when presented a Holder&lt;X> it will
          reflect over the erased Holder.class and conclude that its value is of type Object, not X. Note to self:
          whenever designing a reflective library I will try and accept instances of Type from now on.
          <a href="http://gafter.blogspot.com/2006/12/super-type-tokens.html">Gafter's Gadget</a>
          will be helpful as the user's input device.
        </p>
        <p>Here's some handy code that helps you resolve member types in instantiations of generic types:</p>
        <pre><![CDATA[
  /**
   * Resolve the given type in the given environment. This entails
   * recursively replacing all type variables
   * referred to through by instantiations in env.
   *
   * @param type type of a member of a class in the inheritance tree of the env
   * @param env concrete instantiation of a (possibly parameterized) type
   * @return the resolved type
   */
  public static Type resolve(Type type, Type env) {
    ParameterizedType pt = cook(env);
    Type superclass = classOf(pt).getGenericSuperclass();

    if (superclass != null)
      type = resolve(type, superclass);

    for (Type genericInterface : classOf(pt).getGenericInterfaces())
      type = resolve(type, genericInterface);

    return replace(type, classOf(pt), pt.getActualTypeArguments());
  }

  private static Type replace(Type type, Class c, Type[] typeArguments) {
    if (type == null) return null;
    if (type instanceof TypeVariable) {
      int index = Arrays.asList(c.getTypeParameters()).indexOf(type);
      return index == -1 ? type : typeArguments[index];
    }
    if (type instanceof Class) return type;
    if (type instanceof ParameterizedType) {
      ParameterizedType pt = (ParameterizedType) type;
      Type[] arguments = pt.getActualTypeArguments().clone();
      for (int i = 0; i < arguments.length; i++) {
        arguments[i] = replace(arguments[i], c, typeArguments);
      }
      return ParameterizedTypeImpl.make(classOf(pt), arguments, replace(((ParameterizedType)type).getOwnerType(), c, typeArguments));
    }
    throw new IllegalArgumentException(String.valueOf(type));
  }

  private static Class<?> classOf(ParameterizedType pt) {
    return (Class<?>) pt.getRawType();
  }

  private static ParameterizedType cook(Type t) {
    if (t instanceof ParameterizedType) return (ParameterizedType) t;
    if (t instanceof Class) {
      Class c = (Class) t;
      Type[] args = new Type[c.getTypeParameters().length];
      for (int i = 0; i < args.length; i++) {
        throw new UnsupportedOperationException("Can't (yet) construct a wildcard argument to " + t);
      }
      return ParameterizedTypeImpl.make(c, args, c.getEnclosingClass());
    }

    // have I missed a case?
    throw new IllegalArgumentException(String.valueOf(t));
  }
        ]]></pre>
        <p>
          Example: what type has iterator() in a LinkedList&lt;String>?
        </p>
        <pre><![CDATA[
    resolve(
      AbstractCollection.class.getMethod("iterator").getGenericReturnType(),
      parameterizedType(LinkedList.class, String.class)
    )

    =>

    java.util.Iterator<java.lang.String>
      ]]></pre>
        <p>
          Note that in their infinite wisdom, Sun have made the type hierarchy into interfaces with private
          implementations
          and you're invited to either re-implement them yourself or cross your fingers that
          <code>sun.reflect.generics.reflectiveObjects.*</code>
          is not gonna go away. A public concrete class in java.lang.reflect would have done the job, too, IMHO.
        </p>
        <h3>Comments</h3>
        <p>
          <a href="http://weblogs.java.net/blog/emcmanus">Eamonn McManus</a>
          @ 2007-08-02 04:38:06 PDT:
        </p>
        <div class="comment">
          <p>Excellent!</p>
          <p>Sergey Malenkov and I addressed a similar problem in the JDK. For JavaBeans (Sergey) and MXBeans (me), we
            needed the ability to know that the type of iterator() in a List&lt;String> is Iterator&lt;String>, etc. The
            result of our labours is the class com.sun.beans.TypeResolver in JDK7 (and OpenJDK), which you can see at
            https://openjdk.dev.java.net/source/browse/openjdk/jdk/trunk/j2se/src/share/classes/com/sun/beans/TypeResolver.java?view=markup
          </p>
          <p>There are actually quite a few nasties, of which the lack of concrete classes that you mention is one,
            though not too important for us inside the JDK. Another is doing the right thing in the presence of raw
            types (what is the type of iterator() in a raw List?). Also there's a bug in the way generic arrays are
            handled which means that you can get a GenericArrayType when it should really be a Class like
            String[].class.
          </p>
          <p>I was surprised to see that the spec for ParameterizedType doesn't say that you can modify the returned
            array. The good example of Method.getDeclaredAnnotations() and relations should be generalized. In practice
            it's hard to imagine that an implementation of ParameterizedType would not clone the array before returning
            it to you, so you don't really need to clone it again.
          </p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#generic-reflection</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#generic-reflection"/>
    <a:updated>2007-07-31T10:40:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>The Easy ETag Issue</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="easy-etag" href="#easy-etag"></a>
        <p>
          <a href="http://www.dehora.net/journal/2007/07/earned_value.html">Bill de hÓra</a>:
        </p>
        <blockquote>
          "... Django will calculate an ETag for each request by MD5-hashing the page content, and it'll take care of
          sending Not Modified responses, if appropriate." That's it - you're done.
        </blockquote>
        <p>
          Just an observation: a Java web framework that collects all its output into a string before sending it
          to the client would be considered a poor, if not amateur implementation while we hail its Python competitor
          for it.
          Do Javanese have a premature optimization mindset? Indeed most Java projects never reach the point where they
          need to scale...
        </p>
        <p>
          How about this approach: in absence of a more efficient alternative, calculate the ETag as a streaming digest
          of the content and send it as a trailer field. Iff the client sent an If-None-Match, do the calculation first
          over the content streamed to /dev/null. If matched, send 304. If not matched, do it again, this time streaming
          to the client. In an MVC architecture, we could reuse the computed model and just repeat the rendering phase.
          This way we trade memory consumption against additional processing overhead.
        </p>
        <h3>Comments</h3>
        <p>
          <a href="http://d.hd.org/">Damon Hart-Davis</a>
          @ 2007-07-18 09:59:52 PDT:
        </p>
        <div class="comment">
          <p>...assuming that a page isn't very expensive to generate and is guaranteed to be generated exactly the same
            way twice.
          </p>
          <p>My largest app generates each (JSP) page on the fly each time, and it is very unlikely that the page
            content would be identical twice in a row (eg I drop some content if the page is taking too long to send to
            the user).
          </p>
          <p>On the other hand, generating an ETag on the fly is relatively easy, because I know the timestamps of the
            important constituents of the page.
          </p>
          <p>Thus: the 'run it twice' approach would for me be slow and wrong!</p>
          <p>
            <em>(Matthias) I absolutely agree (that's why I wrote "in absence...")! My proposal only tries to improve on
              the memory
              requirements of the out-of-the box solution people are wishing for so badly. The fundamental weaknesses
              remain: request must actually be performed in order to compute
              the ETag and it's based on the volatile rendered representation.
            </em>
          </p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#easy-etag</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#easy-etag"/>
    <a:updated>2007-07-18T13:30:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Ids are forever ...</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="jroller-ids" href="#jroller-ids"></a>
        <p>
          ... until you decide to change them all. JRoller
          seems to just have done so:
          <img src="jroller.png" alt="150 unread items"/>
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#jroller-ids</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#jroller-ids"/>
    <a:updated>2007-07-17T18:30:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Maneifa Makes A NativE InterFAce</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="maneifa-native-binding" href="#maneifa-native-binding"></a>
        <p>
          So I had to interface with Windows' Lsa* APIs in order to retrieve
          the password of my machine domain account ("$machine.acc") that
          allows me to authenticate as the HOST/hostname kerberos service.
          No problemo. Downloaded the Python Win32 extensions and had the
          string out in like two minutes.
        </p>
        <p>
          Now do the same in Java. JNI is a no go. I looked at
          <a href="https://nlink.dev.java.net/">NLink</a>
          and found
          myself annotating most parameters with @MarshalAs(PVOID)
          and marshalling (e.g. LsaUnicodeString) in and out of ByteBuffers myself.
        </p>
        <p>
          Now don't get me wrong: I don't expect a native interface to implement the
          most wicked marshalling scheme for me. I would rather that it embraces marshalling
          on the Java side in an extensible fashion and only implements the absolute minimum
          in native code. So I came up with this for Win32:
        </p>
        <pre>
          /**
          * Push $words words from address $stack. Invoke $function.
          * After invocation, put the result at $stack. $retType defines
          * the result type (0: void, 1: 32bit int/ptr, 2: 64bit, 3: float,
          * 4: double. If $isCdecl, clear up the stack afterwards.
          */
          public static native void invoke(
          long function,
          long stack,
          int words,
          int retType,
          boolean isCdecl
          );
        </pre>
        <p>
          With the very first inline assembly code of my life it was easy to implement:
        </p>
        <pre>
          JNIEXPORT void JNICALL Java_org_mernst_maneifa_Maneifa_invoke
          (JNIEnv *env, jclass c, jlong function, jlong stack,
          jint words, jint retType, jboolean isCdecl)
          {
          int i, w;
          int *buf = (int*) stack;
          void (*f)() = (void (*))function;

          for(i=words-1; i>=0; i--) {
          w = buf[i];
          __asm push w
          }

          switch(retType) {
          case 0: ((void (_stdcall *)())f)(); break;
          case 1: buf[0] = ((int (_stdcall *)())f)(); break;
          case 2: ((long long *)buf)[0] = ((long long (_stdcall *)())f)(); break;
          case 3: ((float*)buf)[0] = ((float (_stdcall *)())f)(); break;
          case 4: ((double*)buf)[0] = ((double (_stdcall *)())f)(); break;
          }

          if(isCdecl) {
          for(i=0; i&lt;words; i++) {
          __asm add esp, 4
          }
          }
          }
        </pre>
        <p>
          Easy enough. EVERYTHING ELSE CAN BE DONE IN JAVA. Well, almost.
          Three things I need are there but weren't public: ClassLoader#findNative finds
          symbols in DLLs, DirectByteBuffer#address and new DirectByteBuffer(address, cap)
          do the pointer fiddling.
        </p>
        <p>
          For a different architecture this interface might need to be different (wrt registers) but that's ok.
          It reminds me of the approach SWT takes in contrast to AWT: instead of mapping a uniform
          interface to the system in tedious native code, rather use your high-level language.
        </p>
        <p>
          Once it's settled down a little, I might describe what interfaces I use for marshalling. Now it's time for
          lunch.
          Oh, as for the name: Maneifa used to work here at CoreMedia.
        </p>
        <p>
          <em>Update:</em>
          a MacOS/X Intel port was easy enough. Removed _stdcall and added stack padding.
        </p>
        <h3>Comments</h3>
        <p>
          <a href="http://gestalt.monoid.net">Michael Nischt</a>
          @ 2007-07-11 23:15:14 PDT:
        </p>
        <div class="comment">
          <p>
            Definitely nice!
            <br/>
            I'd love to see some usage examples soon..
          </p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#maneifa-native-binding</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#maneifa-native-binding"/>
    <a:updated>2007-07-11T13:01:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Generics and Delegation</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="generics-and-delegation" href="#generics-and-delegation"></a>
        <p>
          <a href="http://tech.puredanger.com/2007/07/03/pattern-hate-template/">Alex</a>
          hates template methods
          and I think he's right. I prefer delegation, too, but traditionally it has a drawback: the delegate's
          type is obscured. In Alex' example, I have to cast to the specific ConnectionFactory type if I wanted to
          use one of its specific methods. That's why I've started to parameterize delegating classes with the
          type of their delegates like so:
        </p>
        <pre>public class ConnectionPool
          <b>&lt;CF extends ConnectionFactory></b>
          {
          public final
          <b>CF</b>
          connectionFactory;
          public ConnectionPool(CF connectionFactory, ...) { ... }
          ...
          }

          public interface ConnectionFactory { ... }
        </pre>
        <p>
          Now a client can have a<code>CountingConnectionFactory</code>, and use it into a pool without casting:
          <code>pool.connectionFactory.numberOfCreatedConnections</code>.
        </p>
        <p>If you don't care about the specific type, just use a<code>ConnectionPool&lt;?></code>. Actually maybe the
          compiler/IDE shouldn't be so picky about raw usage of (especially bounded) parameterized types and just
          be happy with
          <code>ConnectionPool.</code>
          <a href="http://gafter.blogspot.com/2007/07/constructor-type-inference.html">Neal's</a>
          call for type inference for constructors would help to make construction more concise, too.
        </p>
        <p>You may have also noticed the use of a
          <code>public final</code>
          field. I don't quite see the point of hiding
          information that my client provided in the first place (ducking and covering).
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#generics-and-delegation</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#generics-and-delegation"/>
    <a:updated>2007-07-07T14:41:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Bytecode Instrumentation for Jist</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="bytecode-instrumentation-jist" href="#bytecode-instrumentation-jist"></a>
        <p>
          I've added some bytecode instrumentation support to
          <a href="#Get-the-Jist">Jist</a>
          using the always excellent
          <a href="http://asm.objectweb.org/">ASM</a>
          library.
          <code>Agent#instrument(class, methodName, n)</code>
          returns an
          <code>Activity</code>
          that enters and exits as the method is called/returns. Example:
        </p>
        <pre><![CDATA[Aggregation
  .ofDurationOf(Agent.instrument(Thread.class, "run"));
]]></pre>
        <p>
          This code will aggregate statistical data about Thread lifetimes. Unfortunately this code contains some
          problems: it uses Instrumentation#redefineClasses and thus does not interoperate well with other
          instrumentation agents.
          Since Jist only pushes aggregation data every once in a while, thread-local event data may be lost
          when a thread exits. I guess I should inject a forced publish at thread exit and/or add a forcePublish flag to
          an event.
        </p>
        <h3>Comments</h3>
        <p>Alan @ 2007-07-01 09:30:39 PDT:</p>
        <div class="comment">
          <p>Have you looked at retransformClasses? It was added in Java SE 6 to support multiple agents doing BCI.</p>
          <p>
            <em>(Matthias) I have but unfortunately I'm on a Mac. I guess I should download the old old Mustang build
              that Apple provides...
              or look at Parallels and an OpenSolaris Image.
            </em>
          </p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#bytecode-instrumentation-jist</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#bytecode-instrumentation-jist"/>
    <a:updated>2007-07-01T15:06:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Gmail goes Web 1.0</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="gmail-oldschool" href="#gmail-oldschool"></a>
        <p>
          Just pressed "send" and got greeted with "your connection
          to gmail has expired. please log in again". Mail lost. Me seriously grumpy.
          I've had this type of UI with Outlook Web Access long enough.
        </p>
        <h3>Comments</h3>
        <p>Lee @ 2007-07-01 19:59:29 PDT:</p>
        <div class="comment">
          <p>have you looked in your 'drafts' folder?</p>
          <p>
            <em>(Matthias) Thanks, I have. It contains an old draft that doesn't help.</em>
          </p>
        </div>
        <p>
          <a href="http://crazybob.org/">Bob Lee</a>
          @ 2007-07-14 09:19:25 PDT:
        </p>
        <div class="comment">
          <p>When this happens, I log in in a different window, and then I can send the message.</p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#gmail-oldschool</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#gmail-oldschool"/>
    <a:updated>2007-06-29T15:28:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>ariadna for Windows x64?</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="ariadna-winx64" href="#ariadna-winx64"></a>
        <p>
          I'm always happy to hear that someone is using<a href="http://www.mernst.org/ariadna">ariadna</a>.
          Now Neil Ferguson is asking for a Windows x64 build of the agent dll which I cannot provide.
          Can someone help out? Thanks in advance.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#ariadna-winx64</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#ariadna-winx64"/>
    <a:updated>2007-06-26T22:28:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Bad Refactoring</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="bad-refactoring" href="#bad-refactoring"></a>
        <p>
          Case of a refactoring gone bad:
        </p>
        <pre>
          <b>public volatile</b>
          ByteBuffer<b>message</b>;

          public ByteBuffer getMessage() {
          return duplicate(<b>message</b>);
          }

          private ByteBuffer duplicate(ByteBuffer message) {
          return (message != null) ? message.duplicate() : null;
          }
        </pre>
        <p>
          IDEA 7.0M1b will happily inline
          <code>#duplicate</code>
          so that it
          reads
          <code>#message</code>
          twice (<a href="http://www.jetbrains.net/jira/browse/IDEA-13304">Bug</a>):
        </p>
        <pre>
          public ByteBuffer getMessage() {
          return (
          <b>message</b>
          != null) ?<b>message</b>.duplicate() : null;
          }
        </pre>
        <p>
          Always watch your tool!
        </p>
        <h3>Comments</h3>
        <p>
          <a href="http://d.hd.org/">Damon Hart-Davis</a>
          @ 2007-06-18 04:11:33 PDT:
        </p>
        <div class="comment">
          <p>Yuck!</p>
          <p>Now that's really bad, especially with the huge red warning light that is 'volatile'!</p>
          <p>Rgds</p>
          <p>Damon</p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#bad-refactoring</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#bad-refactoring"/>
    <a:updated>2007-06-18T10:35:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Google Groups Virus Detector</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="google-groups-virus-detector" href="#google-groups-virus-detector"></a>
        <p>
          Anyone else get this? I got it on two independent computers now, one Mac, one PC.
          Of course I can't say for sure my computer isn't 0wned but it looks bogus to me.
        </p>
        <img src="sorry.png" alt="Google Error Message"/>
        <h3>Comments</h3>
        <p>
          <a href="http://www.tutorials.de">Thomas Darimont</a>
          @ 2007-06-13 05:32:58 PDT
        </p>
        <div class="comment">
          <p>jep, I also see this message when I browse the guice-google group...
            May be google just want us to solve some Captchas for them ;-)
          </p>

          <p>As in: Human Computation: http://video.google.com/videoplay?docid=-8246463980976635143</p>

          <p>Best regards,
            <br/>
            Tom
          </p>
        </div>
        <p>
          <a href="http://www.elien.de">Björn</a>
          @ 2007-06-14 00:47:12 PDT
        </p>
        <div class="comment">
          <p>Question is, what's meant by "[..] or your network is infected". Eventually you're part of the internet!
          </p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#google-groups-virus-detector</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#google-groups-virus-detector"/>
    <a:updated>2007-06-13T14:10:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Partial APPdates</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="partial-appdates" href="#partial-appdates"></a>
        <p>
          <a href="http://www.snellspace.com/wp/?p=683">James Snell</a>
          and
          <a
            href="http://www.dehora.net/journal/2007/06/app_on_the_web_has_failed_miserably_utterly_and_completely.html">
            Bill de hÓra
          </a>
          point to the PATCH method to handle partial updates of Atom entries through APP. I don't see that need. PUT
          with the If-Match: header is just enough to do the work
          on the client side using optimistic concurrency control. The server side patch model:
        </p>
        <pre>
          Client Server
          --- GET(uri) -->
          &lt;-- ETag, entry ---
          <em>prepare patch</em>
          --- PATCH(uri, patch) -->
          <em>with locked entry
            apply(patch, entry)
          </em>


        </pre>

        can easily be replaced by this:

        <pre>
          Client Server
          --- GET(uri) -->
          &lt;-- ETag, entry ---
          <em>prepare patch
            do
            newEntry = apply(patch, entry)
          </em>

          --- PUT(uri, newEntry, If-Match: etag) -->
          <em>with locked resource
            compare tag ? update : fail
          </em>
          &lt;-- 200 OK or 412 Precondition Failed ---
          <em>if(Precondition Failed)</em>
          --- GET(uri) -->
          &lt;-- ETag, entry ---
          <em>while(Precondition Failed)</em>


        </pre>
        <p>
          The second version requires the same number of roundtrips if there is no conflict and we assume that
          you always read an entry before patching it. Optimistic concurrency control breaks down when you have
          heavy concurrent updates on the same entry, something I'd argue to be rather uncommon. It does require
          the client to handle the patching but I don't think this is an undue burden.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#partial-appdates</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#partial-appdates"/>
    <a:updated>2007-06-10T11:40:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Mobile TV Interop Event</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="mobile-tv-interop-event" href="#mobile-tv-interop-event"></a>
        <p>
          We just spent a great week in Berlin at the BMCO Test Camp to
          test interoperability of OMA BCAST Mobile TV implementations.
          Results cannot be disclosed but I can say it was an amazing event.
          Engineers from all over the world brought handsets, encoders,
          scramblers, smartcards, key management components
          and whatnot in emulation, prototype up to product quality, together with
          assorted IDEs, debuggers, analyzers, flashing equipment. And for
          a broadcasting event, way too many cables :-) Most participants demonstrated
          a great spirit of cooperation and were
          eager to help each other, running high on adrenaline to get their systems to interoperate.
        </p>
        <p>
          Some observations: my NIO/multicast hack has run rock-solid for days except for one VM freeze.
          Hot Swapping is a real winner during testing. It's sad to see people programming ad-hoc HTTP clients
          in C (on a server!) - of course it didn't work. In a stark contrast to Java One, almost noone brought a Mac.
          Some people can go for days with almost no sleep (not me).
        </p>
        <p>
          We are very happy with our results. German engineering paid off! Plus we had a lot of fun.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#mobile-tv-interop-event</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#mobile-tv-interop-event"/>
    <a:updated>2007-06-08T10:46:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Type Operators</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="type-operators" href="#type-operators"></a>
        <p>
          I was talking to someone about the type system of Tycoon2, our research language back in school, and I
          mentioned
          it had a higher order type system with type operators. So they asked me what are type operators good for. And
          I couldn't say.
        </p>
        <p>
          Today I could think of something. I often wish for a Map whose key and value types aren't fixed but instead
          dependent
          on one another. Example: an XmlTypeSystem contains a map from class objects to marshallers. Given a Class&lt;T>
          I can get a Marshaller&lt;T>. Signature:
          <br/>
          <code>&lt;T> Marshaller&lt;T> getMarshaller(Class&lt;T> clazz)</code>.
        </p>
        <p>
          Trying to implement this method using a hashmap I cannot get away without a compiler warning since
          <br/>
          <code>Map&lt;Class&lt;?>, Marshaller&lt;?>> marshallerByClass</code>
          <br/>
          is the best I can come up with in Java.
        </p>
        <p>
          So actually I would like a Map with a signature like this:
        </p>
        <pre>
          interface DMap&lt;T, KeyOperator extends &lt;T>Object, ValueOperator extends &lt;T>Object> {
          &lt;K extends T> ValueOperator&lt;K> get(KeyOperator&lt;K> key);
          }

          // or rather
          interface DMap&lt;T,
          KeyOperator extends &lt;? super T>Object,
          ValueOperator extends &lt;? super T>Object>


        </pre>
        <p>
          To be read as such: A DMap is parameterized by a base type T and two type operators that map any type
          below T to a subtype of Object. The get method is parameterized by a type K below T and maps between the
          application of the first type op to the application of the second. This way we can assign a meaningful
          type to our marshaller map:
        </p>
        <pre>
          DMap&lt;Object, :T=>Class&lt;T>, :T=>Marshaller&lt;T>> marshallerByClass;

          // explicit type arguments for demonstration purposes only
          marshallerByClass.&lt;String>get(String.class) => Marshaller&lt;String>
          marshallerByClass.&lt;Feed>get(Feed.class) => Marshaller&lt;Feed>
        </pre>
        <p>
          So this is what type operators can be good for. I do not think they have a broad application though and I do
          NOT
          propose we do anything like this to Java.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#type-operators</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#type-operators"/>
    <a:updated>2007-05-30T09:09:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Comments</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="comments" href="#comments"></a>
        <p>
          I've finally added some crude Response-O-Matic backed comment forms to my blog.
          Even though they're moderated I hope this lowers the entry barrier for you.
          Keep them rolling in!
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#comments</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#comments"/>
    <a:updated>2007-05-28T13:04:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Cascading: First Patch</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="Cascading-First-Patch" href="#Cascading-First-Patch"></a>
        <p>
          Here's a first patch against b13 that survives simple tests. A number
          of problems remain:
        </p>
        <ul>
          <li>It only cascades method invocations with explicit receiver expressions. Javac does not
            explicitly compute the receiver at typecheck time for implicit this or outer this targets
            and so does not have their types ready.
          </li>
          <li>super.m() has the type of the superclass, not of this.</li>
        </ul>
        <pre>
          <b>--- comp/Attr.java.orig.txt 2007-05-26 13:55:53.000000000 +0200
            +++ comp/Attr.java 2007-05-26 14:15:51.000000000 +0200
          </b>
          <![CDATA[@@ -1315,6 +1315,18 @@
                               restype.tsym);
             }
+            // as a special case, o.m() where m is a void method, has type of o
+            if(restype == Symtab.voidType && !isStatic(TreeInfo.symbol(tree.meth))) {
+                if(tree.meth.tag != JCTree.SELECT) {
+                    log.warning(tree.meth.pos(), "Cannot (yet) cascade unqualified method call");
+                } else {
+                    JCExpression receiver = ((JCFieldAccess) tree.meth).selected;
+                    restype = receiver.type;
+                }
+            }
+
+
+
             // Check that value of resulting type is admissible in the
             // current context.  Also, capture the return type
             result = check(tree, capture(restype), VAL, pkind, pt);]]>

          <b>--- comp/TransTypes.java.orig.txt 2007-05-26 13:56:46.000000000 +0200
            +++ comp/TransTypes.java 2007-05-26 14:15:51.000000000 +0200
          </b>
          <![CDATA[@@ -583,7 +587,8 @@
         tree.args = translateArgs(tree.args, argtypes, tree.varargsElement);

         // Insert casts of method invocation results as needed.
-        result = retype(tree, mt.getReturnType(), pt);
+        // mernst: do not use mt.resType as cascading may have changed it
+        result = retype(tree, types.erasure(tree.type), pt);
     }

     public void visitNewClass(JCNewClass tree) {]]>

          <b>--- jvm/Gen.java.orig.txt 2007-05-26 14:00:07.000000000 +0200
            +++ jvm/Gen.java 2007-05-26 14:16:38.000000000 +0200
          </b>
          <![CDATA[@@ -1664,14 +1664,24 @@
  *************************************************************************/

     public void visitApply(JCMethodInvocation tree) {
+
        // Generate code for method.
        Item m = genExpr(tree.meth, methodType);
+
+        // in case of a cascade, duplicate the receiver
+        boolean cascaded = ((MethodType)tree.meth.type).restype == Symtab.voidType && tree.type != Symtab.voidType;
+        Item stackItem = cascaded ? items.makeStackItem(tree.type) : null;
+        if(cascaded) stackItem.duplicate();
+
        // Generate code for all arguments, where the expected types are
        // the parameters of the method's external type (that is, any implicit
        // outer instance of a super(...) call appears as first parameter).
        genArgs(tree.args,
                TreeInfo.symbol(tree.meth).externalType(types).getParameterTypes());
        result = m.invoke();
+
+        // in case of a cascade, the receiver is top of stack now
+        if(cascaded) result = stackItem;
     }

     public void visitConditional(JCConditional tree) {]]>
        </pre>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Cascading-First-Patch</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Cascading-First-Patch"/>
    <a:updated>2007-05-26T14:21:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Cascading: A Modest Language Proposal</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="AModestLanguageProposal" href="#AModestLanguageProposal"></a>
        <p>
          I've hinted at this
          <a href="http://www.mernst.org/blog/rss.xml#How-Far-is-Fidji">before</a>
          - a discussion
          with my colleague
          <a href="http://www.3plus4.de/">Stefan Aust</a>
          brought the topic back up: I'm proposing to add cascading
          for non-static method invocations of type void to the Java language.
        </p>
        <h3>Informal Discussion</h3>
        <p>
          I propose to make invocations of void methods usable as expressions. The type of a method invocation
          <code>o.m(args)</code>
          where m resolves to a void method would not be void but instead the type of o.
          The result of the method invocation could either be returned, be assigned to a variable, be used as
          a method argument, or be the target of another method invocation. Cascaded method invocations
          of void methods, especially of property setters would be possible:
        </p>
        <pre>final JFrame jFrame = new JFrame()
          .setBounds(100, 100, 100, 100)
          .setVisible(true);
        </pre>
        <p>
          Implementation: the change can be implemented solely by changing the way javac compiles method invocations.
          This
          is advantageous because no old code needs to be recompiled: after computing the receiver, it is simply
          duplicated
          on the stack. Either it is used as the result value or it is discarded as in JLS 14.8 "Expression Statements".
        </p>
        <h3>Required Specification Changes</h3>
        <p>
          JLS 15.12.2.6 Method Result and Throws Types: the type of a method invocation expression needs adjustment. The
          different forms of method invocation need to be discussed - either the type of the receiver expression, this
          or
          outer this.
        </p>
        <p>
          JLS 15.12.4.1 Compute Target Reference (If Necessary): append "if the method returns void and there is a
          target reference,
          the target reference is retained and will become the result value".
        </p>
        <p>
          There seems to be no wording about the result value in 15.12.4.5 "Create Frame, Synchronize, Transfer
          Control".
        </p>
        <h3>Required Compiler Changes</h3>
        <p>
          I don't have the code handy (just browsing) and it looks like two small changes to Gen#visitApply (Gen.java)
          and to
          MemberItem#invoke (Items.java) should be enough.
          <i>Update:</i>
          I forgot the necessary change to the type checker:
          that should be TransTypes#visitApply (TransTypes.java).
        </p>
        <h3>Conclusion</h3>
        <p>
          So far, a void method invocation can only be used as an expression statement, so
          the semantics of existing valid code remain unchanged. Setter invocation orgies
          can now be made a little nicer.
        </p>
        <p>
          If I find time I'll try my first KSL hack.
          What do you think?
        </p>
        <h3>Comments</h3>
        <p>
          <a href="http://weblogs.java.net/blog/forax/">Rémi Forax</a>
          @ May 23, 2007 8:19 PM:
        </p>
        <div class="comment">
          <p>Hi matthias,</p>
          <p>the typechecker of javac is implemented in Attr
            and not in TransTypes.
            Transtypes pass does the erasure (and some tricks like
            inserting inner class backreference etc.)
          </p>

          <p>cheers,
            Rémi
          </p>
        </div>
        <p>Anonymous @ 2007-05-31 09:57:01 PDT</p>
        <div class="comment">
          <p>Thats a feature I've thought about too. It seems really logical and can't break old code. There is one
            disadvantage though. The documentation of the signature sends contradictory signals. And anyway, imagine a
            immutable class. No use there since that already should do what you propose, but in a mutable class, things
            can get strange. Is that method returning this, or another object? Not immediately apparent.
          </p>
        </div>
        <p>
          <a href="http://reuse.sourceforge.net">Peter Kehl</a>
          @ 2007-06-18 03:00:24 PDT:
        </p>
        <div class="comment">
          <p>This looks good and usefull.</p>
          <p>RE Anonymous - immutable objects: Any methods on immutable objects that return void won't modify the object
            (by the definition of immutable). So any void method won't have any side effects on the this object.
          </p>
          <p>Then it's 100% legit to have a sequence of such void calls, and cascading them makes sense. Of course, void
            methods on immutable object won't do a big deal to the object itself - they may either validate the object
            or register it in some static/threadlocal structures.
          </p>
          <p>You may have a setter/modification method on an immutable object, but that method must return a new object
            based on this. So the method won't return void - therefore void cascading won't apply to it.
          </p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#AModestLanguageProposal</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#AModestLanguageProposal"/>
    <a:updated>2007-05-22T23:28:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Wave Particle --- Particle Wave?</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="WaveParticleParticleWave" href="#WaveParticleParticleWave"></a>
        <p>
          Ever so often I'm utterly confused over a design choice. Two alternative designs
          flipping back and forth in my mind with their respective pros and cons and I loathe
          wasting time over them. Other people are much more pragmatic. Examples in no
          particular order:
        </p>
        <dl>
          <dt>Embedding vs Embedded</dt>
          <dd>Be a webapp or embed Jetty? Is the primary purpose
            of your app to speak HTTP or does it just happen to?
          </dd>
          <dt>Synchronization vs Active Object</dt>
          <dd>Thinking of it I couldn't really name you
            a reason to submit tasks to an object instead of having the relevant method synchronized - you have the
            same set of challenges and actually extra context switches.
            Nonetheless pooled-thread-per-object looks attractive and simple.
          </dd>
          <dt>Mutable Object vs Replacement</dt>
          <dd>Instead of changing an object under synchronization I like setting
            up and dropping in a replacement instead which can often be done through a volatile write. Of
            course that means the parent must be mutable and thus the question repeats at a different level.
          </dd>
          <dt>Remote Service vs Multiply Installed Jar</dt>
          <dd>Redundancy is dangerous. A domain rule should not be implemented twice - but does that mean that
            only one component in my distributed system may "physically" contain it? Or is it "ok" to have the same jar
            in many places? Can I promise to update it everywhere? Versioning of algorithms may help.
          </dd>
          <dt>Multithreaded Service vs Decicated Objects</dt>
          <dd>For those how aren't afraid of garbage collection anymore:
            how do you choose? service.service(parameters) vs instance.service()? Oh, more confusion: Spring scopes make
            it easy to inject a proxy representing a "current" entity into a singleton. So service could have a field
            representing the "current context". Ugh.
          </dd>
          <dt>instance.destroy() vs factory.destroy(instance)</dt>
          <dd>More general: object.doIt() vs service.doItTo(object)</dd>
          <dt>NIH vs dependency hell</dt>
          <dd>Is byteArrayToHexString worth a dependency? What if it uses a different logging
            framework?
          </dd>
        </dl>
        <p>
          I could go on forever... Are there other examples you're getting grey hairs about? Many of these have been
          discussed before under various names. Obviously, the pattern books don't have an answer either. They
          just describe the alternatives more eloquently. I guess the truth is: you just have to choose and it helps to
          be
          consistent throughout one piece of software. Maybe you know better afterwards.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#WaveParticleParticleWave</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#WaveParticleParticleWave"/>
    <a:updated>2007-05-05T18:02:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>DLR</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="DLR" href="#DLR"></a>
        <p>
          Microsoft announces<a
          href="http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamic-language-runtime-dlr.aspx">DLR</a>,
          the Dynamic Language Runtime. More details to come so stay tuned on Jim's blog. If I'm not mistaken it's a
          pure user-space
          implementation right now that tries to standardize functionality required for implementations of dynamic
          language interpreters.
          Once those interfaces stabilize Microsoft could go ahead and implement optimizations below in future CLR
          versions.
        </p>
        <p>
          A crucial one of these optimizations, namely VM support for dynamic method invocations, was postulated by
          Gilad Bracha in<a href="http://jcp.org/en/jsr/detail?id=292">JSR 292</a>.
          Bears the question, what ever happened to this JSR? Can we expect to hear any more in this direction?
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#DLR</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#DLR"/>
    <a:updated>2007-05-01T21:02:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>JavaOne Secrets</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="JavaOne-Secrets" href="#JavaOne-Secrets"></a>
        <p>
          Some time it's always gonna be the first time, and this year I'm going to have my JavaOne initiation. So I
          built my session schedule and I'm hoping to turn some of my digital encounters into real ones. If you want to
          meet up, too, or have any tips for the best experience and be it "bring your own sandwich" I would be more
          than glad. Thanks and see you there!
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#JavaOne-Secrets</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#JavaOne-Secrets"/>
    <a:updated>2007-04-27T23:31:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Wieder Runterkommen</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="Just-what" href="#Just-what"></a>
        <p>
          Blood pressure once again at 180. Just who wants to punish me...
        </p>
        <h3>Exhibit A</h3>
        <pre><![CDATA[
try {
  ... new DataFlavor("text/uri-list;class=java.lang.String") ...
} catch (ClassNotFoundException e) {
        ]]></pre>
        A constructor with a java.lang.Class argument wouldn't harm.
        <em>Update:</em>
        to make things worse, there's a "fix by extension"
        available: "javax.activation.ActivationDataFlavor is a special subclass
        of java.awt.datatransfer.DataFlavor that allows to set all three values
        stored by the DataFlavor class via a new constructor." Thanks to
        <a href="http://weblogs.java.net/blog/forax/">R&#x00E9;mi</a>
        (for
        the pointer, not the implementation!).

        <h3>Exhibit B</h3>
        <pre><![CDATA[
try {
  ... DataTypeFactory.newInstance().newDuration(...) ...
} catch (DatatypeConfigurationException e) {
        ]]></pre>
        I wonder when we'll finally get an SPI for implementing java.lang.Integer.

        <h3>Exhibit C (fixed in Java 6)</h3>
        <pre><![CDATA[
try {
  ... "string".getBytes("UTF-8") ...
} catch (UnsupportedEncodingException e) {
        ]]></pre>
        I bet that people who understandably avoid this extra cruft
        are responsible for half of all encoding errors, the other half being those who
        do not understand encoding. Oh didn't someone want to build
        <a
          href="https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=13166&amp;forumID=1463">
          CharSet#UTF8()</a>?

        <h3>Epilogue</h3>

        If you do decide to use checked exceptions,
        <em>please</em>
        go the extra way
        and provide alternatives that are statically known not to throw.
        Adrenaline is bad for my health. Blogging helps a little, and this:

        <pre><![CDATA[
// ... it's like closing the window to the street
<T> T mute({=>T throws Exception} block) {
  try {
    return block.invoke();
  } catch(RuntimeException e) {
    throw e;
  } catch(Exception e) {
    throw new RuntimeException(e);
  }
}
        ]]></pre>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Runterkommen</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Runterkommen"/>
    <a:updated>2007-04-20T18:31:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Annotations are not the API</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="Annotations-are-not-the-API" href="#Annotations-are-not-the-API"></a>
        <p>
          My 2cents towards<a href="http://weblogs.java.net/blog/kohsuke/archive/2007/04/annotaitonmockb.html">mocked
          annotations</a>:
          when designing a library, always design a proper model in plain old classes. Make
          this model a public API and your library a runtime that interprets model instances.
          Use annotations only as a shorthand, as metadata from which a model instance
          can be derived. But leave the door open for alternative, programmatic access.
        </p>
        <p>
          For example, an experimental XML binding API I've played with exposes things like the following:
        </p>
        <pre><![CDATA[
XmlComplexType<V>: binding of a complex type to java objects of type V
JavaProperty<P,C>: getting/setting values of type C into an object of type P
XmlComplexTypeBinding<P, C>: binding of instances of complex type C into parent instances of type P
...
        ]]></pre>
        <p>
          Apart from the programmatic aspect, I find that this model is the most precise way to document
          how the library works. (JAXB does have a model but it's hidden away as implementation detail).
          My XML binder will never be as complete or stable as JAXB or do XML mapping any "better" but it lays
          its cards open about how exactly it bridges between XML and Java.
        </p>
        <p>
          Of course, this all applies just as well to other forms of configuration but we already knew that ...
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Annotations-are-not-the-API</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Annotations-are-not-the-API"/>
    <a:updated>2007-04-11T09:54:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Oh those swedish product names</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="Those-Swedish-Product-Names" href="#Those-Swedish-Product-Names"></a>
        <p>This one might not sell as good.</p>
        <p>
          <img src="fartyg.jpg" alt="fartyg"/>
        </p>

        <div class="comment">
          <p><i>Johan Liesén</i>: Just wanted to let you know that "fartyg" is the Swedish word for ship
            or large boat.
          </p>
        </div>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Those-Swedish-Product-Names</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Those-Swedish-Product-Names"/>
    <a:updated>2007-03-28T23:55:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Scrolling and Paging</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="Scrolling-and-Paging" href="#Scrolling-and-Paging"></a>
        <p>Scrolling and paging: both well accepted and useful forms of visiting an amount of data bigger than your
          screen. What
          drives me nuts is that they are often employed in the same application. Click-scroll-click-scroll until I'm
          steaming. Microsoft Outlook Web
          Access, Google Mail, Google Search, my Xing contact list are all guilty of that. Letting me configure how many
          items I
          want per page is a poor replacement for what I really want: show as many items as fit, stupid. Second worst
          crime, by the way: changing the
          position of the "next" button from page to page.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Scrolling-and-Paging</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Scrolling-and-Paging"/>
    <a:updated>2007-03-27T19:33:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Ferm&#x00E9; pour travaux</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="Ferme-au-travaux" href="#Ferme-au-travaux"></a>
        <p>
          <a href="http://www.musee-fernandleger.fr/">Mus&#x00e9;e national Fernand L&#x00e9;ger</a>, Biot,
          <a href="http://www.antibes-juanlespins.com/fr/culture/musees/picasso/">Mus&#x00e9;e Picasso</a>, Antibes,
          <a href="http://www.musee-matisse-nice.org/">Mus&#x00e9;e Matisse</a>, Nice. At least we got some sun.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Ferme-au-travaux</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Ferme-au-travaux"/>
    <a:updated>2007-03-27T19:30:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Pattern, transient final, serialization</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="Pattern-transient-final-serialization" href="#Pattern-transient-final-serialization"></a>
        <p>
          I tried to find a better fix for
          <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6436458">Bug ID: 6436458</a>
          that would eliminate synchronization altogether. Basically it boils down to the problem of serializing
          transient final fields. In this case some fields of the Pattern class hold the compilation information of the
          regex that we don't want
          serialized but rather reconstructed on deserialization. But we can't assign them in #readObject since they're
          final.
          And we want them final so that Pattern is<a
          href="http://www-128.ibm.com/developerworks/java/library/j-jtp03304/#4.0">initialization safe</a>.
          Sounds like a Catch-22.
        </p>
        <p>
          The solution is #readResolve. We can deserialize an intermediate Pattern instance that holds the pattern
          string
          and the flags - the transients being null - and then resolve it to a compiled instance using Pattern#compile.
          #readResolve is not recursive,
          so we won't end up in an infinite loop.
        </p>
        <pre><![CDATA[public class Pattern implements Serializable {
  private final String pattern;
  private final int flags;
  private transient final ...;

  public static Pattern compile(String pattern, int flags) {
    return new Pattern(pattern, flags);
  }

  private Pattern(String pattern, int flags) {
    this.pattern = pattern;
    this.flags = flags;
    this ... = ...;
  }

  private Object readResolve() {
    return Pattern.compile(pattern, flags);
  }
}]]></pre>
        <p>
          Mission accomplished: initialization safety, slim serialized form and no synchronization altogether.
          <a
            href="https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=19086&amp;forumID=1463">
            Patch</a>.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Pattern-transient-final-serialization</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Pattern-transient-final-serialization"/>
    <a:updated>2007-03-14T17:00:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Get the Jist</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="Get-the-Jist" href="#Get-the-Jist"></a>

        Toying with dtracing Java apps through JNI was fun but had a number of downsides:
        <ul>
          <li>it would only run on Solaris</li>
          <li>I had to jump through JNI hoops</li>
          <li>there was only one probe</li>
          <li>I only had strings</li>
          <li>D is not exactly good for building abstractions. I found myself repeating a lot of
            <code>...-entry { self->x[y]=... }</code>
            boilerplate.
          </li>
        </ul>

        <p>
          So I'm trying a new approach: Jist, Java InSTrumentation. It is heavily DTrace inspired but completely
          implemented in Java, as a simple 55k no-dependency jar. With Jist, you can define low overhead probes in your
          code that can be dynamically
          enabled at runtime. As with DTrace, probes are merely the source of information - you define separately
          how you want to aggregate the data and correlate probes that were written by independent authors and just
          happen
          to run in the same code path. Probes and aggregation functions are thoroughly typed.
        </p>
        <p>
          In comparison to DTrace, what is Jist not ? It only captures what happens in the JVM, it does not come
          with all-purpose providers like syscall, it is not easily invoked from the outside on an arbitrary Java
          process
          (agent attachment notwithstanding) and there is no garantueed safety from misbehaving aggregations.
        </p>
        <h2>Defining and Firing Probes</h2>
        In contrast to DTrace, Jist distinguishes two kinds of probes: activities and events. Activities span an
        interval in the program execution, and can be nested; the stack of activity contexts is managed by Jist. This is
        very
        similar to the -entry and -return convention in DTrace where you often build contexts in a thread-local map.
        Events on the other hand are just points in the program execution. Both types of probes can signal detail data.
        This is how you define and use probes:
        <pre><![CDATA[
class Server {
  public static final Activity<String> Request = new Activity<String>("Request");

  public void handle(String request) {
    Request.enter("request");
    try {
      ...
    } finally {
      Request.exit();
    }
  }
}

class ConnectionPool {
  public static final Event<DataSource> ConnectionOpened = new Event<DataSource>("ConnectionOpened");

  {
    ...
    ConnectionOpened.fire(dataSource);
  }
}
        ]]></pre>

        <p>
          When an activity starts, a Context record is allocated and pushed onto the thread-local stack. As of now,
          there is now way to disable this, but I have the feeling that this cost is negligable in most cases -
          otherwise
          I'll employ a small thread-local cache. Events
          on the other hand are disabled by default. Every time an event fires it checks for enabledness through a
          volatile
          - this should be ok for most cases. As with logging, in case the event argument is expensive to compute, you
          can check beforehand:
          <code>if(ConnectionOpened.isEnabled()) ...</code>
          .
        </p>
        <h2>Simple Aggregation</h2>
        One of the cornerstones of DTrace is in-place aggregation. Instead of saving all instrumentation data for
        offline aggregation, you condense the data as much as possible in place and save only the aggregated data.
        Especially, an aggregation function should have the property that you can feed it data piecemeal: Count,
        Average,
        Sum, are all examples of such functions. Jist, like DTrace, capitalizes on the aggregation function property
        in that it aggregates incrementally in the moment an event happens, and especially, it aggregates events
        thread-locally.
        Less frequently, the thread-local aggregation values are aggregated into a global view. Both incremental and
        thread-local
        aggregation ensure that the instrumentation overhead stays low. An example: the following code defines an
        aggregation
        that will simply count how many times a connection was opened:
        <pre><![CDATA[
Aggregation<?, Long> aggregation = Aggregation.of(Count.ofEvents, ConnectionPool.ConnectionOpened);
aggregation.enable();
while (true) {
  Thread.sleep(1000);
  System.out.println(aggregation);
}
        ]]></pre>
        <p>
          On #enable, the aggregation will attach itself as a listener on the Event. When the event fires, it is
          routed to the aggregation which will increment a thread-local counter. Only sometimes will the counter
          be propagated to the global counter. In that codepath we only have one volatile-get (read listeners), two
          invoke-interface, a
          thread-local get and a counter increment. Every once in a while do we push the counter onto a
          ConcurrentLinkedQueue.
          On my MacBook (two threads repeatedly firing events, 1.8Ghz Core2Duo, -server) that amounts to:
        </p>
        <pre><![CDATA[
number of events (updated each ConnectionOpened) = 0
number of events (updated each ConnectionOpened) = 38947105
number of events (updated each ConnectionOpened) = 38512126
number of events (updated each ConnectionOpened) = 40150689
number of events (updated each ConnectionOpened) = 39189567
        ]]></pre>
        <p>40 million events per second amounts to 100 cycles per event, a number that stays stable at 20 threads, too.
          That's pretty good.
        </p>

        <h2>Correlation</h2>
        <p>
          Now, incrementing counters is not especially interesting and can be done more easily. It gets more interesting
          to correlate
          different, independent probes. For example, we would like to know the number of connection openings
          <em>per request uri</em>
          .
          For that, we can employ a Mapping aggregation function:
        </p>
        <pre><![CDATA[
Aggregation<?, Map<String, Long>> aggregation =
  Aggregation.of(Mapping.of(Server.Request, Count.ofEvents), ConnectionPool.ConnectionOpened);

number of events by Request (updated each ConnectionOpened) = {/uri2=2285635, /uri1=4571279}
number of events by Request (updated each ConnectionOpened) = {/uri2=1833648, /uri1=3667297}
number of events by Request (updated each ConnectionOpened) = {/uri2=1842779, /uri1=3685558}
number of events by Request (updated each ConnectionOpened) = {/uri2=1974581, /uri1=3949161}
        ]]></pre>
        <p>
          This shows the real potential: we can see that requests to /uri1 open twice as many connections as those to
          /uri2. That's something
          no profiler and no DTrace will tell you. Another teaser (numbers highly dubious):
        </p>
        <pre><![CDATA[
Aggregation<?, Map<String, Statistics.Data>> aggregation =
  Aggregation.of(Mapping.of(Server.Request, Statistics.of(Duration.of(Server.Request))), Server.Request.Exit);

statistics for duration in NANOSECONDS of Request by Request (updated each exit from Request) =
  {/uri2={|sample|=1615081, sum=7.43407E8, min=0, max=64524000, avg=460.29084609378725, stddev=96321.15405584917},
   /uri1={|sample|=1615084, sum=9.26188E8, min=0, max=75908000, avg=573.4611945880214, stddev=123748.53849281174}}
statistics for duration in NANOSECONDS of Request by Request (updated each exit from Request) =
  {/uri2={|sample|=1602764, sum=9.54039E8, min=0, max=100171000, avg=595.246087384044, stddev=145823.88277769994},
   /uri1={|sample|=1602763, sum=8.40672E8, min=0, max=77095000, avg=524.5142294899496, stddev=118100.06216280891}}
...
      ]]></pre>

        <h2>Outlook</h2>
        <p>
          One of the perks of DTrace is that you can attach to a process and run D scripts that were not compiled
          into that process. I'm still pondering how to do that. A scripting solution for the definition of aggregations
          might be interesting, one that is defined on dynamically loaded agents or something JMX-based. Right now,
          you'll have to bake in aggregations and export them somehow, i.e. though JMX. Some simple class-redefinition
          to inject probes into foreign code would be nice, too.
        </p>
        <p>
          To some extent I hope that aggregation of independent events will reduce the time you spend sorting log
          records together
          (".. ok, here it starts .. now lets look for the same thread, ok down here, ... go up one page again").
        </p>
        <h2>Get it</h2>
        <p>
          Now that you're mouthwatering enough, go download Jist
          <a href="/jist">here</a>.
          Or get the most recent version:
          <code>hg clone static-http://mernst.org/jist</code>
          .
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Get-the-Jist</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Get-the-Jist"/>
    <a:updated>2007-03-04T12:24:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Experience comes with age</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="Experience-comes-with-age" href="#Experience-comes-with-age"></a>
        <p>
          Germany's facing fierce resistance about moving the retirement age up to 67. Sun
          thinks a little more progressively in this context :-)
        </p>
        <p>
          <img src="fiftyfive.png" alt="Years of experience: 55"/>
        </p>
        <p>
          Anyone? http://www.sun.com/corp_emp/search.cgi?req=548725&amp;p=
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Experience-comes-with-age</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Experience-comes-with-age"/>
    <a:updated>2007-02-03T15:38:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>SDT probes for Java</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="SDT-probes-for-Java" href="#SDT-probes-for-Java"></a>
        <p>
          The real power of
          <a href="http://www.opensolaris.org/os/community/dtrace/">DTrace</a>
          lies in its ability to correlate independently provided data in ways unforeseen by
          the developer. Too often have I been asked things like "nice cache eviction statistics but how can I see which
          algorithm, query, user is responsible for this?". D is the SQL of instrumentation: it enables ad-hoc queries
          over unprepared data.
        </p>
        <p>
          As of today,
          <a href="http://java.sun.com/javase/6/docs/technotes/guides/vm/dtrace.html">DTracing Java</a>
          is cool as long
          as you're doing relatively general performance analysis of the software - questions
          about "which method?", "which class?", "which monitor?" can be answered - to open the ultimate insight into
          application
          space ("which query?", "which dataset?", "which url?") we need to work a little harder.
        </p>
        <p>
          I'm interested in two kind of probes: the ones that establish a thread-local context for a possibly lengthy
          period, i.e. "starting request to /url", "starting transform foo.xsl", "importing x" and the corresponding
          exit
          in order to correlate these with events such as "evicting y" or "creating temp-file z".
        </p>
        <h3>A simple DTrace provider for Java applications</h3>
        <p>
          So I want to do something like this (obviously not in one class):
        </p>
        <pre><![CDATA[
  static final dtrace.DTraceContext<String> REQUEST = new dtrace.DTraceContext<String>("request");
  static final dtrace.DTraceContext<String> TEMPLATE = new dtrace.DTraceContext<String>("template");
  static final dtrace.DTraceContext<String> EL = new dtrace.DTraceContext<String>("el");

  public static void main(String[] args) throws Exception {
    while(true) {
      REQUEST.push("/index.html");
        TEMPLATE.push("outer.jsp");
          // do some real work here
          TEMPLATE.push("inner.jsp");
            EL.push("${something.wild}");
            EL.pop("${something.wild}");
          TEMPLATE.pop();
          // do some real work here
        TEMPLATE.pop();
      REQUEST.pop();
      Thread.sleep(1000);
    }
  }
	]]></pre>

        <p>
          The DTraceContext class looks as follows. It does some stack management and ultimately fires entry and
          exit events through JNI:
        </p>
        <pre><![CDATA[
  public class DTraceContext<T> {
    private static native void init();
    private static native void fireEntry(String name, Object top, Object previous);
    private static native void fireReturn(String name, Object top, Object previous);

    public final String name;
    private final ThreadLocal<ArrayList<T>> value = new ThreadLocal<ArrayList<T>>() {
      protected ArrayList<T> initialValue() {
	return new ArrayList<T>(5);
      }
    };

    public DTraceContext(String name) {
      this.name = name;
    }

    public T get() {
      ArrayList<T> ts = value.get();
      return ts.isEmpty() ? null : ts.get(ts.size()-1);
    }

    public void push(T value) {
      T previous = get();
      this.value.get().add(value);
      fireEntry(name, value, previous);
    }

    public void pop() {
      ArrayList<T> values = this.value.get();
      T value = values.remove(values.size() - 1);
      fireReturn(name, value, get());
    }

    static {
      System.loadLibrary("dtracecontext");
      init();
    }
  }

  JNI code:

  // error checking yadda yadda
  JNIEXPORT void JNICALL Java_dtrace_DTraceContext_fireEntry
    (JNIEnv *env, jclass class, jstring name, jobject top, jobject previous)
  {
    if(DTRACECONTEXT_ENTRY_ENABLED()) {
      const jbyte *namestr = (name==NULL) ? NULL : (*env)->GetStringUTFChars(env, name, NULL);

      jobject tops = (top==NULL) ? NULL : (*env)->CallObjectMethod(env, top, tostring);
      const jbyte *topstr = (tops==NULL) ? NULL : (*env)->GetStringUTFChars(env, tops, NULL);

      jobject previouss = (previous==NULL) ? NULL : (*env)->CallObjectMethod(env, previous, tostring);
      const jbyte *previousstr = (previouss==NULL) ? NULL : (*env)->GetStringUTFChars(env, previouss, NULL);

      DTRACECONTEXT_ENTRY(namestr, topstr, previousstr);

      if(previousstr != NULL) (*env)->ReleaseStringUTFChars(env, previouss, previousstr);
      if(previouss != NULL) (*env)->DeleteLocalRef(env, previouss);

      if(topstr != NULL) (*env)->ReleaseStringUTFChars(env, tops, topstr);
      if(tops != NULL) (*env)->DeleteLocalRef(env, tops);

      if(namestr != NULL) (*env)->ReleaseStringUTFChars(env, name, namestr);
    }
  }

  // ... same for pop
  ]]></pre>
        <p>
          Note how the native methods take Objects but the probes carry strings:
          I do a callback to #toString and extract the UTF-8 sequences only after checking whether the probe is enabled.
          The overhead of the JNI calls for disabled probes seems good if not used in tight loops (like 22 ns per call
          on my machine) - if it turns out to be a problem I'll need to hoist the test into the Java code. The
          DTRACECONTEXT_ENTRY is a macro
          generated by dtrace from my provider description - see
          <a href="http://blogs.sun.com/tpenta/entry/dtrace_using_placing_sdt_probes">"statically defined tracing"</a>
          - basically we compile a call to a dummy external C function into our code, and postprocess it with dtrace
          that will
          patch this code sequence in order to disable/enable the probe. The provider:
        </p>
        <pre>
          provider dtracecontext {
          // args (contextname, context entered, previously active context)
          probe ENTRY(char *, char *, char *);
          // args (contextname, context left, context returned to)
          probe RETURN(char *, char *, char *);
          };
        </pre>
        <p>
          A note to the naming: I tried to name the probes "entry" and "return" first - I thought they would be
          recognized
          by the "-F" (indent flow) option of dtrace but unfortunately that is not so; and return is a dtrace keyword.
          So
          the first thing that came to my mind was capitalization - I will most probably change that.
        </p>
        <p>
          You will have noticed that this provider is very static - there's only two probes for the whole Java
          process and the actual type comes as a string argument. All application probes are disabled and enabled
          together which will have a bigger performance impact - maybe I can come up with some dynamic
          compilation/library
          generation scheme later.
        </p>
        <p>
          I haven't collected really good examples from real software yet - that's why there were no actual dtrace
          scripts
          in action but I hope you could see the possibilities. I think the potential is huge. The demise of logging?
          That would be too good to be true...
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#SDT-probes-for-Java</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#SDT-probes-for-Java"/>
    <a:updated>2007-02-03T12:45:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Euphemism of the Day</a:title>
    <a:content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a name="Euphemism-of-the-Day" href="#Euphemism-of-the-Day"></a>
        <p>
          "HTML allowed" actually means "Comply with those angle brackets or I will swallow all your paragraphs. You
          have been warned.".
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Euphemism-of-the-Day</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Euphemism-of-the-Day"/>
    <a:updated>2007-01-17T17:21:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Solaris 10 Privileges</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Solaris-10-Privileges" href="#Solaris-10-Privileges"></a>
        <p>
          The Solaris 10 kernel supports a fine-grained security model, based on
          <a href="http://www.sun.com/bigadmin/features/articles/least_privilege.html">"least privilege"</a>
          .
          For example, in order to run a server on port 80 you don't need to be root. The PRIV_NET_PRIVADDR privilege is
          sufficient.
        </p>
        <p>
          The same applies to coniguration of the IPsec security associations and policy entries. Unfortunately,
          the respective command line tools 'ipseckey' and 'ipsecconf' do check for uid 0 before they even try
          to talk to the kernel.
        </p>
        <p>
          Luckily, w/ Open Solaris being open source I could quickly fix that. Commented out the checks, did the
          ppriv thing, et voila, a normal user with SYS_NET_CONFIG can now do what I want. Neat!
        </p>
        <p>
          <em>
            Update: I've learnt that I shouldn't use privileges for that directly (will become messy over time)
            but rather a profile that defines the right execution attributes such as the "Network Security" profile. Yet
            that profile doesn't work right now for the outlined reasons (bug filed). Workaround: use your own profile
            and exec_attr with uid=0. No need to recompile the tools - just assign that profile to your user.
          </em>
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Solaris-10-Privileges</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Solaris-10-Privileges"/>
    <a:published>2007-01-17T17:20:00+01:00</a:published>
    <a:updated>2007-02-03T12:49:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Atom in Style</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Atom-in-Style" href="#Atom-in-Style"></a>
        <p>
          WARNING: this is an experiment and may well wreak havoc on your blog-reading experience.
        </p>
        <p>
          I'm cheap and lazy and thus I'm not willing to pay for PHP hosting nor would I want to administer
          a blog system. Yet I want to host my blog on my own domain. I've been using Thingamablog until
          now but their editor has serious limitations, especially when working with pre-formatted code fragments.
          And I can only edit the blog from the one machine where the database is.
        </p>
        <p>
          I have thus changed my blog to one major source file in the Atom format. I'm typing this entry directly
          in atom format into IDEA's XML editor - I have a nice live template to insert the minimum scaffolding.
          When I finish, this source file is then only post-processed (w/ JAXB) to derive &quot;updated&quot;, &quot;link&quot;,
          &quot;id&quot;
          and &quot;a&quot; elements (a process that I could still do by hand if that little piece of Java code is not
          handy).
          I have left all old ids intact and hope that they won't be re-syndicated, even if the
          feed format changes from RSS to Atom (this file will still be called rss.xml).
        </p>
        <p>
          No HTML is generated, the feed is directly styled with CSS, not even XSL. A nice learning experience and
          the capabilities of CSS continue to impress me. As a potential downside, I'm now
          including all my posts in one file. Certainly more than before but not too huge if all participants make use
          of the relevant HTTP mechanisms.
        </p>
        <p>
          I've tried to be as standards compliant as possible but your mileage with various readers may vary:
        </p>
        <ul>
          <li>Firefox renders this feed best. I had to include a lengthy comment header in order to actually enable the
            stylesheet.
          </li>
          <li>IE 7 fairs worst. It won't use the stylesheet (someone? DOCTYPE?) but is fooled by the comment. So you'll
            only see the text() nodes.
          </li>
          <li>
            <i>(Fixed)</i>
            Both Omea Reader and Google Reader have issues with &quot;bleeding&quot; anchor tags (&lt;a../&gt;).
            Obviously they're embedding the XHTML pretty directly into quirks HTML without reprocessing it.
          </li>
          <li>RSS Bandit and BottomFeeder look fine.</li>
          <li>Syndication to PlanetJDK has stopped :-(</li>
        </ul>
        <p>
          The CSS element selectors don't seem to care about namespaces. I don't know whether this will continue to work
          with
          <a href="http://www.w3.org/TR/css3-namespace/">CSS3 Namespace Module</a>
          .
        </p>
        <p>
          The sidebar on the right is implemented as a dedicated feed entry that is styled differently.
        </p>
        <p>
          So much from the low-end side of blog software - please let me know what problems you're having and
          whether they prohibit you from reading this journal any longer. Enhancements to the stylesheet are welcome,
          too.
          You know where you can find it.
        </p>
      </div>
    </a:content>
    <a:id>http://mernst.org/blog/rss.xml#Atom-in-Style</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Atom-in-Style"/>
    <a:updated>2007-01-16T23:37:00+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Maybe it's time to think a little further</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Maybe-its-time-to-think-a-little-further" href="#Maybe-its-time-to-think-a-little-further"></a>
        <p>
          If you're bored of the &quot;property&quot; word, please skip.
        </p>
        <p>
          If not, you may note that some of the REST principles apply to
          properties:
        </p>
        <p>
          We expect to read a property without visibly affecting the object.
          Reading properties is supposed to be a
          <i>safe operation</i>
          . We also
          expect setting the same value for a second time to have no tangible
          effect. Setting properties is supposed to be
          <i>idempotent</i>
          . The
          values we see from properties may or may not be the actual state of an
          object, they are merely a
          <i>representation</i>
          .
        </p>
        <p>
          In a distributed, concurrent environment, atomicity also is of concern.
          I feel progressively unsure about using an array of setter invocations
          for reconfiguration of a service, e.g. through JMX. The REST way of
          PUTting an entire representation of the -desired- resource's state looks
          a lot safer to me. It gives the object a chance to implement atomicity.
          Recently, we built a service that is reconfigurable through PUTting an
          entire configuration document, and this approach feels really solid
          compared to fine grained remoted JMX-based management. The admin UI
          operates not on the object but on a representation of its state and then
          submits it to take effect.
        </p>
        <p>
          What is my point? I believe that applying REST principles to OO
          programming lends itself to separate the &quot;life&quot; objects with their logic
          from &quot;dumb&quot; state representations that can be manipulated or bound to.
          We might not want to bind UI elements directly to property methods. We
          might rather go and implement representations through simple structs w/
          fields that are also nicely transported, persisted, versioned, ...
          Putting that state into side-effects would be of no concern at this
          stage. Useful linguistic support would be compile-time checked field
          references so we can bind some UI element to a field of the state
          representation.
        </p>
        <p>
          There's a ton of open questions - no question about that. And this may
          be a pile of bull. But thinking about how representations (external
          ones, too), state, binding, ... all fit together is definetely a larger
          topic than just syntactic sugar around field declarations.
        </p>
        <div class="comment">
          <p>
            <i>Comment by Eamonn McManus @ Jan 15, 2007 2:58 PM:</i>
          </p>
          <p>
            <i>Atomicity and JMX</i>
          </p>
          <p>
            Hi Matthias,
          </p>
          <p>
            Re your entry &quot;May it's time to think a little further&quot;, indeed I think
            configuring a JMX object with a sequence of setAttribute operations is
            suboptimal. There are a few ways to avoid this within the JMX API:
          </p>
          <ul>
            <li>
              As of Java SE 6, you can use an MXBean with a single complex attribute
              representing the collection of values to set. This is basically a
              &quot;struct&quot;. Because it is mapped to a standard Java type (CompositeData)
              the potential problems with versioning and serialization are reduced.
            </li>
            <li>
              In earlier versions you can still use the MBeanServer.setAttributes
              operation to set a bunch of attributes at the same time. But there's
              no way to require that the attributes all be set together, and there's
              some work needed to make the set atomic. It doesn't have to be very
              much work though, for instance using
              <a href="http://blogs.sun.com/nickstephen/entry/jmx_atomic_access_to_multiple">this
                idea
              </a>
              from Nick Stephen.
            </li>
            <li>
              An alternative to both of the above is to have an MBean operation
              rather than an attribute, the parameters to which are the values to
              set. This means there's no longer a way to set just some of the
              values, which overcomes the chief drawback of the preceding approach;
              it also works better with management consoles such as JConsole than
              either of the two alternatives. The operation can be called
              setSomething without ambiguity.
            </li>
          </ul>
          <p>
            I'm not sure how this fits into the wider debate about properties,
            though. I think the questions that arise when setting things remotely
            are distinct from the questions that arise for local objects, though
            they do overlap. In particular the idea of extending the JavaBeans
            conventions so you can have a setter that sets more than one thing seems
            interesting. One of the advantages of immutable objects is that you
            can't get an inconsistent object state by an unfortunate combination of
            setters, but the same advantage could be had by only providing setters
            that set enough properties to retain consistency.
          </p>
        </div>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/01-01-2007_01-31-2007.html#151</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Maybe-its-time-to-think-a-little-further"/>
    <a:updated>2007-01-16T20:51:30.345+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Aren't properties objects?</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Arent-properties-objects" href="#Arent-properties-objects"></a>
        <p>
          Surface syntax aside, implementation-wise a property is all object-like
          and I'm surprised we're still talking generating methods according to a
          naming convention. A property *has* setter and getter, it can be
          referenced, especially in order to bind it to a UI component, you can
          attach listeners, ...
        </p>
        <p>
          <a href="http://st-www.cs.uiuc.edu/users/brant/papers/ValueModel/ValueModels.htm">ValueModel</a>
          anyone?
        </p>
        <pre>
          public final RWProperty&lt;String&gt; name = new Slot&lt;String&gt;();

          mernst.name.get();
          mernst.name.set(&quot;matthias&quot;);
          mernst.name.attachListener(...);
          label.bind(mernst.name);
        </pre>
        <div class="comment">
          <p>
            <i>Comment by Stephen Colebourne @ Jan 13, 2007 7:28 PM:</i>
          </p>
          <p>
            Hi,
          </p>
          <p>
            See my blogs about this
            <br/>
            <a href="http://www.jroller.com/page/scolebourne?entry=java_7_property_objects">
              http://www.jroller.com/page/scolebourne?entry=java_7_property_objects
            </a>
            <br/>
            <a href="http://www.jroller.com/page/scolebourne?entry=more_detail_on_property_literals">
              http://www.jroller.com/page/scolebourne?entry=more_detail_on_property_literals
            </a>
          </p>
          <p>
            And responses including
            <br/>
            <a href="http://blogs.sun.com/abuckley/entry/properties_in_java">
              http://blogs.sun.com/abuckley/entry/properties_in_java
            </a>
          </p>
          <p>
            Also
            <br/>
            <a href="http://joda-beans.sf.net">http://joda-beans.sf.net</a>
          </p>
          <p>
            As for whether
            <br/>
            &gt; mernst.name.get();
            <br/>
            &gt; mernst.name.set(&quot;matthias&quot;);
          </p>
          <p>
            should be exposed to the application code, I'm not yet convinced that
            isn't too big a leap from the current conventions. It would be nice not
            to have get/set methods though.
          </p>
        </div>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/01-01-2007_01-31-2007.html#143</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Arent-properties-objects"/>
    <a:updated>2007-01-12T08:58:59+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Understanding the threats posed by XmlHttpRequest vs SCRIPT</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Understanding-the-threats-posed-by-XmlHttpRequest-vs-SCRIPT"
           href="#Understanding-the-threats-posed-by-XmlHttpRequest-vs-SCRIPT"></a>
        <p>
          <a href="http://www.innoq.com/blog/st/2007/01/05/samedomain_requirements_and_xmlhttprequest.html">Stefan</a>
          agreed and received comments that matters just ain't so.
        </p>
        <p>
          I admit that my experience with XSS is not extensive, so I went reading,
          too. I'll try and formulate the understanding I've reached now (main
          source being
          <a href="http://jeremiahgrossman.blogspot.com/2007/01/gmail-xsrf-json-call-back-hackery.html">Jeremiah
            Grossman
          </a>
          ):
        </p>
        <p>
          The fundamental threat of XSS is that a script from site A (attacker)
          has the browser talk to site V (victim) (using V's cookies), having V
          reveal some sensitive data, and consequently transfers this data to A.
          That's why cross-site XHR is prohibited. In contrast to XHR, SCRIPT tags
          cannot read the response and thus not make any malicious use of it.
          Instead, the SCRIPT response is evaluated as executable Javascript code
          by the browser. If V never responds with the data in an executable
          format that data is safe from A. Thus SCRIPT tags are allowed to load
          scripts from a different site.
        </p>
        <p>
          Now it has become popular to return data in JSON because it is so
          accessible from Javascript code. When this data is evaluated by a SCRIPT
          it gets dangerous since a clever script can intercept the inocouusly
          looking array- and object constructors and intercept the data - or
          easier, instruct the server to pass the data to a callback function,
          which seems to be popular, too.
        </p>
        <p>
          Conclusion: only data in executable format, returned on a GET
          authenticated through a cookie, is in danger of being hijacked through a
          SCRIPT tag. But that's more a fault of the server than the browser
          security model.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/01-01-2007_01-31-2007.html#140</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Understanding-the-threats-posed-by-XmlHttpRequest-vs-SCRIPT"/>
    <a:updated>2007-01-06T15:10:43+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Two notes on current controversies</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Two-notes-on-current-controversies" href="#Two-notes-on-current-controversies"></a>
        <p>
          <b>On the
            <a href="http://www.25hoursaday.com/weblog/PermaLink.aspx?guid=060ca7c3-b03f-41aa-937b-c8cba5b7f986">JSON v
              XML
            </a>
            debate
          </b>
          :
          what good is a same-domain requirement for
          XmlHttpRequest if you can do a GET on any host via a SCRIPT element?
          It's like saying &quot;applets can't contact arbitrary hosts
          <i>through sockets</i>
          but URLConnections are ok&quot;.
        </p>
        <p>
          <b>On
            <a href="http://gafter.blogspot.com/2006/12/closures-talk-and-spec-update.html">Closures</a>
            and
            <a href="http://msdn.microsoft.com/data/ref/linq/">LINQ</a>
          </b>
          :
          LINQ introduces the notion of expressions. Restricting the contents of
          the curly braces to expressions might seem like an interesting approach.
          It avoids transfer-of-control-problems. But the most interesting part:
          LINQ allows you to
          <a
            href="http://community.bartdesmet.net/blogs/bart/archive/2006/11/22/Getting-started-with-C_2300_-3.0-Expression-Trees.aspx">
            reflect
            over an expression structure
          </a>
          and gives you some interesting options
          to optimize the query.
        </p>
        <p>

        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/01-01-2007_01-31-2007.html#138</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Two-notes-on-current-controversies"/>
    <a:updated>2007-01-05T09:37:16+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Three things hardly anyone wants to know about me</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Three-things-hardly-anyone-wants-to-know-about-me"
           href="#Three-things-hardly-anyone-wants-to-know-about-me"></a>
        <p>
          Thank you,
          <a href="http://www.wuenschenswert.net/wunschdenken/archives/105">Axel</a>
          .
          What can I say?
        </p>
        <p>
          When I helped in the development of the
          <a href="http://www.icsi.berkeley.edu/~sather/">Sather</a>
          compiler, I analyzed and fixed bugs purely by studying the code - my
          machine was way too small to bootstrap the compiler.
        </p>
        <p>
          I met my wife at
          <a href="http://marcellospizzasf.com/">Marcello's</a>
          in the Castro district in San Francisco. With funky shoes and hair she
          thought I was gay and thus safe to talk to - it turned out I wasn't gay
          but european.
        </p>
        <p>
          The first linux I installed came by mail-order and was a stack of 3.5''
          wrapped in packing tape. I wanted it because of xeyes.
        </p>
        <p>
          <a href="http://jandiandme.blogspot.com">Eberhard</a>
          ,
          <a href="http://blogs.sun.com/alanb/">Alan</a>
          and
          <a href="http://www.elien.de/blog/">Grabowski</a>
          .
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/12-01-2006_12-31-2006.html#137</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Three-things-hardly-anyone-wants-to-know-about-me"/>
    <a:updated>2006-12-21T10:15:07+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>NIO &amp; IP Multicast</a:title>
    <a:content type="xhtml">
      <div>
        <a name="NIO--IP-Multicast" href="#NIO--IP-Multicast"></a>
        <p>
          The common wisdom: the two of them don't go together. Some official Java
          version in 2008 might have support, some open source derivative earlier.
          For those of us that need to do multicast today, here's the version that
          works for me with 5.0u9, Win XP, IPV4. CAVEAT: ugliness reigns and this will most
          certainly break with newer or non-Sun versions.
        </p>
        <p>
          In short: we wrap the DatagramChannel's fd in a manually created
          PlainDatagramSocketImpl, join the multicast group and let go of the
          socket again:
        </p>
        <pre>
          // UGLY UGLY HACK: multicast support for NIO
          // create a temporary instanceof PlainDatagramSocket, set its fd and configure it
          Constructor&lt;? extends DatagramSocketImpl&gt; c =
          (Constructor&lt;? extends DatagramSocketImpl&gt;)
          Class.forName(&quot;java.net.PlainDatagramSocketImpl&quot;).getDeclaredConstructor();

          c.setAccessible(true);
          DatagramSocketImpl socketImpl = c.newInstance();

          Field channelFd = Class.forName(&quot;sun.nio.ch.DatagramChannelImpl&quot;).getDeclaredField(&quot;fd&quot;);
          channelFd.setAccessible(true);

          Field socketFd = DatagramSocketImpl.class.getDeclaredField(&quot;fd&quot;);
          socketFd.setAccessible(true);
          socketFd.set(socketImpl, channelFd.get(channel));

          try {
          Method m = DatagramSocketImpl.class.getDeclaredMethod(&quot;joinGroup&quot;, SocketAddress.class,
          NetworkInterface.class);
          m.setAccessible(true);
          m.invoke(socketImpl, socketAddress, networkInterface);
          } finally {
          // important, otherwise the fake socket's finalizer will nuke the fd
          socketFd.set(socketImpl, null);
          }
        </pre>
        <p>Enjoy or let me know why this is a bad idea.</p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/12-01-2006_12-31-2006.html#136</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#NIO--IP-Multicast"/>
    <a:updated>2006-12-18T22:37:06+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Finger Activity</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Finger-Activity" href="#Finger-Activity"></a>
        <p>
          We recently celebrated crossing changelist #100000! A great moment to
          reminisce. We introduced
          <a href="http://www.perforce.com/">Perforce</a>
          in 2000 and haven't regretted it once. Fast, reliable, powerful, good
          support.
        </p>
        <p>
          I will now reveal my very personal electro-codeo-gram to you:
        </p>
        <p align="center">
          <img alt="" height="278" src="http://www.mernst.org/blog/media/tisi_traffic.png" width="384"/>
        </p>
        <p align="center">
          (p4 changes -u mernst | cut -d ' ' -f 4 | cut -d / -f 1-2 | uniq -c).
        </p>
        <p>
          I've decided not to read too much into it.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/11-01-2006_11-30-2006.html#135</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Finger-Activity"/>
    <a:updated>2006-11-30T23:24:22+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>How Far is Fidji?</a:title>
    <a:content type="xhtml">
      <div>
        <a name="How-Far-is-Fidji" href="#How-Far-is-Fidji"></a>
        <p>
          Inspired by
          <a href="http://www.snellspace.com/wp/?p=523">James Snell</a>
          :
          <i>Fidji is deliberately Java-incompatible :-)</i>
        </p>
        <p>
          There's a few things that would be fun to hack into Java, now that we
          could actually share it with the world (Hats off to Sun!). I would
        </p>
        <ul>
          <li>
            get rid of checked exceptions. They're such a pain. As far as I
            understand they're purely a compile-time construct, could be easily
            fixed in Javac and have nothing to do with either security nor VM
            integrity.
          </li>
          <li>
            fill the void. An invocation expression of a method with return type
            void could be treated as if returning the receiver, enabling cascaded
            sends. Bean b = new Bean().setA(a).setB(b);
          </li>
          <li>
            add type inference for locals: todo := problems.size(); next :=
            problems.removeFirst();
          </li>
          <li>
            add
            <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6179333">reliable
              closing of iterators
            </a>
            in the for-each loop. for(line :
            File.lines(&quot;log.txt&quot;)) soutv&lt;TAB&gt;line (try this today without losing a
            file handle!). I've actually already done this one:
            <a
              href="https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=14881&amp;forumID=1463">
              patch
            </a>
          </li>
          <li>
            <a href="http://forums.java.net/jive/thread.jspa?forumID=23&amp;threadID=2522&amp;messageID=36107#36107">
              Resource
              literals
            </a>
            . Akin to X.class, a mechanism for compile-time checked
            references to resources.
          </li>
        </ul>
        <p>
          If I needn't go to work now I could probably think of many more. The big
          BUT: these are all futile if no IDE recognizes them (&quot;Das Rote ist
          gefährlicher Zahnbelag&quot;). I hear NetBeans is javac-based. How much would
          it take?
        </p>
        <p>
          What would you do?
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/11-01-2006_11-30-2006.html#133</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#How-Far-is-Fidji"/>
    <a:updated>2006-11-15T09:42:06+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Wrong way</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Wrong-way" href="#Wrong-way"></a>
        <p>
          I don't understand all the whining about type erasure. Au contraire, an
          elaborate compile-time type system without burdening the runtime is most
          elegant and I wish Java would rather move further into that direction
          instead of getting
          <a href="http://gafter.blogspot.com/2006/11/reified-generics-for-java.html">reified
            generics
          </a>
          .
        </p>
        <p>

        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/11-01-2006_11-30-2006.html#132</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Wrong-way"/>
    <a:updated>2006-11-06T08:20:22+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Climate Matters</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Climate-Matters" href="#Climate-Matters"></a>
        <p>
          Al Gore's film &quot;
          <a href="http://www.climatecrisis.net/">An Inconvenient Truth</a>
          &quot; has arrived in Germany. It is a good movie and
          it deserves that you go, make your friends see it with you and finally
          start doing something about your energy balance.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/10-01-2006_10-31-2006.html#131</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Climate-Matters"/>
    <a:updated>2006-10-26T00:19:17+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>SVG.class!</a:title>
    <a:content type="xhtml">
      <div>
        <a name="SVGclass" href="#SVGclass"></a>
        <p>
          The argument I made when dissing Kirill's SVG to class compilation was
          the overhead of parsing the class files, resolution and verification as
          compared to simply parsing an XML representation into an
          application-level tree representation. I came around to actually measure
          the difference.
        </p>
        <p>
          Note that I'm only talking about the speed of loading, not of drawing.
          The test I performed was: what is the fastest representation to load ?
          In order to get I/O out of the way, I prepared the source representation
          in memory.
        </p>
        <p>
          The contestants:
        </p>
        <ul>
          <li>
            class file: 1000 byte arrays with different classes, each with a
            method doing 1000 method calls, are loaded into a new classloader. An
            instance is created for each class to make sure the class is fully
            initialized.
          </li>
          <li>
            serialization: 1000 serialized object graphs, consisting of 1000 small
            objects each, are deserialized
          </li>
          <li>
            Binding with XML: 1000 XML documents, consisting of 1000 elements
            each, are parsed and bound to an object graph using JAXB.
          </li>
          <li>
            Binding with Fast Infoset: 1000 fast infoset documents, consisting of
            1000 elements each, are bound to an object graph using JAXB.
          </li>
          <li>
            DOM building: 1000 fast infoset documents, consisting of 1000 elements
            each, are transformed into a DOM tree
          </li>
        </ul>
        <p>
          So how do you think the contestants fared?
        </p>
        <p>
          Quite a surprise for me: slowest was the DOM building, followed by XML
          parsing&amp;binding. Next came FI to Java binding, then serialization. And
          the winner is: classloading! It is faster to load a compiled
          representation of method calls into the VM than bind the equivalent
          Infoset representation to heap objects. So except for handcrafting a
          binary format, a jar with compiled .svg icons might indeed be the best
          option.
        </p>
        <p>
          The numbers after some warmup:
        </p>
        <ul>
          <li>
            class loading: 359ms
          </li>
          <li>
            serialization: 500ms
          </li>
          <li>
            fi-&gt;JAXB: 703ms
          </li>
          <li>
            XML-&gt;JAXB: 1516ms
          </li>
          <li>
            fi-&gt;DOM: 1594ms
          </li>
        </ul>
        <p>
          The test was performed using Java 6b101, server VM w/ 256MB initial and
          max heap. The usual caveats apply, especially the data is synthetic and
          simplistic. If you want to take a look at the test code, it's
          <a href="/blog/test.zip">here</a>
          .
        </p>
        <p>
          <i>I have to update my results again. Now with a more realistic
            scenario, the actual bytecode for an actual icon vs the equivalent fast
            infoset document, DOM and serialization are fastest, about 30% faster
            than classloading and binding which come out head to head. Binding
            spends a considerable amount parsing the coordinate and other attributes
            into doubles. With a more efficient representation it would be ahead of
            bytecode. Just using String, it is almost twice as fast. At a
            millisecond per icon, the difference doesn't matter that much anyway.
          </i>
        </p>
        <p>
          <i/>
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/10-01-2006_10-31-2006.html#128</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#SVGclass"/>
    <a:updated>2006-10-24T22:36:57+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Ficken ist so ein schönes Wort</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Ficken-ist-so-ein-schnes-Wort" href="#Ficken-ist-so-ein-schnes-Wort"></a>
        <p>
          Schade, dass man es in den USA
          <a href="http://www.theinquirer.net/default.aspx?article=35246">nicht</a>
          <a href="http://www.cincomsmalltalk.com/blog/blogView?showComments=true&amp;entry=3339007323">schreiben</a>
          <a href="http://www.tbray.org/ongoing/When/200x/2006/10/22/Goodness-Gracious">darf</a>
          .
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/10-01-2006_10-31-2006.html#127</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Ficken-ist-so-ein-schnes-Wort"/>
    <a:updated>2006-10-23T22:14:24+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>SVG.class?</a:title>
    <a:content type="xhtml">
      <div>
        <a name="SVGclass-0" href="#SVGclass-0"></a>
        <p>
          I have to say I cringed when I saw
          <a href="http://weblogs.java.net/blog/kirillcool/archive/2006/10/svg_and_java_ui_3.html">Kirill's
            post
          </a>
          because I'm allergic to code generation (unless it's
          necessary). Graphics are data, not program (see - I neither have a LISP
          nor Postscript background) - it makes about as much sense as compiling
          JSPs. In Suns VM, classes end up in a scarce resource called permspace,
          and I don't expect classloading to be any cheaper than reading a &quot;data&quot;
          file. My take: instead of generating Java code, rather serialize the
          render tree and interpret it.
        </p>
        <p>
          Yet this allergy is highly opion-laden and calls for a comparison. How
          expensive is loading a class in comparison to parsing an XML file and
          binding it to a renderer tree representation? What's the memory
          footprint? Will a &quot;compiled&quot; icon enjoy any benefit from dynamic
          compilation? Ultimately, would the world want another file format that
          corresponds 1-1 to the Java 2D API or isn't that just another form of
          bytecode?
        </p>
        <p>
          In the end, any means to avoid a heap of Batik jars are justified...
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/10-01-2006_10-31-2006.html#125</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#SVGclass-0"/>
    <a:updated>2006-10-23T09:45:00+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Gilad Bracha is leaving Sun</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Gilad-Bracha-is-leaving-Sun" href="#Gilad-Bracha-is-leaving-Sun"></a>
        <p style="margin-top: 0">
          No one has died but I feel like whatever I'll write will sound like
          that; please bear with my limited language. I cannot claim that I know
          Gilad too well. I had the pleasure to meet him seven years ago when I
          had the audacity to invite myself into his office to talk about our
          language work at Hamburg University and received the honour of my own
          StrongTalk tour and a lecture about mixins. I wonder how often Gilad
          must have cursed that the most advanced virtual machine technology
          aquired by Sun was used to drive such an ugly language as Java. But it's
          probably not overrated to say that he's been the pillar for its
          stability and well-definedness, reason amongst others for the commercial
          success of Java. Enough said! Hope there's greater adventures waiting
          for you. Good luck!
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/10-01-2006_10-31-2006.html#124</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Gilad-Bracha-is-leaving-Sun"/>
    <a:updated>2006-10-17T01:26:25+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Neal Gafter's example is bogus</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Neal-Gafters-example-is-bogus" href="#Neal-Gafters-example-is-bogus"></a>
        <p>
          <a href="http://gafter.blogspot.com/2006/10/concurrent-loops-using-java-closures.html">Neal</a>
          makes it look like only closures could hide away the strutting of a
          forEachConcurrently abstraction. I'm all for closures but this is a flawed argument.
          What he should have compared is his closure-using code:
        </p>
        <pre>
          List&lt;Principal&gt; result = new ArrayList&lt;Principal&gt;();
          for eachConcurrently(EventResponse r : getResponses(), threadPool) {
          if (r.mayAttend()) {
          Principal attendee = r.getAttendee();
          synchronized (result) {
          result.add(attendee);
          }
          }
          }
          return result;
        </pre>
        <p>to this:</p>
        <pre>
          final List&lt;Principal&gt; result = new ArrayList&lt;Principal&gt;();
          forEachConcurrently(getResponses(), threadPool, new Runnable1&lt;EventResponse, RemoteException&gt;() {
          public void call(EventResponse r) throws RemoteException {
          if (r.mayAttend()) {
          Principal attendee = r.getAttendee();
          synchronized (result) {
          result.add(attendee);
          }
          }
          }
          });
          return result;
        </pre>
        <p>The supposed library implementation (exception handling and such according to Google):</p>
        <pre>
          public interface Runnable1&lt;Arg1, Ex extends Throwable&gt; {
          public void run(Arg1 arg1) throws Ex;
          }

          public static &lt;E&gt; void forEachConcurrently(
          Collection&lt;? extends E&gt; collection,
          Executor threadPool,
          final Runnable1&lt;E, ? extends Throwable&gt; fun) {
          CompletionService&lt;Void&gt; ecs =
          new ExecutorCompletionService&lt;Void&gt;(threadPool);

          for (final E e : collection) {
          ecs.submit(new Callable&lt;Void&gt;() {
          public Void call() {
          try {
          fun.run(e);
          } catch (Throwable ex) {
          LOGGER.log(Level.SEVERE, &quot;Uncaught Exception&quot;, ex);
          }
          return null;
          }
          });
          }
          // wait for the tasks to complete
          for (final E e : collection) {
          try {
          /*discard*/ ecs.take().get();
          } catch (InterruptedException ex) {
          throw new AssertionError(ex); // shouldn't happen
          } catch (ExecutionException ex) {
          LOGGER.log(Level.SEVERE, &quot;Uncaught Exception&quot;, ex);
          }
          }
          }
        </pre>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/10-01-2006_10-31-2006.html#121</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Neal-Gafters-example-is-bogus"/>
    <a:updated>2006-10-16T00:07:03+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>First Sprouts</a:title>
    <a:content type="xhtml">
      <div>
        <a name="First-Sprouts" href="#First-Sprouts"></a>
        <p>
          After me bitching about the perceived opacity of JDK 7 development,
          JSR 277 has released an
          <a href="http://jcp.org/aboutJava/communityprocess/edr/jsr277/index.html">early
            draft
          </a>
          . A pretty long and detailed document (well, not a quality
          in itself, EJB was, too), too much to have studied it in detail yet.
          My first impressions:
        </p>
        <ul>
          <li>
            there are examples and scenarios for a number of use cases
          </li>
          <li>
            J2SE is expected to become modular itself - whatever the
            implications are for standards. Au revoir -Xbootclasspath?
          </li>
          <li>
            modules and their containing repositories are fully reflected at
            runtime.
          </li>
          <li>
            the specification predicts that JDC 4670071 bug will finally need
            fixing
          </li>
          <li>
            the syntax for module definitions is weird. It resembles
            annotations but not quite. Then, in a different section, using XML
            for URL repository descriptions seems ok for the EG.
          </li>
        </ul>
        <p>
          So far, matters related to language specification have been in
          conservative, if not too rigid hands, so I expect this spec will be
          consistent. It's hard to judge how much easier or more complicated
          developers' lifes will become. According to section 2.18 the authors
          &quot;anticipate many higher level tools and frameworks will build upon
          the module system to provide greater convenience and ease of use.&quot;.
          Let's hope so.
        </p>
        <p>
          So when you send your comments to the JSR comment address and hope
          for reply, why don't you post them on your blog or up the java.net
          forums as well?
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/10-01-2006_10-31-2006.html#120</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#First-Sprouts"/>
    <a:updated>2006-10-15T23:05:15+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>JDK development from the outside</a:title>
    <a:content type="xhtml">
      <div>
        <a name="JDK-development-from-the-outside" href="#JDK-development-from-the-outside"></a>
        <p>
          I'm sure there's a lot of people like me that would like to know where
          things are moving in Java 7. However, it's hard to find out. Danny
          points to a
          <a href="http://blogs.sun.com/dannycoward/entry/channeling_java_se_7">list
            of JSRs
          </a>
          slated for inclusion in Java 7. I'm disappointed that not
          one of the expert groups chose a process as open as JSR166. I'm
          certainly not expected to join all these as an &quot;expert&quot; (what is that
          anyway?), just because I'm interested. In the average case, it will take
          a few months until an EG spits out a zip with JavaDoc and - if I'm lucky
          - a PDF with a little rationale. But a lot will be missing - what was
          tried but didn't work out, alternatives considered, ... And the
          impression I get (the wrong it may be): it's too late in the process to
          change something fundamental anyway.
        </p>
        <p>
          I feel this form of development isn't very compatible with a soon-to-be
          open-source implementation. It may almost provoke forks.
        </p>
        <p>
          My request: open up your mailing list archives and your CVSs, let us
          follow your train of thoughts, and you'll receive so much more valuable
          feedback and contributions. If you want them, that is.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/10-01-2006_10-31-2006.html#74</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#JDK-development-from-the-outside"/>
    <a:updated>2006-10-03T16:56:08+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>A long term suspicion</a:title>
    <a:content type="xhtml">
      <div>
        <a name="A-long-term-suspicion" href="#A-long-term-suspicion"></a>
        <p>
          An observation: almost all WYSIWIG text editors suck at some point.
          We've been beaten up repeatedly for our CMS's text editor but in
          comparison we're actually doing pretty well. The
          <a href="http://thingamablog.sourceforge.net/">editor</a>
          I'm typing this text with is Swing-based and gets confused all the time.
          James Robertson turned off his WYSIWIG comment editor pretty quickly
          again. And today, after noticing the
          <a href="http://crazybob.org/2006/10/java-closure-spectrum.html">BLL
            competing closure proposal
          </a>
          (someone with a U want to join that
          group?), I tried writely. After pasting some dead-simple HTML (just p's
          and text) BACKSPACE wouldn't join two paragraphs but introduce some br
          weiredness. A second BACKSPACE would do the job. Not intuitive.
        </p>
        <p>
          Which leads me back to a long-term suspicion of mine: the base
          abstraction is wrong. A long time ago computer science decided that
          documents shall be trees. Things started to go down after that...
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/10-01-2006_10-31-2006.html#73</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#A-long-term-suspicion"/>
    <a:updated>2006-10-03T12:29:59+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>volatile is the new synchronized</a:title>
    <a:content type="xhtml">
      <div>
        <a name="volatile-is-the-new-synchronized" href="#volatile-is-the-new-synchronized"></a>
        <p>
          Bill Pugh and folks have done an outstanding job to clarify and simplify
          Java's memory model. And they have done a great job to get the word out
          and raise awareness for the issues. Yet what can happen is that people
          have now
          <a href="http://weblogs.java.net/blog/tomwhite/archive/2006/09/are_your_beans.html">gotten
            nervous
          </a>
          about safe publishing and visibility and start sprinkling
          volatile pixie dust. Reminds me of the generous application of
          &quot;synchronized&quot; when one wasn't quite sure ...
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/09-01-2006_09-30-2006.html#71</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#volatile-is-the-new-synchronized"/>
    <a:updated>2006-09-22T08:50:39+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Issues of an aging star</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Issues-of-an-aging-star" href="#Issues-of-an-aging-star"></a>
        <p>
          Three bug reports (
          <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=36541">36541</a>
          ,
          <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=37356">37356</a>
          ,
          <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=38713">38713</a>
          ),
          some observations: Tomcat is full of clever(TM) and buggy
          concurrency code. Even experienced maintainers may not know how the
          memory model works. On a popular project, the more stupid people
          you're dealing with, the more resistant you get to suggestions - to
          the point where you refuse to accept that you're wrong. I don't have
          the scoop on the Tomcat / Glassfish relationship but obviously,
          there's a lot of bitterness involved, too.
        </p>
        <p>
          Sad to see, in a way.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/09-01-2006_09-30-2006.html#70</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Issues-of-an-aging-star"/>
    <a:updated>2006-09-21T09:16:45+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Nil is back with a vengeance ...</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Nil-is-back-with-a-vengeance-" href="#Nil-is-back-with-a-vengeance-"></a>
        <p>
          <a href="http://www.sts.tu-harburg.de/projects/Tycoon2/entry.html">TL2</a>
          ,
          the OO programming language we built in school has no distinction
          between expressions and statements. Everything is an expression and
          correspondingly has a type. The Exception class sports a method &quot;raise&quot;
          - which needs to have a special type: an exception can be thrown at any
          point in the program, where any type is expected. For example
        </p>
        <pre>i :Int := anException.raise()</pre>
        <p>
          The return type of raise() is Nil, corresponding to the bottom type. By
          definition, Nil is subtype of all types in the system, that's why the
          above line typechecks.
        </p>
        <pre>raise :Nil (* the signature of raise *)</pre>
        <p>
          Looking back at this I'm now wondering why we chose subtyping over
          parametric polymorphism. Instead of &quot;raise() produces a value that
          fulfils every other type&quot;, we could as well have said &quot;raise() produces
          any type you want&quot;:
        </p>
        <pre>raise(T&amp;lt;:Void) :T (* T is a type parameter bounded by the top type &quot;Void&quot;, i.e. any type
          *)
        </pre>
        <p>
          Why I'm writing this? I came to think of the parametric throw method at
          a
          <a href="http://weblogs.java.net/blog/forax/archive/2006/08/function_that_d.html">discussion</a>
          on Remy's blog. And now, Nil has resurfaced in the form of ...
          <a href="http://gafter.blogspot.com/2006/09/nominal-closures-for-java-version-02.html">
            java.lang.Unreachable
          </a>
          .
          Do we really need a name for the it?
        </p>
        <p>
          The situation pretty much resembles the one with empty lists. With generics introduced in Java 5, there is no
          type
          to assign to the EMPTY_LIST constant in java.util.Collections. Instead of coming up with a new type we have a
          polymorphic method emptyList() to give us the empty list of choice.
          I say we could do the same with the closure that always throws (as in &quot;der Geist, der stets verneint...&quot;).
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/09-01-2006_09-30-2006.html#68</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Nil-is-back-with-a-vengeance-"/>
    <a:updated>2006-09-15T08:58:22+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>REST is not CRUD, it's COPOPACU</a:title>
    <a:content type="xhtml">
      <div>
        <a name="REST-is-not-CRUD-its-COPOPACU" href="#REST-is-not-CRUD-its-COPOPACU"></a>
        The right
        <a href="http://rest.blueoxen.net/cgi-bin/wiki.pl?MinimumMethods">explanation</a>
        of the main HTTP verbs
        (through
        <a href="http://www.markbaker.ca/blog/">Mark Baker</a>
        ).
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/08-01-2006_08-31-2006.html#67</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#REST-is-not-CRUD-its-COPOPACU"/>
    <a:updated>2006-08-26T10:17:44+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>An alternative to String#intern()</a:title>
    <a:content type="xhtml">
      <div>
        <a name="An-alternative-to-Stringintern" href="#An-alternative-to-Stringintern"></a>
        <p>
          Ethan
          <a href="http://weblogs.java.net/blog/enicholas/archive/2006/06/all_about_inter.html">blogged</a>
          about the usage of String#intern in the Xerces XML parser. Let's not
          delve into the discussion whether interning is particularly useful
          in this context. What does String#intern do? Basically, it
          implements a global weak symbol table that unfortunately populates
          the permspace. As an alternative, let's see what it takes to
          implement #intern at the application level: Since I'm lazy, we'll
          define that you do not actually need the weakness property if you
          have dedicated symbol tables that you can forget and that can be
          GCed as a whole. Luckily, ConcurrentHashMap already implements
          everything we need then, so it's pretty easy:
        </p>
        <pre>
          public class SymbolTable&lt;T&gt; {
          ConcurrentHashMap&lt;T&gt; chm = new ConcurrentHashMap&lt;T&gt;();

          public T unique(T t) {
          T first = chm.putIfAbsent(t, t);
          return (first == null) ? t : first;
          }
          }
        </pre>
        <p>
          Not only does this little class not bloat your permspace but it's
          actually faster than using String#intern(). Just say no.
        </p>
        <p>
          <em>Rémi Forax reminds me that String.intern() is handy in order to
            do identity comparisons against constants. Just don't let yourself
            be fooled into thinking that '==' makes things faster. Interning the
            string in the first place requires you to hash the string and
            compare it to the interned version.
          </em>
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/08-01-2006_08-31-2006.html#59</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#An-alternative-to-Stringintern"/>
    <a:updated>2006-08-26T00:16:18+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Parsing object streams with JAXB</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Parsing-object-streams-with-JAXB" href="#Parsing-object-streams-with-JAXB"></a>
        <p>
          JAXB is a wonderful tool to bind XML to objects. Unfortunately, used
          naively, it has the same problem as DOM: you need to load the whole
          document into memory until you can start consuming the result. If
          you have a document with one root element and tens of thousands of
          children it is a good idea to combine object-binding for each
          child with streaming for the whole list.
        </p>
        <p>
          I'm using a simple solution to do that. It's a list implementation
          that does not store its children but notifies a callback handler
          instead. Use that list in the parent bean and you're all set:
        </p>
        <pre>
          @XmlRootElement(name = &quot;parent&quot;)
          @XmlType(name = &quot;&quot;, propOrder = {&quot;children&quot;})
          public class Parent {
          @XmlElement(name = &quot;child&quot;)
          List&lt;Child&gt; children = new CallbackList&lt;Child&gt;();
          }
        </pre>
        <p>
          Now, whenever JAXB has finished constructing a child object, it will call #add on my list
          and the object is immediately handed to the callback and garbage collected afterwards.
        </p>
        <p>
          You may have noticed that the parent context is not fully constructed yet and
          unknown to the child, thus inaccessible to the callback handler. Also, I haven't found a
          proper way to inject objects into JAXB, so the CallbackList needs to find its callback handler
          through a ThreadLocal which is not exactly pretty. But the net result is great: blazing performance
          combined with the comfort of binding.
        </p>
        <p>
          <i>Next morning:</i>
          alright, I just discovered the UnmarshallerListener. We can use it a) to install
          a write-only sink as the list implementation and b) listen for child objects without the thread-local.
          And without having to change any of the generated classes. Neat!
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/08-01-2006_08-31-2006.html#62</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Parsing-object-streams-with-JAXB"/>
    <a:updated>2006-08-25T23:04:25+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Regaining a name for a wildcard type</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Regaining-a-name-for-a-wildcard-type" href="#Regaining-a-name-for-a-wildcard-type"></a>
        <p>
          When using generics I run into the same problem over and over: a
          class has a field of a parameterized type but actually doesn't care
          about the type. A perfect match for using wildcards. However, within
          a method the using class needs to call methods of the parameterized type
          that have arguments of the type parameter - of course just derived from that very object.
          For example: rotate a linked list.
        </p>
        <pre>
          public class RotateList {
          LinkedList&lt;?&gt; theList;

          public void rotate() {
          LinkedList&lt;?&gt; l = theList;
          theList.addLast(theList.removeFirst());
          }
          }
        </pre>
        <p>
          This does not compile since an important piece of information is lost between calling removeFirst and addLast:
          not only don't we know the type of the result but we also don't know that it's the very type parameter of the
          list we're talking about.
        </p>
        <p>
          At this point I would normally resign and propagate the list's type parameter to the using class. This way,
          type parameters spread throughout my code. But there is hope! We can pull out the code into a generic method,
          parameterized by the list's element type. This way we can give a local name to the wildcard that will
          convince the compiler that we're doing right:
        </p>
        <pre>
          public class RotateList {
          LinkedList&lt;?&gt; theList;

          public void rotate() {
          // what used to be an unknown type
          // regains a name in the method
          // and becomes more useful
          rotate(theList);
          }

          private &lt;T&gt; void rotate(LinkedList&lt;T&gt; l) {
          l.addLast(l.removeFirst());
          }
          }
        </pre>
        <p>Probably not a surprise for generics wizards but I had my aha-moment! Now why do we need an
          extra method? How about a syntax for introducing a type name
          <i>within</i>
          a method?
        </p>
        <pre>
          public class RotateList {
          LinkedList&lt;?&gt; theList;

          public void rotate() {
          &lt;T &gt; List &lt; T &gt; l = theList;
          l.addLast(l.removeFirst());
          }
          }
        </pre>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/07-01-2006_07-31-2006.html#60</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Regaining-a-name-for-a-wildcard-type"/>
    <a:updated>2006-07-15T09:37:43+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Defeated</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Defeated" href="#Defeated"></a>
        <img alt="" src="http://www.corinthianseller.co.uk/prostars/prostars-PRO1122.jpg" style="float: left"/>
        We just got our asses kicked 2:0 in the last three minutes. Trotzdem,
        Jungs, Ihr wart großartig! Dann fahren wir halt nach Stuttgart.
        <br style="clear:both"/>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/07-01-2006_07-31-2006.html#57</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Defeated"/>
    <a:updated>2006-07-05T00:54:09+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Seattle Pictures</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Seattle-Pictures" href="#Seattle-Pictures"></a>
        I spent a few days in Seattle last week. The city sported some fabulous
        weather - thanks! Here's some pictures:
        <img alt="" height="461" src="http://www.mernst.org/blog/media/lighthouse1.jpg" title="West Point" width="615"/>
        <img alt="" height="461" src="http://www.mernst.org/blog/media/lighthouse2.jpg"
             title="The Lighthouse at West Point" width="615"/>
        <img alt="" height="461" src="http://www.mernst.org/blog/media/rainier.jpg" title="Mount Rainier" width="615"/>
        <img alt="" height="461" src="http://www.mernst.org/blog/media/bainbridge1.jpg" title="Bainbridge Island"
             width="615"/>
        <img alt="" height="461" src="http://www.mernst.org/blog/media/bainbridge2.jpg" title="Sunset" width="615"/>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/07-01-2006_07-31-2006.html#54</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Seattle-Pictures"/>
    <a:updated>2006-07-04T03:26:30+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>OSVM in trouble</a:title>
    <a:content type="xhtml">
      <div>
        <a name="OSVM-in-trouble" href="#OSVM-in-trouble"></a>
        Esmertec is closing its Denmark subsidiary after having CTO, CEO and two
        co-founders leave and a dramatic loss in revenue (
        <a href="http://www.esmertec.com/press/index.shtml">press
          releases
        </a>
        ). Sad news since Lars Bak and his team were building OSVM, a
        highly interesting Smalltalk environment for embedded devices. Hopefully
        it doesn't just go away.
        <i>(via
          <a href="http://blog.quenta.org/2006/07/rip.html">Christian
            Plesner Hansen
          </a>
          )
        </i>
        .
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/07-01-2006_07-31-2006.html#53</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#OSVM-in-trouble"/>
    <a:updated>2006-07-03T09:55:14+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Contented Monitor on a T2000</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Contented-Monitor-on-a-T2000" href="#Contented-Monitor-on-a-T2000"></a>
        <p>
          I've ranted about it before, the Jakarta JSP EL-Interpreter up to
          Tomcat 5.5 / JSTL 1.1 does not parse EL expressions at page compile time but goes through a parser
          cache on each evaluation in ELEvaluator.java:
        </p>
        <pre>
          static Map sCachedExpressionStrings =
          Collections.synchronizedMap (new HashMap ());
        </pre>
        <p>
          We've been doing some performance testing on a Sun T2000
          machine and this showed to be a bottleneck. A typical thread dump
          would have many threads waiting for monitor entry on this parser
          cache here:
        </p>
        <pre>
          // See if it's in the cache
          Object ret =
          mBypassCache ?
          null : sCachedExpressionStrings.get(pExpressionString);

          if (ret == null) {
          // Parse the expression
          Reader r = new StringReader(pExpressionString);
          ELParser parser = new ELParser(r);
          try {
          ret = parser.ExpressionString();
          sCachedExpressionStrings.put(pExpressionString, ret);
          }
          }
        </pre>
        <p>
          There's a simple trick I've used on several occasions to reduce contention on this monitor. I made the parser
          cache read-only; any thread that wants to add to the cache must
          allocate a new copy and substitute it for the old version. Since we're talking about EL expressions here
          that you'll only have a few hundred of in your application(s), the process will quickly converge. Reading the
          cache now only costs an additional memory barrier for reading the volatile and is fully concurrent otherwise.
          In this particular case it boosted the performance by 40% from 400 to 550 page impressions / s.
        </p>
        <pre>
          static volatile Map sCachedExpressionStrings = new HashMap();
          ...
          // copy on write
          Map updatedCache = new HashMap(sCachedExpressionStrings);
          updatedCache.put(pExpressionString, ret);
          sCachedExpressionStrings = updatedCache;
        </pre>
        <p>
          Note that there's a race, if two threads both want to update the cache at once, one might lose. In this
          scenario it doesn't really matter, though, and the cache will quickly be complete. Also note, that this
          code is only really legal under the revised Java Memory Model in Java 5. Up to 1.4.2, writing the reference of
          the new map to the volatile variable
          'sCachedExpressionStrings' would not garantuee visibility of the update cache's contents; actually anything
          could happen. I seem to recall though, that on Sun JVM 1.4.2 this code will actually be correct, too.
          <br/>
          <i>Update: it just dawned on me that I could combine copy-on-write with a traditional monitor-protected
            field instead of the volatile. This would still be a much shorter critical section than the synchronized
            map AND entirely legal even according to the 1.4 memory model. Something that might have a chance to
            be accepted as a patch iff the gains are high enough.
          </i>
        </p>
        <p>
          I expect more of this kind of problems the more cores we see in servers. Luckily guys like Doug Lea and Bill
          Pugh make sure we can write code that avoids them. Can't wait for my copy of
          <a href="http://www.amazon.com/gp/product/0321349601/104-6401745-7122342?v=glance&amp;n=283155">this</a>
          ...
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/05-01-2006_05-31-2006.html#51</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Contented-Monitor-on-a-T2000"/>
    <a:updated>2006-05-19T08:48:07+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Russ Beattie goes off the air</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Russ-Beattie-goes-off-the-air" href="#Russ-Beattie-goes-off-the-air"></a>
        <p>
          One of the more interesting blogs has closed its
          <a href="http://www.russellbeattie.com/notebook/1008990.html">last
            page
          </a>
          . Too bad. After going through the website, wiki, blog
          transformation process, maybe Russ is going to come up with a next
          greater way of publishing. Goodbye and good luck!
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/04-01-2006_04-30-2006.html#50</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Russ-Beattie-goes-off-the-air"/>
    <a:updated>2006-04-22T16:39:15+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>debugger experience</a:title>
    <a:content type="xhtml">
      <div>
        <a name="debugger-experience" href="#debugger-experience"></a>
        <p>
          Three annoyances keep coming back to me (at least in the IDEA debugger):
        </p>
        <p>
          <em>I can't see the result of a method</em>
          . If a method ends with
          &quot;return
          <em>expression</em>
          ;&quot; I have to step out and hope that the
          caller stores the result in a variable or introduce an extra local
          myself.
        </p>
        <p>
          <em>I can't put breakpoints on expressions, just on lines</em>
          . If I
          want to break on #doIt in &quot;if(rarelyTrue) doIt();&quot; I have to reformat
          the code or introduce a conditional breakpoint.
        </p>
        <p>
          <em>I can't identify objects very well</em>
          . I catch myself writing down
          OIDs (x.y.z@1234) in order to spot them later in the session. It would
          be great if I could give an object a symbolic name which the debugger
          could show me later. JVMTI tags should be useful for that.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/04-01-2006_04-30-2006.html#49</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#debugger-experience"/>
    <a:updated>2006-04-22T10:56:38+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>The last(?) bastion has folded</a:title>
    <a:content type="xhtml">
      <div>
        <a name="The-last-bastion-has-folded" href="#The-last-bastion-has-folded"></a>
        <p>
          The latest build of Glassfish, the Sun Java Application Server, now
          ships
          <a href="http://blogs.sun.com/roller/page/theaquarium?entry=highlights_from_glassfish_build_b40">with
            security manager disabled
          </a>
          . SJAS always stood out because of this
          and may have been the #1 issue in getting apps to work.
        </p>
        <p>
          I must admit I've never paid much attention to making my code
          security manager enabled. The long list of permissions seemed
          impossible to maintain. It would have to be deployed differently
          with every container (there's no J2EE standard for listing the
          required permissions in the deployment descriptor). And honestly, as
          long as Sun doesn't come up with some reasonable, concise syntax for
          [privileged] blocks (PrivilegedActions are ugly) and a
          <a href="http://bitser.net/isolate-interest/JavaOne2003/goodfences1.html">suitable
            runtime environment
          </a>
          for running untrusted code I guess I won't.
          Setting up a new
          <a href="http://www.opensolaris.org/os/community/zones/">zone</a>
          seems easier.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/03-01-2006_03-31-2006.html#48</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#The-last-bastion-has-folded"/>
    <a:updated>2006-03-15T09:24:37+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>How to create uninitialized objects</a:title>
    <a:content type="xhtml">
      <div>
        <a name="How-to-create-uninitialized-objects" href="#How-to-create-uninitialized-objects"></a>
        <p>
          You never stop learning. A colleague asked me about some code that would
          get stuck in the finalizer. The objects in question were created like
          this:
        </p>
        <pre>new IWMRMUplinkCollection(invoke_method(null, 0x9, DISPATCH_PROPERTYGET).intVal());</pre>
        <p>
          Now it turns out that invoke_method actually throws an exception. So why
          do any IWRMUplinkCollection instances wind up in the finalizer in the
          first place? The JLS contains a surprise: &quot;At run time, evaluation of a
          class instance creation expression is as follows ... Space is allocated
          for the new class instance .. Next, the actual arguments to the
          constructor are evaluated, left-to-right ... Next, the selected
          constructor of the specified class type is invoked.&quot;
        </p>
        <p>
          So surprisingly the instance is allocated
          <em>before</em>
          the
          constructor args are evaluated. And it is put on the finalizer queue
          which turns out to be a VM bug:
          <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4034630">
            http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4034630
          </a>
          which recently celebrated its 8th anniversary. This bug is closed as
          duplicate of 5092933 which is not available for public access. Did
          someone come up with an exploit?
        </p>
        <p>
          For the ones that get tired from prose:
        </p>
        <pre>
          public class UnfinishedButFinalized {
          public static void main(String[] args) {
          while (true) {
          try {
          new Finalizable(new ArrayList(null));
          System.out.println(&quot;Should never succeed&quot;);
          System.exit(1);
          } catch (NullPointerException npe) {
          }
          }
          }

          static class Finalizable {
          List list = Collections.EMPTY_LIST;

          public Finalizable(List list) {
          this.list = list;
          }

          protected void finalize() throws Throwable {
          if (list == null) System.out.println(&quot;I should not be finalized&quot;);
          }
          }
          }
        </pre>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/03-01-2006_03-31-2006.html#46</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#How-to-create-uninitialized-objects"/>
    <a:updated>2006-03-02T23:40:01+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Practical SAX</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Practical-SAX" href="#Practical-SAX"></a>
        <p>
          As a CMS vendor we live on the edge between unstructured text and structured data. And somehow, don't we all
          build
          a little CMS once in a while? We deal with beans and business logic as well as rich and plain ole text and of
          course they interact. This is a writeup of some my experiences with and interpretations of SAX.
        </p>
        <h4>Choosing the representation</h4>
        <p>On the delivery side we deal with practically read-only data. We want to deliver XML content a) fast and b)
          concurrently, yet dynamically transformed per request. Requirement a) hints at an in-memory data structure
          like DOM.
          Now DOM trees tend to use quite some memory but most surprisingly, a DOM tree is not necessarily thread-safe,
          not even
          for reading. Try hitting hard on a Xerces document with several threads and you'll be surprised. XML itself is
          too
          slow if you want to transform it before delivery. So in order to stay lean and thread-safe, we chose a binary
          stream
          encoding similar to what has been done for Fast Infoset (though our format never leaves the JVM). A &quot;Markup&quot;
          as we
          call it, is a frozen representation of SAX events that can be concurrently written onto a chain of
          ContentHandlers.
          Sizewise, with some naive compression in place (like using indices for repeated namespace uris, for example),
          it turns
          out, a Markup takes up about as much space as the original XML.
        </p>
        <h4>SAX and Namespaces</h4>
        <p>SAX namespace support comes in two flavours. Depending on the configuration of a SAX parser's &quot;prefixes&quot;
          option, it
          will deliver xmlns* attributes for namespace declarations and optionally qnames with prefixes. We settled on
          the
          &quot;no-prefixes&quot; default as it carries the least ambiguity. It turns out this is a big weakness of
          dealing with
          SAX. Most
          APIs that deal with SAX do not specify which namespace flavour they would like their events in. They go with
          the default
          (no prefixes) but expect qnames after all (since all parsers deliver them anyway). The correct way would
          be to deal with the XMLReader interface which offers the aforementioned configuration option, like the TraX
          SaxSource
          interface. Yet, J2SE's transformer won't ask a SaxSource for prefixes and will barf if you don't hand them
          anyway (One of my Mustang contributions
          fixed that). The SAXResult API doesn't even give you the chance to define what mode it will be operated in.
          All in all, this is a weak
          point of SAX. They should have settled for exactly one representation.
        </p>
        <h4>Fragments</h4>
        <p>As we mix templated beans and rich text, we're mostly dealing with XML fragments as opposed to whole
          documents. SAX
          is not really well-defined in this area either. Common practice seems to be to send #startDocument and
          #endDocument
          anyway as it serves as init and stop event for serializers. Also, can your serializer deal with namespace
          declarations
          &quot;around&quot; the fragment? startPrefixMapping, startElement, endElement, startElement, endElement,
          endPrefixMapping?
        </p>
        <h4>Mixing SAX and character data</h4>
        <p>We want to interop with character-oriented output in both directions. We want to embed JSP-in-SAX-in-JSP. SAX
          in JSP
          is not too difficult, it's plain serialization, right? It's a little more complicated. Typically your JSP will
          declare
          the outer namespaces using plain text. Now when we serialize a fragment, we want to leverage this context, so
          our
          serializer must support *declaration* of namespaces (so it knows which prefixes to generate) without actually
          printing
          the xmlns attributes (already there). Nothing that the Apache or JDK serializer will do for us. Vice versa,
          while
          we're deep in a chain of filters piping SAX events around, we find that we want to embed another fragment that
          is
          rendered with a JSP. We don't want to parse the JSP's output into SAX; we want to simply embed it raw. SAX
          doesn't
          give us that feature, so we support an extended SAX protocol to transport chunks of &quot;raw&quot; character
          data. (The
          apache
          serializer actually supports something similar, through the #start/#endNonEscaping protocol.) So we have a
          really nice
          embedding option where the JSP writes onto a custom writer that actually sends chunks of non-escaped chars
          down the
          pipeline.
        </p>
        <h4>Transformations</h4>
        <p>Although state machines can be difficult to handle, a little framework code can help you out. I find that a
          filter-based transformation approach works fine for use-cases like link rewriting. You can even easily build
          filters
          that listen to the stream and start processing at a certain XPath and call you back with the fragment below.
          And it's magnitudes faster than XSL. Not to speak of the amount of temporary memory allocated.
        </p>
        <h4>Conclusion</h4>
        <p>SAX is the foster child of the XML APIs. It always ranks as &quot;also&quot;, &quot;low-level&quot;, &quot;if
          you need the speed&quot;. I
          was surprised about the number of ambiguities and bugs I ran into with seemingly straightforward tasks. Yet
          after some persistence,
          it's the ideal choice for us. It's fast, low-overhead and still gives us all the dynamics we need. I'm looking
          forward to some benchmarking on a T2000(?) coming to our house soon.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/02-01-2006_02-28-2006.html#43</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Practical-SAX"/>
    <a:updated>2006-02-23T01:12:34+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Is it so difficult?</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Is-it-so-difficult" href="#Is-it-so-difficult"></a>
        <p>
          <a href="http://www.bobcongdon.net/blog/2006/02/using-using.html">Again</a>
          and
          <a
            href="http://mail-archives.apache.org/mod_mbox/james-server-dev/200512.mbox/%3C1740316083.1135939503301.JavaMail.jira@ajax.apache.org%3E">
            again
          </a>
          ,
          if you're life is too simple, make it complicated. Write a hundred times:
        </p>
        <pre>
          R resource = acquireResource();
          try {
          use(resource);
          } finally {
          release(resource);
          }
        </pre>
        <p>
          Well at least it
          <a href="http://www.cincomsmalltalk.com/blog/blogView?showComments=true&amp;entry=3317283092">saved James
            Roberson's day
          </a>
          ...
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/02-01-2006_02-28-2006.html#42</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Is-it-so-difficult"/>
    <a:updated>2006-02-13T20:59:31+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Moot Challenge</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Moot-Challenge" href="#Moot-Challenge"></a>
        <p>
          Of course
          <a href="http://jroller.com/page/eu?entry=short_and_wrong_way_to">I
            should have been more specific
          </a>
          . Actually this code does exactly what
          I want: the class to define extends another class loaded by the &quot;parent&quot;
          class loader. The invoking code will only refer to it through its
          superclass. A new classloader seems much cleaner to me than injecting
          those bytes into the parent class loader itself, for example like
          java.lang.reflect.Proxy. It makes the generated class eligible for
          collection, too, if it's no longer being used. Or is there some catch
          I'm missing here? How expensive is a class loader anyway? Can the VM
          deal with hundreds or thousands of class loaders? Will the PermSpace
          blow up? Gotta try...
        </p>
        <p>
          A valid point raised by Eugene, though. Challenging the blogosphere
          (can't believe I just wrote this word) if you don't have comments is
          kind of questionable.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/02-01-2006_02-28-2006.html#41</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Moot-Challenge"/>
    <a:updated>2006-02-13T08:39:29+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>The shortest way to define a class ...</a:title>
    <a:content type="xhtml">
      <div>
        <a name="The-shortest-way-to-define-a-class-" href="#The-shortest-way-to-define-a-class-"></a>
        <pre>
          private static &lt;T&gt; Class&lt;T&gt; defineClass(ClassLoader parent, final String className, final byte[]
          bytes) {
          final Class[] result = new Class[1];
          new ClassLoader(parent) {
          {
          result[0] = defineClass(className, bytes, 0, bytes.length);
          }
          };
          return (Class&lt;T&gt;) result[0];
          }
        </pre>
        Can you do it shorter?

        <p>
          <em>
            <a href="http://www.jroller.com/page/tackline/">Tom Hawtin</a>
            can:
          </em>
        </p>
        <pre>
          private static &lt;T&gt; Class&lt;T&gt; defineClass(ClassLoader parent, final String className, final byte[]
          bytes) {
          return new ClassLoader(parent) {
          public Class defineClass() {
          return defineClass(className, bytes, 0, bytes.length);
          }
          }.defineClass();
          }
        </pre>

        I was surprised but yes, the type of an anonymous class construction expression is the full anonymous
        type, not just the supertype: http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.9.1:
        <em>The class being instantiated is the anonymous subclass. ... The type of the class instance creation
          expression
          is the class type being instantiated.
        </em>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/02-01-2006_02-28-2006.html#40</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#The-shortest-way-to-define-a-class-"/>
    <a:updated>2006-02-12T23:32:25+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Compiled EL: an adventure in bytecode engineering</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Compiled-EL-an-adventure-in-bytecode-engineering"
           href="#Compiled-EL-an-adventure-in-bytecode-engineering"></a>
        <p>We have a running gag at work. When a webapp is slow to start,
          we'll say &quot;ah it needs to compile the JSPs&quot;. Actually, nowadays, JSP compilation is
          pretty much useless. No one uses Java code in JSPs anymore. It is string literals,
          custom tags and expression language. Now the sad thing is, the EL is interpreted, too,
          so there's no need to compile JSPs anymore except for legacy compliance.
        </p>
        <p>Interpreted EL turns me off. Too much reflection during evaluation, BeanInfo caching, ... Tomcat's JSP
          implementation doesn't even remember the parsed expression trees with a page instance, so
          they parse every expression anew, mitigated by yet another cache. A nice synchronization bottleneck.
        </p>
        <p>So I've been intrigued by the idea of compiling EL to bytecode. Since I didn't want to wait for
          <a href="http://blogs.sun.com/roller/page/gbracha/20050928">Gilad
            to bring out #invokedynamic
          </a>
          (which is probably running in the lab already), I decided to
          go the strongly typed route. With generic type information, you actually have a fair chance to do proper
          typing
          for an expression without casting. Thus the compiler interface takes a type environment as follows:
        </p>
        <pre>
          public static CompiledExpression compile(
          String expressionString,
          Map&lt;String, ? extends Type&gt; env);

          public interface CompiledExpression {
          Type getResultType();
          Object evaluate(Map&lt;String, ?&gt; env) throws Exception;
          }
        </pre>
        <p>The expression string is parsed with the Commons EL parser. For bytecode generation, the compiler draws all
          its information from the runtime environment; no searching/parsing of class files takes place. The
          java.lang.reflect.Type
          hierarchy holds all the required information. Resolving all wildcards and type variables correctly proved a
          fun
          exercise; the operators and type coercion are a bitch. So back to the fun part; I built a simple interactive
          toplevel which
          looks like follows:
        </p>
        <pre>
          string: class java.lang.String = string
          map: interface java.util.Map[class java.lang.String, class java.lang.String] = {key=value}
          &gt; map.keySet.iterator.next
          Code:
          0: aload_1
          1: ldc #14; //String map
          3: invokeinterface #20, 2; //InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
          8: checkcast #16; //class java/util/Map
          11: invokeinterface #24, 1; //InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
          16: invokeinterface #30, 1; //InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
          21: invokeinterface #36, 1; //InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
          26: checkcast #38; //class java/lang/String
          29: areturn


          type: class java.lang.String
          value: &quot;key&quot;
          &gt; map[&quot;key&quot;].class.newInstance
          Code:
          0: aload_1
          1: ldc #14; //String map
          3: invokeinterface #20, 2; //InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
          8: checkcast #16; //class java/util/Map
          11: ldc #22; //String key
          13: invokeinterface #20, 2; //InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
          18: checkcast #24; //class java/lang/String
          21: invokevirtual #28; //Method java/lang/String.getClass:()Ljava/lang/Class;
          24: invokevirtual #34; //Method java/lang/Class.newInstance:()Ljava/lang/Object;
          27: areturn


          type: ? extends [class java.lang.Object]
          value: &quot;&quot;
        </pre>
        <p>As you can see, you can call methods; a nice add-on to EL is the ability to call methods with arguments. The
          compiler curries one argument a time; a curried call is typed as a Map:
        </p>
        <pre>
          &gt; map.put[&quot;key&quot;]
          ...
          type: interface java.util.Map[class java.lang.String, class java.lang.String]
          value: fun { {key=value}.put(&quot;key&quot;, $0) }
        </pre>
        <p>So Map.put is called with one argument, one remaining. This is represented by a special Map implementation
          that
          completes the call when #get is called. This part right now requires
          reflective method invocation at runtime. However, the Expression instance already contains the Method object
          to invoke and thus profits from java.lang.reflect's bytecode generation. I want to play with functional
          expressions,
          too, e.g. collection[map.get] should apply map.get to each collection element.
        </p>
        <p>If you're interested to toy around with it, let me know.</p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/02-01-2006_02-28-2006.html#39</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Compiled-EL-an-adventure-in-bytecode-engineering"/>
    <a:updated>2006-02-05T01:05:42+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Code snippet: calling javap programmatically</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Code-snippet-calling-javap-programmatically" href="#Code-snippet-calling-javap-programmatically"></a>
        <p>This just came in handy. I'm doing some bytecode generation, using the javap classes to
          disassemble the generated code on the go. You need tools.jar in your classpath:
        </p>
        <pre>
          private static Field JAVAP_C = null;

          static {
          try {
          JAVAP_C = JavapEnvironment.class.getDeclaredField(&quot;showDisassembled&quot;); // :-(
          JAVAP_C.setAccessible(true);
          } catch (NoSuchFieldException e) {
          }
          }

          public static void javap(byte[] classBytes, String methodName) {
          JavapEnvironment env = new JavapEnvironment();
          try {
          if (JAVAP_C != null) JAVAP_C.set(env, true);
          } catch (IllegalAccessException e) {
          throw new RuntimeException(e);
          }

          PrintWriter pw = new PrintWriter(System.out);
          JavapPrinter javapPrinter = new JavapPrinter(new ByteArrayInputStream(classBytes), pw, env);
          ClassData classData = new ClassData(new ByteArrayInputStream(classBytes));
          MethodData[] methods = classData.getMethods();
          for (int i = 0; i &lt; methods.length; i++) {
          MethodData method = methods[i];
          if (method.getName().equals(methodName))
          javapPrinter.printMethodAttributes(method);
          }
          pw.flush();
          }
        </pre>
        <p>Example output:</p>
        <pre>
          Code:
          0: iconst_3
          1: ineg
          2: invokestatic #18; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
          5: areturn
        </pre>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/02-01-2006_02-28-2006.html#38</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Code-snippet-calling-javap-programmatically"/>
    <a:updated>2006-02-05T00:15:57+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>the j.u.logging default configuration</a:title>
    <a:content type="xhtml">
      <div>
        <a name="the-julogging-default-configuration" href="#the-julogging-default-configuration"></a>
        I don't mind the j.u.logging API. Its default configuration sucks hard, however.
        How to enable FINE output programmatically?

        <pre>
          ExpressionCompiler.logger.setLevel(Level.FINE); // you would think
          Logger.getLogger(&quot;&quot;).getHandlers()[0].setLevel(Level.ALL); // #!@#!@$
        </pre>

        Why is that? $JRE_HOME/lib/logging.properties decides what goes to your console:

        <pre>
          # Limit the message that are printed on the console to INFO and above.
          java.util.logging.ConsoleHandler.level = INFO
        </pre>

        See
        <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4462908">
          http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4462908
        </a>
        .
        Looks like I finally arrived in 2001...
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/02-01-2006_02-28-2006.html#37</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#the-julogging-default-configuration"/>
    <a:updated>2006-02-03T10:13:48+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>My vote for Dolphin</a:title>
    <a:content type="xhtml">
      <div>
        <a name="My-vote-for-Dolphin" href="#My-vote-for-Dolphin"></a>
        <p>In case I haven't said this publicly enough yet: I consider
          <a href="http://www.dehora.net/journal/2004/07/the_problem_that_java_isolates_solve.html">Isolates</a>
          the most urgently needed innovation for Java. By far. I'm surprised this doesn't get more attention.
          I'll celebrate the day when we can start and tear down subsystems without worrying about thread
          and memory leaks. The day where I can clearly distinguish between a problem in my software or a
          customer customization. Until then, I have completely given up on webapp redeployment, for example.
        </p>
        <p>A quote from Bill's post: &quot;Isolates are slated for Java 1.6&quot;. Sun, please get this out of the
          door for Dolphin!
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/01-01-2006_01-31-2006.html#36</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#My-vote-for-Dolphin"/>
    <a:updated>2007-01-16T20:51:30.345+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Mustang's HTTP Server</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Mustangs-HTTP-Server" href="#Mustangs-HTTP-Server"></a>
        <p>
          <i>Update: Alan Bateman has kindly provided me with a
            <a
              href="http://download.java.net/jdk6/docs/guide/net/httpserver/spec/com/sun/net/httpserver/package-summary.html">
              link
            </a>
            to the HTTP server API documentation. This
            will soon be hooked up in the Mustang docs.
          </i>
        </p>
        <p>
          Several times, I've seen Mustang's inclusion of an HTTP server
          mentioned. A
          <a href="http://java.sun.com/developer/technicalArticles/J2SE/Desktop/Mustang_build39.html">technical
            article
          </a>
          points to bug
          <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6270015">6270015</a>
          ,
          which asks for support of a lightweight HTTP server API. This bug is
          marked &quot;closed, fixed&quot;. Yet, you won't find anything in the Mustang
          JavaDoc on it. What's the deal? Well, if we read carefully,
          <i>Mustang</i>
          will include an HTTP server API, not
          <i>JSE 6</i>
          . If we follow David
          Herrons
          <a href="http://weblogs.java.net/blog/robogeek/archive/2006/01/the_nonpublic_c.html">recommendation</a>
          ,
          we should therefore forget about this quickly.
        </p>
        <p>
          However, that API looks like it had some thinking put into it, is
          documented and itself distinguishes thoroughly between
          com.sun.* (sort-of presentable?) and sun.* (don't go there?) packages.
          Here's how you run a simple server:
        </p>
        <pre>
          HttpServer httpServer = HttpServer.create(new InetSocketAddress(8000), 5);
          httpServer.createContext(&quot;/&quot;, new HttpHandler() {
          public void handle(final HttpExchange exchange) throws IOException {
          Headers requestHeaders = exchange.getRequestHeaders();
          exchange.getResponseHeaders().set(&quot;Content-Type&quot;, &quot;text/plain;charset=utf-8&quot;);
          exchange.sendResponseHeaders(200, 0);
          OutputStream responseBody = exchange.getResponseBody();
          PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(responseBody, &quot;UTF-8&quot;));
          for (Map.Entry &lt;String, List&lt;String&gt;&gt; entry : requestHeaders.entrySet())
          printWriter.println(entry.getKey() + &quot;: &quot; + entry.getValue());

          printWriter.close();
          }
          });

          // the server will be single-threaded unless you uncomment this line
          // httpServer.setExecutor(Executors.newCachedThreadPool());
          httpServer.start();
        </pre>
        <p>
          Simple enough. If this thing survives further scrutiny it
          has the potential to put Jetty out of business for me for embedded HTTP
          endpoints. If it just weren't for the license...
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/01-01-2006_01-31-2006.html#33</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Mustangs-HTTP-Server"/>
    <a:updated>2006-01-22T23:01:22+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Mastering NIO</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Mastering-NIO" href="#Mastering-NIO"></a>
        <p>
          For the umpteenth time, I'm trying to move from an intellectual to a
          practical understanding of non-blocking network IO and I've come to
          something working this time. I know about
          <a href="http://directory.apache.org/subprojects/network/">MINA</a>
          ,
          I've read about
          <a href="http://jroller.com/page/pyrasun/20040426">emberIO</a>
          ,
          yet I want to learn it the hard way by building a framework myself that
          is simple, purely non-blocking and extensible. I'm not actually
          expecting to reach the fastest or most scalable solution, actually I'm
          more interested in the programming model. Non-blocking IO flips the
          roles: you no longer have an inputstream/outputstream pair that you can
          operate with in a single method call. Instead your code needs to become
          a state machine; input is pushed into it; output is pulled from it.
          That's why it's
          <a href="http://www.mortbay.com/MB/log/gregw/?permalink=servletsMustDieSlowly.html">so
            hard
          </a>
          to get the servlet api together with NIO.
        </p>
        <p>
          So what do I have?
        </p>
        <p>
          An IODispatcher represents a selector with an associated thread pool.
          You add channels and associated protocols to a dispatcher:
        </p>
        <pre>
          class IODispatcher {
          public &lt;C extends SelectableChannel&gt; void addChannel(C channel, Protocol&lt;? super C&gt; protocol)
          }
        </pre>
        Each registered channel runs a protocol, an implementation of the
        following interface:

        <pre>
          public interface Protocol&lt;C&gt; {
          void setConnection(ChannelConnection&lt;? extends C&gt; connection);
          int interest();
          void run() throws IOException;
          void destroy();
          }
        </pre>
        <p>
          The IODispatcher selects on the channel with the protocol's current
          interest. When selected it will run the protocol in the thread pool.
          While running, the channel's interest is set to 0 and the IODispatcher
          ensures that this protocol instance will not run again concurrently.
          When #run finishes, the protocol will be entered for selection again
          with a possibly new interest set. If the protocol closes its channel or
          throws an IOException, the IODispatcher will remove the protocol and
          invoke its #destroy method.
        </p>
        <p>
          A Protocol is a state machine. In order to make writing protocols
          easier, there's a MultiStageProtocol with individual stages that can
          indicate successor stages after running. These are the building blocks I
          hope to build abstractions on; so far I have acceptor, connector and
          writer stages. Input and conversions are typical next candidates. For
          reference, the connector stage looks as follows:
        </p>
        <pre>
          public class Connector&lt;C extends SocketChannel&gt; implements ProtocolStage&lt;C&gt; {
          private ProtocolStage&lt;C&gt; next;

          public Connector(ProtocolStage&lt;C&gt; next) {
          this.next = next;
          }

          public int interest() {
          return SelectionKey.OP_CONNECT;
          }

          public ProtocolStage&lt;C&gt; run(ChannelConnection&lt;? extends C&gt; connection) throws IOException {
          return connection.getChannel().finishConnect() ? next : this;
          }

          public void destroy(ChannelConnection&lt;? extends C&gt; connection) {
          }
          }
        </pre>
        <p>
          The code is running very nicely now; I stumbled over two NIO bugs
          (4729342,5076772) that I'm preparing fixes for. In the longer run, I'd
          like to build a renderer for my Axt template engine that implements a
          pull model and run it on this NIO framework.
        </p>
        <p>
          That was the morning news, time for a shower now.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/01-01-2006_01-31-2006.html#32</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Mastering-NIO"/>
    <a:updated>2006-10-13T08:33:19+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>SPRONG: a strongly typed spring bean container</a:title>
    <a:content type="xhtml">
      <div>
        <a name="SPRONG-a-strongly-typed-spring-bean-container"
           href="#SPRONG-a-strongly-typed-spring-bean-container"></a>
        <p>
          Spring is all over the place. For a reason: spring is well-engineered,
          well-supported and does a lot of things just right.
        </p>
        <p>
          Everyone would agree if it wasn't for the XML bean definitions. These
          files define the application structure by defining instances of bean
          classes and wiring them to each other. So what's wrong with these files?
          First of all they break too easily. You rename a property, you forget to
          add a setter, you forget the default constructor. Tools are getting
          better but they're just not there yet. And sometimes they just cannot
          know. Second, there is no well-defined extension mechanism. As an ISV,
          we're shipping software with a bunch of .xml descriptors and it is very
          difficult to distinguish parts that we want the customer to customize
          and which we don't. What's the strategy?
        </p>
        <p>
          Spring does not depend on the XML in any way. You can just as well
          instantiate all the beans in Java code. So what is it that makes me
          write XML anyway? I see a number of properties:
        </p>
        <ul>
          <li>
            You don't need to compile them and you can easily tweak them after
            deployment. That's a moot point, I think. Au contraire, I'm writing
            this because I _want_ to compile them.
          </li>
          <li>
            Auto-wiring: basically, you don't need to define all properties
            yourself, Spring will find right candidates by name or type. I could
            use it all the time but I'm wary about this and avoid it.
          </li>
          <li>
            Automatic singleton-ness. Unless told otherwise, the spring bean
            factory will instantiate a bean definition only once.
            <br/>
          </li>
          <li>
            Lifecycle and postprocessing. Spring invokes init/destroy methods and
            fulfills a number of common dependencies through *Aware interfaces
            (ServletContextAware, ResourceLoaderAware, ...).
          </li>
          <li>
            Automatically right order of initialization. If bean A depends on bean
            B, B must be initialized first.
          </li>
        </ul>
        <p>
          The last three are important to me. So what I want is a strongly typed,
          Java mechanism for bean definitions that still supports those &quot;container
          properties&quot;.
        </p>
        <p>
          My solution looks as follows:
        </p>
        <ul>
          <li>
            Instead of an XML file, you write a Java class, representing the
            container.
          </li>
          <li>
            For every bean definition you write a property getter method. In order
            to make it a &quot;bean definition&quot; method, you apply a @Bean annotation.
          </li>
          <li>
            A container api lets you create instances of that class that honor the
            container properties. How does it do that? It uses CGLib to generate a
            subclass of the original class and adds fields for the singletons,
            initialization flags and lifecycle/postprocessing code.
          </li>
        </ul>
        <p>
          A glimpse:
        </p>
        <pre>
          class App {
          String driverUrl;

          @Configuration(key = &quot;db.driverUrl&quot;)
          public void setDriverUrl(String url) {
          this.driverUrl = url;
          }

          @Bean
          protected DataSource getDataSource() {
          return new DriverManagerDataSource(driverUrl);
          }

          @Bean
          public ServiceA getServiceA() {
          return new ServiceA(getDataSource());
          }

          @Bean
          public ServiceB getServiceB() {
          return new ServiceB(getDataSource());
          }
          }
          ...
          ContainerBeanFactory&lt;App&gt; f = ContainerBeanFactory.newFactory(App.class);
          App app = f.create(properties); // actually a subclass of App
          assert app.getServiceA() == app.getServiceA();
          assert app.getServiceA().getDataSource() == app.getServiceB().getDataSource();
        </pre>
        <p>
          Before I go, you can see three great things already: configuration
          properties can be imported (a la ${xxx} in Spring XML), #getDataSource
          constitutes a container-private bean and App itself is a strongly typed
          interface of the set of beans exported. I'll use that to actually define
          the interface the Spring MVC Dispatcher Servlet has with a Spring MVC
          webapp. So expect more later.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/12-01-2005_12-31-2005.html#31</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#SPRONG-a-strongly-typed-spring-bean-container"/>
    <a:updated>2005-12-29T10:27:22+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>10-Fix Delivered</a:title>
    <a:content type="xhtml">
      <div>
        <a name="10Fix-Delivered" href="#10Fix-Delivered"></a>
        <p>
          So,
          <a href="https://mustang.dev.java.net/files/documents/2817/25363/mustang-b63.html">Mustang
            b63
          </a>
          ships with my Java reimplementation of File#deleteOnExit. Apps
          using a lot of these will now experience a proper out of heap error.
          Nothing exciting, still I'm glad it made it.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/12-01-2005_12-31-2005.html#30</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#10Fix-Delivered"/>
    <a:updated>2005-12-09T23:19:15+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>OutOfMemoryError</a:title>
    <a:content type="xhtml">
      <div>
        <a name="OutOfMemoryError" href="#OutOfMemoryError"></a>
        <p>
          I'm more and more convinced that OutOfMemoryErrors are useless. They
          don't have a clear cause and as such the recipient of the error has no
          way to correct them. Especially in multithreaded applications a random
          thread gets hit and will cease to work. As I commented on
          <a href="http://blogs.sun.com/roller/page/alanb/20051128">Alan's
            Posting
          </a>
          I've had several occasions where a Tomcat servlet engine
          would go mute because the acceptor thread got hit by OOM.
        </p>
        <p>
          Second, memory allocation is such a fundamental prerequisite on the Java
          platform that handling such an error in Java is likely to not work
          anyway. My catch/finally/ShutdownHook runs in a very ill-defined
          environment. The same way a VM-, Internal- or whatever error is not
          useful up there. It's like 'No keyboard present. Hit F1 to continue.'
        </p>
        <p>
          I think a VM that runs into OOM should just panic and terminate. ASAP.
        </p>
        <p>
          That being said, the fact that I have to tell my JVM in advance how much
          memory I'm going to need feels so MacOS 8 to me.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/12-01-2005_12-31-2005.html#29</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#OutOfMemoryError"/>
    <a:updated>2005-12-04T19:37:44+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Mustang Contributions</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Mustang-Contributions" href="#Mustang-Contributions"></a>
        I've made two contributions to Mustang. A small fix for
        <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6305029">a TrAX bug</a>
        and a &quot;jumbo&quot; patch to replace the native implementation of File#deleteOnExit. The second issue once
        cost me a
        lot of time to track down - I didn't want anyone else to fall into that trap again. It actually tackles a number
        of bug reports. The first one is &quot;fix in progress&quot; now and the second one is coming along well, too.
        You can
        track your submissions
        <a href="http://download.java.net/jdk/JDK-Contribution.html">here</a>
        . I really like the idea, however I wonder how cost-efficient that process is. It takes a lot of work to review
        and integrate patches if you want to maintain a certain level of quality and I get the impression that some Sun
        engineers are very careful people.
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/10-01-2005_10-31-2005.html#28</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Mustang-Contributions"/>
    <a:updated>2005-10-29T19:45:41+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Multi-Core CPUs and the concurrency hype</a:title>
    <a:content type="xhtml">
      <div>
        <a name="MultiCore-CPUs-and-the-concurrency-hype" href="#MultiCore-CPUs-and-the-concurrency-hype"></a>
        Lately, there's been a lot of buzz about how multi-core CPU's will
        change the face of the software world. Programmers would be facing a new challenge: to write concurrent
        software, otherwise the software won't perform. I'm surprised about the level of attention. I think this is
        rather old news. Multiprocessors have been around for a long time; we've been paying attention to actually using
        the available CPUs for a long time. And our customers are doing the same - they complain if we don't.
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/10-01-2005_10-31-2005.html#27</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#MultiCore-CPUs-and-the-concurrency-hype"/>
    <a:updated>2005-10-29T19:20:32+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>MSNBot hallo ?</a:title>
    <a:content type="xhtml">
      <div>
        <a name="MSNBot-hallo-" href="#MSNBot-hallo-"></a>
        Is that what I'm paying my bandwidth for? Get a grip folks!

        <pre>
          65.54.188.103 - - [18/Aug/2005:09:40:39 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:09:47:50 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:09:53:02 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:09:58:14 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:10:02:06 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:10:07:02 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:10:12:01 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:10:18:22 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:10:28:06 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:10:33:48 +0200] &quot;GET /robots.txt HTTP/1.0&quot; 404 204 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:10:37:45 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:10:45:19 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:10:53:56 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:10:59:44 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
          65.54.188.103 - - [18/Aug/2005:11:08:41 +0200] &quot;GET /blog/rss.xml HTTP/1.0&quot; 200 20823 &quot;-&quot;
          &quot;msnbot/1.0 (+http://search.msn.com/msnbot.htm)&quot;
        </pre>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/08-01-2005_08-31-2005.html#26</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#MSNBot-hallo-"/>
    <a:updated>2005-08-25T23:51:42+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>ariadna: heap dump without ctrl-break</a:title>
    <a:content type="xhtml">
      <div>
        <a name="ariadna-heap-dump-without-ctrlbreak" href="#ariadna-heap-dump-without-ctrlbreak"></a>
        I just uploaded a new version of
        <a href="http://www.mernst.org/ariadna/">ariadna</a>
        that allows for generating a heap dump from within the application, not just CTRL-break/SIGQUIT. It's still
        written to fixed files - no added luxury here :-)

        It's simpler than I thought: an agent dll is automatically searched for JNI entry points, so I didn't have to
        deal with RegisterNatives().
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/08-01-2005_08-31-2005.html#25</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#ariadna-heap-dump-without-ctrlbreak"/>
    <a:updated>2005-08-25T09:27:27+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>CLR versions</a:title>
    <a:content type="xhtml">
      <div>
        <a name="CLR-versions" href="#CLR-versions"></a>
        <p>I just downloaded Avalon &amp; Indigo RC. Avalon would not install - I figure it's because of the Avalon CTP
          that's still lying around. Trying to UNINSTALL Avalon CTP, I get the following neat error message:
        </p>
        <p>
          <img alt="" src="http://www.mernst.org/blog/media/avalon.GIF"/>
        </p>
        <p>I guess I haven't figured out Microsoft's versioning story yet. I have a more recent 2.0 beta 2. Why can't it
          just use that one? What do I do? I will _NOT_ deinstall beta 2, install 204xxx in order to deinstall Avalon
          CTP. .NET's beta track feels much more painful than Java to me. C# Express and SQL Server Express had
          incompatible CLR requirements as well. I understand that, but why can't I simply install both?
        </p>
        <p>I would appreciate some tips on this.</p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/05-01-2005_05-31-2005.html#20</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#CLR-versions"/>
    <a:updated>2005-05-24T08:20:54+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Class.newInstance and Pawlovian dogs</a:title>
    <a:content type="xhtml">
      <div>
        <a name="ClassnewInstance-and-Pawlovian-dogs" href="#ClassnewInstance-and-Pawlovian-dogs"></a>
        <p>I'm a Pawlovian dog. My bell is Class#newInstance. Whenever I see a framework that allows you to configure
          extensions via classname and does Class.forName().newInstance(), I think &quot;you should integrate that with
          spring&quot;.
        </p>
        <p>Here's how I did it for ULC. ULC is Canoo's &quot;Universal Lightweight Client&quot; - a ui framework that
          runs a swing
          ui engine on the client but all the ui and application logic on the server. ULC comes as a servlet accepts the
          application class as an init-parameter. For every new UI session, it will instantiate it and call start() -
          then you're left alone. Now you can go and find friends - typically via ServletContext. Since I prefer
          dependency injection over service locators I want Spring to instantiate my application class WITH
          dependencies.
        </p>
        <p>Unsurprisingly, it's very easy. I wrapped the ULC servlet in a controller which gives it a bootstrap
          application class name. This bootstrap application grabs the current application context and the application
          bean name from the request, instantiates the application bean (MUST be prototype bean definition), and
          delegate all ULC lifecycle calls to it. Alternatively, my code can instantiate a whole child context per UI
          session if you have more beans you want to set up per session. For example:
        </p>
        <pre>
          &lt;!DOCTYPE beans PUBLIC &quot;-//SPRING//DTD BEAN//EN&quot; &quot;http://www.springframework.org/dtd/spring-beans.dtd&quot;&gt;
          &lt;beans&gt;
          &lt;bean id=&quot;listModel&quot; class=&quot;com.ulcjava.base.application.DefaultListModel&quot;/&gt;

          &lt;bean id=&quot;eventDispatcher&quot; class=&quot;org.mernst.ulcjava.EventDispatcher&quot;&gt;
          &lt;property name=&quot;eventQueue&quot; ref=&quot;eventQueue&quot;/&gt;
          &lt;property name=&quot;delay&quot; value=&quot;5000&quot;/&gt;
          &lt;property name=&quot;handlers&quot;&gt;
          &lt;map&gt;
          &lt;entry key=&quot;org.mernst.ulcjava.ListUpdateEvent&quot;&gt;
          &lt;bean class=&quot;org.mernst.ulcjava.ListUpdateHandler&quot;&gt;
          &lt;property name=&quot;model&quot; ref=&quot;listModel&quot;/&gt;
          &lt;/bean&gt;
          &lt;/entry&gt;
          &lt;/map&gt;
          &lt;/property&gt;
          &lt;/bean&gt;

          &lt;bean class=&quot;org.mernst.ulcjava.Viewer&quot;&gt;
          &lt;property name=&quot;listModel&quot; ref=&quot;listModel&quot;/&gt;
          &lt;/bean&gt;
          &lt;/beans&gt;
        </pre>
        <p>Net result: ULC applications can be easily set-up in Spring - no more service lookup necessary. The code
          should appear soon on
          <a href="http://ulc-community.canoo.com/">http://ulc-community.canoo.com/</a>
          .
        </p>
        <p>Spring starts to be the all-integrating technology - lately we built an integration to host the WASP
          container and export Spring-managed web service implementations.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/05-01-2005_05-31-2005.html#19</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#ClassnewInstance-and-Pawlovian-dogs"/>
    <a:updated>2005-05-13T12:24:04+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Specs and Implementations</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Specs-and-Implementations" href="#Specs-and-Implementations"></a>
        <p>Something's wrong with software specifications. Almost every JSR defines an API in form of Java interfaces.
          Can I download these interfaces in a jar file? No, the API typically comes in form of JavaDoc that every
          implementation has to reverse-engineer into Java code and a &quot;reference implementation&quot; that contains
          _a_
          version of the interfaces. As it stands, there are no official servlet-api jars to write software against.
          There's the Tomcat servlet apis and there's a lot of others. Have you found yourself with two, say, jmx.jar in
          your app? Nominally the same version, yet different size? Can I drop one, you ask yourself? Will something
          break?
        </p>
        <p>Even worse are specifications that spell out algorithms over pages in pseudo-formal notation. Bullet points
          instead of loops. Ambiguous, natural language, open for interpretation. Have a look at the JSF
          specification:
        </p>
        <blockquote>
          <i>Examine the FacesContext instance for the current request. If it already contains a
            UIViewRoot:
          </i>
          <ul>
            <li>
              <i>Set the locale on this UIViewRoot to the value returned by the
                getRequestLocale() method on the ExternalContext for this request.
              </i>
            </li>
            <li>
              <i>For each component in the component tree, determine if a ValueExpression for
                binding is present. If so, call the setValue() method on this
                ValueExpression, passing the component instance on which it was found.
              </i>
            </li>
            <li>
              <i>Take no further action during this phase, and return.</i>
            </li>
          </ul>
        </blockquote>
        <p>This goes on for pages. The whole request cycle spelt out in Jenglish. What the heck? Why don't they invest
          all the time they've debated about the words in a better base implementation with useful extension points?
          Instead a verification kit is produced to ensure a vendor did a correct job translating the english back into
          code. When I look at many bugs I encounter in standards implementations I question the quality of these
          TCKs.
        </p>
        <p>Well, enough now, I actually wanted to read the JSF spec ...</p>

      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/05-01-2005_05-31-2005.html#17</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Specs-and-Implementations"/>
    <a:updated>2005-05-08T10:37:51+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>JSP: reusable chunks of markup</a:title>
    <a:content type="xhtml">
      <div>
        <a name="JSP-reusable-chunks-of-markup" href="#JSP-reusable-chunks-of-markup"></a>
        <p>[This is a reply to
          <a href="http://www.theserverside.com/news/thread.tss?thread_id=33326#166473">
            http://www.theserverside.com/news/thread.tss?thread_id=33326#166473
          </a>
          ; theserverside forums wouldn't let me post this: &quot;invalid html&quot; although there is none]
        </p>
        <p>JSP lacks in so many ways.
        </p>


        * reusable markup: tag files should have an invocation api from Java. I once hacked Jasper to allow that. You
        could get a SimpleTag instance for a path and invoke it. Spec people weren't interested. Promised me something
        else exciting - I'm still waiting.
        <br/>
        * The grand unified EL still cannot call methods. ${content.isVisibleTo(user)} ?
        <br/>
        * JSPs can't be called from somewhere else than the web app. Template staging in a CMS? No way.
        <br/>
        * JSPs need compilation. Precompile, ja ja.
        <br/>
        * Look ma, no escaping. Oh you're doing markup? Please use a taglib. Otherwise welcome scripting attacks.
        <br/>
        <p>I've had it. That's why I'd like to advertise a lightweight, fast, embeddable, XML-centric template engine
          I've built:
          <a href="https://axt.dev.java.net">https://axt.dev.java.net</a>
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/04-01-2005_04-30-2005.html#14</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#JSP-reusable-chunks-of-markup"/>
    <a:updated>2005-04-16T10:43:56+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>BBCB</a:title>
    <a:content type="xhtml">
      <div>
        <a name="BBCB" href="#BBCB"></a>
        I'm in!

        <blockquote>I thought coming to the CLR team I'd be more popular among my peers, more respected by my native
          Australians, and maybe even win the &quot;Australian of the year&quot; award for my contributions to society
          and my
          display of willingness to put up with this country… Unfortunately, my dreams have not been realized.
          Instead, whenever I proudly proclaim to my peers that I, Joel Pobar, am a member of the Common Language
          Runtime team, the immediate response is “Can you tell Chris Brumme to add new stuff to his blog? I've been
          waiting a year now!.

          I've reevaluated my goals and ambitions. I've decided to cave in to the wants and needs of our customers
          who prefer architectural quality meat, instead of sour Australian PM potatoes. I'm campaigning to Bring Back
          Chris Brumme's Blog!
        </blockquote>

        From Joel Pobar, via
        <a href="http://blogs.msdn.com/brada/archive/2005/04/07/406090.aspx">BradA</a>
        .
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/04-01-2005_04-30-2005.html#11</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#BBCB"/>
    <a:updated>2005-04-08T08:55:34+02:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Axt Design Choices</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Axt-Design-Choices" href="#Axt-Design-Choices"></a>
        <p>So what was I thinking? There's few things the world needs less than a new template engine. Here's my feature
          list that made me roll my own anyway:
        </p>
        <ul>
          <li>A template ist editable in an xml editor. Don't give me the &lt;a href='&lt;c:url value=&quot;...&quot;/&gt;'&gt;
            mess. A template is at least be well-formed xml. This rules out #velocity.hashmichtot#, too.
          </li>
          <li>A template is previewable. A design with template annotations applied stills look exactly the same in a
            browser. This means you can keep your &quot;blindtext&quot; (placeholder text) around.
          </li>
          <li>A template is fed with a binding of names to (java) objects accessed through an easy yet powerful
            expression language (OGNL).
          </li>
          <li>A template garantuees well-formed xml output. It does so by generating output to a SAX ContentHandler, not
            a Writer.
          </li>
          <li>A template is extendable with plugins that can manipulate their body content. Just as a JSP 2.0 SimpleTag
            can evaluate its body on a custom Writer and apply filtering, ... an axt template can evaluate its body to a
            custom ContentHandler and perform any manipulation it likes.
          </li>
          <li>Axt is easily embeddable. There are no dependencies on the filesystem, a compiler, a servlet engine. The
            only
            requirements are DOM, SAX, OGNL.
          </li>
          <li>Of course, it must be fast. Templates and OGNL expressions are pre-parsed and thread-safe. The OGNL
            interpreter is also thread-safe and caches its introspection results. I've been able to churn out 1300
            (small) pages per second (about 5MB/s) from an 8 processor Sun using Axt to render pages in Tomcat 5. And it
            scales wonderfully to many clients.
          </li>
          <li>It's simple. 28 files, 1200 LOC. Apache Jasper is 30 times that big. Small things rule.</li>
        </ul>

        Interested? Go try it, the project has been approved meanwhile. The documentation is poor, so you want to dig
        into the source. Drop me a mail and I'll get you started if you have problems.
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/03-01-2005_03-31-2005.html#10</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Axt-Design-Choices"/>
    <a:updated>2005-03-03T22:57:54+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Templating for XML</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Templating-for-XML" href="#Templating-for-XML"></a>
        How do you create XML programmatically? I've been fed up with the
        templating options known to me for a number of reasons:
        <ul>
          <li>JSP: JSP does not directly target XML. You have to use custom tags to do escaping. The spec regards markup
            as the exceptional case: (paraphrased) &quot;in the unlikely event you want to do xml, ... use something
            like
            c:out&quot;. There also is no JSP implementation that neither uses a web container, the filesystem nor
            compilation, although the JSP 2.0 API and EL would allow for such scriptless, interpreted templates.
          </li>
          <li>Velocity: much easier to embed, but still targeted at producing characters, not infoset.</li>
          <li>XSLT: garantuees well-formed output. However, takes XML as input where I'm looking for something that
            accepts a map of Java beans. Xalan Java extensions make some things possible but it's not a natural
            integration.
          </li>
        </ul>
        <p>There may be other options, but I bet they're either plaintext or XML transformations. I'm looking for XML
          production out of beans. So I decided to roll my own, &quot;axt&quot;, &quot;attributes-only xml templates&quot;.
          The project at
          <a href="https://axt.dev.java.net/">https://axt.dev.java.net</a>
          has its approval pending. A copy from the description:
        </p>
        <p>
          <cite>&quot;A template processor for producing XML. It takes XML templates as input, garantuees well-formed
            output
            unlike JSP or Velocity, is designed to process beans as a data model unlike XSLT. axt uses the OGNL
            expression language for expressions. axt exclusively uses namespaced attributes as template annotations and
            no elements, like Zope's tal.&quot;
          </cite>
        </p>
        <p>I have to go now but I'll write more about it later.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/02-01-2005_02-28-2005.html#9</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Templating-for-XML"/>
    <a:updated>2005-02-28T09:54:10+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Spring prototype definitions as a factory</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Spring-prototype-definitions-as-a-factory" href="#Spring-prototype-definitions-as-a-factory"></a>
        <p>Mike
          <a href="http://www.pyrasun.com/mike/mt/archives/2004/11/07/12.58.49/index.html">wrote</a>
          about using spring to create job processors dynamically from job types. We use a similar pattern in our
          content management system. Documents in our CMS have types and different attributes based on type. Document
          types are grouped in a hierarchy. It's obvious to map document types to a Java class hierarchy - and it's
          obvious that an application programmer wants to extend these classes.
        </p>
        <p>We want to provide the developer with a factory interface that you can hand an arbitrary document and you'll
          receive an instance of the corresponding java class. Easy enough, we thought, we'll have a map from document
          types to class objects, call #newInstance and #setDocument. However, it's not that easy. The application
          developer will want to access different application services from within such a bean - we either need to
          provide a service locator or the services need to be injected into the beans. I disliked the service locator
          idea and since we're using spring to wire our framework objects it was only natural to let the developer tap
          into that functionality as well. So instead of having our own map, we simply ask spring's bean factory for an
          implementation (which must not be a singleton, of course), based on a naming convention:
        </p>
        <pre>
          &lt;bean id=&quot;doctypeA&quot; class=&quot;ABean&quot; singleton=&quot;false&quot;/&gt; &lt;!-- no services
          --&gt;
          &lt;bean id=&quot;doctypeB&quot; class=&quot;BBean&quot; singleton=&quot;false&quot;&gt; &lt;!-- inject
          service --&gt;
          &lt;property name=&quot;service&quot;&gt;...&lt;/property&gt;
          &lt;/bean&gt;
        </pre>
        <p>This way, our factory is basically just a thin wrapper around a spring bean factory:</p>
        <pre>
          Object getObject(Document document) {
          result = beanFactory.getBean(document.type.name); // create bean
          result.document = document;
          return result;
          }
        </pre>
        <p>Although the principle is so simple, I still find the effect of DI stunning. This factory pattern actually
          reminds me of the technique of currying: in a way, what the factory holds for &quot;docTypeB&quot; is a
          parameterless
          function that is the result of pre-binding the &quot;service&quot; parameter.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/11-01-2004_11-30-2004.html#6</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Spring-prototype-definitions-as-a-factory"/>
    <a:updated>2004-11-15T20:03:47+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>ariadna: memory leaks be gone</a:title>
    <a:content type="xhtml">
      <div>
        <a name="ariadna-memory-leaks-be-gone" href="#ariadna-memory-leaks-be-gone"></a>
        <p>I've posted
          <a href="http://www.mernst.org/ariadna/">ariadna</a>
          , a tool for dumping a JVM's heap and analyzing it for unwanted reference chains.
        </p>
        <p>The tool, respectively its predecessor
          <a href="http://www.virtualmachine.de">heapprofile</a>
          , grew out of my frustration about commercial profilers. You have a piece of software that you know leaks
          memory. Go ahead and find a tool that helps you. All I found was all-encompassing profiler packages &gt;50MB
          that
          run very slowly. And they try to visualize ten thousands of objects as boxes in a graph on a small canvas.
          Ridiculous. Also they record where objects are created. Pretty unnecessary, my IDE can tell me that. All I
          want is a tool that shows me: &quot;there's 200 JSomethings&quot; where there shouldn't and &quot;this
          JSomething is around
          because ...&quot;.
          <a href="http://hat.dev.java.net">HAT</a>
          is such a tool and it's been around forever. We used it to debug our editor back with JDK 1.2. Only it took a
          lot of memory and the agent required in the VM would slow things down, too. Reproducing in slo-mo.
        </p>
        <p>Anyway, ariadna is my attempt at attacking this. I guess tools have become better by now but feeling up the
          VM from your agent is fun anyway. What it does? At first, I load all classes, tag them and remember their
          name. Then I iterate over the heap, again tagging each object with a unique id (I wonder how much memory that
          costs in the VM; have to browse the 1.5 SRL code). Finally I iterate over all references, dumping referrer and
          referee tag to a file. For each object, I also dump its class tag. An analyzer server maps the file into
          memory, sorts it by referee's tag. Now the incoming references of each object can be found in O(log(n)) which
          feels lightning fast on small heaps. It's so fast that the shortest reference chain from the root set is
          displayed with every object you navigate to. I'll should have tried larger heaps before going public ...
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/11-01-2004_11-30-2004.html#2</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#ariadna-memory-leaks-be-gone"/>
    <a:updated>2004-11-11T00:03:13+01:00</a:updated>
  </a:entry>
  <a:entry>
    <a:title>Enter</a:title>
    <a:content type="xhtml">
      <div>
        <a name="Enter" href="#Enter"></a>
        <p>This is my third attempt at writing my very first blog entry. I decided it would be on the blog software I
          chose. My web space doesn't provide any CGI/PHP/Perl and I actually don't want to administer it anyway.
        </p>
        <p>
          <a href="http://thingamablog.sourceforge.net/" target="_blank">Thingamablog</a>
          is completely standalone, written in Java and will publish my entries as static files along with an RSS 2.0
          feed via FTP. Nice. A rich client UI makes it all the better. Kudos so far. I've expected much worse of a Java
          UI because I've only seen worse.
        </p>
        <p>In the future, I hope to let you know about me and what I'm doing. And if nobody reads this it can be my
          journal.
        </p>
      </div>
    </a:content>
    <a:id>http://www.mernst.org/blog/archives/11-01-2004_11-30-2004.html#0</a:id>
    <a:link href="http://www.mernst.org/blog/rss.xml#Enter"/>
    <a:updated>2004-11-10T23:37:12+01:00</a:updated>
  </a:entry>
  <script type="text/javascript"><![CDATA[
    showCommentForm=function() {
      w=window.open("comment.html", "comment", "width=500, height=750, resizable=yes, scrollbars=yes");
      w.entryname=this.parentNode.parentNode.previousSibling.previousSibling.childNodes[0].nodeValue;
      w.focus();
    };

    ATOM='http://www.w3.org/2005/Atom'; XHTML='http://www.w3.org/1999/xhtml';
    entries = document.documentElement.getElementsByTagNameNS(ATOM, 'entry');
    for(i=1; i<entries.length; i++) {
      entry = entries.item(i);
      title = entry.getElementsByTagNameNS(ATOM, 'title').item(0).childNodes.item(0).nodeValue;
      div = entry.getElementsByTagNameNS(ATOM, 'content').item(0).getElementsByTagNameNS(XHTML, 'div').item(0);
      s = document.createElementNS(XHTML, 'span');
      t = document.createTextNode('\u25B6 Add Comment (Moderated)');
      s.appendChild(t);
      s.onclick=showCommentForm;
      div.appendChild(s);
    }
  ]]></script>
  <script type="text/javascript" src="http://www.google-analytics.com/ga.js"/>
  <script type="text/javascript">
    document.domain="www.mernst.org";
    document.cookie="";
    <!--_uacct = "UA-2198728-1";-->
    <!--_udn="mernst.org";-->
    var pageTracker = _gat._getTracker("UA-2198728-1");
    pageTracker._initData();
    pageTracker._trackPageview();
    <!--urchinTracker();-->
  </script>
</a:feed>
