<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-17720202</id><updated>2008-06-30T13:40:56.128-04:00</updated><title type='text'>organic thoughts</title><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default?start-index=26&amp;max-results=25'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>29</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-17720202.post-8531529616968357905</id><published>2008-06-30T13:22:00.002-04:00</published><updated>2008-06-30T13:40:56.160-04:00</updated><title type='text'>Official Groovy/Grails Support in NetBeans 6.5</title><content type='html'>Judging from the list of features that will be included in NetBeans 6.5, &lt;a style="font-weight: bold;" href="http://wiki.netbeans.org/NewAndNoteWorthyMilestone1NB65#section-NewAndNoteWorthyMilestone1NB65-Groovy"&gt;Groovy and Grails will be officially supported&lt;/a&gt; by the NB team.  From the wiki text, Groovy and Grails will be first-class citizen in NB65 with features that will include:&lt;br /&gt;- Editor support (code completion, color highlights, etc)&lt;br /&gt;- Two-way Java / Groovy class integration&lt;br /&gt;- Seamless Grail project support (support for all Grails artifacts and commands)&lt;br /&gt;- Jetty integration for development-time deployment/testing.&lt;br /&gt;&lt;br /&gt;It remains to be seen if NB65 Groovy support will be as comprehensive as IntelliJ which currently has the most extensive support for Groovy / Grails development.&lt;br /&gt;&lt;br /&gt;For more, go to:&lt;br /&gt;&lt;a href="http://wiki.netbeans.org/NewAndNoteWorthyMilestone1NB65#section-NewAndNoteWorthyMilestone1NB65-Groovy"&gt;http://wiki.netbeans.org/NewAndNoteWorthyMilestone1NB65#section-NewAndNoteWorthyMilestone1NB65-Groovy&lt;/a&gt;</content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2008/06/official-groovygrails-support-in.html' title='Official Groovy/Grails Support in NetBeans 6.5'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/8531529616968357905'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/8531529616968357905'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-2469913930383037885</id><published>2008-05-09T18:19:00.002-04:00</published><updated>2008-05-09T18:25:13.514-04:00</updated><title type='text'>JavaOne 2008 - Last Day Notables</title><content type='html'>The last day of JavaOne 2008 was heralded by the final General Session where Sun showcased several cool projects.  Here are a few you maybe interested in.  Some are useful others just plain cool:&lt;br /&gt;&lt;br /&gt;1. VisualVM - This is a great (and seems to be indispensable) tool to do VM runtime monitoring and profiling.  It runs outside of the an IDE and lets you look deep into the VM and your runninig application at runtime.  The profiler is the same that is found in NetBeans and provides a hierarchical navigation and snapshot of all activities of a running application.  Check it out at &lt;a href="https://visualvm.dev.java.net/" target="_blank"&gt;https://visualvm.dev.java.net/&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;2. NetBeans 6.1 JavaScript Support - if you do a lot of JavaScript, then the NetBeans is for you.  In the demo shown on stage, Netbeans manages to make JavaScript development as well-supported as regular Java.  The IDE provides Javadoc-like support, code completion, data structure navigation, on-the-fly documentation, even code hints, etc, etc.  While other IDE such as Intellij has had support for JavaScript for a while, this is the first glimpse of it on the NetBeans platform.&lt;br /&gt;&lt;br /&gt;3. LiveScribe (&lt;a href="http://livescribe.com/" target="_blank"&gt;http://livescribe.com&lt;/a&gt;) - this is not a developer tool, but rather a pen-base computing platform based on the Java Micro Edition.  It records pen stroke and voice as you write.  Describing it here does not do it justice, but the one demo that caught my attention was a translating demo where the presenter wrote words in one language and the pen automatically translates it into different language...&lt;br /&gt;&lt;br /&gt;4. Sentilla, Pervasive Computing Device: Sentilla sells small computing devices meant to be used in sensor networks.  Pervasive computing is the notion that everything around us will (some day) have a microchip.  Companies such as sells a platform to build and deploy these devices everywhere.&lt;br /&gt;&lt;br /&gt;5. JFugue, Music Processing Software - this open source software lets you programmatically build music players in Java.  It uses a simple text base language to describe music timing, rythm, notes, sound bank, etc.  With the JFugue API, you can create music in several ways including direct notation and pattern inference.</content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2008/05/javaone-2008-last-day-notables.html' title='JavaOne 2008 - Last Day Notables'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/2469913930383037885'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/2469913930383037885'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-6132890863651433802</id><published>2008-05-08T21:22:00.001-04:00</published><updated>2008-05-08T21:26:17.260-04:00</updated><title type='text'>Integrating Spring and JBoss SAR Components</title><content type='html'>            &lt;font id="to:20" size="4"&gt;&lt;b id="owr30"&gt;Integrating Spring and JBoss SAR Components&lt;/b&gt;&lt;/font&gt;&lt;br id="qbzy0"&gt;          Last time I wrote about JBoss, it was a discussion on how to create a JBoss service component (SAR).  However, in many cases, a SAR component has to be integrated with other component-based technologies.  In this article, I will discuss how to accomplish this by integrating the JBoss with the Spring component model and how to expose Spring components to receive management services from within JBoss JMX Console.&lt;br id="qbzy1"&gt; &lt;br id="qbzy2"&gt; &lt;font id="ls170" size="4"&gt;&lt;b id="owr31"&gt;Integration&lt;/b&gt;&lt;/font&gt;&lt;br id="qbzy3"&gt;          The architecture and implementation of the &lt;span id="onxa0"&gt;&lt;b id="k5ka0"&gt;JBoss service component system differ vastly from the Spring Framework&lt;/b&gt;&lt;/span&gt;'s component model.  &lt;span id="onxa1"&gt;&lt;b id="k5ka1"&gt;JBoss &lt;/b&gt;&lt;/span&gt;(version 4.x and below) &lt;span id="p6xm0"&gt;&lt;b id="k5ka2"&gt;implements its internal kernel&lt;/b&gt;&lt;/span&gt;, for its component container, &lt;span id="p6xm1"&gt;&lt;b id="k5ka3"&gt;completely on the &lt;/b&gt;&lt;/span&gt;&lt;a title="Wikipedia - Java Management Exension" target="_blank" href="http://en.wikipedia.org/wiki/Java_Management_Extensions" id="vom2"&gt;&lt;b id="k5ka4"&gt;Java Management Extension API&lt;/b&gt;&lt;/a&gt;.  As such, when you build a &lt;span id="j3_i0"&gt;&lt;b id="k5ka5"&gt;JBoss components&lt;/b&gt;&lt;/span&gt;, you automatically &lt;span id="j3_i1"&gt;&lt;b id="k5ka6"&gt;inherits all the management facilities exposed by JMX&lt;/b&gt;&lt;/span&gt;.  The &lt;span id="j3_i2"&gt;&lt;b id="k5ka7"&gt;Spring &lt;/b&gt;&lt;/span&gt;container, on the other hand, is &lt;span id="d6yq0"&gt;&lt;b id="k5ka8"&gt;designed &lt;/b&gt;&lt;/span&gt;to be &lt;span id="d6yq1"&gt;&lt;b id="k5ka9"&gt;a lightweight and portable container &lt;/b&gt;&lt;/span&gt;and has the ability to host &lt;a target="_blank" title="POJO on Wikipedia" href="http://en.wikipedia.org/wiki/POJO" id="o8ds"&gt;POJO's&lt;/a&gt; as components.  Therefore, &lt;span id="mb9u0"&gt;&lt;b id="k5ka10"&gt;Spring has become the container of choice&lt;/b&gt;&lt;/span&gt; for many system designers because of its simplicity and portability to be hosted in any environment.&lt;br id="c4dc0"&gt; &lt;br id="qbzy4"&gt; &lt;img id="c-q50" style="width: 496px; height: 323px;" src="http://docs.google.com/File?id=df3qdpw5_83r987gwf6_b"&gt;&lt;br id="ftz60"&gt; &lt;div id="w6pa" style="padding: 1em 0pt; text-align: left;"&gt;As you can see, &lt;span id="r3-v0"&gt;&lt;b id="k5ka11"&gt;integrating Spring&lt;/b&gt;&lt;/span&gt; in another container r&lt;span id="r3-v1"&gt;&lt;b id="k5ka12"&gt;equires some sort of adapter&lt;/b&gt;&lt;/span&gt; that controls how and when the Spring context is created and destroyed.  As we will see later in this document, this can be easily accomplished using a few API calls.&lt;br id="ftz62"&gt; &lt;/div&gt; &lt;font id="ls171" size="3"&gt;&lt;b id="owr32"&gt;Motivation&lt;/b&gt;&lt;/font&gt;&lt;br id="qbzy6"&gt; &lt;span id="ju880"&gt;&lt;b id="owr33"&gt;Why would I want to integrate Spring and JBoss you ask?&lt;/b&gt;&lt;/span&gt; Well, there is an application domain that is not suited to be implemented as web-based apps.  Inevitably, at some point in your career, you will need to implement headless services that expose functionalities without a GUI.  These type of &lt;span id="z5nc0"&gt;&lt;b id="owr34"&gt;services &lt;/b&gt;&lt;/span&gt;are &lt;span id="z5nc1"&gt;&lt;b id="owr35"&gt;temporally durable&lt;/b&gt;&lt;/span&gt; and operate without any human intervention.  When creating these types of &lt;span id="zowh0"&gt;&lt;b id="owr36"&gt;GUI-less services&lt;/b&gt;&lt;/span&gt;, you may decide to use the Spring container as your core operating environment for  POJO components.  Since Spring exposes a uniform abstraction layer for the Enterprise Java API's,  it makes sense to code around Spring so that your implementation is portable to any environment that can host enterprise services (JBoss container, ServiceMix, Mule, EJB's, etc).  Then, your Spring components can leverage services offered by that enterprise environment (database, timers, messaging, adapters, management, etc). &lt;br id="lvrv0"&gt; &lt;br id="lvrv1"&gt; &lt;font id="hpr40" size="3"&gt;&lt;b id="owr37"&gt;Integration Point&lt;/b&gt;&lt;/font&gt;s&lt;br id="qbzy14"&gt;           The portability and programmability of the Spring container makes it an attractive platform for developers to create POJO component-driven apps.  For web-based apps, Spring provides ready-made adapters to easily integrate your Spring context within the servlet container.  However, for &lt;span id="zowh1"&gt;&lt;b id="owr38"&gt;non-web system&lt;/b&gt;&lt;/span&gt;, &lt;span id="aurk0"&gt;&lt;b id="owr39"&gt;Spring does not readily provide specific hooks for integration&lt;/b&gt;&lt;/span&gt; (this is a good thing, it keeps things simple). On the other hand, the Spring API exposes a simple API that makes programming the integration, of Spring in your environment, a seamless effort.  &lt;br id="lywe0"&gt; &lt;br id="l2nt0"&gt; &lt;div id="k:1x" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img style="height: 371px; width: 707px;" id="izu50" src="http://docs.google.com/File?id=df3qdpw5_843wsfrrgw_b"&gt;&lt;/div&gt;          The picture above shows how &lt;span id="mq.v0"&gt;&lt;b id="k5ka13"&gt;Spring integration with the JBoss Application Server can be easily achieved&lt;/b&gt;&lt;/span&gt;.  You &lt;span id="xhnb0"&gt;&lt;b id="owr310"&gt;create a JBoss service component that serves as an adapter&lt;/b&gt;&lt;/span&gt; to the Spring container.  As the JBoss &lt;span id="h-kw0"&gt;&lt;b id="owr311"&gt;service object receives lifecycle events&lt;/b&gt; from the application server&lt;/span&gt;, event-handling logic can be inserted in the adapter to control the creation and management of the Spring context.  &lt;span id="g75d0"&gt;&lt;b id="k5ka14"&gt;Once booted&lt;/b&gt;&lt;/span&gt; and running, the &lt;span id="g75d1"&gt;&lt;b id="k5ka15"&gt;Spring container takes over and mounts its internal POJO components&lt;/b&gt;&lt;/span&gt; and registers them with the available &lt;span id="g75d2"&gt;&lt;b id="k5ka16"&gt;MBean Server&lt;/b&gt;&lt;/span&gt; for management.&lt;br id="qbzy9"&gt;           &lt;br id="qbzy10"&gt; &lt;font id="liwb0" size="4"&gt;&lt;b id="owr312"&gt;The Spring Directory Scanner&lt;/b&gt;&lt;/font&gt;&lt;br id="qbzy11"&gt;          Extending on the example presented in the &lt;a title="Creating A JBoss Service Archive" target="_blank" href="http://vladimirvivien.com/blogs/ot/2007/01/this-write-up-provides-look-into-jboss.html" id="l0jt"&gt;&lt;b id="k5ka17"&gt;previous blog on JBoss components&lt;/b&gt;&lt;/a&gt;,  this example demonstrates how to create a &lt;span id="hq6d0"&gt;&lt;b id="k5ka18"&gt;Spring-based directory scanner&lt;/b&gt;&lt;/span&gt; that gets hosted within the JBoss application container.  The &lt;span id="wz6a0"&gt;&lt;b id="k5ka19"&gt;previous example&lt;/b&gt;&lt;/span&gt;, all of the &lt;span id="wz6a1"&gt;&lt;b id="k5ka20"&gt;logic of the scanner was implemented directly into the JBoss&lt;/b&gt;&lt;/span&gt; service component.  While there's nothing wrong with that approach, &lt;span id="wz6a2"&gt;&lt;b id="k5ka21"&gt;it tightly couples your code with JBoss&lt;/b&gt;&lt;/span&gt; and make it far less portable.  In &lt;span id="wz_g0"&gt;&lt;b id="k5ka22"&gt;this version&lt;/b&gt;&lt;/span&gt; of the scanner, the &lt;span id="vbg20"&gt;&lt;b id="k5ka23"&gt;logic is encapsulated in POJO's hosted within a Spring&lt;/b&gt;&lt;/span&gt; context. &lt;br id="kjdr0"&gt; &lt;br id="kjdr1"&gt; &lt;div id="djsj" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img id="rnl20" style="width: 714px; height: 514px;" src="http://docs.google.com/File?id=df3qdpw5_85cxpgk396_b"&gt;&lt;/div&gt;     A &lt;span id="mjqq0"&gt;&lt;b id="v0_j0"&gt;JBoss service component serves as a Spring adapter&lt;/b&gt;&lt;/span&gt; and manages the creation and destruction of the Spring context from within the JBoss container.  The &lt;span id="mjqq1"&gt;&lt;b id="v0_j1"&gt;spring context is booted up by the JBoss service component&lt;/b&gt;&lt;/span&gt; through life cycle event hooks from the server.  Upon initialization, Spring mounts its POJO's and &lt;span id="g_jc0"&gt;&lt;b id="v0_j2"&gt;exposes the Directory Scanner&lt;/b&gt;&lt;/span&gt; component &lt;span id="g-vt0"&gt;&lt;b id="v0_j3"&gt;for runtime management and control through JMX&lt;/b&gt;&lt;/span&gt;.  Using the &lt;a title="About JConsole" target="_blank" href="http://openjdk.java.net/tools/svc/jconsole/" id="jd-3"&gt;JConsole&lt;/a&gt; or JBoss' Jmx-Console, these components can be managed at runtime locally or remotely.&lt;br id="qbzy12"&gt; &lt;br id="g-vt1"&gt; &lt;font id="lg9g0" size="3"&gt;&lt;b id="v0_j4"&gt;  The Code&lt;/b&gt;&lt;/font&gt;&lt;br id="o01c0"&gt;          The code itself is simple and self explanatory.  The JBoss service component responds to JBoss application server's life cycle events.  These events are used to manage the creation and management of the Spring context.  The &lt;span id="hedl0"&gt;&lt;b id="a5yp0"&gt;Directory Scanner &lt;/b&gt;&lt;/span&gt;Spring component is driven by a Timer Task object mounted in Spring.  Every time the timer expires, it executes the scan() method on the Directory Scanner instance.&lt;br id="e1vk0"&gt; &lt;font id="azkt0" size="3"&gt;&lt;br id="t8540"&gt; &lt;/font&gt;&lt;font id="jm9d0" size="3"&gt;&lt;span id="lg9g1"&gt;&lt;b id="v0_j5"&gt;  The JBoss Service Spring Adapter&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;br id="t8541"&gt;          The JBoss service component is a a plain Java class with life cycle methods named create, destroy, start, stop.  It implements a management interface which exposes these methods for JMX control.  The component deployer will automatically execute methods create() then start() upon instantiation of the service component.&lt;br id="ke.t0"&gt; &lt;br id="ke.t1"&gt; &lt;br id="ke.t2"&gt; &lt;div id="mg8n0"&gt; &lt;table id="sj3j" border="1" bordercolor="#000000" cellpadding="3" cellspacing="0"&gt;&lt;tbody id="mg8n1"&gt; &lt;tr id="mg8n2"&gt; &lt;td id="mg8n3" width="100%"&gt;&lt;code id="cv1w0"&gt; public &lt;span id="cv1w1"&gt;&lt;b id="v0_j6"&gt;interface JBossSpringAdapterMBean &lt;/b&gt;&lt;/span&gt;{&lt;br id="mg8n4"&gt;            void create();&lt;br id="mg8n5"&gt;            void destroy();&lt;br id="mg8n6"&gt;            long getErrorCount();&lt;br id="mg8n7"&gt;            long getSpringComponentCount();&lt;br id="mg8n8"&gt;            String[] getSpringComponents();&lt;br id="mg8n9"&gt;            String getSpringConfigPath();&lt;br id="mg8n10"&gt;            boolean isSpringLoaded();&lt;br id="mg8n11"&gt;            boolean isStarted();&lt;br id="mg8n12"&gt;            void setSpringConfigPath(String path);&lt;br id="mg8n13"&gt;            void start() throws Exception;&lt;br id="mg8n14"&gt;            void stop();&lt;br id="mg8n15"&gt;        } &lt;/code&gt;&lt;br id="mg8n16"&gt; &lt;br id="mg8n17"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;br id="qbzy16"&gt;      Besides the life cycle methods, there are other management methods that are added for convenience. For instance, there's a method that returns the error count or one that returns the list components loaded in the spring context. &lt;br id="rs1p0"&gt; &lt;br id="klk_0"&gt;       During the &lt;span id="rcah0"&gt;&lt;b id="lu8_0"&gt;deployment of the JBoss Spring adapter&lt;/b&gt;&lt;/span&gt; (implemented as JBoss service component), the &lt;span id="a40j0"&gt;&lt;b id="lu8_1"&gt;create()&lt;/b&gt;&lt;/span&gt;, &lt;span id="a40j1"&gt;&lt;b id="lu8_2"&gt;destroy()&lt;/b&gt;&lt;/span&gt;, and &lt;span id="a40j2"&gt;&lt;b id="lu8_3"&gt;start() methods&lt;/b&gt;&lt;/span&gt; of the adapter &lt;span id="fs1u0"&gt;&lt;b id="lu8_4"&gt;will be invoked&lt;/b&gt;&lt;/span&gt;&lt;span id="ppct0"&gt;&lt;b id="lu8_5"&gt; by&lt;/b&gt;&lt;/span&gt; the&lt;span id="ppct1"&gt;&lt;b id="lu8_6"&gt; JBoss service archive deployer&lt;/b&gt;&lt;/span&gt;.  This provides an opportunity to instantiate and manage the Spring context at key points during the lifetime of the adapter.  &lt;br id="t0zc2"&gt; &lt;br id="t0zc3" style="font-weight: bold;"&gt; &lt;span id="t0zc4"&gt;&lt;b id="lu8_7"&gt;Booting Spring&lt;/b&gt;&lt;/span&gt;&lt;br id="t0zc5"&gt;    The &lt;span id="eb2j0"&gt;&lt;b id="v0_j8"&gt;create&lt;/b&gt;&lt;/span&gt;() method is called &lt;span id="qr9t0"&gt;&lt;b id="lu8_8"&gt;after&lt;/b&gt;&lt;/span&gt; all the &lt;span id="qr9t1"&gt;&lt;b id="lu8_9"&gt;setters&lt;/b&gt;&lt;/span&gt; are injected with values from the JBoss service descriptor.&lt;br id="gfeg0"&gt; &lt;br id="gfeg1"&gt; &lt;div id="t3gd0"&gt; &lt;table id="au9y" border="1" bordercolor="#333333" cellpadding="3" cellspacing="0"&gt;&lt;tbody id="t3gd1"&gt; &lt;tr id="t3gd2"&gt; &lt;td id="t3gd3" width="100%"&gt;&lt;code id="e.5y0"&gt;public &lt;span id="te0l0"&gt;&lt;b id="lu8_10"&gt;class JBossSpringAdapter&lt;/b&gt;&lt;/span&gt; implements &lt;span id="te0l1"&gt;&lt;b id="lu8_11"&gt;JBossSpringAdapterMBean&lt;/b&gt;&lt;/span&gt; {&lt;br id="q3th0"&gt;     private ClassPathXmlApplicationContext &lt;span id="ktnp1"&gt;&lt;b id="v0_j9"&gt;spring&lt;/b&gt;&lt;/span&gt;; &lt;br id="ktnp2"&gt; &lt;br id="q3th1"&gt; ...   &lt;br id="t3gd4"&gt; &lt;br id="q3th2"&gt;     public void &lt;span id="e.5y1"&gt;&lt;b id="v0_j10"&gt;create&lt;/b&gt;&lt;/span&gt;(){&lt;br id="t3gd5"&gt;              log.info("**** CYCLE: CREATE ****");&lt;br id="t3gd6"&gt;              if(!created){&lt;br id="t3gd7"&gt;                  try{&lt;br id="t3gd8"&gt;                      &lt;span id="ktnp3"&gt;&lt;b id="v0_j11"&gt;spring &lt;/b&gt;&lt;/span&gt;= new &lt;span id="ktnp4"&gt;&lt;b id="v0_j12"&gt;ClassPathXmlApplicationContext&lt;/b&gt;&lt;/span&gt;(&lt;span id="eb2j1"&gt;&lt;b id="v0_j13"&gt;springConfigPath&lt;/b&gt;&lt;/span&gt;);&lt;br id="t3gd9"&gt;                      &lt;span id="eb2j2"&gt;&lt;b id="v0_j14"&gt;spring&lt;/b&gt;&lt;/span&gt;.&lt;span id="eb2j3"&gt;&lt;b id="v0_j15"&gt;registerShutdownHook&lt;/b&gt;&lt;/span&gt;();&lt;br id="t3gd10"&gt;                      created  = true;&lt;br id="t3gd11"&gt;                  }catch(Exception ex){&lt;br id="t3gd12"&gt;                      errorCount++;&lt;br id="t3gd13"&gt;                      created=false;&lt;br id="t3gd14"&gt;                      log.error("Unable to start Spring Context", ex);&lt;br id="t3gd15"&gt;                  }&lt;br id="t3gd16"&gt;              }&lt;br id="t3gd17"&gt;          }&lt;br id="q3th3"&gt; &lt;br id="t3gd18"&gt;      ...&lt;br id="t3gd19"&gt; &lt;/code&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;br id="hhvj0"&gt;     The &lt;span id="y4.60"&gt;&lt;b id="v0_j16"&gt;create() method is used to instantiate the Spring context&lt;/b&gt;&lt;/span&gt;.  In the code snippet, the path to the &lt;span id="gtom0"&gt;&lt;b id="lu8_12"&gt;Spring context is injected during deployment&lt;/b&gt;&lt;/span&gt; from the deployment descriptor using the &lt;span id="gtom1"&gt;&lt;b id="lu8_13"&gt;setSpringConfigPath()&lt;/b&gt;&lt;/span&gt; method.  The &lt;span id="gtom2"&gt;&lt;b id="lu8_14"&gt;registerShutdownHook()&lt;/b&gt;&lt;/span&gt; method registers Spring to listens to VM shutdown signal so the context can properly deactivate all of its registered components.&lt;br id="w.vn0"&gt; &lt;br id="tooj0"&gt; &lt;span id="cs8o0"&gt;&lt;b id="lu8_15"&gt;  Shutting Down the Context&lt;/b&gt;&lt;/span&gt;&lt;br id="tooj1"&gt;    On the other hand, when your JBoss adapter class receives a shutdown signal (say, the server is shutting down for instance), you wan to have your Spring context gracefully go down as well. By providing a destroy() method, the JBoss deployer invoke that method when the server sends out a shutdown signal.&lt;br id="kn:n0"&gt; &lt;br id="kn:n1"&gt; &lt;div id="ccsm0"&gt; &lt;table id="zimi" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0"&gt;&lt;tbody id="ccsm1"&gt; &lt;tr id="ccsm2"&gt; &lt;td id="ccsm3" width="100%"&gt;&lt;code id="yl9k0"&gt;    public void &lt;span id="yl9k1"&gt;&lt;b id="lu8_16"&gt;destroy&lt;/b&gt;&lt;/span&gt;() {&lt;br id="w.v20"&gt;            log.info("**** CYCLE: DESTROY ****");&lt;br id="w.v21"&gt;            if(created){&lt;br id="w.v22"&gt;                try{&lt;br id="w.v23"&gt;                    stop();&lt;br id="w.v24"&gt;                    if(spring.isActive()){&lt;br id="w.v25"&gt;                        spring.&lt;span id="yl9k2"&gt;&lt;b id="lu8_17"&gt;close&lt;/b&gt;&lt;/span&gt;();&lt;br id="w.v26"&gt;                      &amp;amp;nbsp; spring.&lt;span id="yl9k3"&gt;&lt;b id="lu8_18"&gt;destroy&lt;/b&gt;&lt;/span&gt;();&lt;br id="w.v27"&gt;                        spring = null;&lt;br id="w.v28"&gt;                    }&lt;br id="w.v29"&gt;                    created = false;&lt;br id="w.v210"&gt;                }catch(Throwable ex){&lt;br id="w.v211"&gt;                    log.error(" Failed to destroy component. ", ex);&lt;br id="w.v212"&gt;                }&lt;br id="w.v213"&gt;            }&lt;br id="w.v214"&gt;        }&lt;/code&gt;&lt;br id="w.v215"&gt; &lt;br id="ccsm4"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;br id="w.v216"&gt; &lt;span id="en5c0"&gt;&lt;b id="lu8_19"&gt;    Controlling the Spring Context&lt;/b&gt;&lt;/span&gt;&lt;br id="qd-s0"&gt;  Another desirable aspect of the adapter is the ability to &lt;span id="ymp70"&gt;&lt;b id="a5yp1"&gt;c&lt;/b&gt;&lt;/span&gt;&lt;span id="l4vt0"&gt;&lt;b id="lu8_20"&gt;ontrol the Spring context with a start / stop functionality&lt;/b&gt;&lt;/span&gt;.  While it is not a necessary, it affords a runtime convenience where the Spring context can be controlled and managed from a JMX console.&lt;br id="w.v217"&gt; &lt;/div&gt; &lt;br id="n1lz0"&gt; &lt;div id="b8l:0"&gt; &lt;table id="av4k" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0"&gt;&lt;tbody id="b8l:1"&gt; &lt;tr id="b8l:2"&gt; &lt;td id="b8l:3" width="100%"&gt;&lt;code id="bmas0"&gt;...&lt;br id="c8yt0"&gt;      public void &lt;span id="w-:y0"&gt;&lt;b id="lu8_21"&gt;start&lt;/b&gt;&lt;/span&gt;() throws Exception {&lt;br id="c8yt1"&gt;          log.info("**** CYCLE: START ****");&lt;br id="c8yt2"&gt;          if(!started){&lt;br id="c8yt3"&gt;              try{&lt;br id="c8yt4"&gt;                  if(!spring.isActive()){&lt;br id="c8yt5"&gt;                      spring.refresh();&lt;br id="c8yt6"&gt;                      spring.start();&lt;br id="c8yt7"&gt;                  }&lt;br id="c8yt8"&gt;                  started = true;&lt;br id="c8yt9"&gt;                  log.info("**** Spring context started OK.****");&lt;br id="c8yt10"&gt;              }catch(Throwable ex){&lt;br id="c8yt11"&gt;                  errorCount++;&lt;br id="c8yt12"&gt;                  started = false;&lt;br id="c8yt13"&gt;                  log.error("**** Failed to start Spring context:", ex);&lt;br id="c8yt14"&gt;              }&lt;br id="c8yt15"&gt;          }&lt;br id="c8yt16"&gt;      }&lt;br id="mvtk0"&gt; &lt;br id="c8yt17"&gt;  ...&lt;br id="c8yt18"&gt; &lt;br id="mvtk1"&gt;      public void &lt;span id="c1o00"&gt;&lt;b id="lu8_22"&gt;stop&lt;/b&gt;&lt;/span&gt;() {&lt;br id="mvtk2"&gt;          log.info("**** CYCLE: STOP ****");&lt;br id="mvtk3"&gt;          if(started){&lt;br id="mvtk4"&gt;              try{&lt;br id="mvtk5"&gt;                  spring.close();&lt;br id="mvtk6"&gt;                  started = false;&lt;br id="mvtk7"&gt;              log.info("**** Spring context stopped OK.****");&lt;br id="mvtk8"&gt;              }catch(Throwable ex){&lt;br id="mvtk9"&gt;                  errorCount++;&lt;br id="mvtk10"&gt;                  started = false;&lt;br id="mvtk11"&gt;                  log.error("**** Failed to stop Spring context:", ex);&lt;br id="mvtk12"&gt;              }&lt;br id="mvtk13"&gt;          }&lt;br id="mvtk14"&gt;      }&lt;br id="mvtk15"&gt; &lt;br id="mvtk16"&gt;  ...&lt;/code&gt;&lt;br id="b8l:4"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;br id="qxn70"&gt; &lt;span id="ui_50"&gt;&lt;b id="lu8_23"&gt;The JBoss Service Component Descriptor&lt;/b&gt;&lt;/span&gt;&lt;br id="pt2g0"&gt; The last part of creating the JBoss Spring Adapter, is to create a JBoss Service Descriptor file (jboss-service.xml).  Using this file, you can inject runtime values, and point to a descriptive &lt;span id="enf40"&gt;&lt;b id="lu8_24"&gt;xmbean descriptor file &lt;/b&gt;&lt;/span&gt;that is used to export your service archive component as an JMX MBean.&lt;br id="zng-0"&gt; &lt;br id="zng-1"&gt; &lt;div id="x_tp0"&gt; &lt;table id="nx_t" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" height="152" width="574"&gt;&lt;tbody id="x_tp1"&gt; &lt;tr id="x_tp2"&gt; &lt;td id="x_tp3" width="100%"&gt;&amp;lt;?&lt;span id="rjm_0"&gt;&lt;b id="lu8_25"&gt;xml &lt;/b&gt;&lt;/span&gt;version="1.0" encoding="UTF-8"?&amp;gt;&lt;br id="rjm_1"&gt; &amp;lt;&lt;span id="rjm_2"&gt;&lt;b id="lu8_26"&gt;server&lt;/b&gt;&lt;/span&gt;&amp;gt;&lt;br id="rjm_3"&gt;     &amp;lt;&lt;span id="rjm_4"&gt;&lt;b id="lu8_27"&gt;mbean &lt;/b&gt;&lt;/span&gt;code="integration.jboss.JBossSpringAdapter" &lt;br id="rjm_5"&gt;            name="demo.integration:name=JBossSpringAdapter,type=Adapter"&lt;br id="rjm_6"&gt;            &lt;span id="rjm_7"&gt;&lt;b id="lu8_28"&gt;xmbean-dd&lt;/b&gt;&lt;/span&gt;="META-INF/spring-adapter-xmbean.xml"&amp;gt;&lt;br id="rjm_8"&gt;         &amp;lt;attribute name="&lt;span id="d40x0"&gt;&lt;b id="z6vp0"&gt;SpringConfigPath&lt;/b&gt;&lt;/span&gt;"&amp;gt;/META-INF/spring.xml&amp;lt;/attribute&amp;gt;&lt;br id="rjm_9"&gt;     &amp;lt;/&lt;span id="rjm_10"&gt;&lt;b id="lu8_29"&gt;mbean&lt;/b&gt;&lt;/span&gt;&amp;gt;&lt;br id="rjm_11"&gt; &amp;lt;/server&amp;gt;&lt;br id="x_tp4"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;br id="rk9s0"&gt; For details about creating a JBoss service component and how to format jboss-service.xml and the Xmbean descriptor file, visit the &lt;a title="See how to create a JBoss service archive" target="_blank" href="http://docs.jboss.org/jbossas/jboss4guide/r2/html/ch2.chapter.html#ch2.writembean.sect" id="pc-y"&gt;JBoss 4 User Guide&lt;/a&gt;.&lt;br id="rjm_13"&gt; &lt;/div&gt; &lt;br style="font-weight: bold;" id="ui_51"&gt; &lt;span id="rfd20"&gt;&lt;b id="lu8_30"&gt;Deploying the JBoss Spring Service Adapter&lt;/b&gt;&lt;/span&gt;&lt;br id="ui_52"&gt; Without going into the implementation of the Spring Directory Scanner component, let's see what happens when the JBoss service archive is deployed.  We expect the JBoss SAR deployer to recognize our JBoss Spring Adapter component as a valid JBoss service archive component and deploy it.  Once deployed, we can validate the deployment through the log and through the JMX Console.&lt;br id="b7qu0"&gt; &lt;br id="e3p20"&gt; &lt;span id="if.c0"&gt;&lt;b id="a5yp2"&gt;JBoss SAR Starting&lt;/b&gt;&lt;/span&gt;&lt;br id="b7qu1"&gt; &lt;div id="ofgv" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img id="w43b0" style="width: 534px; height: 108px;" src="http://docs.google.com/File?id=df3qdpw5_866wzt9rfk_b"&gt;&lt;/div&gt; During deployment, we see the &lt;span id="rfd21"&gt;&lt;b id="lu8_31"&gt;JBossSpringAdapter service component being deployed&lt;/b&gt;&lt;/span&gt; by the application server.  We can also see that the Spring context is being instantiated.&lt;br id="ffbg0"&gt; &lt;br id="e3p21"&gt; &lt;img id="rfd22" style="width: 436px; height: 413px;" src="http://docs.google.com/File?id=df3qdpw5_879qrj69c8_b"&gt;&lt;br id="plgm0"&gt; &lt;br id="plgm1"&gt; JBoss JMX Console shows &lt;span id="plgm2"&gt;&lt;b id="lu8_32"&gt;the JBoss service component JMX management interface&lt;/b&gt;&lt;/span&gt;.&lt;br id="plgm3"&gt; &lt;br id="plgm4"&gt; &lt;div id="b98a" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img id="d6uu0" style="width: 273px; height: 395px;" src="http://docs.google.com/File?id=df3qdpw5_884npxp3df_b"&gt;&lt;/div&gt; The JMX operations for the Spring service adapter are shown above. Notice that &lt;span id="nxk60"&gt;&lt;b id="a5yp3"&gt;you can start and stop the spring container &lt;/b&gt;&lt;/span&gt;at runtime.  That gives you the ability to conrol the lifescyle of your Spring container at runtime without redployment of the application  . This maybe useful if you want to make a configuration change in production without redeployment of the entire application.&lt;br id="u26x0"&gt; &lt;br id="pu8z0"&gt; &lt;font id="i7am0" size="3"&gt;&lt;b id="a5yp4"&gt;The Directory Scanner Spring Component&lt;/b&gt;&lt;/font&gt;&lt;br id="if.c1"&gt; The scanner is a simple Java object which uses the standard java.io.File package to get filtered list of files in a given directory.  You will notice that there are some annotations around the class.  These are Spring-specific annotations used to expose the Directory Scanner class as a managed JMX MBean (this is not covered in this writeup).  I also introduce an interface called Controllable for good form (not necessary).&lt;br id="zqhx0"&gt; &lt;br id="zqhx1"&gt; &lt;span id="iauh0"&gt;&lt;b id="a5yp5"&gt;The Controllable Interface&lt;/b&gt;&lt;/span&gt;&lt;br id="d8iu3"&gt; &lt;br id="d8iu4"&gt; &lt;div id="t10e1"&gt;&lt;/div&gt; &lt;div id="gm.-0"&gt; &lt;table id="vef4" border="1" bordercolor="#000000" cellpadding="3" cellspacing="0" height="104" width="273"&gt;&lt;tbody id="gm.-1"&gt; &lt;tr id="gm.-2"&gt; &lt;td id="gm.-3" width="100%"&gt;&lt;br id="gm.-4"&gt; &lt;code id="iauh1"&gt; public interface &lt;span id="h-ie0"&gt;&lt;b id="a5yp6"&gt;Controllable &lt;/b&gt;&lt;/span&gt;{&lt;br id="gm.-5"&gt;     public void start();&lt;br id="gm.-6"&gt;     public void stop();&lt;br id="gm.-7"&gt; }&lt;/code&gt;&lt;br id="gm.-8"&gt; &lt;br id="gm.-9"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;br id="wo5w0"&gt; This interface shows control points that can be implemented in the Directory Scanner.  This is not necessary, but added for completion.&lt;br id="iauh2"&gt; &lt;br id="iauh3"&gt; &lt;span id="x_810"&gt;&lt;b id="a5yp7"&gt;The Directory Scanner Class&lt;/b&gt;&lt;/span&gt;&lt;br id="iauh4"&gt; The class that implements the logic for scanning the directory is divided into three distinct sections&lt;br id="lfkt0"&gt; &lt;ul id="x_811"&gt; &lt;li id="x_812"&gt;The properties (getter/setters) for the component&lt;/li&gt; &lt;li id="x_813"&gt;The life cycle control methods&lt;/li&gt; &lt;li id="x_814"&gt;The scanning method which is invoked to do a sweep of a a directory&lt;/li&gt; &lt;/ul&gt; &lt;br id="r90w0"&gt; &lt;div id="gp0p0"&gt; &lt;table id="lxn3" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0"&gt;&lt;tbody id="gp0p1"&gt; &lt;tr id="gp0p2"&gt; &lt;td id="gp0p3" width="100%"&gt;&lt;code id="h-ie1"&gt;@&lt;span id="h-ie2"&gt;&lt;b id="a5yp8"&gt;ManagedResource&lt;/b&gt;&lt;/span&gt;(description="Directory Scanner Component.",&lt;br id="gp0p4"&gt; objectName="demo.integration:name=DirectoryScanner,type=SpringComponent")&lt;br id="gp0p5"&gt; public &lt;span id="h-ie3"&gt;&lt;b id="a5yp9"&gt;class DirectoryScanner &lt;/b&gt;&lt;/span&gt;implements &lt;span id="h-ie4"&gt;&lt;b id="a5yp10"&gt;Controllable&lt;/b&gt;&lt;/span&gt;{&lt;br id="gp0p6"&gt; &lt;br id="gp0p7"&gt; ...&lt;br id="gp0p8"&gt;     &lt;br id="gp0p9"&gt;     @&lt;span id="h-ie5"&gt;&lt;b id="a5yp11"&gt;ManagedAttribute&lt;/b&gt;&lt;/span&gt;(description="Comma separated list ....")&lt;br id="gp0p10"&gt;     public String &lt;span id="h-ie6"&gt;&lt;b id="a5yp12"&gt;getExtensionList&lt;/b&gt;&lt;/span&gt;() {&lt;br id="gp0p11"&gt;         return (fileFilter != null) ? fileFilter.toString() : null;&lt;br id="gp0p12"&gt;     }&lt;br id="gp0p13"&gt;     &lt;br id="gp0p14"&gt;     @&lt;span id="h-ie7"&gt;&lt;b id="a5yp13"&gt;ManagedAttribute&lt;/b&gt;&lt;/span&gt;&lt;br id="gp0p15"&gt;     public void &lt;span id="h-ie8"&gt;&lt;b id="a5yp14"&gt;setExtensionList&lt;/b&gt;&lt;/span&gt;(String extensionList) {&lt;br id="gp0p16"&gt;         fileFilter = new FileListFilter(extensionList);&lt;br id="gp0p17"&gt;     }&lt;br id="gp0p18"&gt; &lt;br id="gp0p19"&gt;     @&lt;span id="h-ie9"&gt;&lt;b id="a5yp15"&gt;ManagedAttribute&lt;/b&gt;&lt;/span&gt;(description="The directory location to scan.")&lt;br id="gp0p20"&gt;     public String &lt;span id="h-ie10"&gt;&lt;b id="a5yp16"&gt;getLocation&lt;/b&gt;&lt;/span&gt;() {&lt;br id="gp0p21"&gt;         return (location != null) ? location.getPath() : null;&lt;br id="gp0p22"&gt;     }&lt;br id="gp0p23"&gt; &lt;br id="gp0p24"&gt;     @&lt;span id="h-ie11"&gt;&lt;b id="a5yp17"&gt;ManagedAttribute&lt;/b&gt;&lt;/span&gt;&lt;br id="gp0p25"&gt;     public void &lt;span id="h-ie12"&gt;&lt;b id="a5yp18"&gt;setLocation&lt;/b&gt;&lt;/span&gt;(String location) {&lt;br id="gp0p26"&gt;         this.location = new File(location);&lt;br id="gp0p27"&gt;     }&lt;br id="gp0p28"&gt; &lt;br id="gp0p29"&gt; ...&lt;br id="gp0p30"&gt; &lt;br id="gp0p31"&gt;     @&lt;span id="arbb0"&gt;&lt;b id="a5yp19"&gt;ManagedOperation&lt;/b&gt;&lt;/span&gt;(description="Lifecycle to start component.")&lt;br id="gp0p32"&gt;     public void &lt;span id="arbb1"&gt;&lt;b id="a5yp20"&gt;start&lt;/b&gt;&lt;/span&gt;() {&lt;br id="gp0p33"&gt;         started = true;&lt;br id="gp0p34"&gt;         log.info("**** Directory Scanner Compoennt started OK.");&lt;br id="gp0p35"&gt;     }&lt;br id="gp0p36"&gt; &lt;br id="gp0p37"&gt;     @&lt;span id="arbb2"&gt;&lt;b id="a5yp21"&gt;ManagedOperation&lt;/b&gt;&lt;/span&gt;(description="Lifecycle to stop component.")&lt;br id="gp0p38"&gt;     public void &lt;span id="arbb3"&gt;&lt;b id="a5yp22"&gt;stop&lt;/b&gt;&lt;/span&gt;() {&lt;br id="gp0p39"&gt;         started = false;&lt;br id="gp0p40"&gt;         log.info("**** Directory Scanner Compoennt stopped OK.");&lt;br id="gp0p41"&gt;     }&lt;br id="gp0p42"&gt; &lt;br id="gp0p43"&gt; ...&lt;br id="gp0p44"&gt; &lt;br id="gp0p45"&gt;     public void &lt;span id="arbb4"&gt;&lt;b id="a5yp23"&gt;scan&lt;/b&gt;&lt;/span&gt;() throws RuntimeException {&lt;br id="gp0p46"&gt;         if (started) {&lt;br id="gp0p47"&gt;             if (location != null &amp;amp;&amp;amp; location.isDirectory()) {&lt;br id="gp0p48"&gt;                 File[] list = location.listFiles(fileFilter);&lt;br id="gp0p49"&gt;                 log.info("Scanned files with extensions [ " + fileFilter.toString() + "]" +&lt;br id="gp0p50"&gt;                         " from [" + location.getAbsolutePath() + "]");&lt;br id="gp0p51"&gt;             } else {&lt;br id="gp0p52"&gt;                 log.warn("Unable to scan location  Make sure it's valid.");&lt;br id="gp0p53"&gt;             }&lt;br id="gp0p54"&gt;         }&lt;br id="gp0p55"&gt;     }&lt;br id="gp0p56"&gt; &lt;br id="gp0p57"&gt; }&lt;/code&gt;&lt;br id="gp0p58"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;br id="e6eu0"&gt; As you can see, this is a simple class.  The thing to notice is the Spring-specific annotations that decorate the class.  They are used to export and describe the class as a JMX MBean server.  It's beyond the scope of this write up to go into the details of how to do this in Spring.  However the next section shows the Spring file that describes and wire it all together.&lt;br id="c.7y0"&gt; &lt;br style="font-weight: bold;" id="c.7y1"&gt;&lt;span id="kanm0"&gt;&lt;b id="a5yp24"&gt; The Spring Configuration File&lt;/b&gt;&lt;/span&gt;&lt;br id="c.7y2"&gt; The configuration of this component is simple and straight forward.  &lt;br id="hya00"&gt; &lt;br id="ok0o0"&gt; &lt;div id="s6ao0"&gt; &lt;table id="igif" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0"&gt;&lt;tbody id="s6ao1"&gt; &lt;tr id="s6ao2"&gt; &lt;td id="s6ao3" width="100%"&gt;&lt;code id="labh0"&gt;    &amp;lt;bean id="scanner" class="component.spring.DirectoryScanner" init-method="start" destroy-method="stop"&amp;gt;&lt;br id="wadj0"&gt;         &amp;lt;property name="location" value="../../"/&amp;gt;&lt;br id="wadj1"&gt;         &amp;lt;property name="extensionList" value="*"/&amp;gt;&lt;br id="wadj2"&gt;     &amp;lt;/bean&amp;gt;&lt;/code&gt;&lt;br id="s6ao4"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; Above, we see the &lt;span id="labh2"&gt;&lt;b id="a5yp25"&gt;DirectoryScanner &lt;/b&gt;&lt;/span&gt;being configured to scan two directory up from where the application is invoked.  Also, we set the list of files to scan.&lt;br id="hya01"&gt; &lt;br id="wadj3"&gt; &lt;br id="wadj4"&gt; &lt;div id="od8s0"&gt; &lt;table id="t93m" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" height="344" width="748"&gt;&lt;tbody id="od8s1"&gt; &lt;tr id="od8s2"&gt; &lt;td id="od8s3" width="100%"&gt;&lt;code id="labh3"&gt;    &amp;lt;bean id="timerFactory"&lt;br id="od8s4"&gt;           class="org.springframework.scheduling.timer.TimerFactoryBean"&amp;gt;&lt;br id="od8s5"&gt;         &amp;lt;property name="scheduledTimerTasks"&amp;gt;&lt;br id="od8s6"&gt;             &amp;lt;list&amp;gt;&lt;br id="od8s7"&gt;                 &amp;lt;ref bean="scheduledTimerTask" /&amp;gt;&lt;br id="od8s8"&gt;             &amp;lt;/list&amp;gt;&lt;br id="od8s9"&gt;         &amp;lt;/property&amp;gt;&lt;br id="od8s10"&gt;     &amp;lt;/bean&amp;gt;&lt;br id="od8s11"&gt;     &lt;br id="od8s12"&gt;     &amp;lt;bean id="scheduledTimerTask"&lt;br id="od8s13"&gt;           class="org.springframework.scheduling.timer.ScheduledTimerTask"&amp;gt;&lt;br id="od8s14"&gt;         &amp;lt;property name="period" value="3000" /&amp;gt;&lt;br id="od8s15"&gt;         &amp;lt;property name="timerTask" ref="timer" /&amp;gt;&lt;br id="od8s16"&gt;     &amp;lt;/bean&amp;gt;&lt;br id="od8s17"&gt;     &lt;br id="od8s18"&gt;     &amp;lt;bean id="timer"&lt;br id="od8s19"&gt;           class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean"&amp;gt;&lt;br id="od8s20"&gt;         &amp;lt;property name="targetObject" ref="scanner" /&amp;gt;&lt;br id="od8s21"&gt;         &amp;lt;property name="targetMethod" value="scan" /&amp;gt;&lt;br id="od8s22"&gt;     &amp;lt;/bean&amp;gt;&lt;/code&gt;&lt;br id="od8s24"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; The stuff above is&lt;span id="ngng0"&gt;&lt;b id="a5yp26"&gt; boiler plate for setting up timer services&lt;/b&gt;&lt;/span&gt; from Spring.  Here we are &lt;span id="kanm1"&gt;&lt;b id="a5yp27"&gt;declaratively &lt;/b&gt;&lt;/span&gt;setting the timer to invoke the scan() method on the DirectoryScanner POJO wired above.&lt;br id="h7510"&gt; &lt;br id="h7512"&gt; &lt;div id="nrpc0"&gt; &lt;table id="mjay" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" height="344" width="749"&gt;&lt;tbody id="nrpc1"&gt; &lt;tr id="nrpc2"&gt; &lt;td id="nrpc3" width="100%"&gt;&lt;code id="labh4"&gt;    &amp;lt;bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"&amp;gt;&lt;br id="p4tp0"&gt;         &amp;lt;property name="assembler" ref="assembler"/&amp;gt;&lt;br id="p4tp1"&gt;         &amp;lt;property name="namingStrategy" ref="namingStrategy"/&amp;gt;&lt;br id="p4tp2"&gt;         &amp;lt;property name="autodetect" value="true"/&amp;gt;&lt;br id="p4tp3"&gt;         &amp;lt;property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/&amp;gt;&lt;br id="p4tp4"&gt;     &amp;lt;/bean&amp;gt;&lt;br id="p4tp5"&gt;     &amp;lt;bean id="jmxAttributeSource"&lt;br id="p4tp6"&gt;           class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/&amp;gt;&lt;br id="p4tp7"&gt; &lt;br id="p4tp8"&gt;     &amp;lt;!-- will create management interface using annotation metadata --&amp;gt;&lt;br id="p4tp9"&gt;     &amp;lt;bean id="assembler"&lt;br id="p4tp10"&gt;           class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"&amp;gt;&lt;br id="p4tp11"&gt;         &amp;lt;property name="attributeSource" ref="jmxAttributeSource"/&amp;gt;&lt;br id="p4tp12"&gt;     &amp;lt;/bean&amp;gt;&lt;br id="p4tp13"&gt; &lt;br id="p4tp14"&gt;     &amp;lt;!-- will pick up the ObjectName from the annotation --&amp;gt;&lt;br id="p4tp15"&gt;     &amp;lt;bean id="namingStrategy"&lt;br id="p4tp16"&gt;           class="org.springframework.jmx.export.naming.MetadataNamingStrategy"&amp;gt;&lt;br id="p4tp17"&gt;         &amp;lt;property name="attributeSource" ref="jmxAttributeSource"/&amp;gt;&lt;br id="p4tp18"&gt;     &amp;lt;/bean&amp;gt;&lt;/code&gt;&lt;br id="nrpc4"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; Finally, the code snippet above &lt;span id="foi.0"&gt;&lt;b id="a5yp28"&gt;sets up the POJO to be exported &lt;/b&gt;&lt;/span&gt;as an &lt;span id="foi.1"&gt;&lt;b id="a5yp29"&gt;MBean &lt;/b&gt;&lt;/span&gt;into the running &lt;span id="foi.2"&gt;&lt;b id="a5yp30"&gt;MBeanServer&lt;/b&gt;&lt;/span&gt;.  This configuration relies on the annotation embedded in the class to derive the meta data used to describe the class inside the MBeanServer.&lt;br id="c2m20"&gt;&lt;br style="font-weight: bold;" id="c2m21"&gt;&lt;span id="u75e0"&gt;&lt;b&gt;Download Source&lt;/b&gt;&lt;/span&gt;&lt;br id="c2m22"&gt;&lt;a title="You can download" target="_blank" href="http://vladimirvivien.com.s3.amazonaws.com/jBoss-spring-integration.zip" id="k5-a"&gt;&lt;b&gt;You can download&lt;/b&gt;&lt;/a&gt; the application sample application to get the code source.&lt;br id="u75e1"&gt;&lt;br id="lihu0"&gt;&lt;font id="rvh90" size="4"&gt;&lt;b id="a5yp31"&gt;Observations&lt;/b&gt;&lt;/font&gt;&lt;br id="jcp40"&gt;&lt;ul id="h51v0"&gt;&lt;li id="h51v1"&gt;&lt;span id="rvh91"&gt;&lt;b id="a5yp32"&gt;Think in Component&lt;/b&gt;&lt;/span&gt; - &lt;span id="f-:j0"&gt;&lt;b id="a5yp33"&gt;component-based development is incredibly easy to get into and understand&lt;/b&gt;&lt;/span&gt;.  It facilitates the separation of concerns and promotes forces you into better coding practices (testing, loose coupling, re-usability, etc).&lt;/li&gt;&lt;li id="h51v2"&gt;&lt;span id="nar30"&gt;&lt;b id="a5yp34"&gt;JBoss Service Component Evolving&lt;/b&gt;&lt;/span&gt; - Starting with version 4.x, &lt;span id="f-:j1"&gt;&lt;b id="a5yp35"&gt;JBoss components can now be annoted&lt;/b&gt;&lt;/span&gt; (instead of using the descriptor file) to describe its meta characteristics for JMX.  Starting with version 5, JBoss will switch to OSGi as the executable unit for its components.&lt;/li&gt;&lt;li id="h51v3"&gt;&lt;span id="bp_10"&gt;&lt;b id="a5yp36"&gt;Exception Management&lt;/b&gt;&lt;/span&gt; - &lt;span id="xrt80"&gt;&lt;b id="a5yp37"&gt;When deploying components&lt;/b&gt;&lt;/span&gt; into a container (such as JBoss app server), great care must be taken to &lt;span id="xrt81"&gt;&lt;b id="a5yp38"&gt;handle exceptions properly&lt;/b&gt;&lt;/span&gt;.  In JBoss (version 4.x), when a component throws an &lt;span id="n6yj0"&gt;&lt;b id="a5yp39"&gt;unhandled exception&lt;/b&gt;&lt;/span&gt;, that &lt;span id="u4j50"&gt;&lt;b id="a5yp40"&gt;component is immediately disabled&lt;/b&gt;&lt;/span&gt; and shutdown.  You must catch all exceptions and handle them properly.  In &lt;span id="p27r0"&gt;&lt;b id="a5yp41"&gt;DirectoryScanner&lt;/b&gt;&lt;/span&gt;, for instance, &lt;span id="lhk70"&gt;&lt;b id="a5yp42"&gt;if the scan() method throws&lt;/b&gt;&lt;/span&gt; an exception during a scanning request, the &lt;span id="jkhl0"&gt;&lt;b id="a5yp43"&gt;entire component is deactivated&lt;/b&gt;&lt;/span&gt;.&lt;/li&gt;&lt;li id="h51v3"&gt;&lt;span id="a3vj0"&gt;&lt;b id="a5yp44"&gt;(OSGi) Components Are Here to Stay&lt;/b&gt;&lt;/span&gt; - &lt;span id="by8h0"&gt;&lt;b id="a5yp45"&gt;All major containers&lt;/b&gt;&lt;/span&gt; including &lt;span id="by8h1"&gt;&lt;b id="a5yp46"&gt;JBoss AS&lt;/b&gt;&lt;/span&gt;, &lt;span id="i8c20"&gt;&lt;b id="a5yp47"&gt;SpringSource App Platform&lt;/b&gt;&lt;/span&gt;, IBM &lt;span id="i8c21"&gt;&lt;b id="a5yp48"&gt;WebSphere&lt;/b&gt;&lt;/span&gt;, &lt;span id="i8c22"&gt;&lt;b id="a5yp49"&gt;Glassfish&lt;/b&gt;&lt;/span&gt;, and &lt;span id="i8c23"&gt;&lt;b id="a5yp50"&gt;JOnAs &lt;/b&gt;&lt;/span&gt;&lt;span id="no4x0"&gt;&lt;b id="a5yp51"&gt;support OSGi&lt;/b&gt;&lt;/span&gt; bundles as their coarse component model.&lt;br id="yjff0"&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br id="rvh92"&gt;&lt;font id="pt3i0" size="4"&gt;&lt;b id="a5yp52"&gt;Refereces&lt;/b&gt;&lt;/font&gt;&lt;br id="q1u00"&gt;&lt;ol id="c2m23"&gt;&lt;li id="c2m24"&gt;&lt;span id="c2m25"&gt;&lt;b&gt;Source for Directory Scanner&lt;/b&gt;&lt;/span&gt; - &lt;a title="http://vladimirvivien.com.s3.amazonaws.com/jBoss-spring-integration.zip" target="_blank" href="http://vladimirvivien.com.s3.amazonaws.com/jBoss-spring-integration.zip" id="x8hq"&gt;http://vladimirvivien.com.s3.amazonaws.com/jBoss-spring-integration.zip&lt;/a&gt; &lt;/li&gt;&lt;li id="c2m26"&gt;JBoss Server Microkernel - &lt;a title="http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch2.chapter.html" target="_blank" href="http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch2.chapter.html" id="ot7-"&gt;http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch2.chapter.html&lt;/a&gt; &lt;/li&gt;&lt;li id="c2m27"&gt;Spring Documentation - &lt;a title="http://static.springframework.org/spring/docs/2.5.x/reference/index.html" target="_blank" href="http://static.springframework.org/spring/docs/2.5.x/reference/index.html" id="aumn"&gt;http://static.springframework.org/spring/docs/2.5.x/reference/index.html&lt;/a&gt; &lt;/li&gt;&lt;li id="c2m28"&gt;Spring JMX Documentation - &lt;a title="http://static.springframework.org/spring/docs/2.5.x/reference/jmx.html" target="_blank" href="http://static.springframework.org/spring/docs/2.5.x/reference/jmx.html" id="hc92"&gt;http://static.springframework.org/spring/docs/2.5.x/reference/jmx.html&lt;/a&gt; &lt;/li&gt;&lt;li id="c2m29"&gt;OSGi - &lt;a title="http://en.wikipedia.org/wiki/OSGi" target="_blank" href="http://en.wikipedia.org/wiki/OSGi" id="hsuh"&gt;http://en.wikipedia.org/wiki/OSGi&lt;/a&gt; &lt;/li&gt;&lt;li id="c2m210"&gt;OSGi and Spring - &lt;a title="http://www.infoq.com/interviews/osgi-adrian-colyer" target="_blank" href="http://www.infoq.com/interviews/osgi-adrian-colyer" id="lo7n"&gt;http://www.infoq.com/interviews/osgi-adrian-colyer&lt;/a&gt; &lt;/li&gt;&lt;/ol&gt; &lt;br id="fvy30"&gt;&lt;br id="sq100"&gt;&lt;br id="zex_0"&gt;&lt;br id="iyjz0"&gt;&lt;br id="mvaf0"&gt;&lt;br id="n5fu0"&gt;</content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2008/05/integrating-spring-and-jboss-sar.html' title='Integrating Spring and JBoss SAR Components'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/6132890863651433802'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/6132890863651433802'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-6552334684584236481</id><published>2008-05-08T12:11:00.003-04:00</published><updated>2008-05-08T12:23:35.495-04:00</updated><title type='text'>JavaOne - OSGi Is Huge Here!</title><content type='html'>If you doubted that OSGi can achieve mass appeal, the list of sessions at J1 proves contrary.   Most major tool vendors has either implemented it or have plans to support OSGi bundles:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;OSGi has been in IBM's  arsenal for while now (Eclipse, Websphere, etc)&lt;/li&gt;&lt;li&gt;SpringSource's new Spring Application Platform uses OSGi has its &lt;/li&gt;&lt;li&gt;Glassfish Version 3 will be OSGi-bundle compatible&lt;/li&gt;&lt;li&gt;JBoss 5's kernel will load its component as OSGi&lt;/li&gt;&lt;li&gt;JSR 277, the Java Module system, slated for JDK7, can load OSGi bundles&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;From small embedded devices, to desktop, to the large application server, OSGi seems to be the component model that the industry is adopting.  It will be interesting to see how the corporate developer integrates OSGi in their development rituals.</content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2008/05/javaone-osgi-is-huge-here.html' title='JavaOne - OSGi Is Huge Here!'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/6552334684584236481'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/6552334684584236481'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-6112084086072090468</id><published>2008-05-07T10:08:00.004-04:00</published><updated>2008-05-07T10:55:39.303-04:00</updated><title type='text'>JavaOne 2008 - Sun, Lifestyle Company?</title><content type='html'>On day one of the JavaOne, the theme is clear:  JavaFx (http://javafx.com/) is here to stay.  The FX story is coalescing into a platform clearly targeting digital lifestyle experiences.  It is clear that tremendous of resources are being devoted to bring the FX story together as technology stack with support for rich that stretches from mobile devices, desktop, to the backend.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The Tools&lt;/span&gt;&lt;br /&gt;- Continued JavaFX support from NetBeans&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;Photoshop/Illustrator&lt;/span&gt; plug-in's to export art work as JavaFx artifacts directly&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The Features&lt;/span&gt;&lt;br /&gt;- JDK 6 update 10 (jdk 6u10) - setting the path for the desktop features envisioned by Sun&lt;br /&gt;- Applets - Sun is going back to the Applets as a way to augment browsing experiences.&lt;br /&gt;- Audio/Video - under the FX unbrella Sun is offereing an HD qualility a/v codec for Java&lt;br /&gt;- FX is slated to target devices such as cellphones and other mobile stacks with a consistent user experience from device to desktop.&lt;br /&gt;- Project Hydrazyne: another Sun initiative to let users easily create rich content and experiences dritributed in a Sun hosted cloud.&lt;br /&gt;&lt;br /&gt;I would like to see this effort successeed, for anything elese, just to have competition in the content technology market place.  Adobe leads that sector, Microsoft is making inroad with Silverlight, now Sun wants to give Java developer a way into the rich content user exeperience.&lt;br /&gt;&lt;br /&gt;You just have to read the blogs around the net to find doubters about this strategy laid out by Sun.  However, I think if the company remains on message, provide the tools, continue to share the vision, there will be new convert.  Lets see what happens!</content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2008/05/javaone-2008-sun-lifestyle-company.html' title='JavaOne 2008 - Sun, Lifestyle Company?'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/6112084086072090468'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/6112084086072090468'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-4761886190472352352</id><published>2008-04-09T06:41:00.002-04:00</published><updated>2008-04-09T07:05:23.968-04:00</updated><title type='text'>Introducing Groovy JMX Builder</title><content type='html'>After I attended the &lt;span style="font-weight: bold;"&gt;Groovy/Grails Experience&lt;/span&gt; in February this year, I realize that the Groovy builder pattern can be used to façade many other API's (not just swing).  So, I decide to create, yet another builder, for the JMX API and here it is!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://code.google.com/p/groovy-jmx-builder/"&gt;http://code.google.com/p/groovy-jmx-builder/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;&lt;span style="font-size:130%;"&gt;&lt;a id="Features"&gt;Features&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;a id="Features"&gt;Ability to &lt;strong&gt;expose any class&lt;/strong&gt; instance for management for both Java and Groovy classes. &lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a id="Features"&gt;&lt;strong&gt;No need&lt;/strong&gt; to implement a specific management interface. &lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a id="Features"&gt;&lt;strong&gt;Shield developer from complexity&lt;/strong&gt; of JMX API &lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a id="Features"&gt;&lt;strong&gt;Use&lt;/strong&gt; familiar Groovy &lt;strong&gt;builder pattern&lt;/strong&gt; &lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a id="Features"&gt;Exposes &lt;strong&gt;attribute&lt;/strong&gt;, &lt;strong&gt;constructors&lt;/strong&gt;, &lt;strong&gt;operations&lt;/strong&gt;, &lt;strong&gt;parameters&lt;/strong&gt; &lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;Suppose you have a class called Greeter&lt;/span&gt; (on your class path) that prints out greeting to a specified person in a specified language, so the class may look like this&lt;br /&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;&lt;a id="Example"&gt;public class Greeter {&lt;br /&gt;private String name;&lt;br /&gt;private String language = "en";&lt;br /&gt;&lt;br /&gt;// ...&lt;br /&gt;&lt;br /&gt;public String getName() {&lt;br /&gt;    return name;&lt;br /&gt;}&lt;br /&gt;public void setName(String name) {&lt;br /&gt;    this.name = name;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// ...&lt;br /&gt;&lt;br /&gt;public String greet(){&lt;br /&gt;    String greet = (String) (langs.containsKey(getLanguage()) ?&lt;br /&gt;        langs.get(getLanguage()) : langs.get("en"));&lt;br /&gt;    return greet + " " + getName();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt; String greet(String person){&lt;br /&gt;    return  langs.get(language) + " " + person&lt;br /&gt;}&lt;br /&gt;}&lt;/a&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a id="Groovy_JMX_Builder"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/a&gt;You can &lt;span style="font-weight: bold;"&gt;use Groovy Jmx Builder to expose an instance&lt;/span&gt; of that class for management as an MBean.&lt;br /&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;&lt;a id="Example"&gt;def greeter = new Greeter()&lt;br /&gt;JmxBuilder jmx = new JmxBuilder()&lt;br /&gt;def server = jmx.export(svr){&lt;br /&gt; bean(greeter){&lt;br /&gt;     name("greeterDemo:service=greeting")&lt;br /&gt;     desc("This service prints a greeting on console")&lt;br /&gt;     attribute(name:"name", desc:"name of person to greet", writable:true)&lt;br /&gt;     attribute(name:"language", desc:"the language to use", editable:true)&lt;br /&gt;     operation(name:"greet", desc:"Sends greeting to user")&lt;br /&gt;     operation(name:"greet", desc:"Send greeting to user"){&lt;br /&gt;         parameter(type:"java.lang.String", name:"Person", desc:"The person to send greeting to")&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; bean(object:greeter, name:"greeterDemo:service=greeting2")&lt;br /&gt;}&lt;/a&gt;&lt;/pre&gt;You use the JmxBuilder() class to capture meta data about your class instance that will be made available at runtime for management.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;In JConsole&lt;/span&gt;, the generated MBean may look like this&lt;br /&gt;&lt;br /&gt;&lt;img src="http://groovy-jmx-builder.s3.amazonaws.com/jmx-builder-jconsole.png" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Feedbacks&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;I am interested in feedbacks for this project.  So, download it and give it a try.  I will be adding more features to it in the future.</content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2008/04/introducing-groovy-jmx-builder.html' title='Introducing Groovy JMX Builder'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/4761886190472352352'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/4761886190472352352'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-5142844489258748659</id><published>2008-03-04T19:02:00.001-05:00</published><updated>2008-03-04T19:04:39.929-05:00</updated><title type='text'>Using Groovy's FactoryBuilderSupport to Build Internal DSL</title><content type='html'>            &lt;font size="5"&gt;&lt;br&gt;&lt;b&gt;Using Groovy's FactoryBuilderSupport to Build Internal DSL&lt;/b&gt;&lt;/font&gt;&lt;br&gt; &lt;br&gt; Couple of weeks ago at the &lt;a href="http://groovygrails.com/gg/2gexperience" id="dwhg" title="http://groovygrails.com/gg/2gexperience"&gt;Groovy/Grails Experience&lt;/a&gt; conf, &lt;a href="http://groovy.codehaus.org/Dynamic+Groovy" id="flql" title="Groovy's meta programming"&gt;&lt;b&gt;Groovy's meta programming&lt;/b&gt;&lt;/a&gt;   was a big theme there.  Since then, I &lt;a title="http://vladimirvivien.com/blogs/ot/2008/02/creating-simple-builder-with-groovys.html" href="http://vladimirvivien.com/blogs/ot/2008/02/creating-simple-builder-with-groovys.html" id="cb5:"&gt;blogged about using Groovy's built-in Meta Object Protocol&lt;/a&gt; (MOP) mechanism to create a simple XML builder.  Then I got curious about other builders such as Swing and SwingX.  Talking to &lt;a title="http://www.jameswilliams.be/blog/entry/index" href="http://www.jameswilliams.be/blog/entry/index" id="eyxm"&gt;James Williams&lt;/a&gt; (SwingXBuilder creator), I found out that Groovy's &lt;a href="http://groovy.codehaus.org/FactoryBuilderSupport" id="cwno" title="Groovy's FactoryBuilderSupport"&gt;&lt;b&gt;FactoryBuilderSupport&lt;/b&gt;&lt;/a&gt;  interface is designed specifically to allow developers create builder-style DSL.  While the FactoryBuilderSupport provides a rich interface to create your own DSL, examples are hard to come by.  Thankfully, James had just created another builder called &lt;a title="http://www.jameswilliams.be/blog/entry/60" href="http://www.jameswilliams.be/blog/entry/60" id="us3b"&gt;Java3DBuilder&lt;/a&gt; &lt;a href="http://www.jameswilliams.be/blog/entry/60" id="phc_" title="Java3DBuilder"&gt;&lt;/a&gt; which uses the FactoryBuilder interface and a good starting point.  This shows a small example on using the FactoryBuilderSupport.&lt;br&gt; &lt;br&gt; The &lt;b&gt;FactoryBuilderSupport&lt;/b&gt; along with Groovy's &lt;b&gt;Factory&lt;/b&gt; interface offer a structured approach to constructing internal DSL's.  Unlike tapping directly into MOP to manage your DSL nodes, the factory approach requires you to explicitly register by name each node with the FactoryBuilder.  The Factory interface exposes &lt;b&gt;event callbacks&lt;/b&gt; to intercept different phases of node traversal by the FactoryBuilder which lets manage state and behavior of your DSL. Here is how &lt;b&gt;Groovy's website&lt;/b&gt; describes the Factory interface and its methods:&lt;br&gt; &lt;div id="wczc" style="padding: 1em 0pt; text-align: left;"&gt;   &lt;img src="http://docs.google.com/File?id=df3qdpw5_74f6n7mghn" style="width: 723px; height: 241px;"&gt;&lt;br&gt;   &lt;br&gt;&lt;b&gt;A quick note about newInstanceMethod()&lt;/b&gt; - when the factory builder creates a new instance of your node, it will pass in these params: an instance of the factory builder, the name of the node being processed, an argument value (if used as the form &lt;b&gt;node(arg)&lt;/b&gt; ), and optionally a &lt;b&gt;map&lt;/b&gt; if the node is used as &lt;b&gt;node(key:value...)&lt;/b&gt;.&lt;br&gt;   &lt;br&gt;&lt;font size="4"&gt;&lt;b&gt;Saying Hello, the DSL Way&lt;/b&gt;&lt;/font&gt;&lt;br&gt;So, using the information above (and some some sleuthing on my part), I was able to figure out how to use the FactoryBuilderSupport class to build a simple DSL to display a greeting message.  So, the first thing is to specify how the language will look and feel.  Since we are using the builder pattern, our DSL will have the familiar construct we have seen in other builders:&lt;br&gt;&lt;br&gt;&lt;span style="font-family: Courier New;"&gt;builder.&lt;b&gt;using&lt;/b&gt;(a given language) {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;    &lt;b&gt;greet&lt;/b&gt;(person1)&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;    &lt;b&gt;greet&lt;/b&gt;(person2)&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;    &lt;b&gt;greet&lt;/b&gt;(person4)&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;...&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;    &lt;b&gt;greet&lt;/b&gt;(personN)&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;A call to &lt;b&gt;builder.build()&lt;/b&gt; will print out the greeting in the proper language.&lt;br&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;/font&gt;&lt;br&gt;First, let us look at the backing structure that will support our DSL.  It consists of a &lt;b&gt;Person&lt;/b&gt; object and &lt;b&gt;GroupGreeter &lt;/b&gt;class.  The latter actually stores the persons we want to greet and apply the logic to build the greeting string.&lt;br&gt;&lt;br&gt;&lt;div id="qqk_" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img style="width: 698px; height: 636px;" src="http://docs.google.com/File?id=df3qdpw5_75f5h46pdn"&gt;&lt;/div&gt;The greetings can be in several languages including English, French, German, Spanish, Italian, and Portuguese.  The greetings map (line 9)stores the greeting text as well as the conjunction to use when we are greeting more than one person.&lt;br&gt;&lt;br&gt;Disclaimer: I am not a language geek.  This translation is straight from &lt;a title="http://www.google.com/language_tools" href="http://www.google.com/language_tools" id="fpal"&gt;Google Language Tools&lt;/a&gt; .  So, I am not responsible for greetings that are colloquially incorrect or used in the wrong context!&lt;br&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;b&gt;On to the Builder&lt;/b&gt;&lt;/font&gt;&lt;br&gt;The next code snippet shows the &lt;b&gt;FactoryBuilderSupport&lt;/b&gt; and the factories that it manages.  Each node in your DSL is implemented by a factory instance.  In our example, the nodes are are &lt;b&gt;using&lt;/b&gt; and &lt;b&gt;greet&lt;/b&gt;.  Node using is registered with &lt;b&gt;GroupGreetingNode&lt;/b&gt; and greet is registered with class GreetingNode. &lt;br&gt;&lt;br&gt;&lt;img style="width: 851px; height: 690px;" src="http://docs.google.com/File?id=df3qdpw5_76hcgg2nch"&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;GroupGreetingNode&lt;/b&gt; represents the parent node.  It sets up a &lt;b&gt;GroupGreeter&lt;/b&gt; object (see previous section) with the language passed in as its argument and returns the newly created GroupGreeter object.  The &lt;b&gt;GreetingNode&lt;/b&gt; is a child node of the &lt;b&gt;GroupGreetingNode&lt;/b&gt;.  When the "greet" node is encountered, the builder calls newInstance() on GreetingNode and a new instance of the Person object with the name as an argument and returns the newly created person back to the builder.  The builder will eventually call setParent() on the GreetingNode.  At that point, the person object that was created in is added to the parentNode (which is an instance of GroupGreeter). That's it!&lt;br&gt;&lt;br&gt;&lt;font size="4"&gt;&lt;b&gt;Running the Code&lt;/b&gt;&lt;/font&gt;&lt;br&gt;The following shows two usage of the Greeting DSL&lt;br&gt;&lt;div id="eqf7" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img style="width: 444px; height: 219px;" src="http://docs.google.com/File?id=df3qdpw5_77d4hq3zjw"&gt;&lt;/div&gt;The code above produces &lt;br&gt;&lt;br&gt;&lt;div&gt;&lt;table id="vh2t" bgcolor="#cccccc" border="0" cellpadding="3" cellspacing="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width="100%"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;b&gt;Hallo, Jon, David und Ella&lt;/b&gt;&lt;/span&gt;&lt;br style="font-family: Courier New; font-weight: bold;"&gt;&lt;span style="font-family: Courier New;"&gt;&lt;b&gt; Salut Mireille&lt;/b&gt;&lt;/span&gt;&lt;br&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;font size="4"&gt;&lt;br&gt;&lt;b&gt;Observations&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt; The semantic for your DSL requires an appropriately fitting backing API and data structure&lt;/li&gt;&lt;li&gt;Model your backing data structure close to your DSL.  It makes implementation of the builder simpler.&lt;/li&gt;&lt;li&gt;If you can't change the backing API, try model your DSL syntax and semantic close to your API.&lt;br&gt;&lt;/li&gt;&lt;li&gt;FactoryBuilderSupport and Factory simply facilitates the traversal of the DSL nodes.  They should not be used to implement the backing data structure.&lt;/li&gt;&lt;li&gt;How you process the nodes is subjective and depends on how your backing data model is structured.&lt;/li&gt;&lt;li&gt;Process data at the intended node level.  So, a child node should process all of its data not pass it to the parent.&lt;/li&gt;&lt;/ul&gt; &lt;br&gt;&lt;font size="4"&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/font&gt;&lt;br&gt;There's no doubt that Groovy makes developing DSL easy.  As we have seen the combination of the &lt;b&gt;FactoryBuilderSupport&lt;/b&gt; class and the &lt;b&gt;Factory&lt;/b&gt; interface provides a structured approach to creating DSL that conforms to the builder pattern.  In this write up I demonstrated how to create a simple DSL to print out greeting on the screen.  The same techniques used here are used to create more complex DSL such as &lt;b&gt;Java3DBuilder&lt;/b&gt;.&lt;br&gt;&lt;br&gt;References&lt;br&gt;0. Download Groovy source code - &lt;a title="http://vladimirvivien.com.s3.amazonaws.com/GreetingBuilderDemo.groovy" href="http://vladimirvivien.com.s3.amazonaws.com/GreetingBuilderDemo.groovy" id="a515"&gt;http://vladimirvivien.com.s3.amazonaws.com/GreetingBuilderDemo.groovy&lt;/a&gt; &lt;br&gt;1.  Dynamic Groovy - &lt;a href="http://groovy.codehaus.org/Dynamic+Groovy" id="ji:w" title="http://groovy.codehaus.org/Dynamic+Groovy"&gt;http://groovy.codehaus.org/Dynamic+Groovy&lt;/a&gt;&lt;br&gt;2. Groovy FactoryBuilderSupport - &lt;a title="http://groovy.codehaus.org/FactoryBuilderSupport" href="http://groovy.codehaus.org/FactoryBuilderSupport" id="copu"&gt;http://groovy.codehaus.org/FactoryBuilderSupport&lt;/a&gt; &lt;br&gt;3. Jame William's Java3DBuilder - &lt;a title="http://www.jameswilliams.be/blog/entry/60" href="http://www.jameswilliams.be/blog/entry/60" id="tw4x"&gt;http://www.jameswilliams.be/blog/entry/60&lt;/a&gt; &lt;br&gt;&lt;br&gt;Hope you enjoyed it!&lt;br&gt;&lt;/div&gt; </content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2008/03/using-groovys-factorybuildersupport-to.html' title='Using Groovy&apos;s FactoryBuilderSupport to Build Internal DSL'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/5142844489258748659'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/5142844489258748659'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-6819538851770102281</id><published>2008-02-25T18:16:00.001-05:00</published><updated>2008-02-26T07:00:58.439-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Groov'/><category scheme='http://www.blogger.com/atom/ns#' term='Dyanic Languages'/><category scheme='http://www.blogger.com/atom/ns#' term='Grails'/><title type='text'>Creating a Simple Builder with Groovy's methodMissing()</title><content type='html'>&lt;font size="5"&gt;&lt;b&gt;Creating a Simple Builder with Groovy's methodMissing()&lt;/b&gt;&lt;/font&gt;&lt;br&gt; &lt;br&gt; One of the main theme here at Groovy/Grails Experience is Meta Programming: the ability to use Groovy to dynamically modify the behavior of the language at runtime.  During one of Graeme Rocher's session, he did a live demo on how to build a simple Xml builder and Vankat Subramaniam demo'ed the creation of a simple DSL using Groovy. These sessions showed the simplicity and power of Meta programming in Groovy.  So, rather than go on and praise the merits of Groovy and make this an all fluff write up (and get crap for it from my buddy &lt;a href="http://www.jameswilliams.be/" id="qd8f" title="James Williams"&gt;James Williams&lt;/a&gt; ), I will show a concrete example below.&lt;br&gt; &lt;br&gt; &lt;font size="4"&gt;&lt;b&gt;A Simple Xml Builder in Groovy&lt;/b&gt;&lt;/font&gt;&lt;br&gt; This simple xml builder is able to handle most xml tag constructs including:&lt;br&gt; &lt;br&gt; &lt;ul&gt;   &lt;li&gt;     &lt;span style="font-family: Courier New;"&gt;&amp;lt;tag/&amp;gt;  &lt;/span&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;span style="font-family: Courier New;"&gt;&amp;lt;tag atrrib="val"/&amp;gt;  &lt;/span&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;span style="font-family: Courier New;"&gt;&amp;lt;tag&amp;gt;String content&amp;lt;/tag&amp;gt;&lt;/span&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;span style="font-family: Courier New;"&gt;&amp;lt;tag attrib="val"&amp;gt;content&amp;lt;/tag&amp;gt;&lt;/span&gt;   &lt;/li&gt;   &lt;li&gt;     &lt;span style="font-family: Courier New;"&gt;&amp;lt;tag attrib="val"&amp;gt;&amp;lt;tag&amp;gt;... tag[n] ...&amp;lt;/tag&amp;gt;&amp;lt;/tag&amp;gt;&lt;br&gt;     &lt;br&gt;     &lt;/span&gt;   &lt;/li&gt; &lt;/ul&gt; Sorry, there is &lt;b&gt;no namespace support&lt;/b&gt; of the form &amp;lt;namespace:tag/&amp;gt;&lt;br&gt; &lt;br&gt; So, here is a sample usage of the SimpleXmlBuilder class to build XML nodes:&lt;br&gt; &lt;br&gt; &lt;div id="u.ih" style="padding: 1em 0pt; text-align: left;"&gt;   &lt;img src="http://docs.google.com/File?id=df3qdpw5_55gb848gds" style="width: 644px; height: 200px;"&gt; &lt;/div&gt; The code snippet above will generate this HTML code:&lt;br&gt; &lt;br&gt; &lt;div&gt;   &lt;table id="l549" bgcolor="#666666" border="0" cellpadding="1" cellspacing="0" width="100%"&gt;     &lt;tbody&gt;     &lt;tr&gt;       &lt;td width="100%"&gt;         &lt;font style="font-family: Courier New;" color="#000000" size="2"&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&lt;b&gt;&amp;lt;html xmlns="htt://namespace" &amp;gt;&amp;lt;header&amp;gt;&amp;lt;title&amp;gt;Hello&amp;lt;/title&amp;gt;&amp;lt;/header&amp;gt;&amp;lt;body&amp;gt;&amp;lt;p&amp;gt;Hello World Sample&amp;lt;/p&amp;gt;&amp;lt;span id="greet" style="font-family:sans-serif" &amp;gt;Hello World!!&amp;lt;/span&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;/tbody&gt;   &lt;/table&gt; &lt;/div&gt; &lt;br&gt; &lt;br&gt; &lt;font size="4"&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;/font&gt;&lt;br&gt; Disclaimer: this was put together in less an hour while sitting in a session at the &lt;a href="http://groovygrails.com/gg/2gexperience" id="hw2z" title="G2 Experience"&gt;G2 Experience&lt;/a&gt;.  I am sure it can be done in a more elegant way.  The code simply evaluates each of the syntatic possiblities (discussed above) and take appropritae action.  So, with that out of the way, here is the code for simple xml builder:&lt;br&gt; &lt;br&gt; &lt;div id="rhlw" style="padding: 1em 0pt; text-align: left;"&gt;   &lt;img src="http://docs.google.com/File?id=df3qdpw5_56hjp3v8gq" style="width: 580px; height: 944px;"&gt; &lt;/div&gt; Click to &lt;a title="Download source code" href="http://vmatters.googlepages.com/SimpleBuilderDemo.groovy" id="lj56"&gt;&lt;b&gt;download the Groovy source code&lt;/b&gt;&lt;/a&gt;.&lt;br&gt;&lt;br&gt; &lt;font size="4"&gt;&lt;b&gt;MOP - methodMissing()&lt;/b&gt;&lt;/font&gt;&lt;br&gt; If you are new to Groovy then you may not understand what's going on.  &lt;b&gt;Groovy's meta object protocol (MOP)&lt;/b&gt; lets developers &lt;b&gt;expand the syntactical constraints of the core language at runtime&lt;/b&gt;.  This capability makes Groovy the perfect platform to &lt;b&gt;create Domain Specific Language (DSL)&lt;/b&gt; where you develop small language with a concise syntax to address a given domain (software dev, business, etc).  The &lt;b&gt;methodMissing() &lt;/b&gt;method is one of the hooks exposed by Groovy's MOP mechanism that &lt;b&gt;intercepts all calls to undefined methods&lt;/b&gt; on a given object.  By overriding methodMissing(), &lt;b&gt;you can implement behaviors of methods that are not statically defined on the class&lt;/b&gt;. &lt;br&gt; &lt;br&gt; When Groovy's MOP intercepts an method call,  it invokes &lt;b&gt;methodMissing(String methodName, args) &lt;/b&gt;with two parameters: the &lt;b&gt;name of the missing method&lt;/b&gt; that was invoked and an &lt;b&gt;array representing the method's parameters&lt;/b&gt;.  So, for instance, when Groovy intercepts  &lt;b&gt;xml.title("Hello")&lt;/b&gt;, the first parameter of methodMissing() has a value of &lt;b&gt;"title"&lt;/b&gt; and &lt;b&gt;args.length = 1&lt;/b&gt; where &lt;b&gt;arg[0]&lt;/b&gt; = &lt;b&gt;"Hello"&lt;/b&gt;. &lt;br&gt; &lt;br&gt; When the syntax is as follows, &lt;b&gt;xml.header {...}&lt;/b&gt;, methodMissing's method name has a value of &lt;b&gt;"header"&lt;/b&gt;.  Here, however, &lt;b&gt;args[0] is a closure&lt;/b&gt;.  A &lt;a href="http://en.wikipedia.org/wiki/Closure_%28computer_science%29" id="z1p6" title="Closure on Wikipedia"&gt;closure is an executable&lt;/a&gt; (callable) code block that can be treated as a variable.  As such, we must tell Groovy that we want to execute that code block.  However, before we blindly call the closure, we &lt;b&gt;reassign the closure's target&lt;/b&gt; to be the &lt;b&gt;SimpleXmlBuilder&lt;/b&gt; class (&lt;b&gt;args[0].delegate = this&lt;/b&gt; line 11 and 49).  Therefore, the next method dispatch request on the closure will be handled by the SimpleXmlBuilder.&lt;br&gt; &lt;br&gt; Finally, when the syntax of our builder takes the form of &lt;b&gt;xml.html(xmlns:"http;//somenamespace"){ ... }&lt;/b&gt;, Groovy's MOP invokes methodMissing where the method name is &lt;b&gt;"html"&lt;/b&gt; as expected.  In this case, however, &lt;b&gt;argument array has two memebers&lt;/b&gt;: the &lt;b&gt;first one is a map&lt;/b&gt; and the &lt;b&gt;second member&lt;/b&gt; is &lt;b&gt;another closure&lt;/b&gt;.  Knowing this, we can handle tags with both attributes and function as a container tag as shown above (starting with line 37).&lt;br&gt; &lt;br&gt; &lt;font size="4"&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/font&gt;&lt;br&gt; &lt;br&gt; This sample code above demonstrates how Groovy's MOP mechanism can let developers change and extend the language's syntactical behavior to build functional DSL that fit specific needs.  Here, in about 30 lines of code, we created a simple XML builder which is able to output well-formed xml document.  This is a simple example and shows just a small glimpse of the capabilities of Groovy's meta programming.  I hope this inspires you to continue to explore Groovy and come up with your own use for MOP.&lt;br&gt; &lt;br&gt; &lt;font size="4"&gt;&lt;b&gt;References&lt;/b&gt;&lt;/font&gt;&lt;br&gt; 0. Download Groovy source file - &lt;a href="http://vmatters.googlepages.com/SimpleBuilderDemo.groovy" id="b0mn" title="Download Groovy source code"&gt;http://vmatters.googlepages.com/SimpleBuilderDemo.groovy&lt;/a&gt;&lt;br&gt; 1. Dynamic Groovy - &lt;a href="http://groovy.codehaus.org/Dynamic+Groovy" id="ji:w" title="http://groovy.codehaus.org/Dynamic+Groovy"&gt;http://groovy.codehaus.org/Dynamic+Groovy&lt;/a&gt;&lt;br&gt; 2. Using methodMissing and propertyMissing - &lt;a href="http://groovy.codehaus.org/Using+methodMissing+and+propertyMissing" id="rfd3" title="http://groovy.codehaus.org/Using+methodMissing+and+propertyMissing"&gt;http://groovy.codehaus.org/Using+methodMissing+and+propertyMissing&lt;/a&gt;&lt;br&gt; 3. Meta Programming with Groovy Part 1 - &lt;a href="http://groovy.dzone.com/articles/metaprogramming-groovy-i" id="rhmc" title="http://groovy.dzone.com/articles/metaprogramming-groovy-i"&gt;http://groovy.dzone.com/articles/metaprogramming-groovy-i&lt;/a&gt;&lt;br&gt; 4. Meta Programming with Groovy Part 2 - &lt;a href="http://groovy.dzone.com/articles/metaprogramming-groovy-ii-expa" id="i484" title="http://groovy.dzone.com/articles/metaprogramming-groovy-ii-expa"&gt;http://groovy.dzone.com/articles/metaprogramming-groovy-ii-expa&lt;/a&gt;&lt;br&gt; 5. Google Doc version of this write up - &lt;a id="publishedDocumentUrl" class="tabcontent" target="_blank" href="Doc?id=df3qdpw5_53chtkh89r"&gt;http://docs.google.com/Doc?id=df3qdpw5_53chtkh89r&lt;/a&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;br&gt;</content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2008/02/creating-simple-builder-with-groovys.html' title='Creating a Simple Builder with Groovy&apos;s methodMissing()'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/6819538851770102281'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/6819538851770102281'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-8711577303503848547</id><published>2008-02-05T11:12:00.000-05:00</published><updated>2008-02-07T07:42:37.767-05:00</updated><title type='text'>Integrating Groovy Classes in Spring</title><content type='html'>            &lt;font size="5"&gt;&lt;b&gt; Spring Meets Groovy!&lt;/b&gt;&lt;/font&gt;&lt;br&gt; &lt;br&gt;[&lt;b&gt;View in Google Doc: &lt;/b&gt;&lt;a title="Google Doc Version" class="tabcontent" href="Doc?id=df3qdpw5_51fqxz7cft" id="publishedDocumentUrl" target="_blank"&gt;&lt;/a&gt;&lt;a title="http://docs.google.com/Doc?id=df3qdpw5_51fqxz7cft" target="_blank" href="Doc?id=df3qdpw5_51fqxz7cft" id="rjjm"&gt;http://docs.google.com/Doc?id=df3qdpw5_51fqxz7cft&lt;/a&gt; ]&lt;br&gt;&lt;br&gt; &lt;b&gt;If you don't use Spring or care to know about it, then this write up is not for you&lt;/b&gt;.  I will look at how your Java-based Spring component can made Groovier!!  Again, as a pre-requisite, you must already be using Spring (2.0 or better) and have a working knowledge of Groovy.&lt;br&gt; &lt;br&gt; &lt;font size="4"&gt;&lt;b&gt;Why Groovy and Spring?&lt;/b&gt;&lt;/font&gt;&lt;br&gt; After more than ten years of Java, we can all agree that one language does not fit all.  We (collective Java community) have been banging square pegs into round holes (with patterns, anti-patterns, best practices, frameworks as lubricant).  With the advent of dynamic languages such Groovy and Ruby in the enterprise, we are realizing that it is time to start building &lt;b&gt;polyglot&lt;/b&gt; systems.  Poly-who, you ask??  A system that is made up of one or more languages.  Each language addresses a specific domain (i.e. structural, configuration, business, ui, etc) so that your pegs fit where they should.  We are already do this today when we write our &lt;b&gt;views in JSP's&lt;/b&gt;, &lt;b&gt;controllers in Java&lt;/b&gt;, retrieve &lt;b&gt;data using SQL&lt;/b&gt;, and &lt;b&gt;configure &lt;/b&gt;our apps using &lt;b&gt;XML&lt;/b&gt;.&lt;br&gt; &lt;br&gt;&lt;font size="3"&gt;&lt;b&gt; Groovy in Spring Example&lt;/b&gt;&lt;/font&gt;&lt;br&gt; Wiring Groovy beans in Spring is easy and require little deviation from what you already know.  You can create your beans following these steps&lt;br&gt; &lt;br&gt; &lt;font size="3"&gt;&lt;b&gt;1. Create a Java Interface&lt;/b&gt;&lt;/font&gt;&lt;br&gt; Currently, Groovy beans in Spring must implement an Java-defined interface so that Spring can get type information about your Groovy beans.  So, let's create a &lt;b&gt;Payment interface&lt;/b&gt;:&lt;br&gt; &lt;br&gt; &lt;div&gt;   &lt;table id="dbna" bgcolor="#cccccc" border="0" cellpadding="3" cellspacing="0"&gt;     &lt;tbody&gt;     &lt;tr&gt;       &lt;td width="100%"&gt;         &lt;span style="font-family: Courier New;"&gt;&lt;font size="2"&gt;package demo.vladimirvivien;&lt;br&gt;         &lt;br&gt;         import java.util.HashMap;&lt;br&gt;         &lt;br&gt;         public &lt;b&gt;interface Payment&lt;/b&gt; {&lt;br&gt;             void &lt;b&gt;pay&lt;/b&gt;(&lt;b&gt;HashMap&lt;/b&gt; info);&lt;br&gt;         }&lt;/font&gt;&lt;br&gt;         &lt;/span&gt;&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;/tbody&gt;   &lt;/table&gt; &lt;/div&gt; &lt;br&gt; &lt;br&gt; &lt;font size="3"&gt;&lt;b&gt;2. Implement in Groovy&lt;/b&gt;&lt;/font&gt;&lt;font size="3"&gt;&lt;br&gt; &lt;/font&gt;Create a Groovy class that implements the interface.  Place your Groovy file somewhere on the classpath.  In this example, the file is placed in groovy/CreditCardPayment.groovy.  Your Groovy class has access to any classes on the classpath as well, so you can reference other Java classes or other Groovy classes.  The class has two properties (&lt;b&gt;mechantId &lt;/b&gt;and &lt;b&gt;serviceUrl&lt;/b&gt;) which can be injected at runtime by Spring (see below).&lt;br&gt; &lt;br&gt; &lt;div&gt;   &lt;table id="yp5q" bgcolor="#cccccc" border="1" bordercolor="#000000" cellpadding="3" cellspacing="0"&gt;     &lt;tbody&gt;     &lt;tr&gt;       &lt;td width="100%"&gt;         &lt;font size="2"&gt;&lt;span style="font-family: Courier New;"&gt;import demo.vladimirvivien.Payment&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;import java.lang.Util.*&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;import org.apache.commons.logging.Log;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;import org.apache.commons.logging.LogFactory;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;br style="font-family: Courier New;"&gt;         &lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;class &lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;&lt;b&gt;CreditCardPayment implements Payment &lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;{&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;    static Log log = LogFactory.getLog(Payment.class)&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;             &lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;    String merchantId;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;    String serviceUrl;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;             &lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;    void pay(HashMap info) {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        log.info("Processing Payment...")&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;                 &lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        println "---------------------------"&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        println "Merchant ID:t${merchantId}"&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        println "Service URL:t${serviceUrl}"&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        println "Payer:nt${info.PAYER_NAME}nt${info.PAYER_ADDR}ntCard:${info.PAYER_CCNUM} Exp:${info.PAYER_CCEXP}"&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;                 &lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        // process payment here&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;    }&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;/font&gt;&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;/tbody&gt;   &lt;/table&gt; &lt;/div&gt; &lt;br&gt;  &lt;div&gt; &lt;/div&gt; &lt;br&gt; &lt;font size="3"&gt;&lt;b&gt;3. Wire in Spring&lt;/b&gt;&lt;/font&gt;&lt;br&gt; The first thing to notice is the XML schema declaration.  It makes reference to the XML lang namespace and the lang XSD.  This allows you to use the specially provided &lt;b&gt;&amp;lt;lang:groovy/&amp;gt;&lt;/b&gt; tag.  The tag lets you wire in Groovy beans and inject property values into them.  Here, we are injecting mechantId and serviceURL with values just as we do regular Java POJO's.&lt;br&gt; &lt;br&gt; &lt;div&gt;   &lt;table id="k8n6" bgcolor="#cccccc" border="1" bordercolor="#000000" cellpadding="3" cellspacing="0"&gt;     &lt;tbody&gt;     &lt;tr&gt;       &lt;td width="100%"&gt;         &lt;span style="font-family: Courier New;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;&lt;b&gt;beans &lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;       &lt;b&gt;xmlns:lang="http://www.springframework.org/schema/lang&lt;/b&gt;"&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;       xsi:schemaLocation="&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;&lt;b&gt;http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd&lt;/b&gt;"&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;br style="font-family: Courier New;"&gt;             &lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;    &amp;lt;&lt;b&gt;lang:groovy&lt;/b&gt; id="&lt;b&gt;payManager&lt;/b&gt;" script-source="classpath:&lt;b&gt;groovy/CreditCardPayment.groovy&lt;/b&gt;"&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        &amp;lt;lang:&lt;b&gt;property&lt;/b&gt; name="merchantId" value="ID343432-4434-34" /&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        &amp;lt;lang:&lt;b&gt;property &lt;/b&gt;name="serviceUrl" value="http://paymentservice/processor.do" /&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;    &amp;lt;/&lt;b&gt;lang:groovy&lt;/b&gt;&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;&amp;lt;/&lt;b&gt;beans&lt;/b&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;/tbody&gt;   &lt;/table&gt; &lt;/div&gt; &lt;br&gt; &lt;font size="4"&gt;&lt;b&gt;Run the Example&lt;/b&gt;&lt;/font&gt;&lt;br&gt; Here, we have a Java class that runs the example.  However, you can imagine this setup working in other context such as a web application, a standalone process, or any other context where Spring can live.  Note in the code that once the Groovy bean is retrieved from the Spring context, it is used as a regular Java class.&lt;br&gt; &lt;div&gt;   &lt;table id="h4pm" bgcolor="#cccccc" border="1" bordercolor="#000000" cellpadding="3" cellspacing="0"&gt;     &lt;tbody&gt;     &lt;tr&gt;       &lt;td width="100%"&gt;         &lt;span style="font-family: Courier New;"&gt;package demo.vladimirvivien;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;import java.util.HashMap;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;import org.springframework.context.ApplicationContext;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;import org.springframework.context.support.ClassPathXmlApplicationContext;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;public &lt;b&gt;class Main&lt;/b&gt; {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;    public &lt;b&gt;static void main(String[] args&lt;/b&gt;) {&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        &lt;b&gt;ApplicationContext &lt;/b&gt;ctx = new &lt;b&gt;ClassPathXmlApplicationContext&lt;/b&gt;("&lt;b&gt;META-INF/spring-context.xml&lt;/b&gt;");&lt;br&gt;         &lt;br&gt;                 // pull an instance of the Groovy Payment bean&lt;br style="font-family: Courier New;"&gt;         &lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;        Payment payment = (Payment) ctx.getBean("payManager");&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        HashMap&amp;lt;String,String&amp;gt; info = new HashMap&amp;lt;String,String&amp;gt;();&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        info.put("PAYER_NAME", "John Foo");&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        info.put("PAYER_ADDR", "12345 Main Street, USA");&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        info.put("PAYER_CCNUM", "1234564343343");&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;        info.put("PAYER_CCEXP", "0910");&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;       &lt;br&gt;                 // call the implemented mehod pay()&lt;br style="font-family: Courier New;"&gt;         &lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;        &lt;b&gt;payment.pay(info);&lt;/b&gt;&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;    }&lt;/span&gt;&lt;br style="font-family: Courier New;"&gt;         &lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br&gt;         &lt;br&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;/tbody&gt;   &lt;/table&gt; &lt;/div&gt; &lt;br&gt; You should see the followings on the screen:&lt;br&gt; &lt;div&gt;   &lt;table id="a0ya" border="1" bordercolor="#000000" cellpadding="3" cellspacing="0"&gt;     &lt;tbody&gt;     &lt;tr&gt;       &lt;td width="100%"&gt;         &lt;div id="r7ho" style="padding: 1em 0pt; text-align: left;"&gt;           &lt;img src="http://docs.google.com/File?id=df3qdpw5_52dmfxz4hf" style="width: 357px; height: 112px;"&gt;         &lt;/div&gt;       &lt;/td&gt;     &lt;/tr&gt;     &lt;/tbody&gt;   &lt;/table&gt; &lt;/div&gt; &lt;br&gt; &lt;br&gt; &lt;font size="4"&gt;&lt;b&gt;So What?&lt;/b&gt;&lt;/font&gt; &lt;br&gt; You may be saying "Why should I care? I can do the same thing in Java!"  You would be correct.  This is not meant to supplant Java but rather complement it.  Integrating a dynamic language such as Groovy into your enterprise development gives you a new level of flexibility and configurability that was not there before (or at least requires additional steps to work smoothly).  You can use this approach in several scenarios&lt;br&gt; - &lt;b&gt;Configuration:&lt;/b&gt; Use Groovy beans to capture configuration rules for your system or for your business logic including page flow, process flow, etc.&lt;br&gt; - &lt;b&gt;Business Rules:&lt;/b&gt; some business logic tend to change.  You can use Groovy to&lt;br&gt; - &lt;b&gt;Handle Event:&lt;/b&gt; Use Groovy to react to system or application events (i.e. if inventory falls below a level, send email.  This works well in conjunction with JMX)&lt;br&gt; - &lt;b&gt;Validation:&lt;/b&gt; validation rules is another context susceptible to changes.  Capturing your validation in Groovy lets you adjust to your business needs.&lt;br&gt; - &lt;b&gt;Expose Edge Services&lt;/b&gt;: these are the services that expose functionalities at the boundaries of your system (i.e. MVC controllers, web services, REST services, etc).  See project &lt;a href="http://grails.codehaus.org/" id="n9a1" target="_blank" title="Go to Grails Site"&gt;&lt;b&gt;Grails&lt;/b&gt;&lt;/a&gt; .&lt;br&gt; &lt;br&gt;&lt;font size="4"&gt;&lt;b&gt; Conclusion&lt;/b&gt;&lt;/font&gt;&lt;br&gt; We looked at how Groovy can be integrated in your application using Spring.  Groovy is a natural choice for Polyglot programming on the Java VM given its flexibility and growing popularity.  This write up shows a small instance how Groovy can be integrated into your system using the Spring Framework.  Groovy can be injected in your enterprise stack to handle the more fluid context where logic tends to be updated to keep up with business requirements.&lt;br&gt; &lt;br&gt; &lt;font size="4"&gt;&lt;b&gt;References&lt;/b&gt;&lt;/font&gt;&lt;br&gt; 0. Google Doc for write up - &lt;a title="http://docs.google.com/Doc?id=df3qdpw5_51fqxz7cft" class="tabcontent" href="Doc?id=df3qdpw5_51fqxz7cft" id="publishedDocumentUrl" target="_blank"&gt;http://docs.google.com/Doc?id=df3qdpw5_51fqxz7cft&lt;/a&gt;&lt;br&gt; 1. Spring Dynamic Language Support - &lt;a href="http://static.springframework.org/spring/docs/2.5.x/reference/dynamic-language.html" id="jgy2" target="_blank" title="http://static.springframework.org/spring/docs/2.5.x/reference/dynamic-language.html"&gt;http://static.springframework.org/spring/docs/2.5.x/reference/dynamic-language.html&lt;/a&gt;&lt;br&gt; 2. Ola Bimi - Language Exploration (blog) - &lt;a href="http://ola-bini.blogspot.com/2008/01/language-explorations.html" id="y8ij" target="_blank" title="http://ola-bini.blogspot.com/2008/01/language-explorations.html"&gt;http://ola-bini.blogspot.com/2008/01/language-explorations.html&lt;/a&gt;&lt;br&gt; 3. Neal Ford - Polygot Programming (blog) - &lt;a href="http://memeagora.blogspot.com/2008/01/polyglot-programming-parallels-perched.html" id="wl.q" target="_blank" title="http://memeagora.blogspot.com/2008/01/polyglot-programming-parallels-perched.html"&gt;http://memeagora.blogspot.com/2008/01/polyglot-programming-parallels-perched.html&lt;/a&gt;&lt;br&gt; 3. Grok - Polyglot Programming (blog) - &lt;a href="http://www.grok-programming.com/2007/11/25/polyglot-programming-is-it-just-too-much-to-ask/" id="l77n" target="_blank" title="http://www.grok-programming.com/2007/11/25/polyglot-programming-is-it-just-too-much-to-ask/"&gt;http://www.grok-programming.com/2007/11/25/polyglot-programming-is-it-just-too-much-to-ask/&lt;/a&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;  &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;</content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2008/02/spring-is-groovy-if-you-dont-use-spring.html' title='Integrating Groovy Classes in Spring'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/8711577303503848547'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/8711577303503848547'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-8426882999182036190</id><published>2008-01-20T09:36:00.000-05:00</published><updated>2008-01-20T10:16:58.322-05:00</updated><title type='text'>Grails Is Changing My Entrepreneurial Ambitions</title><content type='html'>I have been playing with Grails for a couple months now.  It made me realize the power of (G)Rails approach, mainly "... get things done ... " I have used ASP Dot Net, at least 3 Java Web Frameworks, ColdFusion (not to mention Perl), I must say Grails is by far the most enjoyable. &lt;br /&gt;&lt;br /&gt;Why all the buzz about Grails?  Well, after you understand Grails and its paradigm, In about , hmmm, 7 minutes you can have a simple, fully-functional, web application.  Grails' intuitive MVC mechanism and data access objects do most of the tedious, mind-numbing boiler plate infrastructural crap you usually have to do in other Java frameworks.  You concentrate on what you know "... your business logic ..."&lt;br /&gt;&lt;br /&gt;Grails  (&lt;a href="http://grails.codehaus.org/"&gt;http://grails.codehaus.org/&lt;/a&gt;) is based on Groovy, Hibernate, Spring and have a well-defined Plug-In architecture.  Now, you are probably thinking "... I don't want to learn these technologies ...."  The cool thing is, you don't have to!  You never see Spring nor Hibernate (unless you want to) Grails does an excellent job of shielding its users from the low-level infrastructural crap.  O, yeah, hmmm, grails generates a WAR file that you can drop on any web container.  Nothing special is needed!&lt;br /&gt;&lt;br /&gt;So, I say this length intro to Grails to get to this: if you are a consultant, own a small operation, or the guy looking to develop the next social site, Grails maybe for you.  As a startup, you know the name of the game is to get things done... Well, Grails lets you get things done... and you can actually get things done fast and the right way (did I mention that you get all the benefits of a full JEE environment without the fuss). &lt;br /&gt;&lt;br /&gt;After a few hours of development, my next project is so far along that it feels unfair... yes... it feels unfair.   It feels as if I should have more code to write... or more design decisions to make,  or more academic bs that I should be concerning myself with (pattern this pattern that)... Instead, I actually have a product, something I can play with, make changes to, and derive motivation from.&lt;br /&gt;&lt;br /&gt;Grails is all about agility... Grails bring dynamics to not only your code, but also the way you develop by giving you the ability to change make changes in mid-development with minimal impact to your level of efforts.  Give it a try!  I have!</content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2008/01/grails-is-changing-my-entrepreneurial.html' title='Grails Is Changing My Entrepreneurial Ambitions'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/8426882999182036190'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/8426882999182036190'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-1407695328792171360</id><published>2008-01-10T22:20:00.000-05:00</published><updated>2008-01-10T22:25:50.069-05:00</updated><title type='text'>Groovy + Spring + Broadway = { -&gt; Resource Monitoring }</title><content type='html'>So, I have been getting some feedbacks regarding Broadway after I first announced it.  So, now it's time to delve into how you can use Groovy, Spring, and Broadway to create monitors.  Using these technologies along with the Broadway API, you can build monitors that evaluate a given expression (default is Groovy) and execute a specified action when that expression returns the desired value (true or false).  In this write up, I will show how to use Groovy, Spring, and Broadway to observe two directories and keep them synchronize.  This is a trivial example, however it shows how Broadway can be integrated with Spring and Groovy to build powerful monitors (see &lt;a href="http://docs.google.com/Doc?id=df3qdpw5_50hs7pn3fv"&gt;Google Doc&lt;/a&gt;).&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;b&gt;Directory Synchronizer [&lt;a href="http://docs.google.com/Doc?id=df3qdpw5_50hs7pn3fv"&gt;Google Doc&lt;/a&gt;]&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;Broadway was designed as component-based API and therefore it plays really well with the Spring component container. As the name implies, we will setup Broadway to monitor two directories (one primary and a secondary). The monitor will keep the secondary directory synchronized with the primary.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;How Does It Work?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;A &lt;b&gt;monitor component&lt;/b&gt; will &lt;b&gt;observe two directories directory for size differences&lt;/b&gt;. When the sizes of the two directories differ, files from the primary are copied to the secondary automatically. This can be easily accomplished using Broadway and Spring. The only required piece of code is the logic for the Action component.  The action will be executed when the monitor detects the condition (in this case, directory sizes differ). As we will see, &lt;b&gt;the logic for the Action can be captured in Groovy Beans (POGO's)&lt;/b&gt; wired in within Spring.&lt;br /&gt;&lt;br /&gt;NOTE: this is by no mean meant to be a robust directory synchronizer, you are welcome to explore ways to make this more robust (i.e caching, thread safety, two-way synchronization, etc).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;An Observed Resource&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;To make it easier to observe the directories, we will create a &lt;b&gt;component that represents the directory structure being observed&lt;/b&gt;.  This class provides a facade to the a file system and expose specific states to be observed. This sort of domain-specific observed components are not required. However, they can expose richer set of data to be observed by your monitors. NOTE: this observed directory class can be integrated using Groovy as well.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;    // Java code for ObservedDirectory&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;    public class ObservedDirectory {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        private String root;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        public String getRoot() {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                return root;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        public void setDirectoryName(String root) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                this.root = root;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        public String getDirectoryName(){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                return root;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        public boolean isEmpty(){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                long size = org.apache.commons.io.FileUtils.sizeOfDirectory(new File(getDirectoryName()));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                return (size &gt; 0) ? false : true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        public long getDirectorySize(){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                return FileUtils.sizeOfDirectory(new File(getDirectoryName()));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;Using Spring's Dynamic Language Support&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;b&gt;Spring's Dynamic Language support&lt;/b&gt; feature was introduced in starting with version 2.0. where you can wire a Groovy (JRuby or BeanShell) beans into a Spring context as if they are regular Java POJO's. This implies that you can inject values into your Groovy bean and wire with other beans in Spring context. If you want to learn more about Spring's Dyanamin Language Support, go to &lt;a title="Spring Dyanamic Language Support online documentation" href="http://static.springframework.org/spring/docs/2.0.x/reference/dynamic-language.html" id="rjsd"&gt;Spring Dyanamic Language Support online documentation&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Spring must be configured properly&lt;/b&gt; to use the dynamic language support. You must have the proper &lt;b&gt;XML schema declarations&lt;/b&gt; or your bean will not be mounted properly in the Spring context.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;&amp;lt;beans xmlns="http://www.springframework.org/schema/beans"&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        xmlns:lang="http://www.springframework.org/schema/lang"&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        xsi:schemaLocation="&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        http://www.springframework.org/schema/beans&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        http://www.springframework.org/schema/lang&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        http://www.springframework.org/schema/lang/spring-lang-2.0.xsd"&amp;gt;&lt;/span&gt;  &lt;span style="font-family:Courier New;"&gt;...&lt;/span&gt;  &lt;span style="font-family:Courier New;"&gt;&amp;lt;/beans&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;[See the &lt;a title="full Spring Config File" href="http://code.google.com/p/broadway-monitor/wiki/SpringConfigXml" id="p0-m"&gt;&lt;b&gt;full Spring Config File&lt;/b&gt;&lt;/a&gt; ]&lt;br /&gt;&lt;br /&gt;Now, we are ready to wire the remainder for the Broadway components to create the directory synchronizer.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;Wiring Broadway Components&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;Since Broadway components follow the JavaBean notation, it's easy to wire them together in Spring. To build the directory synchronizer with Broadway, we will wire the Observed Directory component, the Monitor component, and an Action component.&lt;br /&gt;&lt;b&gt;Wire Observed Directory&lt;/b&gt;&lt;br /&gt;In the Spring configuration file, we have two observed directory components wired. The primary directory is ./dir1 and the secondary directory is ./dir2. When the size of observed directory one differ from that observed directory 2, the Action component will execute its script to syncrhonize the two directories.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;        &amp;lt;!-- ====================== Observed Resources ======================= --&amp;gt;&lt;br /&gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        &amp;lt;bean id="firstDir"&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                class="org.broadway.demo.spring.ObservedDirectory"&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                &amp;lt;property name="directoryName" value="./dir1" /&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        &amp;lt;/bean&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        &amp;lt;bean id="secondDir"&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                class="org.broadway.demo.spring.ObservedDirectory"&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                &amp;lt;property name="directoryName" value="./dir2" /&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Wiring the Monitor&lt;/b&gt;&lt;br /&gt;The Monitor component observes state changes that is expressed by the "monitorExpression" property below. Here, we can see how we can use Groovy as an expression language to define when to take action based on the observed condition.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;        &amp;lt;!-- ======================= Monitor Setup ========================== --&amp;gt;&lt;br /&gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        &amp;lt;bean id="monitor" class="org.broadway.monitor.BeanMonitor"&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                &amp;lt;property name="monitorExpression"&amp;gt; &lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                        &amp;lt;value&amp;gt;&amp;lt;![CDATA[context.resources.firstDir.directorySize != context.resources.secondDir.directorySize]]&amp;gt;&amp;lt;/value&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                &amp;lt;/property&amp;gt;&lt;/span&gt;                  &lt;span style="font-family:Courier New;"&gt;                &amp;lt;property name="action" ref="action"/&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                &amp;lt;property name="resourceCollector"&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                        &amp;lt;bean&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                                class="org.broadway.monitor.MappedResourceCollector"&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                                &amp;lt;property name="resources"&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                                        &amp;lt;map&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                                                &amp;lt;entry key="firstDir"  value-ref="firstDir" /&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                                                &amp;lt;entry key="secondDir" value-ref="secondDir" /&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                                        &amp;lt;/map&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                                &amp;lt;/property&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                        &amp;lt;/bean&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                &amp;lt;/property&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;The monitor sets up three main properties 1) The monitoring expression using Groovy as an expression language 2)A reference to the action component (see below) 3) the collection of the observed resources (stored in a map).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Wiring the Action&lt;/b&gt;&lt;br /&gt;The Action component is wired into Spring using Spring &amp;lt;lang:groovy&amp;gt; tag.  This tag facilitates the integration of Groovy objects into the Spring context and provides several other settings (such as refresh, etc).  Here, we are using the tag to point to script file located on the class path.&lt;br /&gt;&lt;br /&gt;        &amp;lt;&lt;b&gt;lang&lt;/b&gt;:&lt;b&gt;groovy &lt;/b&gt;id="action" script-source="classpath:scripts/SyncAction.groovy"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The Groovy Action Class&lt;/b&gt;&lt;br /&gt;The Groovy Action class implements the Action interface (from Broadway API) directly to carry out the logic for the synchronizer. If you don't care about the Spring dependency, this is a better option then using the ScritpedAction component provided by Broadway (see below). However, you need to do some tedious class casting to get to the values in the context object. Here is what the Groovy Action class looks like:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;class SyncAction implements Action{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        public Object execute(Context ctx){&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                HashMap resources = (HashMap)ctx.getValue(MonitorConstants.MonitorKeys.RESOURCE_COLLECTION);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                String dirPath1 = resources["firstDir"].directoryName;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                String dirPath2 = resources["secondDir"].directoryName;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                File dir1 = new File(dirPath1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                dir1.eachFile {origFile -&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                        String origFileName = origFile.name;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                        File destFile = new File(dirPath2+ File.separator + origFileName);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                        if(!destFile.exists() || (destFile.lastModified() &lt;&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                                print "Synching file File $origFile.name ...\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                                def fis = origFile.newInputStream();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                                new FileOutputStream(destFile).withStream {fos -&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                                        fos &lt;&lt;&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                                }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;An Alternative to Groovy Action Class&lt;/b&gt;&lt;br /&gt;If you do not want to use Spring's dynamic language support, you can still use Groovy to execute the action.  Broadway provides a component called &lt;b&gt;ScriptedAction &lt;/b&gt;that lets you specify a script file on the classpath or the system file path.  Using this option, you can specify the script for your action in a simpler way.&lt;br /&gt;&lt;br /&gt;To &lt;b&gt;wire the ScriptedAction&lt;/b&gt; do:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;        &amp;lt;&lt;/span&gt;&lt;span style="font-family:Courier New;"&gt;&lt;b&gt;bean &lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;"&gt;id="action"&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                class="org.broadway.monitor.ScriptedAction"&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;                &amp;lt;property name="scriptFileLocation" value="scripts/synchronizeDir.groovy" /&amp;gt;&lt;/span&gt; &lt;span style="font-family:Courier New;"&gt;        &amp;lt;/&lt;/span&gt;&lt;span style="font-family:Courier New;"&gt;&lt;b&gt;bean&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;Here, the component points to a Groovy script file located on the classpath.  The Groovy script that gets executed by the ScriptedAction component is the following:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;def dirPath1 = context.resources.firstDir.directoryName;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;def dirPath2 = context.resources.secondDir.directoryName;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;print "***** Synchronizing Directories [Mirror dir2 to Dir1] *****\n";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;def File dir1 = new File(dirPath1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;dir1.eachFile {origFile -&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        def origFileName = origFile.name;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        def destFile = new File(dirPath2+ File.separator + origFileName);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        if(!destFile.exists() || (destFile.lastModified() &lt;&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                print "Synching file File $origFile.name ...\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                def fis = origFile.newInputStream();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                new FileOutputStream(destFile).withStream {fos -&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                        fos &lt;&lt;&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;We've seen how easy it is to use Groovy, Spring, and Broadway to wire together monitors.  This example shows how to create a directory synchronizer with little effort.  I encourage you to take a look at Broadway and let me know what you think.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;More Info&lt;br /&gt;&lt;/b&gt;Google Doc - &lt;/span&gt;&lt;a id="publishedDocumentUrl" class="tabcontent" target="_blank" href="http://docs.google.com/Doc?id=df3qdpw5_50hs7pn3fv"&gt;http://docs.google.com/Doc?id=df3qdpw5_50hs7pn3fv&lt;/a&gt;&lt;br /&gt;Broadway - &lt;a title="http://code.google.com/p/broadway-monitor/" href="http://code.google.com/p/broadway-monitor/" id="xmae"&gt;http://code.google.com/p/broadway-monitor/&lt;/a&gt;&lt;br /&gt;Download Broadway - &lt;a title="http://broadway-monitor.googlecode.com/files/broadway-0.5.zip" href="http://broadway-monitor.googlecode.com/files/broadway-0.5.zip" id="gila"&gt;http://broadway-monitor.googlecode.com/files/broadway-0.5.zip&lt;/a&gt;&lt;br /&gt;Download Tutorial - &lt;a title="http://broadway-monitor.googlecode.com/files/broadway-tutorial.zip" href="http://broadway-monitor.googlecode.com/files/broadway-tutorial.zip" id="pl26"&gt;http://broadway-monitor.googlecode.com/files/broadway-tutorial.zip&lt;/a&gt;</content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2008/01/groovy-spring-broadway-resource_10.html' title='Groovy + Spring + Broadway = { -&amp;gt; Resource Monitoring }'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/1407695328792171360'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/1407695328792171360'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-7964496285952662970</id><published>2007-12-31T03:45:00.000-05:00</published><updated>2007-12-31T04:19:01.812-05:00</updated><title type='text'>Introducing Project Broadway Monitor</title><content type='html'>I have been working on this on and off for the past 3 years.  As with free-time projects, it started out as something completely different and progressively turned into what it is today.  If you find the project interesting, send some feedbacks!  So, here it is:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://code.google.com/p/broadway-monitor/"&gt;&lt;span style="font-weight: bold;"&gt;Project Broadway&lt;/span&gt;&lt;/a&gt; is an extensible and customizable monitoring API.  Broadway lets developers easily create monitor components to observe pre-defined conditions and specify how to react when these conditions are encountered.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://vmatters.googlepages.com/broadway-object-monitor.png" /&gt;&lt;br /&gt;&lt;br /&gt;At its core, Broadway lets you separate the monitoring concerns from the observed resources.  It has a  flexible design,   which allows it to work in any context where JavaBean-style getter property values can be read either directly through in-VM method invocation or through some detached mechanism (i.e. proxy, reflection, rmi, jmx, web service, etc).  Broadway's simplified design offers two major high level components a Monitor and an Action.  The Monitor components lets you specify resources to monitor and express some rules to monitor using a scripting language (&lt;span style="font-weight: bold;"&gt;Groovy &lt;/span&gt;is the default).  The Action component specifies the action to execute when a specified condition is realized.  Action can be pure Java classes or they can be written in scripting languages such as Groovy or JavaScript, etc.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Broadway Offers&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Ability to monitor both in-VM and distributed resources. &lt;/li&gt;&lt;li&gt;API with rich level of programmability through a monitor DSL. &lt;/li&gt;&lt;li&gt;Leverages existing frameworks including JavaBean, JMX, Java scripting, Apache BSF, etc. &lt;/li&gt;&lt;li&gt;Support expressive monitoring rules using scripting language (default is Groovy) &lt;/li&gt;&lt;li&gt;Create compound expression to monitor multiple resources which can be in different context. &lt;/li&gt;&lt;li&gt;Architecture allows plug-in of different scripting engine supported Apache BSF (default is Groovy). &lt;/li&gt;&lt;li&gt;Scripted action component to execute script files to react to monitor expressions. &lt;/li&gt;&lt;/ul&gt;For more details, visit &lt;a style="font-weight: bold;" href="http://code.google.com/p/broadway-monitor/"&gt;http://code.google.com/p/broadway-monitor/&lt;/a&gt;</content><link rel='alternate' type='text/html' href='http://vladimirvivien.com/blogs/ot/2007/12/introducing-project-broadway-monitor.html' title='Introducing Project Broadway Monitor'/><link rel='replies' type='application/atom+xml' href='http://vladimirvivien.com/blogs/ot/feed/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/7964496285952662970'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17720202/posts/default/7964496285952662970'/><author><name>vmatters</name><uri>http://www.blogger.com/profile/15062049812941486249</uri><email>noreply@blogger.com</email></author></entry><entry><id>tag:blogger.com,1999:blog-17720202.post-6300037360247180642</id><published>2007-10-13T14:04:00.000-04:00</published><updated>2007-10-14T09:13:18.304-04:00</updated><title type='text'>NFJS Atlanta</title><content type='html'>Last weekend I attended the &lt;a href="http://www.nofluffjuststuff.com/conference/atlanta/2007/10/index.html"&gt;No Fluff Just Stuff Atlanta&lt;/a&gt; as a speaker.  The series has a wide set of topics ranging from front-end development to ESB.  There was something for everyone doing enterpr