<?xml version="1.0" encoding="UTF-8"?>
<!--Generated by Squarespace Site Server v5.11.81 (http://www.squarespace.com/) on Wed, 30 May 2012 09:59:37 GMT--><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>Cliff Meyers</title><link>http://cliffmeyers.com/blog/</link><description>HTML5 and Javascript. Enterprise Java, Spring, Hibernate. Adobe Flex and AIR. Software development and technology.</description><lastBuildDate>Thu, 17 May 2012 16:45:55 +0000</lastBuildDate><copyright>Copyright 2012 Cliff Meyers. All Rights Reserved.</copyright><language>en-US</language><generator>Squarespace Site Server v5.11.81 (http://www.squarespace.com/)</generator><item><title>Integrating Sencha Touch and Hogan.js for Easy HTML Templating</title><category>HTML5</category><category>Hogan.js</category><category>Javascript</category><category>Mustache</category><category>Sencha Touch</category><dc:creator>cliffmeyers</dc:creator><pubDate>Thu, 29 Mar 2012 19:35:49 +0000</pubDate><link>http://cliffmeyers.com/blog/2012/3/29/integrating-sencha-touch-and-hoganjs-for-easy-html-templatin.html</link><guid isPermaLink="false">1362984:16032732:15643687</guid><description><![CDATA[<p>I've been working with Sencha Touch lately and I've been impressed with it so far. &nbsp;It's a really nice full-stack solution for HTML5 mobile web development. &nbsp;There was however a pain point I came across that I needed to solve.</p>

<p>Sencha Touch has a nice component called DataView that can dynamically render HTML based on a collection of data. With a DataView, you have the ability to specify a template ("itemTpl") which is a chunk of HTML rendered for each element in the Store. Unfortunately the framework only supports declaring this in Javascript, so you are left with some pretty nasty syntax:</p>

<script src="https://gist.github.com/95f379e9369275c61cf8.js"></script>

<p>Fortunately I was able to hack together a quick and dirty workaround for this based off <a href="http://twitter.github.com/hogan.js/">Hogan.js</a>, Twitter's Mustache-compatible HTML templating system. First I wrote a simple HTML template named <em>myTemplate.mustache:</em></p>

<script src="https://gist.github.com/a66271eaa5d350145920.js"></script>

<p>Then I used Hogan's "hulk" executable to compile the template to a Javascript file. If you have multiple templates, hulk will merge them into a single file. The template will be available in Hogan via its name, in this case "myTemplate". The output of the file isn't important nor is it very readable, so we'll skip that part.</p>

<p>Then I edited my main HTML file to include the Hogan library and my compiled templates:</p>

<script src="https://gist.github.com/39a6e888a875de34633f.js"></script>

<p>Next I wrote a subclass of Ext's XTemplate to serve as an adapter between their template API and Hogan's. I haven't tested this very thoroughly yet; there are likely a bunch of other methods that need overriding to get this solid:</p>

<script src="https://gist.github.com/6a7cb695ee1b107c3c53.js"></script>

<p>And then updated the original code snippet to use the following:</p>

<script src="https://gist.github.com/f7424df6a3f3c3ce13a3.js"></script>

<p>and presto, it just works :)</p>

<p>Adapting this for <a href="http://github.com/janl/mustache.js/">Mustache.js</a> should be straightforward provided they expose a similar API with a synchronous render() method.</p>
]]></description><wfw:commentRss>http://cliffmeyers.com/blog/rss-comments-entry-15643687.xml</wfw:commentRss></item><item><title>Why I finally ditched Hibernate native APIs for JPA</title><category>Hibernate</category><category>Java</category><category>Spring</category><dc:creator>cliffmeyers</dc:creator><pubDate>Mon, 18 Jul 2011 08:47:00 +0000</pubDate><link>http://cliffmeyers.com/blog/2011/7/18/why-i-finally-ditched-hibernate-native-apis-for-jpa.html</link><guid isPermaLink="false">1362984:16032732:15621918</guid><description><![CDATA[<p>If you&#39;re looking for the short answer, go check out the <a href="http://www.springsource.org/spring-data/jpa" target="_blank">Spring Data JPA</a> project. &#0160;This is an incredible product that offers a tremendous productivity boost for projects using JPA. &#0160;If you&#39;re interested in the more gory details, read on below :)</p>
<p>I&#39;ve been a Hibernate user since 2005 and have used JPA + Hibernate Annotations since 2006 when 1.0 of the JPA spec was released. &#0160;Unlike many others I did not immediately jump to the JPA APIs (EntityManager, PersistenceContext, etc) and continued using the&#0160;native Hibernate APIs (Session, SessionFactory, etc). &#0160;JPA was still missing quite a few useful features such as a Criteria API and I wasn&#39;t ready to give that up just to use a &quot;standard API.&quot; &#0160;When JPA 2.0 was released in late 2009 the feature sets of the two products were generally comparable making the decision a little tougher. &#0160;But since I&#39;ve never really bought into the &quot;vendor portability&quot; promise of JPA, I continued happily on with native Hibernate APIs to much success.</p>
<p>Over the past month or two, I&#39;ve come to the decision it&#39;s time to fully embrace JPA.</p>
<p>JPA has grown beyond its original purpose as an object-relational mapping framework into a more generic persistence API. &#0160;NoSQL / data grid solutions have become incredibly important and popular over the past few years. &#0160;Several JPA-based implemenations for these solutions have already been developed, including Google App Engine / Big Table and Hibernate&#39;s own Object/Grid Mapper (OGM). &#0160;I started to experiment with GAE about a month ago and was surprised how quickly I could be productive with its JPA implementation. &#0160;While JPA likely isn&#39;t the best fit for the diverse range of NoSQL implementations out there, the ease of use for JPA developers is undeniable.</p>
<p>While industry trends are important, I&#39;ve finally found the killer app for JPA: the <a href="http://www.springsource.org/spring-data/jpa" target="_blank">Spring Data JPA</a> project. &#0160;At its core, SDJ is about generating JPQL at runtime so you don&#39;t have to write tedious queries. &#0160;Some of the awesome features include:</p>
<ul>
<li>Out-of-the-box support for data pagination and sorting.</li>
<li>Query creation from method names. &#0160;Creating a method signature of findByEmailAddressAndLastName(String emailAddress, String lastName) creating a backing query that does exactly what you&#39;d expect.</li>
<li>Specification API to define and combine predicates in a manner similar to the Criteria API.</li>
</ul>
<p>Check out the <a href="http://static.springsource.org/spring-data/data-jpa/docs/current/reference/html/" target="_blank">reference documentation</a> for Spring Data JPA. &#0160;The project just dropped its first 1.0 release candidate. &#0160;I&#39;m excited to see what they&#39;ll come up with in future releases.</p>]]></description><wfw:commentRss>http://cliffmeyers.com/blog/rss-comments-entry-15621918.xml</wfw:commentRss></item><item><title>Starting with Git and github on Windows</title><category>Git</category><dc:creator>cliffmeyers</dc:creator><pubDate>Wed, 04 Aug 2010 01:04:53 +0000</pubDate><link>http://cliffmeyers.com/blog/2010/8/3/starting-with-git-and-github-on-windows.html</link><guid isPermaLink="false">1362984:16032732:15621929</guid><description><![CDATA[<p>My attempt at a very brief tutorial for starting with Git on Windows:</p>
<ol>
<li>Head over to <a href="http://github.com" target="_self">http://github.com</a> and create an account.</li>
<li>Create a new repository next. &#0160;Please remember that unless you pay for a github account, any repository you create will be PUBLIC. &#0160;After creating the project, keep the page open so you can refer to &quot;Next Steps&quot; later.</li>
<li>Download and install msysgit from&#0160;<a href="http://code.google.com/p/msysgit/downloads/list">http://code.google.com/p/msysgit/downloads/list</a>; look for a file in form of Git-version-date.exe with the &quot;Featured&quot;tag. &#0160;Use the installer&#39;s defaults.</li>
<li>Launch the &quot;Git Bash&quot; shell and setup your identity:
<ul>
<li>git config --global user.name &quot;Your Name&quot;</li>
</ul>
<ul>
<li>git config --global user.email &quot;username@email.com&quot;</li>
</ul>
</li>
<li>Next create a SSH key pair for yourself using the following command:<br />
<ul>
<li>ssh-keygen -C &quot;username@email.com&quot; -t rsa</li>
</ul>
</li>
<li>The file will be created at c:\Users\username\.ssh\﻿﻿id_rsa.pub; copy the contents of this file and return to github. &#0160;Click on &quot;Account Settings&quot; and then &quot;SSH Public Keys.&quot; &#0160;Add your key here by pasting the content into the provided text box. &#0160;<strong>Your local git installation and github accounts are now properly linked on this machine.</strong></li>
<li>Refer back to the &quot;Next Steps&quot; section mentioned earlier. &#0160;Open &quot;Git Bash&quot; and follow the steps to create a new project and push it to GitHub. &#0160;Your project is now ready. &#0160;<strong>You can write some useful code!</strong></li>
</ol>
<p>If you prefer to avoid the command line for Git operations, launch the &quot;Git GUI&quot; and follow these steps when you want to make a commit and push:</p>
<ol>
<li>Press the &quot;Rescan&quot; button to see your changes</li>
<li>Select the files you wish to commit from the list in the upper-left and choose &quot;Commit&quot; -&gt; &quot;Stage To Commit&quot;</li>
<li>Enter a commit message at the bottom of the screen and press &quot;Commit.&quot; &#0160;The changes are now saved in the local repository.</li>
<li>Click the &quot;Push&quot; button and examine the popup window. &#0160;Note that the &quot;Destination Repository&quot; is remote and named &quot;origin&quot;; this refers to the repo at github. &#0160;Click &quot;Push&quot; again to commit.</li>
<li><strong>Your changes are now committed to github.</strong> You can verify this by browsing to the project home page.</li>
</ol>
<p>I hope others find this tutorial useful. &#0160;A more detailed tutorial can be found here:&#0160;<a href="http://kylecordes.com/2008/git-windows-go">http://kylecordes.com/2008/git-windows-go</a></p>]]></description><wfw:commentRss>http://cliffmeyers.com/blog/rss-comments-entry-15621929.xml</wfw:commentRss></item><item><title>HFCD for Flash Builder: Build Your Flex App 2-3x Faster</title><category>Flex</category><category>Java</category><category>Tools</category><dc:creator>cliffmeyers</dc:creator><pubDate>Sat, 14 Nov 2009 00:49:26 +0000</pubDate><link>http://cliffmeyers.com/blog/2009/11/13/hfcd-for-flash-builder-build-your-flex-app-2-3x-faster.html</link><guid isPermaLink="false">1362984:16032732:15621931</guid><description><![CDATA[<p><a href="http://stopcoding.wordpress.com" target="_blank">HFCD</a> is an extension for Flash/Flex Builder that delegates compilation of your Flex application to a&#0160;special&#0160;&quot;compiler daemon&quot; which can run locally or on a remote machine. &#0160;The goal of the project is simple: faster builds! &#0160;HFCD is the brainchild of <a href="http://stopcoding.wordpress.com/about/" target="_blank">Clement Wong</a>, the former compiler engineering lead on the Flex SDK team. &#0160;Here are a few useful things to understand about HFCD:</p><p></p><ul>
<li>HF installs as a Flex Builder plugin which will delegate compilation to a separate OS-level process running either locally or on a remote machine.</li>
<li>The compiler daemon process is persistent, meaning it continues to run across multiple builds. &#0160;This allows the Java virtual machine to optimize compilation execution each time that a build is run. &#0160;The JVM is *very* good at this.</li>
<li>The Flex Builder plugin watches for file modifications and immediately pushes these changes to the compiler daemon process. &#0160;The daemon has an internal representation of the project&#0160;file system and will launch internal incremental builds automatically when files change.</li>
</ul>
<p>So, how fast is it really? &#0160;I benchmarked HFCD on two different machines. &#0160;I used the Flex 3.4.1 SDK for compilation and ran clean builds of my application each time. &#0160;My test project was a real-world Flex app currently in development consisting of about 15 modules and 350 MXML files and ActionScript classes.</p><p>2006 Intel Macbook Pro, Core Duo 2.16 GHz, 2 GB RAM, 7200 RPM HD, Leopard 10.5, 32-bit Java 5</p><p></p><ul>
<li>Stock: 135 seconds average</li>
<li>HFCD (1st run): 155 seconds</li>
<li>HFCD (successive): 75 seconds average</li>
</ul>
<p></p><p>Intel Core i7 920 @ 3.2 GHz, HT off, 12 GB RAM, dual 7200 RPM HD&#39;s in RAID 0, Vista 64-bit, 32-bit Java 6</p><p></p><ul>
<li>Stock: 65 seconds average</li>
<li>HFCD (1st run): 52 seconds</li>
<li>HCFD (successive): 21 seconds average (!!!)</li>
</ul>
<p>As indicated in the documentation, the performance of HFCD increases dramatically after the first build due to the numerous&#0160;optimizations&#0160;in HellFire and the JVM itself. &#0160;The Macbook was nearly 2x faster while the Windows box was just over 3x faster. &#0160;Very impressive and a real time saver!</p><p>I hope to post some new benchmarks soon. &#0160;I need to do some more research to get HFCD running on a 64-bit JVM as that isn&#39;t supported out of the box. &#0160;Also I&#39;d like to configure my Macbook to delegate the compilation to my Windows box, especially to ascertain what kind impact the network topology has on build performance.</p><p></p><p></p>]]></description><wfw:commentRss>http://cliffmeyers.com/blog/rss-comments-entry-15621931.xml</wfw:commentRss></item><item><title>Subversive install for Eclipse has finally improved!</title><category>Eclipse</category><category>Subversion</category><dc:creator>cliffmeyers</dc:creator><pubDate>Sat, 17 Oct 2009 17:01:43 +0000</pubDate><link>http://cliffmeyers.com/blog/2009/10/17/subversive-install-for-eclipse-has-finally-improved.html</link><guid isPermaLink="false">1362984:16032732:15621932</guid><description><![CDATA[<p>About a year ago the <a href="http://www.eclipse.org/subversive/">Subversive</a> plugin moved into the Eclipse foundation and became the &quot;official&quot; SVN provider plugin for the platform. Unfortunately due to a licensing issue popular SVN connectors such as JavaHL and SVNKit cannot be shipped with the Eclipse IDE, so a fully-functional SVN Team Provider can&#39;t currently (and may never?) ship with Eclipse. The steps required previous to install and get Subversive working were pretty tedious in the past, so I&#39;m happy to report that recently this experience has been greatly improved! There are now only two very straightforward steps to get Subversive running:</p><p>Launch the Eclipse plugin installer dialog and select &quot;Subversive SVN Team Provider.&quot;</p><p>

<a href="http://s3.media.squarespace.com/production/1362984/16032732/.a/6a00d83549daf569e20120a647a385970c-pi" style="display: inline;"><img alt="Install_subversive_svn_provider" border="0" class="asset asset-image at-xid-6a00d83549daf569e20120a647a385970c image-full " src="http://s3.media.squarespace.com/production/1362984/16032732/.a/6a00d83549daf569e20120a647a385970c-800wi" title="Install_subversive_svn_provider" /></a></p>

<p>After installation, restart the workbench.&#0160; Then open the &quot;SVN Repository Explorer&quot; perspective.&#0160; The following dialog will be displayed automatically:</p>

<p><a href="http://s3.media.squarespace.com/production/1362984/16032732/.a/6a00d83549daf569e20120a5f09df8970b-pi" style="display: inline;"><img alt="Install_svn_connectors" border="0" class="asset asset-image at-xid-6a00d83549daf569e20120a5f09df8970b image-full " src="http://s3.media.squarespace.com/production/1362984/16032732/.a/6a00d83549daf569e20120a5f09df8970b-800wi" title="Install_svn_connectors" /></a></p><p>Choose a SVN connector (I typically use the latest SVNKit), click Finish, restart the workbench one more time and you&#39;re ready to go.&#0160; Hopefully the licensing issues will be resolved eventually so that Eclipse can ship with the Subversive SVN Team Provider by default but at least in the mean time the installation&#39;s been made pretty painless.</p>
]]></description><wfw:commentRss>http://cliffmeyers.com/blog/rss-comments-entry-15621932.xml</wfw:commentRss></item><item><title>Mixing and Matching Spring JdbcTemplate and HibernateTemplate</title><category>Hibernate</category><category>Java</category><category>Spring</category><dc:creator>cliffmeyers</dc:creator><pubDate>Wed, 17 Dec 2008 17:39:19 +0000</pubDate><link>http://cliffmeyers.com/blog/2008/12/17/mixing-and-matching-spring-jdbctemplate-and-hibernatetemplat.html</link><guid isPermaLink="false">1362984:16032732:15621934</guid><description><![CDATA[<p>The JdbcTemplate and HibernateTemplate convenience classes from Spring really make working with the respective APIs a breeze.  Unfortunately getting both of these classes to work together within a single Transaction is not straightforward.  This comes up very frequently in JUnit tests where you want to verify Hibernate is working with the database in the way you expect, either by inserting data and letting Hibernate load it or by checking to see that Hibernate creates the data you expect.  The same will hold true in application code where you need to add JDBC code alongside Hibernate code to meet various requirements.  The testing scenarios are simple and illustrative so let's explore those.</p>

<p>One common use case is to persist an object with HibernateTemplate and then verify the data was inserted correctly using JdbcTemplate.  Usually Hibernate will not flush the data out to the DB until the transaction commits, meaning that the query done by JdbcTemplate won't be able to see the new data.  This one isn't hard to work around: just call HibernateTemplate.flush() to execute the SQL on demand so that subsequent calls to JdbcTemplate will see the new data.</p>

<p>The second use case is a lot tricker: let's say you want to create some data with JdbcTemplate and then make sure that calls to HibernateTemplate will see that data.  By default this will not work.  You can actually insert with JdbcTemplate, make a call to load the data with HibernateTemplate (it won't find it) and then make another call to JdbcTemplate which will show that the data is there.  The problem is that since JdbcTemplate is injected with a DataSource it doesn't really have any knowledge of the transactions from HibernateTransactionManager; thus operations from the two templates are isolated from one another.</p>

<p>Fortunately Spring offers a solution in the TransactionAwareDataSourceProxy class.  Just like the name imples, this class acts as a wrapper for an existing DataSource so that all collaborators will participate in Spring-managed transactions.  Configuration of this class is trivial:</p>

<pre><code>&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy"&gt;
&lt;property name="targetDataSource"&gt;
&lt;bean class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt;
...
&lt;/bean&gt;
&lt;/property&gt;
&lt;/bean&gt;
</code></pre>

<p>Note: you may or may not want to define the "real" DataSource as an inner bean that doesn't get registered in the ApplicationContext itself.  If you are autowiring your DataSource purely by type, having two different implementations of DataSource will be a problem for you.  Workarounds include autowiring using @Qualifier or using @Resource to inject the bean by name.</p>

]]></description><wfw:commentRss>http://cliffmeyers.com/blog/rss-comments-entry-15621934.xml</wfw:commentRss></item><item><title>On Hibernate, Spring, Sessions and Transactions</title><category>Hibernate</category><category>Java</category><category>Spring</category><dc:creator>cliffmeyers</dc:creator><pubDate>Wed, 03 Dec 2008 22:54:46 +0000</pubDate><link>http://cliffmeyers.com/blog/2008/12/3/on-hibernate-spring-sessions-and-transactions.html</link><guid isPermaLink="false">1362984:16032732:15621935</guid><description><![CDATA[<p>I was recently working with Spring and Hibernate on a pet project and ran into some issues with Session and Transaction management that proved to be pretty interesting in the end.  The following assumes a working knowledge of Hibernate and Spring...</p>

<p>I was in the midst of writing some JUnit 4.x tests using SpringJUnit4ClassRunner and the @TransactionalConfiguration / @Transactional annotations for automatic rollback of @Test methods.  I wanted to do some manipulation of the database prior to my tests using a separate method annotated with @Before.  What I was reminded of very quickly is that Spring's class runner will not apply a transactional aspect to this method since it's not actually a @Test.  This isn't a problem if you are using HibernateTemplate / HibernateCallback, since it ultimately has a reference back to your TransactionManager to handle transactions.  But if you want to work with the raw Hibernate APIs it can be problematic.</p>

<p>There are two things to keep in mind: (1) SessionFactory.getCurrentSession() will only work if you have configured the SessionFactory appropriately, and (2) depending on the configuration, you may have to manage Transactions explicitly.  The configuration property in question is "hibernate.current_session_context_class" and it is commonly configured one of three different ways:</p>

<p><strong>1. Omitted the property from the configuration</strong></p>

<p>Hibernate will throw an exception on calls to getCurrentSession() complaining that there is no CurrentSessionContext configured.</p>

<p><strong>2. Configured with 'thread'</strong></p>

<pre><code>hibernate.current_session_context_class=thread
</code></pre>

<p>Hibernate will bind the Session returned from getCurrentSession() to the current thread and you must manage transactions programmatically.  Generally all that's required is to call Session.beginTransaction().  You can also invoke Transaction.commit() or rollback() if you wish.</p>

<p><strong>3. Configured with SpringSessionContext</strong></p>

<pre><code>hibernate.current_session_context_class=org.springframework.orm.hibernate3.SpringSessionContext
</code></pre>

<p>Hibernate will assume it is executing inside of a Spring transactional context (i.e. through a Spring transactional aspect) and Spring will now manage your transaction for you.  However if you call getCurrentSession() outside of such a context, Hibernate will throw an exception complaining that no Session is bound to the thread.</p>

<p>What does all this mean?</p>

<ol>
<li>Use SpringSessionContext if your operations will be done through classes that are invoked through a Spring-managed transactional context or if you can introduce HibernateTemplate and/or HibernateCallback wherever you need it.</li>
<li>Use "thread" if you need to raw with the raw Hibernate Session/Transaction API and remember that you'll need to manage transactions programmatically.</li>
</ol>]]></description><wfw:commentRss>http://cliffmeyers.com/blog/rss-comments-entry-15621935.xml</wfw:commentRss></item><item><title>Book Review: The Definitive Guide to Terracotta</title><category>Books</category><category>Java</category><dc:creator>cliffmeyers</dc:creator><pubDate>Mon, 13 Oct 2008 11:36:10 +0000</pubDate><link>http://cliffmeyers.com/blog/2008/10/13/book-review-the-definitive-guide-to-terracotta.html</link><guid isPermaLink="false">1362984:16032732:15621936</guid><description><![CDATA[<p>Terracotta is a “transparent clustering technology” that allows you to make data structures available across a cluster of machines in a highly-scalable and robust manner.  Unlike many other clustering solutions (including the very popular memcached), it doesn’t expose an API that a developer leverages to push data structures in and out of a big distributed container.  Rather, it’s a library that’s boot-strapped into your JVM while the behavior is driven by an XML config file.  This allows for sharing data in the fields of a class across the cluster as well as synchronized access to objects, just like in any multithreaded application.  Terracotta is able to do this through some very interesting decoration of bytecode as Java classes are loaded into the JVM. What this ultimately allows for is something like a large shared memory heap shared by all JVMs which can survive JVM crashes since all data is also written to disk.  Additionally, since Terracotta doesn’t use a peer-to-peer approach of data replication, it’s easier to achieve linear scalability.</p>

<p>Sound interesting?  Learn more at the <a href="http://www.terracotta.org">Terracotta web site</a>.</p>

<p>This is an excellent book.  The prose is well-written and engaging and the book flows very well from section to section.  There are massive amounts of Java code and configuration such that you very rarely have to picture anything in your mind, you can just read it there on the page.  There are helpful diagrams where appropriate.  It’s unlikely that a reader with a good understanding of Java will become confused at any point during the book.  It’s informative and provides some excellent examples of real world use, including especially chapters on integration with things like like Spring, Hibernate, session replication and more.  There is also an extensive chapter on using Terracotta to create a Master/Worker compute grid.  If you’re looking to learn more about Terracotta I really can’t recommend this book enough: it helped fill so many gaps that I had after skimming some of the documentation and reading a few of the white papers.</p>

<p>The only real negative is that the book is slow to get started.  The first two chapters (~40 pages) serve as an introduction and history to the technology respectively but taken together, it’s just a very lengthy introduction that rehashes a lot of the same concepts.  Maybe this was tedious for me given that I’d already read a lot of documentation on Terracotta but it just seemed like the intro could have been a bit shorter.</p>

<p>I’ll now run down the other chapters in the book and detail some that I found particularly interesting.</p>

<p>Chapter 3 is a quick jump into the framework and some tooling while Chapter 4 gets into the nitty-gritty details of POJO clustering.  This is important to read to understand how Terracotta does what it does.  Chapter 5 talks about how to do caching and this is where you start to understand the real world problems that can be solved using the tool.  Your database will thank you!</p>

<p>Chapter 6 is where it gets really interesting.  Here you will learn how to use Terracotta as a 2nd-level cache provider for Hibernate to significantly boost performance over using something like Ehcache .  More startling than that is a proposed architecture where the notion of POJO clustering is used to effectively put data structures that hold detached objects (those not attached to an active Hibernate Session).  You are shown how to change application code that uses the Hibernate API in a “typical” fashion to achieve performance increases measured in orders of magnitude.  This is truly an eye-opener.</p>

<p>Chapter 7 shows you how to cluster HTTP Sessions and how you can be freed from some of the annoying restrictions of the Servlet container Session API, such as implementing Serializable and religiously using setAttribute(). ; This is the sort of thing you can plug into an existing application very quickly and realize enormous scalability gains.</p>

<p>Chapter 8 is about clustering Spring beans.  Spring and Terracotta follow a very similar philosophy in that they are non-invasive frameworks.  As such, they compliment each other very nicely.  This chapter shows how easy it is to cluster Spring beans: even easier perhaps than clustering POJOs as in Chapter 4.  At this point, if you are a user of Spring and Hibernate, you’re starting to see how easy it can be to achieve seriously scalability and performance improvements.</p>

<p>Chapter 9 talks about Terracotta Integration Modules which is a sort of package that provides additional features to the Terracotta core: this is how integration with Hibernate and Spring are achieved.  Chapter 10 gives an extended treatment of thread coordination, showing how well-written multithreaded code can be used with Terracotta to achieve thread coordination across multiple JVMs.  Chapter 11 takes this further to detail the Master/Worker pattern for computing grids.  Chapter 12 rounds things out by showing the visualization tools that can be used to monitor and debug an app using Terracotta.</p>

<p>As I said before, this is a great book.  If you’re interesting in scaling out enterprise Java applications, you owe it to yourself to check out Terracotta and this book.</p>

]]></description><wfw:commentRss>http://cliffmeyers.com/blog/rss-comments-entry-15621936.xml</wfw:commentRss></item><item><title>ActionScript Annoyances (Part 1): Limitations on Default Parameter Values</title><category>Flex</category><dc:creator>cliffmeyers</dc:creator><pubDate>Fri, 29 Aug 2008 16:49:33 +0000</pubDate><link>http://cliffmeyers.com/blog/2008/8/29/actionscript-annoyances-part-1-limitations-on-default-parame.html</link><guid isPermaLink="false">1362984:16032732:15621919</guid><description><![CDATA[<p>Every time I encounter something in AS3 that annoys me, I'm going to compel myself to blog about it, with the hope that it will filter through the Internet ethos to the desk of some of the Flash Player engineers in San Francisco.</p>

<h2>Can't use static constants as default values for function parameters</h2>

<p>Example:</p>

<pre><code>public class PropertyType {
public static const LISTING_RESIDENTIAL : String = "ListingResidential";
...
}

public function createSearch(propertyType : String = PropertyType.LISTING_RESIDENTIAL) : void {
...
}
</code></pre>

<p>Results in this compiler error:</p>

<blockquote>
<p>1047: Parameter initializer unknown or is not a compile-time constant.</p>
</blockquote>

<p>Of course the bigger complaint here might be that there are no enumerated types in ActionScript... but that's probably asking too much. :)</p>

]]></description><wfw:commentRss>http://cliffmeyers.com/blog/rss-comments-entry-15621919.xml</wfw:commentRss></item><item><title>Integrating Blaze Data Services and Spring Security</title><category>Flex</category><category>Java</category><category>Spring</category><dc:creator>cliffmeyers</dc:creator><pubDate>Sun, 22 Jun 2008 00:09:51 +0000</pubDate><link>http://cliffmeyers.com/blog/2008/6/22/integrating-blaze-data-services-and-spring-security.html</link><guid isPermaLink="false">1362984:16032732:15621920</guid><description><![CDATA[<p>One thing to keep in mind with the out-of-the-box security support in Blaze DS is the approach to integration is container-specific: there is support for Tomcat (and therefore JBoss), WebSphere, Weblogic and Oracle through various implementations of the LoginCommand interface. Unfortunately if you have custom security requirements for authentication that means you're dealing with a lot of cumbersome, container-specific security configuration and/or writing and configuring JAAS plugins. The authorization support in Blaze DS is limited to specifying which roles have access to a particular destination which isn't nearly flexible enough.</p>

<p>Fortunately Spring Security provides solutions to many common problems in Java EE space, including features like container portability, a flexible authentication provider model, authorization of service method invocation via AOP and even some very cool ACL support to enforce granular security at the domain object level. Integrating Spring Security with Blaze DS isn't as hard as you think either: I was able to bang out a quick proof of concept over a weekend.</p>

<p>The config for Spring Security 2 is quite straightforward with the new XML namespace support in your Spring config files:</p>

<pre><code>&lt;security:http&gt;
&lt;security:form-login&gt;
&lt;/security:form-login&gt;
</code></pre>

<p>This is basically a very stripped-down configuration since things like RememberMeServices (using cookies) don't usually apply in a Flex-based RIA. You can also throw in a very simple AuthenticationProvider like this one from the SS2 docs:</p>

<pre><code>&lt;security:authentication-provider&gt;
&lt;security:user-service&gt;
&lt;security:user name="jimi" password="jimispassword" authorities="ROLE_USER, ROLE_ADMIN"/&gt;
&lt;security:user name="bob" password="bobspassword" authorities="ROLE_USER"/&gt;
&lt;/security:user-service&gt;
&lt;/security:authentication-provider&gt;
</code></pre>

<p>There are two items you need to add to your web.xml to bootstrap SS2 in a Servlet container:</p>

<pre><code>&lt;filter&gt;
&lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
&lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
&lt;/filter&gt;

&lt;filter&gt;
&lt;filter-name&gt;securityContextAwareFilter&lt;/filter-name&gt;
&lt;filter-class&gt;org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter&lt;/filter-class&gt;
&lt;/filter&gt;

&lt;filter-mapping&gt;
&lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
&lt;url-pattern&gt;/*&lt;/filter-mapping&gt;
&lt;/filter-mapping&gt;

&lt;filter-mapping&gt;
&lt;filter-name&gt;securityContextAwareFilter&lt;/filter-name&gt;
&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
&lt;/filter-mapping&gt;
</code></pre>

<p>The first filter is standard part of any Spring Security configuration. The "SecurityContextHolderAwareRequestFilter" adapts SS2 to the Servlet environment so that calls like getPrincipal() and isUserInRole() behave as expected. This really comes in handy when you have other code in your projects that assumes a "standard" Java security setup.</p>

<p>Now we need a little config in the Blaze services-config.xml file:</p>

<pre><code>&lt;security&gt;
&lt;login-command class="net.histos.util.spring.SpringSecurityLoginCommand" server="Tomcat"/&gt;
&lt;security-constraint id="valid-user"&gt;
&lt;auth-method&gt;Custom&lt;/auth-method&gt;
&lt;roles&gt;
&lt;role&gt;ROLE_USER&lt;/role&gt;
&lt;/roles&gt;
&lt;/security-constraint&gt;
&lt;/security&gt;
</code></pre>

<p>Blaze DS seems to require that a "server" attribute be specified for any LoginCommand even though this isn't really used in our implementation. The security-constraint isn't necessary if you are going to use SS2's service method invocation authorization support. However if your security requirements are more straightforward you can do role/destination based restrictions here. Then simply add this element to the appropriate destinations:</p>

<pre><code>&lt;security&gt;
&lt;security-constraint ref="valid-user"/&gt;
&lt;/security&gt;
</code></pre>

<p>The last part is some Java code. If you extend AppServerCommand you get a default impl for this method:</p>

<pre><code>protected boolean doAuthorization(Principal principal, List roles, HttpServletRequest request) throws SecurityException
</code></pre>

<p>This method makes use of isUserInRole(), so by adding the servlet filter referred to above, this logic can work without any modification required. This leaves only two methods in your LoginCommand impl:</p>

<pre><code>public Principal doAuthentication(String username, Object credentials) {
log.debug("doAuthentication");
// get the ProviderManager from app context
Map&lt;string, providermanager=""&gt; map = getContext().getBeansOfType(ProviderManager.class);
if (map.size() != 1)
throw new RuntimeException("Spring ApplicationContext must contain exactly one ProviderManager bean");
ProviderManager provider = map.get( map.keySet().iterator().next() );
// authenticate
String password = extractPassword(credentials);
Authentication auth = provider.authenticate( new UsernamePasswordAuthenticationToken(username, password) );
SecurityContextHolder.getContext().setAuthentication(auth);
return auth;
}

public boolean logout(Principal principal) {
log.debug("logout");
SecurityContextHolder.getContext().setAuthentication(null);
return true;
}
</code></pre>

<p>Those are the basics! As I said, this a proof of concept that I haven't had time to test extensively yet but it should get you started! One other note: I noticed while testing the Flex side that calling login() or logout() on a RemoteObject without calling a "regular" service method would result an error; apparently the ChannelSet hadn't been defined yet. I did a little digging and found that apparently you're supposed to call login() or logout() on the underlying ChannelSet itself. I wrote a very simple ChannelSet implementation that can be easily instantiated in MXML and bound as the channelSet property for your RemoteObjects:</p>

<pre><code>package net.histos.flex.util
{
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;

public class SimpleChannelSet extends ChannelSet
{
public function set url(channelUrl : String) : void {
addChannel(new AMFChannel("defaultChannel", channelUrl));
}
}
}

&lt;util:SimpleChannelSet id="channelSet" url="http://localhost:8080/testapp/messagebroker/amf"/&gt;
</code></pre>

<p>Then simply invoke login() and logout() on the ChannelSet itself and you should have no problems.</p>

]]></description><wfw:commentRss>http://cliffmeyers.com/blog/rss-comments-entry-15621920.xml</wfw:commentRss></item></channel></rss>
