<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Jacob Hookom&apos;s Blog</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/" />
<modified>2008-02-13T18:06:09Z</modified>
<tagline></tagline>
<id>tag:weblogs.java.net,2008:/blog/jhook/272</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2007, jhook</copyright>
<entry>
<title>RIA - Why can&apos;t any of them work?</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2007/10/ria_why_cant_an.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2007-10-10T06:53:34Z</issued>
<id>tag:weblogs.java.net,2007:/blog/jhook/272.8405</id>
<created>2007-10-10T06:53:34Z</created>
<summary type="text/plain">RIA is killing me.</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p><b>AJAX/HTML</b> - On one hand, I've grown a new appreciation for the platform.  It forces you to <a href="www.enverio.com" target="_new">keep things simple</a> for users and working directly with the full Java stack on the server is a bonus for maintenance and monitor-ability.  The problem when you look at doing anything worthy of ooh's and aah's is that AJAX/HTML and browser dependencies must always be coded for the lowest common denominator and whatever faults it presents.  I'm consistently amazed at widget libraries like <a href="http://extjs.com/" target="_new">ext-js</a>, but find some people's browsers struggle through much more basic content.  Lastly, I doubt you could simply populate some of these widgets with <a href="http://www.jamesward.org/census/" target="_new">large sets of data</a> and expect usable performance.</p>

<p><b>Flex/AIR</b> - I've fallen in love with the markup based solution and the desktop deployment-- but why does Adobe torture me and place my app in a glass cage?  The limited API and the initial <a href="http://labs.adobe.com/wiki/index.php/AIR:Developer_FAQ#Will_developers_be_able_to_extend_Adobe_AIR_with_native_code.3F" target="_new">security policies</a> for the platform present a doubtful outlook for anyone attempting to do anything but create a fancy web page.  Yes there's file system support, but <i>please</i>, at least allow us to create modules in native (C++) code if Adobe's not going to provide the feature out of the box (specifically thinking of device connectivity).</p>

<p><b>Java WebStart/JavaFX</b> - Today I went to Java.com, hoping to see some examples of Java WebStart, after all, I've heard a bit on JavaScript/deployment issues.  Of course, I was rewarded with about five JavaScript errors when I loaded Java.com-- lovely.  What can I say about JavaFX now?  While I liked programming in Lisp in college, I don't care to write:{my:[{UI:'s'}, in:it]}.</p>]]>

</content>
</entry>
<entry>
<title>JavaOne 2007 - JavaFX, Desktop, and JSF</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2007/05/javaone_2007_ja_1.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2007-05-08T22:41:42Z</issued>
<id>tag:weblogs.java.net,2007:/blog/jhook/272.7302</id>
<created>2007-05-08T22:41:42Z</created>
<summary type="text/plain">I knew F3 was interesting, but until today, I didn&apos;t realize how much weight would be put behind it from Sun.  Between MS, Adobe, and Sun-- will these become the preferred choice for &quot;beyond the traditional web application&quot;?</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>At JavaOne this year, I've decidedly filled my schedule with Desktop track sessions and network-related talks.  Everything is becoming more appealing now with Sun's commitment to providing a "Consumer" release of Java SE mid-2008 (expected) which will include fixes/enhancements around webstart, swing, user experience/performance, and finally the inclusion of JavaFX.</p>

<p>Much of this goes back to my <a href="http://weblogs.java.net/blog/jhook/archive/2007/02/the_failure_of_1.html">previous blog</a> on desktop Java and deployment-- where it's becoming much more appealing for business services.  To me, it's not a matter of blurring the user experience, but of optimal data boundaries and scalability of deployment from a features standpoint.</p>

<p>Now, with JavaFX and the potential that it offers (again mainly because of Sun's announced product strategy and commitment), I'm still firmly behind <a href="http://weblogs.java.net/blog/jhook/archive/2007/04/web_application_1.html">my statement before</a> on JSF 2.0 with pushing for a renewed focus on traditional web paradigms or at least optimizing for it.  If we push for even more catering to AJAX within the <bold>spec</bold> as a rich client solution, I'm afraid that as we spiral down that path-- the ground will come up to meet us fairly quickly out of renewed consumer desktop solutions and changed deployment strategies.</p>

<p>Lastly, when we are talking about specs/JSRs, we aren't creating solutions for <i>now</i>, it's more like two to three years from now.  Where will the rest of the platform be going and when will JSF become the optimal choice for all web sites, including things on the scale of eBay or Yahoo?</p>]]>

</content>
</entry>
<entry>
<title>JSF 1.2 RI - Bean Instantiation and Annotations</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2007/05/jsf_12_ri_backi.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2007-05-01T23:38:51Z</issued>
<id>tag:weblogs.java.net,2007:/blog/jhook/272.7198</id>
<created>2007-05-01T23:38:51Z</created>
<summary type="text/plain">JavaServer Faces 1.2 includes support for Resource Injection and annotations such as @PostConstruct and @PreDestroy.  Coming from action frameworks, these &apos;implicit&apos; hooks make composite presentations a bit easier to pull together, even in the stateless HTTP GET case.</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>JavaServer Faces 1.2 includes support for Resource Injection and annotations such as <code>@PostConstruct</code> and <code>@PreDestroy</code>.  Coming from action frameworks, these 'implicit' hooks make composite presentations a bit easier to pull together, even in the stateless HTTP GET case.</p>

<p>JavaServer Faces currently has a couple great frameworks that extend application coordination and ease development.  Since not everyone uses these frameworks, I wanted to write a short blog on what you can do <i>out of the box</i> with JavaServer Faces 1.2 and the reference implementation.</p>

<h4>Push vs. Pull in Views</h4>

<p>Since JSF's inception, you've been able to declare any number of java objects within multiple <code>faces-config.xml</code> files as termed 'managed beans'.  Traditionally with action frameworks, each request is primarily sourced from a single action instance-- anything it can create is <i>pushed</i> into existence for the view to use.  With JSF's managed beans, you can compose a series of stand-alone objects which can be <i>pulled</i> into the view in any quantity.</p>

<p>Sometimes it's difficult with action frameworks to be able to setup (push) everything the view may or may not need at the time of evaluation.  When you have something like managed beans and EL within JSF, nothing needs to be pre-executed as your view can just pull in the managed beans it needs.</p>

<p>A simple use case is displaying data conditionally in the view-- happens all the time.  Since you can pull only what you need into your view, there's less concern of pushing unnecessary database state into a view which may not actually need it.  A second case is reuse.  You may need to generate a list of current orders in multiple places.  With JSF, the practice is to just create a 'CurrentOrdersBackingBean' which can be <i>pulled</i> into any view. Often many from the Struts world would've populated that list within any possible action that results in a view which <i>may</i> display the list of orders.</p>

<p>Basically, the development mentality with a pull MVC is to create fine-grained beans with a single purpose (SRP).  JSF's managed bean declarations will allow you to wire in other state from session beans or request parameters.  In the case of displaying a list of orders, you may end up with a config like so:

<pre><code>
&lt;managed-bean>
  &lt;managed-bean-name>ListOrdersBean&lt;/managed-bean-name>
  &lt;managed-bean-class>ex.view.ListOrdersBean&lt;/managed-bean-class>
  &lt;managed-bean-scope>request&lt;/managed-bean-scope>
  &lt;managed-property>
    &lt;property-name>credentials&lt;/property-name>
    &lt;value>#{AuthManager}&lt;/value>
  &lt;/managed-property>
&lt;/managed-bean>
&lt;managed-bean>
  &lt;managed-bean-name>AuthManager&lt;/managed-bean-name>
  &lt;managed-bean-class>ex.view.AuthManager&lt;/managed-bean-class>
  &lt;managed-bean-scope>session&lt;/managed-bean-scope>
&lt;/managed-bean></code></pre>

</p>

<p>The above configuration will allow views to use/declare <code>ListOrdersBean</code> and when JSF instantiates it, the <code>AuthManager</code> will be assigned, allowing the <code>ListOrdersBean</code> to pull the correct set of orders for the current set of credentials in the session.</p>

<h4><code>@PostConstruct</code> and <code>@PreDestroy</code></h4>

<p>There's a problem from a programming standpoint with the above example.  Even if JSF assigns the credentials to your <code>ListOrdersBean</code>, when does your bean know to actually fetch the list of orders?  When 'getOrders()' is called by the view?  JSF has five phases to it's lifecycle-- 'getOrders()' can be called with each phase and you don't want to duplicate lazy instantiation with each call.  What do you do?</p>

<p>Aside from hacking the <code>if (this.orders != null) ...</code> within the getter, JavaServer Faces 1.2 has the <code>@PostConstruct</code> which gets called before returning the bean for use.
<pre><code>public class ListOrdersBean {
    private List orders;
    private Credentials credentials;

    @PostConstruct
    public void init() {
       if (this.credentials != null) {
         this.orders = ....;
       } else {
         this.orders = Collections.EMPTY_LIST;
       }
    }

    public List getOrders() {
       return this.orders;
    }
    
    public void setCredentials(Credentials cred) {
       this.credentials = cred;
    }
}</code></pre>
</p>

<p>The <code>init()</code> method will be called once for instantiating the request-scoped bean and succeeding calls to <code>getOrders()</code> will not need to have a bunch of lazy initialization code.</p>

<p>You can take this one step further with List/Detail views and 
stateless HTTP GET requests (<code>/employee.jsf?id=456</code>).

<pre><code>
&lt;managed-bean>
  &lt;managed-bean-name>EmployeeFinder&lt;/managed-bean-name>
  &lt;managed-bean-class>ex.view.EmployeeFinder&lt;/managed-bean-class>
  &lt;managed-bean-scope>request&lt;/managed-bean-scope>
  &lt;managed-property>
    &lt;property-name>id&lt;/property-name>
    &lt;value>#{param.id}&lt;/value>
  &lt;/managed-property>
&lt;/managed-bean></pre></code>
</p>

<p>Notice that we can instantiate this backing bean for the request and have JSF automatically assign a request parameter (<code>id</code>) to the backing bean.

<pre><code>public class EmployeeFinder {
    private long id;
    private Employee result;
    
    @PostConstruct
    public void findEmployee() {
        if (this.id > 0) {
           this.result = ...;
        }
    }

    public void setId(long id) {
        this.id = id;
    }

    public Employee getResult() {
        return this.result;
    }
}</code></pre>

</p>

<p>Your <code>employee.html</code> page can then simply just use <code>#{EmployeeFinder.result}</code> to display the employee that matches the <code>id</code> parameter passed.  If none was found, you can just display an error message without producing a second page (as is a traditional practice with action frameworks).</p>

<p>Who says every JSF request has to be a POST?</p>

<p>Another good point is that this granularity of backing beans without Servlet API dependencies makes unit testing much more practical.</p>

<h4>Resource Injection</h4>

<p>I'm not going to discuss resource injection because there's a bunch of other great articles/blogs on the topic [1].  But the flow within the JSF 1.2 RI for instantiating managed beans is as follows:

<ol>
<li>New the bean declared using the default constructor</li>
<li>Inject any <code>@Resource</code> declarations</li>
<li>Assign any managed-properties declared, cascading this process if new beans are referenced</li>
<li>Call <code>@PostConstruct</code> on the bean if declared</li>
<li>Store the bean in the correct scope and return</li>
</ol>

</p>

<p>With the JSF 1.2 RI, you can get the pre/post events outside of a Java EE 5 container by simply having the <code>annotations.jar</code> in your classpath.</p>

<p>I hope this blog answers some questions on how to properly instantiate managed beans with JavaServer Faces 1.2, it's a big improvement over JavaServer Faces 1.1 and usable today with the RI.</p>

<ul>
<li>[1] Resource Injection References
   <ul>
   <li><a href="http://java.sun.com/developer/technicalArticles/J2EE/injection/">Resource Injection and Java EE 5</a></li>
   <li><a href="http://blogs.sun.com/rlubke/entry/jsf_ri_1_2_and">Pluggable Resource Injection and JSF RI</a></li>

</li>
</ul>]]>

</content>
</entry>
<entry>
<title>Web Application Paradigm Specialization and JSF 2.0</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2007/04/web_application_1.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2007-04-07T07:42:42Z</issued>
<id>tag:weblogs.java.net,2007:/blog/jhook/272.7004</id>
<created>2007-04-07T07:42:42Z</created>
<summary type="text/plain">Many developers are making the partial migration to rich web applications with AJAX and giant JavaScript libraries while retaining traditional page-oriented paradigms.  Sitting in the gray area of web application paradigms often leaves you with less than ideal results.</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>In some ways, this blog could be considered my recap of 2007 and the mistakes and knowledge I've gained.  In other ways this blog acts as a foundation for ways I'd like to view JSF 2.0.</p>

<p>When the AJAX gimmicks clear, we'll be left with two camps: the keep it simple page paradigm and then those who want the full rich client.  Where people are getting bit right now, or possibly realize they will be, is when you sit in the gray area of the two camps.  Right now, that's about everyone.</p>

<p>Let's talk technical first.</p>

<p>Let's start out in the traditional page paradigm which is 99.9% of everything on the web.  Let's add in some JavaScript and AJAX functionality.  To do that, we add in about 150 KB of JavaScript to our pages which drops load times (yes, even cached) and then use all of those nifty behavioral decorations which walk the DOM tree assigning dynamic behavior-- dropping page performance even more.  The kicker is that probably 90% of your page activity still causes a new page to be loaded where you get to re-introduce all of this overhead again.</p>

<p>If you continue this route and keep layering in functionality with AJAX/JS as the solution, you'll end up with neither a rich client app nor an efficient web application.</p>

<p><i>We took this route and then ended up backing a bunch of it out because of performance issues.  Don't get me wrong, we were by the book with all of the tricks and optimizations-- beyond the appeal of AJAX-- functionally, nothing was really gained that couldn't be rethought from a pure task flow standpoint.</i></p>

<p>Now lets get ridiculous and talk (best) case scenarios.  You are using JSF-EXT or Flex to build your pages-- you still wouldn't kick the user into a different page [load] with mouse clicks would you?  Even if you did have WPF or Firefox 8.0 with better performance and features, you must also serve the end user and clever uses of AJAX and JS behavior can sometimes be difficult to interact with.  Either go simple click-to-page flows, or stay in familiar boundaries of the desktop paradigm.</p>

<h4>The Role of JavaServer Faces 2.0</h4>

<p>If we commit to saying there's only two paradigms in web application development and say that anything between will be covered by supplementing the two extreme use cases, then JSF 2.0 needs dramatic changes from JSF 1.2.</p>

<p>On one side, you have the traditional page paradigm.  JSF works well in this solution, but comes at the cost of stateful management and processing overhead.  In addition, JSF's actions are represented in POST requests, not efficiently handling the traditional GET/Restful actions which content-based sites follow.</p>

<p>On the other side of full rich UI clients, JSF works well here too, but to a point.  It does a great job of setting up a screen of rich AJAX components, but when it comes to loading in new pieces dynamically or introducing a new tab of content, things start to fall apart as JSF's navigation structure is stuck in the page paradigm.  In addition, the screens' state is retained in a singular whole, which forces you to load everything up front or run into discontinuities later.</p>

<p>You could say that JSF today sits in the gray area of solutions for web application paradigms.  While this covers a large number of scenarios, it doesn't surprise me at all that a single development group may use multiple UI frameworks for their applications which are specialized to the two primary application paradigms.  Example, using WebWork or Struts for your public application, but JSF or Flex for your internal maintenance/data applications.</p>

<h4>What I'd like to see for Java EE 6</h4>

<p>With JSF 2.0, I'd like to see a re-write of JSP and basically say tags are stateless components.  Introduce annotations and reduce XML within JSP into a very efficient and handy templating solution on the web which can be used with other frameworks or with simple servlets.  Then come in with JSF 2.0 and add in support for stateful components which work seemlessly with the stateless components-- introduce @Stateful or @Event concepts into the foundation of the new JSP presentation framework.</p>

<p>This easy to use JSP templating solution would more than solve the traditional page paradigm avenue while providing a foundation for rendering back service-based messages for rich clients.  Simply put, low overhead, stateless, and compiled for performance.</p>

<p>Like icing on a cake, layering in JSF 2.0 features can then more easily scale with functionality in a highly optimized manner.  If we approach this strategy of integration, developers can be much more flexible in the Java EE 6 platform in accomodating different use cases, even when we are mixing paradigms.  Conceptually, developers work with one kind of component and no longer would there be multiple phases in view construction which consistently confuse developers.</p>

<p>The fundamental gain of JSF as your application controller is the idea of automatic composition and scalability of complexity.  I've written about this before, but even in stateless component form, this architecture would be like declaratively wiring together 10 or 15 Struts Actions, reflective of your matching UI.</p>

<p>You may read the above and ask how is that any different than JSF 1.2 and JSP 2.1 today and the answer is simple-- JSP and JSF weren't originally written together and succeeding maintenance releases have too much legacy compatability issues to really deliver the simplicity developers expect today.</p>]]>

</content>
</entry>
<entry>
<title>The Failure of Web-Based ASP Business Models</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2007/02/the_failure_of_1.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2007-02-11T21:39:21Z</issued>
<id>tag:weblogs.java.net,2007:/blog/jhook/272.6505</id>
<created>2007-02-11T21:39:21Z</created>
<summary type="text/plain">Application Service Providers have migrated to the web in an attempt to provide quick channels of distribution; but more accessible web-based applications doesn&apos;t translate well for customer integration.</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>With the tech market in an upturn, we are seeing an revitalization of startups on the web for application service providers.  Sometimes these are analytical/informational services or point of sale applications which provide supplemental support for one part or all of the customer's business.</p>

<p>First, lets take a look at the pro's of web-based ASP models:
<ul>
<li>Quick to develop and deploy.</li>
<li>Maintenance cycles and patches can be immediately applied for all customers.</li>
<li>Internal, centralized distribution on controlled hardware.</li>
<li>Zero install on the part of the customer by using existing browser platforms.</li>
</ul>
</p>

<p>Basically we have a list of pro's for the developer which are founded in ease of deployment.  The exception is zero install on the part of the customer as a pro for the end user.  But, rationally speaking, this is where we draw the line.</p>

<p>The con's of web-based ASP models are:
<ul>
<li>Single point of failure (the fallacies of the network).</li>
<li>High demands on your own capital in the form of bandwidth and hardware.</li>
<li>Maintenance of customer's volatile data, how to integrate?</li>
<li>Limitations of the browser platform.</li>
</ul>
</p>

<p>When providing a service over the web, the crucial point of issue is how to integrate your data models with the customers'?  In the case of providing a singular service as a facet of a customer's business, such as reporting or CSR facilities-- how will the customer's other systems, services and data integrate with your application?  Often times this is approached through manual import tools to port data over for external storage within your own hardware.</p>

<p>Also consider how much the customer depends on your services to make their business function.  If you have a web-based application, can <i>they</i> afford down time?  Even as an example of non-ASP models, sometimes centralizing functionality to a central data center can cripple your business if not scaled out correctly.  Online magazines reported some of the biggest IT failures of 2006 were attempts at centralizing business-critical operations.</p>

<p>So am I suggesting reverting back to pre-dot com with installed software nightmares?  No.  Just that we should be more open to moving back to distributed software on the client.  Data is king-- and in application service models, it's often the customer that owns all of the data.  Understandably in this condition, off site application services deployments seem to be wrong route.</p>

<p>Following the 80/20 rule, a majority of operational information is localized to the business where the minority service provided can instead be remoted into a localized platform on the client.  In addition, you have a much more valuable and tangible revenue channel with the customer instead of a service that can simply be dropped next week (<i>because it's too much of a headache to maintain data in multiple places just to use your service</i>).</p>

<p>What's changed in Java world that makes desktop deployments more practical?</p>

<h4>Hybridizing Java on the Desktop</h4>

<p>Bruce Eckle recently blogged about hybridizing Java.  Hybridizing for what?  Prettier animations with flash? The Java runtime download now sits at 7 MB, which is fairly reasonable (<a href="http://weblogs.java.net/blog/stanleyh/archive/2005/05/deployment_unde_1.html">more info here</a>).  While both Flash and Java are OS agnostic, can the Flash platform deliver the springboard of functionality that exists in the Java platform?  If I'm committing to doing a desktop deployment (where the mechanics of the web aren't going to fit), I'll want to be able to 'really' integrate with the network, data, OS, etc.  Not just deliver a pretty UI over the web.  If there was a real benefit from delivering a pretty UI, Flash would've been much more popular for application delivery years ago.  Adobe Apollo shows a bit more promise, but then again it still doesn't have everything the Java platform has or ever will.</p>

<h4>.NET vs. Java on the Desktop</h4>

<p>I've been going through phases at work where I keep feeling like I need to pick up .NET for desktop development.  But a few things dawned on me.  If I commit to .NET, then there's the whole issue of installing the .NET runtime, which is just as large, if not <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=262d25e3-f589-4842-8157-034d1e7cf3a3&displaylang=en">larger</a> then Java.  From my experience with ASP businesses, even with deploying to windows OS, the .NET runtime installations and updates come up constantly with support issues.  Secondly, with the increasing popularity of Linux and the Mac, even with exceptions, the .NET platform isn't as 'native' here.</p>

<h4>Swing vs. Eclipse on the Desktop</h4>

<p>One of luxuries that web-based ASP models afford you is easy patching and updating.  As a web developer, it's extremely difficult to pull yourself away from that security blanket.  So what has Swing and Eclipse done to alleviate this concern?  Swing hasn't done much.  The whole module, OSGi attempts within the JCP have been <a href="http://www.osgi.org/blog/2006/10/jsr-277-review.html">poorly spec'ed</a>.  I was somewhat interested in the Swing application JSR, but all it ended up being was an exploration in the academic ideology of coding an application.  It doesn't have any tangible benefits for actually solving the Java on the desktop issue except for add more useless code abstractions to the runtime.</p>

<p>Eclipse RCP on the other hand has deployment and modularization built in with native rendering.  <b>I can't emphasize enough over the importance of this in making Java work on the desktop!</b>.  Finally we have a solution that allows developers to push out updates and features the same as you would in web-based deployments.  From an ASP perspective, you have a localized deployment where additional features can be added/purchased all while the customer continues to have ownership over the data.  Ah, the security blanket exists on the desktop too.</p>

]]>

</content>
</entry>
<entry>
<title>Persistence Caching Part II</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2007/01/persistence_cac_2.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2007-01-06T06:07:44Z</issued>
<id>tag:weblogs.java.net,2007:/blog/jhook/272.6271</id>
<created>2007-01-06T06:07:44Z</created>
<summary type="text/plain">After more investigation, and monitoring-- I continue my rant :-)</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>Often when you are looking at caching 'requirements', you have a couple things to think about:</p>

<ol>
<li>Allowable duration (only guarantee the object/data for 30 or 20 minutes at most)</li>
<li>Optimized memory use (don't cache too much)</li>
</ol>

<p>No where do requirements base themselves on '<i>do not store more than 200 widgets at once in memory</i>'.  So why do these caching implementations work that way?  Granted, there's opportunity to roll over to the file systems in these cache frameworks, but really-- if I wanted to guarantee persistence like that, I'd just store it to the disk in the first place or in the DB.  <i>Seriously.</i>  Anything I'd throw into a 'cache' would be just extra.  Hibernate has strongly referenced 1st level caching, which makes complete sense for transactions, second level caches are just there to help with performance.</p>

<p>So what do we do?  Lets take OSCache as an example.  What I really want to do is specify a time to live (requirement 1) and either softly or weakly reference the data to allow the JVM to naturally optimize memory use.  This means I can store an unbounded set of widgets in memory (None of this LRU/FIFO/LFU stuff), but still enforce that if the widget sticks around long enough, to put some restriction on how long until we allow it to be dirty again (forcing a re-fetch).</p>

<p>If you are dealing with bounded sets-- such as a couple of known articles or highlighted data, then fine, use a cache capacity/LRU-- but for unbounded sets where caching is purely there to enhance performance of the overall system-- just weakly or softly reference the data.  It is a <i>cache</i> after all.</p>

<p>This becomes especially important in web applications where traditionally, we store data per session to optimize the user experience.  But-- what if 80% of that data is required by another user?  Could we push the cache to a global scope, out of the session and weakly reference it, such that all users share the same memory?  I guess you could still store reference in your session, but globally weakly referencing the data would be an 'automatic' way of sharing common session data that's purely there for cache optimization.</p>

<p>The other thing would be to softly reference everything.  In this case, you would just be able to store whatever you can globally, knowing that it will get cleaned up as the VM needs to allocate memory elsewhere.  Still retaining the time to live policy here is important to prevent objects from sticking around for days at a time when you want to 'update' the cached instance after 20 or 30 minutes.</p>

<p>Another performance tweak to this with soft references, if the overhead of using soft references becomes too much, you can decide to 'chunk' your caches into segments where a whole series of caches can be softly referenceable, instead of per object.</p>

<pre><code>net.java.project.Widget.cache.duration=1800
net.java.project.Widget.cache.ref=soft
net.java.project.Widget.cache.chunk=100</code></pre>

<p>Lookups would then be Key to Reference, Reference to Cache, Key to Instance.</p>

<p>Anyways, again, let me know your thoughts-- I've committed to using an existing cache implementation, but all of the settings of these popular libraries just seems disjoint to actual application use cases.</p>

<h4>Update from Bob's Comments</h4>
<p>I implemented a straight <code>ConcurrentHashMap&lt;String,SoftReference></code> as a cache, then experimented with also queuing a <code>TimerTask</code> to force clean up of older objects.  As a control, I also used a straight hard reference cache <code>ConcurrentHashMap&lt;String,Object></code>.</p>

<p>What I wanted to see is how accurate the use of <code>SoftReferences</code> in keeping the largest chunk of recently added objects.  It'd be bad if the GC tossed out all the references you never cared about.  Adding the TimerTask would hopefully help the GC recover the correct memory by cleaning references ourselves. So lets see what happens with varying sized objects:</p>

<ul>
<li>Ran until added 50,000 objects, or ran out of memory.</li>
<li>Size is the size of the cache at the end of the run (how many retained).</li>
<li>Time is the time in ms to populate the cache until success/fail.</li>
<li>Failed is true-- if it failed.</li>
<li>Oldest is walking from the last in to see what the oldest continous block of objects available, starting from the 50,000th.</li>
<li>Hits mean different things, SoftValueCache counts hits as how many were gc'ed from the cache before ending the test.  ThreadCache is how many of those <code>TimerTask</code> runs actually removed the object before the gc did (higher the better).</li>
</ul>

<code><pre>Small Objects (100b):
HardCache[total=14057,size=14057,time=735,failed=true,oldest=0,hits=14057]
SoftValueCache[total=50000,size=3759,time=1547,failed=false,oldest=46241,hits=46241]
ThreadCache[total=50000,size=9031,time=1984,failed=false,oldest=40969,hits=24124]

Medium Objects (500b):
HardCache[total=3437,size=3437,time=781,failed=true,oldest=0,hits=3437]
SoftValueCache[total=50000,size=427,time=7297,failed=false,oldest=49573,hits=49573]
ThreadCache[total=50000,size=2085,time=8844,failed=false,oldest=47915,hits=43633]

Large Objects (1,000b):
HardCache[total=1849,size=1849,time=547,failed=true,oldest=0,hits=1849]
SoftValueCache[total=50000,size=430,time=10078,failed=false,oldest=49570,hits=49570]
ThreadCache[total=50000,size=393,time=11391,failed=false,oldest=49607,hits=45769]</pre></code>

<p>So what do the numbers mean?  ThreadCaching adds some overhead, to time/memory, but when the timer is able to clean up references before the GC, then we do get a better set of recent objects sticking around in the cache (good).  For large objects, they get gc'ed before the timer can get to them, rendering them useless.</p> ]]>

</content>
</entry>
<entry>
<title>Persistence Caching</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2007/01/persistence_cac.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2007-01-04T05:54:25Z</issued>
<id>tag:weblogs.java.net,2007:/blog/jhook/272.6253</id>
<created>2007-01-04T05:54:25Z</created>
<summary type="text/plain">Working with Hibernate and attempting to wrap caching services elsewhere in one of our applications, I&apos;m concerned with the way these caching frameworks handle expiration.</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>Working with Hibernate and attempting to wrap caching services elsewhere in one of our applications, I'm concerned with the way these caching frameworks handle expiration.</p>

<p>If you have many different types of domain artifacts that you want to cache with a given lifespan, how come all of these caching frameworks (EHCache, OSCache, etc) don't automatically clean up the memory?  It becomes a game of roulette in trying to optimize the most memory usage vs. potential usage for any given time of day.</p>

<p>This becomes a greater issue when we get into SOA where we've previously been able to sneak away with scoping information in the session, knowing well that it will be cleaned up after a certain period of use.  With stateless service tiers, the caches are based on some interval-- but EHCache/OSCache don't guarantee object expiration when the objects aren't needed anymore.</p>

<p>It seems just silly that these caches will retain reference to Objects needed 2 days ago, only to tell me they are no good when/if someone wants them again.</p>

<p>Am I wrong in this expectation? I would the execution would go something like:</p>

<pre><code>public void store(String key, Object value, long time) {
    this.concurrentMap.put(new TempKey(key, System.currentTimeMillis() + time), value);
    this.queueThread.notify();
}

protected final Thread queueThread = new Thread(new Runnable() {
    public void run() {
      try {
          this.wait();
          // clean up expired keys
      } catch (Exception e) { ... }
    } 
});</code></pre>]]>

</content>
</entry>
<entry>
<title>JSE 7 No Arrows Please</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2006/12/jse_7_no_arrows.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2006-12-29T05:11:07Z</issued>
<id>tag:weblogs.java.net,2006:/blog/jhook/272.6220</id>
<created>2006-12-29T05:11:07Z</created>
<summary type="text/plain">I agree that getter/setters should be simplified in operational syntax, but arrows?!</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>I'm finding so much of Java's APIs to be extremely literal and long-winded at times.  While this produces self documenting code, I'd still like to see some better ideas for the getter/setter shorthand than '-&gt;'.</p>

<p>More on the topic here: <a href="http://www.almaer.com/blog/archives/001325.html">Dion's Blog</a></p>

<p>I'm of the opinion that if you are willing to make a commitment to closures, then we do the same for properties-- something similar to C#.  Spending time <i>extending</i> the long winded get/set <i>convention</i> is the wrong direction for the spec.  Do everyone a favor and do properties right-- leaving the old Bean Property spec alone for APIs to accommodate and treating properties as a first class citizen in the metadata starting in SE 7.</p>

<pre><code>Property[] p = class.getProperties();</code></pre>

<p>Aside from the misread syntax of an assignment arrow ('-&gt;'), I can see a lot of people get confused by <i>implying</i> method associations by some naming convention.  Actually introducing a literal property syntax into the spec will make code much more maintainable in the long run, than visual guessing games around field accessors.</p>

<p>Some senior developers may scoff at the thought of bean naming conventions as confusing, but from being on web/el/mvc dev lists for many years, you are guaranteed to get those people who have problems with reading properties because they didn't capitalize/lowercase the right letter.</p>

<p>Please SE folks-- think <i>outside</i> the box.</p>]]>

</content>
</entry>
<entry>
<title>Class Metadata Caching</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2006/12/class_metadata.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2006-12-11T00:38:01Z</issued>
<id>tag:weblogs.java.net,2006:/blog/jhook/272.6140</id>
<created>2006-12-11T00:38:01Z</created>
<summary type="text/plain">With Annotations being popular and more dynamic frameworks, how can we efficiently cache associated Metadata/assignments per Class without causing ClassLoader and memory leaks?</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>A lot of frameworks are building off of simple Annotations or dynamic invocation, basically extensions per Class instance.  To avoid re-mining this data, we attempt to cache it.  This works fine, except when we deal with hot deploys or restarts with statically scoped caches.  Keeping reference to some classes/ClassLoaders after repeated restarts could quickly gobble resources.</p>

<p>So I've been seriously looking for strategies that would prevent memory leaks, detecting dynamic changes in ClassLoaders or Classes.  Some solutions go as far as to check the file system for class file changes, seems like a quite of overhead.</p>

<p>From talking with some of the guys from Sun, looking at ClassLoaders/Class implementations within the JVM, I thought looking at using WeakHashMaps and ConcurrentHashMaps together might provide a solution.</p>

<p>First, we would have a top-level WeakHashMap of ClassLoaders as the key.  Secondly, we'll make the value of this ClassLoader WeakHashMap be a child Map of Class <b>names</b> to metadata (finally).</p>

<pre><code>WeakHashMap&lt;ClassLoader, ConcurrentHashMap&lt;String, ClassMetaData>></code></pre>

<p>
The reason for this setup is:
<ol>
<li>WeakHashMaps keep weak references to the key, not the value-- so we can prevent retaining reference to old ClassLoaders.</li>
<li>Using the ClassLoader at the top level key is less volatile than per Class, can help avoid synchronization locks with WeakHashMaps.</li>
<li>We use a ConcurrentHashMap for efficient synchronization, for the per ClassLoader information.</li>
<li>We key off of the Class name instead of the Class instance based on the fact that per ClassLoader can only have one instance loaded, but we know that the class could possibly change.</li>
<li>The final value stored is wrapped by a touple that retains reference to the target class so we can check that the one instance cached matches the class passed, even though they have the same name.</li>
</ol>
</p>

<p>Based on these points, I started throwing together a generic cache implementation that can be used to store anything per class, while attemping to avoid long term memory leaks.</p>

<p>
<pre><code>public class ClassCache&lt;V> {
    
    private class ClassValue&lt;V> {
        private final Class type;
        private V value;
        
        public ClassValue(Class type, V value) {
            this.type = type;
            this.value = value;
        }
        
        public boolean matches(Class type) {
            return this.type.equals(type);
        }
        
        public V get() {
            return this.value;
        }
    }
    
    private class ClassMap&lt;V> extends ConcurrentHashMap&lt;String, ClassValue&lt;V>> {}
    
    private class ClassLoaderMap extends WeakHashMap&lt;ClassLoader, ClassMap> {}
    
    private ClassLoaderMap classLoaders = new ClassLoaderMap();
    
    public ClassCache() {}
    
    public void set(Class type, V value) {
        if (type == null) return;
        ClassLoader loader = type.getClassLoader();
        if (loader == null) loader = Thread.currentThread().getContextClassLoader();
        
        ClassMap map = this.classLoaders.get(loader);
        if (map == null) {
            map = new ClassMap();
            ClassLoaderMap replace = new ClassLoaderMap();
            
            // copy on write
            replace.putAll(this.classLoaders);
            replace.put(loader, map);
            this.classLoaders = replace;
        }
        
        map.put(type.getName(), new ClassValue(type, value));
    }
    
    public V get(Class type) {
        if (type == null) return null;
        ClassLoader loader = type.getClassLoader();
        if (loader == null) loader = Thread.currentThread().getContextClassLoader();
        
        ClassMap&lt;V> map = this.classLoaders.get(loader);
        if (map != null) {
            ClassValue&lt;V> value = map.get(type.getName());
            if (value != null && value.matches(type)) {
                return value.get();
            } else {
                map.remove(type.getName());
            }
        }
        
        return null;
    }
}</code></pre>
</p>

<p>This is just some ideas I've put together, does anyone else have specific suggestions on how to do this better/properly?</p>]]>

</content>
</entry>
<entry>
<title>JSF StateSaving and Compression</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2006/12/jsf_statesaving_1.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2006-12-08T07:25:54Z</issued>
<id>tag:weblogs.java.net,2006:/blog/jhook/272.6125</id>
<created>2006-12-08T07:25:54Z</created>
<summary type="text/plain">The Sun JSF RI team (Ryan Lubke, etc) is constantly making enhancements to their project here on Java.net.  One of the banes of JSF&apos;s architecture is StateSaving, so we ran some tests to see if there was room for improvement.</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>StateSaving in JSF is the uncle no one wants to talk about.  You get a lot of things for 'free' with JSF, but for the most part, these features end up adversely affecting the state size of the view.</p>

<p>JSF has two options for StateSaving: client and server (actually pluggable for anything you want).  The basic rule of thumb is if you want to save memory, you go with client state saving-- pushing Object state to the client, encoded in the view.  StateSaving server is a bit more performant, but retains stacks of views in the user's HttpSession.</p>

<p>What I want to focus on is client StateSaving.  With saving state on the client, you are basically serializing an object graph and outputting it into the page as a Base64 String.  Optional features here include encryption and compression.  Encryption is only needed in rare cases-- but compression is often enabled.  From my own tests, compressing JSF state means a reduction in size by at least a factor of 10 (hmmm... maybe this tells us something ;-).</p>

<p>By default, client state is compressed with normal GZip.  I believe MyFaces actually opts out of compression by default, but any of Jason Hunter's old articles on Compression Filters actually tell you that compression is a good thing with network latency.  Yes, compression adds processor overhead, but lets see if we can't look at some alternatives to GZip?</p>

<p>Diving through java.util.zip, I know that there are other 'Deflaters' available which have interesting 'types'-- such as Best Performance, Huffman, Best Compression, etc.  Let's see how these compare with a grossly large JSF page (basically 100 pages put together in one) and averaged over hundreds of iterations of StateSaving:</p>

<p>Update: I've added Ryan's JMeter results from trying some of these algorithms against the CarDemo app with 50 threads running for 5 minutes at random intervals of 200-300ms.</p>

<p>
<table border="1">
<thead>
<tr>
<th>Algorithm/Type</th>
<th>Size in Bytes</th>
<th>Write in Milliseconds</th>
<th>Read in Milliseconds</th>
<th>Total in Milliseconds</th>
<th>Request/Second</th>
<th>Bytes/Second</th>
<th># of Hits</th>
</tr>
</thead>
<tbody>
<tr>
<td>None (Default MyFaces)</td>
<td>174,345</td>
<td>78.14</td>
<td>198.12</td>
<td>276.26</td>
<td style="background: #EEE">91.8</td>
<td style="background: #EEE">2,529.89</td>
<td style="background: #EEE">27,598</td>
</tr>
<tr>
<td>GZip (Default RI)</td>
<td>12,864</td>
<td>103.72</td>
<td>205.68</td>
<td>309.4</td>
<td>58.6</td>
<td>518.05</td>
<td>17,633</td>
</tr>
<tr>
<td>Default Compress</td>
<td>12,852</td>
<td>93.42</td>
<td>174.08</td>
<td>267.50</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>Best Compress</td>
<td style="background: #EEE">11,855</td>
<td>110.24</td>
<td style="background: #EEE">171.04</td>
<td>281.28</td>
<td>62.2</td>
<td>544.76</td>
<td>18,695</td>
</tr>
<tr>
<td>Best Speed</td>
<td>16,480</td>
<td>86.58</td>
<td>176.24</td>
<td>262.82</td>
<td>63.5</td>
<td>569.02</td>
<td>19,091</td>
</tr>
<tr>
<td>Huffman</td>
<td>15,190</td>
<td>79.46</td>
<td>175.22</td>
<td style="background: #EEE">254.68</td>
<td>63.8</td>
<td>590.21</td>
<td>19,181</td>
</tr>
<tr>
<td>Filtered</td>
<td>16,480</td>
<td style="background: #EEE">79.36</td>
<td>176.88</td>
<td>256.24</td>
<td style="background: #EFF">64.1</td>
<td style="background: #EFF">600.97</td>
<td style="background: #EFF">19,272</td>
</tr>
</tbody>
</table>
</p>

<p>The different algorithms are listed within the java.util.zip package in the javadocs, but I found the numbers to be pretty interesting.  Of course, I'm a compression n00b, so if anyone had any comments on why it would be bad to switch to one of the other algorithms as a set-able option with JSF, please let me know!</p>

<p>I should note too that smaller page sizes, all the algorithms fluxate in timings between runs by quite a bit (5ms > 0ms) which may be attributed purely to GC or the ObjectOutput/InputStream itself.</p>]]>

</content>
</entry>
<entry>
<title>AJAX Responses Strategies</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2006/12/ajax_responses.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2006-12-04T02:12:59Z</issued>
<id>tag:weblogs.java.net,2006:/blog/jhook/272.6080</id>
<created>2006-12-04T02:12:59Z</created>
<summary type="text/plain">Trying to implement capturing multiple responses at once within a single Http Response from the server is quite difficult.  In working on Avatar again, I&apos;ve come to an alternate way of communicating XHTTP responses (somewhat humorous).</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>Part of Avatar for JSF was being able to make a single, lightweight request to the Server and actually receive multiple elements at once in a single HTTP Response. An example would be a single button that would force re-rendering of 5 different parts of the page with one AJAX request.  IMHO, this approach is MUCH more efficient that all of these client-side event/observer systems that produce 4 or 5 separate AJAX requests for updates (the network sucks).</p>

<p>Anyways, if we have 5 different things we want to respond back with at once, how do we structure the HTTP response without ruining the original data-- may it be Strings, HTML, XML, or JSON?</p>

<p>We also have the use case of accepting the targeted response data, in <i>addition</i> to any other elements that are to be refreshed.  An example would be responding back with some String, but your listeners on the server also want to re-render the cart total and a few other elements on the screen-- not part of the original response.</p>

<h4>Response Headers</h4>
<p>My first solution was to demarcate the response into separate headers.  Each element to be updated had it's own header to occupy, leaving the body of the message alone (see above).  This was a perfect or natural way of separating the response up based on HTTP's own spec.  The problem is that HTTP containers never intended to carry that much information in their headers, and to prevent buffer attacks, many are capped at a few kb in size.  So your refresh of the main table of data would always get chopped off or force an error in the container.  Anyways, I think IE also caps the header size acceptable in the response.</p>
<p>So while this solution worked, it has a size cap which is very hard for a framework to enforce.</p>

<h4>XML Response</h4>
<p>Another idea, which many use, is to break up the response into separate XML nodes in a parent document, allowing CDATA chunks of XML, HTML, or JSON:</p>
<pre><code>&lt;async-response id="5434">
    &lt;encode id="table">&lt;![CDATA[ ... ]]&gt;&lt;/encode>
    &lt;encode id="cartSpan">&lt;![CDATA[ ... ]]&gt;&lt;/encode>
    &lt;encode id="footerTotal">&lt;![CDATA[ ... ]]&gt;&lt;/encode>
    &lt;body>&lt;![CDATA[ ... ]]&gt;&lt;/body>
&lt;/async-response></code></pre>
<p>While we've moved all of the response out of headers and into the body, we've created issues for ourselves around doubling CDATA blocks, which are illegal according to the w3c police.  Even if you do the ']]]]&gt;' trick, you will still have problems with some browsers.  It's still somewhat tricky.</p>

<h4>JSON Response</h4>
<p>JSON offers the same capabilities as using XML, being extremely flexible in representing different bits of data, but there's one major problem-- double encoding JSON.  If we are trying to create a solution that accomodates all response types, who's to say that one of the responses isn't already JSON, and if we re-encode as JSON, we could end up with unusable garbage in the response.</p>
<pre><code>{
    id:543,
    state:'REALLY+LONG+STRING',
    encode: {
        'table':'....',
        'cartSpan':'....',
        'footerTotal':'....'
    },
    body: '....'
}</code></pre>

<h4>VLSN Response</h4>
<p>If we choose XML or JSON, it seems we might clobber encoding by either doubling CDATA/entity markup or double escaping JavaScript.  So lets try to take those strategies out and just take the simplest approach of producing one <b>V</b>ery <b>L</b>ong <b>S</b>tring <b>N</b>otation!</p>

<p>Instead of trying to demarcate within a single body (XML, JSON), we just write everything out in one continuous String, noting when each chunk starts and stops in a separate table.  This table can then be stored as a much smaller Response Header or as the first line of the response body.</p>

<pre><code>{id:[0,3],state:[4,4503],encode:{'table':[4504,6004],'cartSpan':[6005,6240],'footerTotal':[6241,6733]},body:[6734,7320]}
340XHHUERe+JeKljfaefe.....</code></pre>

<p>Now you don't have to worry about encoding at all, you just take everything written as is!</p>]]>

</content>
</entry>
<entry>
<title>Facelets 1.1.12 Uploaded</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2006/12/facelets_1112_u.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2006-12-02T06:12:21Z</issued>
<id>tag:weblogs.java.net,2006:/blog/jhook/272.6077</id>
<created>2006-12-02T06:12:21Z</created>
<summary type="text/plain">Just tested/uploaded another release of Facelets with many small bug fixes for JSF 1.1 and JSF 1.2.</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>Facelets 1.1.12 was just uploaded to Java.net and includes many small bug fixes for JSF 1.1 (MyFaces 1.1.4) and JSF 1.2 (RI 1.2_03b5).</p>
<p style="font-size: 20px;"><a href="https://facelets.dev.java.net/files/documents/3448/44872/facelets-1.1.12.zip">Download Here</a></p>
<p>This release is considered 'draft' until users call it stable for production use.  More information is found over at <a href="https://facelets.dev.java.net">Facelets' web site</a>.</p>
<p>Please give it a whirl and post any issues to the tracker or dev/user lists so we can push for another stable release!</p>
]]>

</content>
</entry>
<entry>
<title>Extending EL Syntax</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2006/11/extending_el_sy.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2006-11-27T10:08:55Z</issued>
<id>tag:weblogs.java.net,2006:/blog/jhook/272.6037</id>
<created>2006-11-27T10:08:55Z</created>
<summary type="text/plain">Continuing on the EL testing, I started to extend the EL parser for the new EL-API within JSR 245 (JSP 2.1).  I&apos;ve added things like method invocation and simple projections.</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>I've been working a bit on extending EL, but found that the API is missing a few features desired to fully make the language pluggable by third parties.</p>
<p>First is method invocations.  Caching reflected data is so difficult to do without causing some kind of memory leak.  I really wish JSE had some kind of ClassLoader listener API as a safer alternative to statically scoped data in web containers.  Maybe others have more experience in this area?  Anyways, performance of method invocation is pretty fast, it takes the same time to do <code>a.b</code> as to do <code>a.getB()</code>-- averaging 0.0016 ms on my laptop for both.</p>
<p>To be safe, I did add some logic for finding the best match if there are multiple methods with the same name.  Tis better than nothing :-)</p>
<p>The more important addition is projections: <code>a.{x|x.b}</code> which means iterate over the Collection (a), for each, get (b).</p>
<p>Projections are useful in the presentation tier for binding sets of properties instead of requiring two parts: items="#{a}" var="v", value="#{v.b}".  Actually, it may be more performant with the equivalent projection if you were to do: items="#{a.{x|x.b}}" var="v", value="#{v}".  Anyways, there's a subtle difference in my implementation of projections as opposed to others.</p>
<p>Here's our model: A company has many departments, which have many employees.  If I wanted to generate a list of employee names, I would do something like this:</p>
<p><code>#{company.departments.{x|x.employees}.{x|x.name}}</code></p>
<p>The OGNL equivalent is a little lighter in syntax:</p>
<p><code>company.departments.{employees.{name}}</code></p>
<p>..but produces a List of a List of Strings:</p>
<p><code>[['Bob','John','Sally'],['Jason','Marge','Kelly']]</code></p>
<p>That's not what we wanted!  With the EL implementation, you instead get:</p>
<p><code>['Bob','John','Sally','Jason','Marge','Kelly']</code></p>
<p>Which seems more correct to me.  The main reason is that EL is supposed to represent pointers to instances, so if I take the pointer (ValueExpression) and call the setValue on it-- I would expect that my target (each employee's name) would be set.  So why would I return a List of Lists then?</p>
<p>Another cool feature of projections under the EL-API is the use of MethodExpressions.  MethodExpressions work perfectly for hooking into Framework APIs as JSF has with generic actions, validators, etc.  So lets say your backing model had a collection of Validators, but you didn't want to express each one separately?</p>
<p><code>&lt;h:inputText value="#{bean.name}" validator="#{bean.validators.{x|x.validate}}"/></code></p>
<p>What I'd really like to see added to the EL-API though is pluggable type conversion and method invocation.  Right now you can plug in your own property resolution, but the strange thing is that if you take the expression #{a.b} as a value, you can customize the resolution of (b), but if you take it as a method, then you cannot customize the resolution of (b), so the method must always exist on that instance in accordance with the EL implementation's rules.</p>
<p>To correct these two missing pieces, I would like to see two methods added to the ELResolver API which allow near everything to be customized with:</p>
<p><code>public Object convertType(ELContext ctx, Object in, Class type)</code></p>
<p><code>public Object invoke(ELContext ctx, Object base, Object method, Object[] params)</code></p>
<p><code>public MethodInfo getMethodInfo(ELContext ctx, Object base, Object method, Object[] params)</code></p>
<p>The execution of these methods would work the same as the other ELResolver methods, requiring the propertyResolved to be set to 'true'.  It'd be great then to allow customized extensions of Iterable/Collections/Maps such that one could do:</p>
<p><code>#{company.departments.asc{x|x.employees.{x|x.name}}}</code></p>
<p>Which would call into the ELResolver chain with the following:</p>
<p><code>public Object invoke(ctx, Collection, "asc", new Object[] { closure })</code></p>
<p>This would allow you to treat closures as value-types for some pretty extreme customization with mixing your own Java code into the execution of 'inlined' EL without requiring full API changes within the JSE.</p>
<p>Basically, these are just some future ideas for EL, whenever it becomes it's own JSR.  With Facelets and custom EL-API implementations, such as this one, you can just set one property on the compiler and away you go with the added features.</p>
<p>(I have to start releasing stuff again)</p>

]]>

</content>
</entry>
<entry>
<title>Trying out NetBeans 5.5</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2006/11/trying_out_netb.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2006-11-26T22:49:14Z</issued>
<id>tag:weblogs.java.net,2006:/blog/jhook/272.6034</id>
<created>2006-11-26T22:49:14Z</created>
<summary type="text/plain">I decided to give NetBeans a try and I found myself fumbling through some features.</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>I use Eclipse both at home and at work, but finally decided to give NetBeans a spin.  Overall, the IDE is solid, but some of the features seem too 'literal'.  For lack of a better word, let me use an example instead.  When I'm writing test cases, I'll constantly comment and uncomment lines.  Instead of providing <b>one</b> comment toggle control, NetBeans has two different ones:</p>
<ul>
<li>ctrl+shift+T to comment</li>
<li>ctrl+shift+D to uncomment</li>
</ul>
<p>Two things: does T and D have anything to do with the noun 'comment', and why isn't the IDE smart enough to do this with one command?  Consequently, running the comment command multiple times will keep on adding more '//' to the beginning of your lines.  Great.</p>

<p>Hotkeys aside, I'll always try to right click to find associated features.  This is fairly confusing in NetBeans for common tasks such as implementing abstract methods or generating bean accessors.  When you are writing APIs and deal with inner classes, this only adds additional confusion with the IDE.</p>

<p>Right-clicking on a Class, under the Refactor sub-menu, you are presented with a list of options for all Java types-- including: Extract Method and Change Method Parameter types-- what does that have to do with a Class declaration?  Feel free to pick these options, but you will be presented with an error.</p>

<p>If I'm declaring a new class, or add an additional abstract method, why can't I right-click and implement those methods.  Yes, the option is on the top menu, under 'Source', but I'm concerned with the context of my cursor in the code-- may it be a method or class file, not 'mousing' away from it to the top menu under 'Source'.</p>

<p>Finally, many of the options around refactoring are always forced into a review dialog before committing the changes.  If I want to generate getters and setters, and select the fields I want, why always force me to review in a second dialog?  I've gotten caught off guard so many times because that bottom pane has everything loaded into it for output, junit results, etc.  Clicking on 'next' in the pop-up dialogs, closes the dialog, then adds yet another tabbed panel to the bottom with the next step to confirm what I just said I wanted to do.  It seems unecessary and should be an optional flow-- and even if I wanted confirmation, why close the dialog and put the next step in another panel?</p>

<p>Overall, NetBeans isn't bad.  It's just not as intuitive as others I've used.  It's still never obvious to me with what classes have errors and which ones don't without hitting the recompile button.</p>]]>

</content>
</entry>
<entry>
<title>EL Comparisons</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/jhook/archive/2006/11/el_comparisons_1.html" />
<modified>2008-02-13T18:06:09Z</modified>
<issued>2006-11-16T20:28:26Z</issued>
<id>tag:weblogs.java.net,2006:/blog/jhook/272.5972</id>
<created>2006-11-16T20:28:26Z</created>
<summary type="text/plain">Based on some recent posts on different EL libraries and performance comparisons, I decided to run my own.</summary>
<author>
<name>jhook</name>

<email>jacob@hookom.net</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/jhook/">
<![CDATA[<p>Updated 11/17/2006 with JEXL and upgraded MVEL and added Serialized size</p>

<p>I decided to test the following EL libraries available today:</p>

<ul>
<li><b>Commons EL</b> (<a href="http://jakarta.apache.org/commons/el/">http://jakarta.apache.org/commons/el/</a>)<br/>Implementation of the JSP EL API that's existed forever.  This library can be found in many JSP containers (Tomcat for example) or used as a foundation for within many vendor's J2EE servers. </li>
<li><b>OGNL</b> (<a href="http://www.ognl.org/">http://www.ognl.org/</a>)<br/>One of the most expressive ELs available today and widely used with WebWork (Struts 2) and Tapestry.</li>
<li><b>MVEL</b> (<a href="http://wiki.mvflex.org/index.php?title=MVFLEX_Expression_Language">http://wiki.mvflex.org/index.php?title=MVFLEX_Expression_Language</a>)<br/>A newcomer to EL which is part of the MVFlex/Valhalla project.  Features look more in line with OGNL's offering with method invocation and some interesting regular expression support.</li>
<li><b>EL-API</b> (<a href="http://jcp.org/en/jsr/detail?id=245">http://jcp.org/en/jsr/detail?id=245</a>)<br/>Sun's reference implementation of the new EL-API which is part of JEE 5 and available with Glassfish.  Syntax features are basically the same as the EL from JSP, but with additinal API features.</li>
<li><b>JEXL</b> (<a href="http://jakarta.apache.org/commons/jexl/">http://jakarta.apache.org/commons/jexl/</a>)<br/>An implementation based on Velocity's parser.  Because of this, it acts more like a limited templating solution with things like method invocation.</li>
</ul>

<p>Here's a table of features I thought were pertinent:</p>

<table border="1" cellspacing="0">
<thead>
<tr>
<td>Library</td>
<td>A.B Accessors</td>
<td>Math</td>
<td>Method Invocation</td>
<td>Projections</td>
<td>Regular Expressions</td>
<td>Coercion</td>
<td>Conversion</td>
<td>Pluggable Property Resolution</td>
<td>Pluggable Method Resolution</td>
<td>Serializable</td>
<td>Factory Caching</td>
</tr>
</thead>
<tbody>
<tr>
<td>Commons-EL</td>
<td>Yes</td>
<td>Yes</td>
<td>No (functions)</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td>OGNL</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<td>MVEL</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>?</td>
<td>No</td>
</tr>
<tr>
<td>EL-RI</td>
<td>Yes</td>
<td>Yes</td>
<td>No (functions)</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>JEXL</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
</tbody>
</table>

<p>Pretty obvious things that stand out are that OGNL and MVEL have a lot more syntax features compared to the standardized EL.  I think this is largely impart to the fact that EL was only intended for simple notation within the View counterparts and not as a scripting language.  I will say that there's absolutely no reason why these other syntax features shouldn't be added to future releases.</p>

<p>Pertaining to pluggability of syntax evaluation, OGNL is the most expressive with Method, Property, Index, etc. The new EL-API has similar capabilities for Property and Index Accessors with chainable ELResolvers.</p>

<p>*Factory Cached means the API's factory method inherently cache expressions to some degree and do not re-parse on every call.</p>

<p>API Use:</p>

<b>Commons-EL</b>
<pre><code>ExpressionFactory fact = new ExpressionFactoryImpl();
VariableResolver vars = new VariableResolverImpl(..);
Expression expr = fact.parseExpression(str, Object.class, null);
Object value = expr.evaluate(vars);</code></pre>

<b>OGNL</b>
<pre><code>Map vars = new HashMap();
Object expr = Ognl.parseExpression(str);
Object valu = Ognl.getValue(expr, vars);</code></pre>

<b>MVEL</b>
<pre><code>Map vars = new HashMap();
Object value = Interpreter.eval(str, vars);</code></pre>

<b>EL-RI</b>
<pre><code>ExpressionFactory fact = new ExpressionFactoryImpl();
ELContext ctx = new ELContext(...);
ValueExpression ve = fact.createValueExpression(ctx, str);
Object value = ve.getValue(ctx);</code></pre>

<b>JEXL</b>
<pre><code>Expression e = ExpressionFactory.createExpression( jexlExp );
JexlContext jc = JexlHelper.createContext();
Object value = e.evaluate(jc);
</code></pre>

<p>Finally, I have some performance numbers at 10,000 iteration, average time in milliseconds:</p>

<table border="1" cellspacing="0">
<thead>
<tr>
<td>Library</td>
<td>test.fubar != null</td>
<td>test.num + 10 - 1</td>
</tr>
<thead>
<tbody>
<tr>
<td>Commons-EL</td>
<td>0.00249</td>
<td>0.00343</td>
</tr>
<tr>
<td>OGNL</td>
<td>0.20751</td>
<td>0.23535</td>
</tr>
<tr>
<td>MVEL</td>
<td>0.02032</td>
<td>0.03775</td>
</tr>
<tr>
<td>EL-RI</td>
<td>0.00714</td>
<td>0.00715</td>
</tr>
<tr>
<td>JEXL</td>
<td>0.34199</td>
<td>0.21907</td>
</tr>
<tr>
<td>Commons-EL (re-use)</td>
<td>0.00597</td>
<td>0.01462</td>
</tr>
<tr>
<td>OGNL (re-use)</td>
<td>0.00342</td>
<td>0.00712</td>
</tr>
<tr>
<td>EL-RI (re-use)</td>
<td>0.00394</td>
<td>0.00767</td>
</tr>
<tr>
<td>JEXL (re-use)</td>
<td>0.04946</td>
<td>0.01123</td>
</tr>
</tbody>
</table>

<p>*re-use means take the Expression returned from the factory and keep evaluating that instance instead of going back to the factory again.  This didn't show much of a difference for those EL libraries that cache within their factories, but it did show a big improvement with OGNL and JEXL.</p>

<p>Serialization can be important for some libraries and the EL-RI was optimized for use with JSF's state-saving architecture.  I'm sure other frameworks may have similar concerns.  Here are the sizes in bytes for the couple libraries that were actually Serializable.</p>

<table border="1" cellspacing="0">
<thead>
<tr>
<td>Library</td>
<td>test.fubar != null</td>
<td>test.num + 10 - 1</td>
</tr>
</thead>
<tbody>
<tr>
<td>OGNL</td>
<td>594</td>
<td>764</td>
</tr>
<tr>
<td>EL-RI</td>
<td>170</td>
<td>169</td>
</tr>
</tbody>
</table>
<p>Synchronization was another thing I wanted to test, but haven't yet.  Supposedly OGNL has some unwanted synchronization blocks and JEXL has not been optimized at the Factory level at all-- putting a synchronization block around expression creation, with calls to commons-logging.</p>

<p>In summary, here's just my observations from an afternoon of testing.  While I'm not an expert on all of the libraries listed, feel free to comment on where I might have missed a point or gotten things wrong.</p>]]>

</content>
</entry>

</feed>