jsr341-experts@el-spec.java.net

[jsr341-experts] Operations on collections

From: Kin-man Chung <kinman.chung_at_oracle.com>
Date: Mon, 17 Oct 2011 11:08:17 -0700

Dear experts,

I've decided to raise the priority for collection operation support
(construction, selection and projection etc) and seriously consider
including it in the EL 3.0 spec.

I've been helping the performance and monitoring team to use EL in their
work. Current EL is ideal for displaying information like "the heap
size for jvm 1 of instance 3", but cannot provide answers to queries
such as "the number of instances whose average cpu usage is greater than
50%". I realized that for EL to be useful, some kind of collection
operation support is needed. Other EL engines (OGNL, Spring, MVEL, and
jBoss) has some limited support, so it would be a great omission if we
don't include it in EL 3.0.

The difficult part is to decide on the syntax. I don't like the
syntaxes use in the other EL engines: not only are they all different,
they are all very cryptic and not easily extensible. I am thinking of
using a syntax like that in SQL query. It is very readable and
extensible, and maps well into our ELResolver, since all the operations
can be built-in methods in the collections (list, map, or array) that
can be implemented in the collection ELResolver's. So to compute "the
average cpu usage" we can write

     cpu.usage.avg()

Here "cpu.usage" is a array (or list) of sampled cpu usage , and avg is
a builtin method in the collection.

To compute the number of instance whose average cpu usage is greater
than 50%, we can write

     instances.select("$.cpu.usage.avg() > 50").size()

where "$" is the collection item instance in the iteration, and select
is again a builtin method, which returns a new collection with entries
that satisfy the given condition. Note that the condition is specified
as a String, not another EL expression, since we don't have in our EL
the ability to pass a code fragment (i.e. a ValueExpression without
evaluation) to a method. Consider this a poor man's closure or lambda
expression, if you like.

What do you think? I know this is a big feature addition, but I think
is important, especially to the stand-alone EL. I'll work on the
details and come up with a proposal soon. Thanks.

Kin-man