<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Meeraj Kunnumpurath&apos;s Blog</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/meeraj/" />
<modified>2008-01-28T10:30:04Z</modified>
<tagline></tagline>
<id>tag:weblogs.java.net,2008:/blog/meeraj/68</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2008, meeraj</copyright>
<entry>
<title>Introducing Service Component Architecture (SCA)</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/meeraj/archive/2008/01/introducing_ser.html" />
<modified>2008-01-28T10:30:04Z</modified>
<issued>2008-01-26T12:45:43Z</issued>
<id>tag:weblogs.java.net,2008:/blog/meeraj/68.9072</id>
<created>2008-01-26T12:45:43Z</created>
<summary type="text/plain">For the past twelve months, I have been involved with the Service Component Architecture (SCA) specifications and two of the open source SCA implementations. Now that SCA is gaining industry traction, I would like to use my weblog here to introduce the technology and demostrate how SCA can be used for building standards-based enterprise class applications using service orineted principles and paradigms, through a series of weblog entries covering both the theory and practical aspects of SCA.</summary>
<author>
<name>meeraj</name>

<email>meeraj@lycos.com</email>
</author>
<dc:subject>Distributed</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/meeraj/">
For the past twelve months, I have been involved with the Service Component Architecture (SCA) specifications and two of the open source SCA implementations. Now that SCA is gaining industry traction, I would like to use my weblog here to introduce the technology and demostrate how SCA can be used for building standards-based enterprise class applications using service orineted principles and paradigms, through a series of weblog entries covering both the theory and practical aspects of SCA.
<![CDATA[<p>
In the past few years SOA has evolved into one of the most prevalent architectural paradigms in building enterprise class middleware applications. Despite its wide spread adoption, SOA has pretty much stayed a vague set of principles, interpreted differently based on the perspective of the interpreter. More than often practitioners use the terms SOA and Web Services invariably, even though, web services based technologies are only one of the means of realising service-oriented architecture.
</p>

<p>
There has been a significant lack of standards and specifications that provide prescriptive and definitive guidelines into how service-oriented business applications are to be developed. However, with the inception of Service Component Architecture (SCA) by <a href="http://www.osoa.org">OSOA</a>, SOA has been made a realistic proposition for enterprise developers and architects. SCA is now being ratified under the OASIS Open Composite Services Architecture (<a href="http://www.oasis-opencsa.org/sca">OpenCSA</a>) initiative.
</p>

<h2>What is SCA?</h2>
<p>
SCA is a set of specifications, addressing both runtime vendors and enterprise application developers and architects, for developing applications based on service oriented architectural principles and paradigms. SCA advocates a compositional architectural pattern for building enterprise class service oriented applications. It addresses the assembly of both fine-grained tightly coupled and coarse-grained loosely coupled components. SCA composition is based on recursive assembly where fine-grained tightly coupled components are composed together to build coarse-grained components. These coarse grained components can be used in a higher-level contexts to build even coarser grained components and enterprise applications.
</p>

<h2>SCA Key Concepts</h2>
<p>
The key SCA concepts are,
</p>
<h3>Assembly Model</h3>
<p>
SCA assembly model primarily defines the recursive assembly of components into services. The recursive assembly allows fine-grained components to be wired into what in SCA terms is called composites. These composites than can be used as components in higher-level composites and applications. The type of a component generally defines the services exposed by the component, properties that can be configured on the components and dependencies the component has on services exposed by other components.
</p>
<p>
The diagram below shows an example of an SCA assembly model,
<br/>
<br/>
<img alt="sca-blog-image-1.jpeg" src="http://weblogs.java.net/blog/meeraj/archive/images/sca-blog-image-1.jpeg" width="1004" height="647" />
<br/>
<br/>
<br/>
</p>
<p>
In the diagram above Composite X is composed of two components Component Y and Component Z, which themselves are composites. Composite X exposes its service using web services. 
</p>
<p>
Composite Y is composed of a Java component, a Groovy component and a Jython component. The service offered by Java component is promoted outside the composite. The Java component depends on services offered by the Groovy and Jython components. In SCA terminology these dependencies are called references. All the references for the Java component are satisfied by services offered by other components within the same composite. However, the reference on the Groovy component has been promoted outside the composite and will have to be satisfied in a context within which Composite Y is used as a component. In the diagram above this is achieved using the service promoted by Composite Z.
</p>
<p>
Composite Z is composed of a Java component, a BPEL component and a Spring component, the service offered by the BPEL component is promoted to be used when the composite is used as a component in a higher level composite.
</p>
<p>
As you can see SCA allows building of compositional service-oriented applications using components built on heterogeneous technologies and platforms. SCA assembly model is generally expressed in an XML based language called Service Component Description Language (SCDL).
</p>
<h3>Client & Implementation Model</h3>
<p>SCA client and implementation (C & I) model describes how components, services, references etc are represented, defined and packaged in multiple languages and technology platforms. The current SCA suite of specifications cover the client and implementation model for Java, Spring, BPEL, C++ etc.
<p>
<h3>Bindings</h3>
<p>
SCA bindings enable services and references to be accessed over multiple transport and data binding protocols. The current SCA suite of specifications cover bindings for Web Services, JMS, EJB etc.
</p>
<h3>Intents and Policies</h3>
<p>
The policy framework is one of the key aspects of SCA. Policy framework allows Quality of Service (QoS) aspects to be defined, managed, enforced and governed, orthogonally to component implementations and assembly using declarative intents and corresponding policy sets. Like all the other SCA aspects, policy framework is highly extensible as well. Policy framework allows policies to be defined using standard mechanisms like WS-Policy or using your own policy language.
</p>
<p>
<b><i>Note: </i></b>I will cover SCA assembly model, client & implementation model, policy framework and bindings in detail later.
</p>
<h2>Current SCA Specifications at OpenCSA</h2>
<p>
The current set of SCA specifications hosted on the OSOA site includes,
<br/>
<br/>
<a href="http://osoa.org/download/attachments/35/SCA_AssemblyModel_V100.pdf?version=1">SCA Assembly Model</a>
<br/>
<a href="http://osoa.org/download/attachments/35/SCA_Policy_Framework_V100.pdf?version=1">SCA Policy Framework</a>
<br/>
<a href="http://osoa.org/download/attachments/35/SCA_JavaComponentImplementation_V100.pdf?version=1">SCA Java Client & Implementation</a>
<br/>
<a href="http://osoa.org/download/attachments/35/SCA_ClientAndImplementationModelforBPEL_V100.pdf?version=1l">SCA BPEL Client & Implementation</a>
<br/>
<a href="http://osoa.org/download/attachments/35/SCA_SpringComponentImplementationSpecification-V100.pdf?version=1">SCA Spring Client & Implementation</a>
<br/>
<a href="http://osoa.org/download/attachments/35/SCA_ClientAndImplementationModel_Cpp-V100.pdf?version=2">SCA C++ Client & Implementation</a>
<br/>
<a href="http://osoa.org/download/attachments/35/SCA_WebServiceBinding_V100.pdf?version=2">SCA Web Services Binding</a>
<br/>
<a href=http://osoa.org/download/attachments/35/SCA_JMSBinding_V100.pdf?version=2">SCA JMS Binding</a>
<br/>
<h2>Summary</h2>
<p>
SCA provides a set of specifications, addressing both runtime vendors and enterprise developers/architects, for building service-oriented enterprise applications. For the first time we have a set of specifications that address how SOA can be built rather than what SOA is about. I have provided a bird's eye view of SCA as a technology. In the coming days I will cover in further detail each aspect of SCA as well as practical examples on building SCA based applications using one of the open source SCA runtimes I am heavily involved with, Fabric3.
</p>]]>
</content>
</entry>
<entry>
<title>TSS Symposium Europe - Day 3</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/meeraj/archive/2006/06/tss_symposium_e_1.html" />
<modified>2006-06-24T12:12:30Z</modified>
<issued>2006-06-24T12:10:39Z</issued>
<id>tag:weblogs.java.net,2006:/blog/meeraj/68.5086</id>
<created>2006-06-24T12:10:39Z</created>
<summary type="text/plain">Day 3 started with a panel discussion entitled Developer&apos;s Odyssey. There were also intresting sessions by James Strachan on ActiveMQ and Heinz Kabutz. </summary>
<author>
<name>meeraj</name>

<email>meeraj@lycos.com</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/meeraj/">
<![CDATA[<p>
I think the whole theme of the conference has been based mainly around Grid, with different parties trying to push their technology as the best fit for realising grid-based computing. We had four different technologies (some of them I would say can complement each other) claming to be grid-enablers.
<li>Spaces based grids pushed by the Gigaspaces guys</li>
<li>Grid based on high-performant messaging using something like ActiveMQ by James. Interestingly enough James had a quite indifferent view on spaces.</li>
<li>Transparent JVM clustering by the Terracotta guys</li>
<li>Distributed transactional caches like Tangosol by Cameron and JBossCache by Bela Ban</li>
</p>

<p>
I have got some interesting views of comparing spaces and JMS, which I will cover later.
</p>

<p>
The panel discussion in the morning was led by Cedric, Wayne Beaton, Bruce Tate and Eric Doernenburg. The panel discussed a lot of topics related to development including,
<li>Need for dynamic languages -> mainly from Bruce :-)</li>
<li>The psychology of testing, importance of having proper functional  tests to cater for architectural refactoring in XP environments -> I mentioned this briefly in one of my previous blogs</li>
<li>Dominance of Eclipse and IntelliJ over poor Netbeans. Surprisingly (or not) only one amongst the audience admitted to using Netbeans</li>
<li>Importance of debugging to increase productivity. I would be interested to know how many of you debug actively as part of your development</li>

Interestingly, nothing much was said on build tools, continuous integration etc.
</p>

<p>
Heinz's session was quite refreshing in increasing developer productivity. I think I will try to cover the whole of Heinz's session in another blog by the end of this weekend. It does deserve an entry on its own.
</p>

<p>
John Davies from C24 gave a session on a case study on the use of grid in investment banking. It started with a lot of promise in terms of real world examples of using grid-enabled technologies. Didn't cover much in the end. As I said earlier, I have got an interesting entry coming up comparing JMS and spaces, I warn you guys, it is going to be a bit controversial :-)
</p>

<p>
James presented a nice session on ActiveMQ. Covered some of the advanced features. He was quite excited about message groups. We already use that at work using Oracle AQ's support for correlation ids in messages. Interacting with a JMS server from the telnet console was pretty cool. Other features included,
<li>Wildcard search and hierarchical topics</li>
<li>Composite destinations</li>
<li>XPath based filtering on messages with XML body</li>
<li>A variety of client types etc</li>
</p>

<p>
Overall the conference was a nice experience. Without naming names, I thought some technologies were overly hyped up. All in all, TSS did a very good job organizing the conference.
</p>]]>

</content>
</entry>
<entry>
<title>TSS Symposium Europe - Day 2</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/meeraj/archive/2006/06/tss_symposium_e_2.html" />
<modified>2006-06-24T10:38:57Z</modified>
<issued>2006-06-22T20:19:09Z</issued>
<id>tag:weblogs.java.net,2006:/blog/meeraj/68.5077</id>
<created>2006-06-22T20:19:09Z</created>
<summary type="text/plain">Today&apos;s sessions started with a keynote address by SImon Phipps from Sun on the benefits of open source software. Simon emphasised on the importance of community-based ownership and the different models behind open source software development. There were a whole variety of other interesting sessions including message-based architecture, an update on Spring 2.0, WSRP, JBI &amp; Servicemix, JPA, transparent JVM clustering, space-based architecture etc.</summary>
<author>
<name>meeraj</name>

<email>meeraj@lycos.com</email>
</author>
<dc:subject>Community</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/meeraj/">
<![CDATA[<p>
The first session I attended was by Ted Neward on the importance of message-based architecture. I was quite impressed with Ted's presentation and delivery style. Though, I thought Ted was trying to over-emphasise the superiority of message-based model over an RPC-based model. All I would say is messaging can improve scalability and percieved performance, RPC has its use cases as well in terms of QoS and user responsiveness. Also, as soon as you step into the world of transactional and persistent messaging, some of the scalability gain would start suffering badly. Another interesting point was the notion of tight-coupling with an interface-based approach for RPC compared to the percieved loose-coupling with messaging. I am not sure how true this is. As soon as the producer changes the message structure, the consumer should be able to adapt with this. This is often achieved by using a text-based data representation protocol or something like a JMS map message. A counter argument would be that you can achieve the same level of loose coupling by using loosely typed arguments for your RPC calls. Some of these points were clarified further by Ted during the Q&A session. Had an interesting chat with him on XA and recovery after the session. Quite friendly and approachable guy.
</p>

<p>
I missed the session by Bruce Snyder on JBI & Servicemix due to work commitments. There were also a parallel session by Rikard Oberg on WSRP.
</p>

<p>
The next session was by the <a href="http://www.terracottatech.com">Terraccotta</a> on transparent JVM clustering. Imagine the piece of code below,
</p>

<pre>
public class MyCache {

  private Map cache = new HashMap();
  
  public synchronized Object get(String key) {
    return cache.get(key);
  }
  
  public synchronized void put(String key, Object value) {
    cache.put(key, value);
  }
  
}
</pre>

<p>
A mundane thread-safe cache. Now imagine you can take this class and transparently apply the native Java syntax and semantics for threading across multiple JVMs on a replicated instance of this class. This is what Terracotta provides. I have seen this is implemented in a few payment switches I have come across. However it is nice to have a product that allows you to transparently cluster any application. There are a lot of use cases I can use this in the applications I am working on, including cluster-wide singletons, keeping track of cluster-wide running totals etc.
</p>

<p>
The next talk was on JPA by Mike Keith. The talk was more API and spec focused. The talk before by Patrick Linskey on a more subjective view of JPA would have been more interesting. I don't want to over-elaborate on JPA itself as more than enough has already been written on the topic. However, I would say Hibernate style criteria objects would have been great. An interesting thing was pluggable persistence providers and Spring 2.0 offering a JPA provider. I think this concept started out in EJB 2.0 and disappeared from the final version. I am a bit skeptical about the portability aspect, I am sure the vendors will be tempting developers with proprietary annotations. Do you want a good example, Spec has left to the providers on how to perform eager fetching. So the provders can say, hey, you can use sub-select fetch or join fetch using our proprietary annotations. I have similar apprehensions about the whole concept of bulk updates and the grey area around how the current attached objects are kept in sync with the underlying datastore.
</p>

<p>
The last session for the day was by Nati Shalom from <a href="http://www.gigaspaces.com">Gigaspaces</a> and Rod. They showed a neat example on how Spring can hide the transport intricacies of accessing a clustered space. I think a lot of people are doing the same kind of things with spaces, with <a href="http://mule.codehaus.org">Mule</a> providing similar support. I have been playing around with writing a spaces binding for the SCA implementation <a href="http://incubator.apache.org/tuscany/">Tuscany</a>. It was quite interesting when Nati said we didn't need relational databases anymore (or did I get him wrong?). It may be true for greenfield projects with the rubustness provided by spaces implementation like Gigaspaces (how about durable storage?). However, with terrabytes of corporate data residing in enterprise relational databases and systems being built around existing information set, databases are here to say. The key is finding the right synergy between using existing information stores with space-based grid paradigm. Anyway, the demo was quite impressive. I am sure I will be going back to Nati on more info on how this fits into stuff I have been doing. On a side note it was quite nice to catch up with Rod after a while.
</p>]]>

</content>
</entry>
<entry>
<title>TSS Symposium Europe - Day 1</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/meeraj/archive/2006/06/tss_symposium_e.html" />
<modified>2006-06-26T07:51:15Z</modified>
<issued>2006-06-21T23:09:44Z</issued>
<id>tag:weblogs.java.net,2006:/blog/meeraj/68.5069</id>
<created>2006-06-21T23:09:44Z</created>
<summary type="text/plain">The Serverside symposium in Europe kicked off in Barcelona, this morning. The first day included a variety of sessions on SOA, ESB, flow and continuations, AJAX &amp; DWR, web services, BPM, EJB 3.0, TestNG etc. Since there were always three sessions running in parallel, it was difficult to cover all the topics that was being discussed. This is a quick overview of sessions I could attend.</summary>
<author>
<name>meeraj</name>

<email>meeraj@lycos.com</email>
</author>
<dc:subject>Community</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/meeraj/">
<![CDATA[<p>
The symposium kicked of with a keynote session by John Davies, the CTO of <a href="http://www.c24.biz">C24</a>. John’s address mainly covered the choice of technology stack in the investment-banking sector. It was heartening to hear finally Jini and JavaSpaces are being adopted as a mainstream technology for realising enterprise middleware. John also mentioned the increasing acceptance of open source software like Maven, Spring and Hibernate in the banking arena. Maven is increasingly becoming the build tool of choice, despite the criticisms by most who have never had the good fortune of using it and just want to jump on the bandwagon on whining about how complex Maven is. It was also interesting to hear how big investment banks are shying away from full-stack J2EE containers and instead using Tomcat along the lightweight persistent frameworks. We will have to wait and see whether this trend would be reversed with the adoption of JEE 5.0 and EJB 3.0. Another interesting point was that Java 5 is being adopted for the performance gains more than the new language and API features.
</p>

<p>
The next session I attended was by Geert Bevin on flow and continuations. Geert did a good job explaining continuations at a conceptual level. It is a quite powerful concept and quite affective for complex control logic that is difficult to solve with primitive control constructs available in modern programming languages. Geert , then showed how continuations were implemented in the <a href="http://rifers.org"/>RIFE</a> web application framework. It was interesting how RIFE implemented pause and continuation by byte-code amendment and taking a snapshot of the stack frame. I am not sure how efficient this is. It would also be interesting to see whether a future version of Java language would have language level support for continuations.
</p>

<p>
Next session was something I was eagerly waiting for, Gavin King’s session on <a href="http://labs.jboss.com/portal/jbossseam"/>Seam</a>. I was a bit disappointed with the session as a whole, as Gavin spent half of the session on how flawed was the whole concept of stateless architecture and criticising dependency injection and some of the popular DI frameworks. Al though, some of Gavin’s arguments were valid and interesting, the point on HTTP session replication and the Servlet specification mandating a call to <code>setAttribute</code> to enable session replication was factually incorrect. Though, I have always had the same opinion on developers being concerned about using stateful session beans, because of state replication overheads in a cluster, however having no inhibitions in dumping everything and the kitchen sink into the HTTP session. All in all, Seam appeared to be an interesting framework for integrating JSF and EJB component models with a heavy emphasis on stateful session beans.
</p>

<p>
Mike Keith presented a session on EJB 3.0. It was more on the component model rather than JPA. I am not sure I quite like this concept of being able to inject only certain kind of references into only managed components like EJBs, Servlets etc. This will encourage the developers to write everything as an EJB or a Servlet. I am looking forward to Mike’s session on JPA tomorrow.
</p>

<p>
I was really in two minds about whether to go for <a href="http://www.eaipatterns.com">Gregor Hohpe’s</a> session on SOA or Ross Mason’s session on <a href="http://mule.codehaus.org">Mule</a>. Finally, ended up at Ross’s session because of the recent work I have been doing with Mule. The session was pretty basic, didn’t get to know much more than what I already knew. However, had an interesting chat with Ross on roadmap for Mule.
<p>

<p>
Last session for the day was by Cedric Beust on <a href="http://testng.org">TestNG</a>. Junit has revolutionized the way we test in the last five years or so. It has been a wonderful framework. However, it has also shaped our psychology and mindset on jow we do testing. This is more of the fault of us using JUnit for something it was not intended for. Junit is a unit-testing framework and by design has an extremely stateless paradigm for testing. This doesn’t really fit into the more complex requirements of functional, component-level and system testing. To test a complex piece of functionality you often need to execute a set of tests in a stateful context, and this is what TestNG offers. Cedric’s session was the best of the day. It was quiet relieving that TestNG annotations can use either Java 5 or Javadoc tags for JDK 1.4.
</p>]]>

</content>
</entry>
<entry>
<title>Interceptors with EJB 3</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/meeraj/archive/2006/01/interceptors_wi.html" />
<modified>2006-01-25T12:15:43Z</modified>
<issued>2006-01-25T12:15:27Z</issued>
<id>tag:weblogs.java.net,2006:/blog/meeraj/68.3997</id>
<created>2006-01-25T12:15:27Z</created>
<summary type="text/plain">I have been having a look at EJB 3.0 interceptors with Glassfish. EJB 3.0 allows you to define interceptor methods that are called around the business methods and lifecycle events on the bean instances. The interceptor methods can either be defined within the bean class or in separate interceptor classes. Interceptor definitions and binding interceptors to bean classes or specific methods within the beans can be done either using annotations or within the deployment descriptors. Here, I will try to provide a simple example of using interceptors on business methods using annotations.</summary>
<author>
<name>meeraj</name>

<email>meeraj@lycos.com</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/meeraj/">
<![CDATA[<p>
I have been having a look at EJB 3.0 interceptors with <a href="https://glassfish.dev.java.net/">Glassfish</a>. EJB 3.0 allows you to define interceptor methods that are called around the business methods and lifecycle events on the bean instances. The interceptor methods can either be defined within the bean class or in separate interceptor classes. Interceptor definitions and binding interceptors to bean classes or specific methods within the beans can be done either using annotations or within the deployment descriptors. Here, I will try to provide a simple example of using interceptors on business methods using annotations.
</p>

<p>
Methods that intercept invocations to business methods or lifecycle events can be defined either in the bean class or in separator interceptor classes. Only one interceptor method is allowed per class. The interceptor methods should be annotated with the <code>@AroundInvoke</code> annotation and should have the signature,
<code>Object &lt;methodName&gt;(javax.ejb.InvocationContext)</code>. If the bean class has a method with the above signature and annotation, the method will be used to interpose on all the business method invocations on that bean. Additionally, you can define interceptors for all the business methods on the bean or individual business methods using the <code>@Interceptors</code> annotation. The value of this annotation is the list of interceptor classes. The interceptor classes are required to have a single interceptor method with the same signature and annotation as explained earlier. Interceptor classes have the same lifecycle as the associated bean instance and can have dependency injection, which will be done using the same naming context as the bean.
</p>

<p>
<h2>InvocationContext</h2>
InvocationContext allows you to propagate state across a chain of interceptors. In addition it allows to get/set method parameters, get a reference to the bean, get the invoked method name etc. The methods provided by InvocationContext interface are,

<li><code>Object getBean()</code>: Returns a reference to the bean. </li>
<li><code>Method getMethod()</code>: Returns a reference to the invoked method. </li>
<li><code>Object[] getParameters()</code>: Returns the parameters passed to the method. </li>
<li><code>void  setParameters(Object[] parameters) </code>: Sets the parameters. </li>
<li><code>Map getContextData()</code>: Get contextual data that can be shared in a chain. </li>
<li><code>Object proceed()</code>: Proceed to the next interceptor in the chain or the business method if it is the last interceptor. </li>
</p>

<p>
<h2>Order of Interception</h2>
The interceptors are invoked in the order in which they are declared in the annotation. Bean level interceptors using interceptor classes are invoked before method level interceptors using interceptor classes. Interceptor method defined in the bean class itself is invoked at the end. If the bean or the interceptor classes have super classes with interceptor methods, they are invoked before the interceptor methods on the sub-classes are called.
</p>

<p>
<h2>Example</h2>
Now we will have a look at a simple example for doing interception on an EJB's business method.
<h3>Bean Class</h3>
<pre>
package com.acme.ejb;

import javax.ejb.AroundInvoke;
import javax.ejb.Interceptors;
import javax.ejb.InvocationContext;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;

@Stateless
@WebService
@Interceptors( { Interceptor2.class })
public class HelloWorldBean {

	@Interceptors( { Interceptor1.class })
	@WebMethod
	public String sayHello() {
		return "Hello";
	}

	@WebMethod
	public String sayHi() {
		return "Hi";
	}

	@AroundInvoke
	public Object log(InvocationContext invocationContext) throws Exception {
		System.err.println(invocationContext.getMethod().getName() + " called from interceptor 3");
		return invocationContext.proceed();
	}

}
</pre>
The bean class has an <code>AroundInvoke</code> method, a bean level interceptor and a method level interceptor. A call to <code>sayHello</code> will invoke the interceptors in the order bean level interceptor, method level interceptor and the <code>AroundInvoke</code> method within the bean class. A call to <code>sayHi</code> will invoke the interceptors in the order bean level interceptor and the <code>AroundInvoke</code> method within the bean class.
<h3>Interceptor Classes</h3>
<pre>
package com.acme.ejb;

import javax.ejb.AroundInvoke;
import javax.ejb.InvocationContext;

public class Interceptor1 {

	@AroundInvoke
	public Object log(InvocationContext invocationContext) throws Exception {
		System.err.println(invocationContext.getMethod().getName() + " called from interceptor 1");
		return invocationContext.proceed();
	}

}

package com.acme.ejb;

import javax.ejb.AroundInvoke;
import javax.ejb.InvocationContext;

public class Interceptor2 {

	@AroundInvoke
	public Object log(InvocationContext invocationContext) throws Exception {
		System.err.println(invocationContext.getMethod().getName() + " called from interceptor 2");
		return invocationContext.proceed();
	}

}

</pre>
<h3>Testing the Example using Glassfish</h3>
The classes shown above can be packaged as a jar file and copied to the auto deploy directory of your Glassfish domain. The EJB is annotated with the <code>@WebService</code> annotation and the methods are annotated with the <code>@WebMethod</code> annotation, you can easily test the method invocations using the Glassfish console.
</p>
]]>

</content>
</entry>
<entry>
<title>Resource injection in web applications</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/meeraj/archive/2005/12/resource_inject.html" />
<modified>2008-01-02T17:42:16Z</modified>
<issued>2005-12-15T10:35:01Z</issued>
<id>tag:weblogs.java.net,2005:/blog/meeraj/68.3805</id>
<created>2005-12-15T10:35:01Z</created>
<summary type="text/plain">I have been looking at the Servlet 2.5 specification (Maintenance Review). One of the key additions is the ability to inject dependencies to classes whose lifecycle are maintained by the container.</summary>
<author>
<name>meeraj</name>

<email>meeraj@lycos.com</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/meeraj/">
<![CDATA[<p>
I have been looking at the Servlet 2.5 specification (Maintenance Review). One of the key additions is the ability to inject dependencies to classes whose lifecycle are maintained by the container. 
</p>

<p>
The types of resources that can be injected in are generally the ones currently available for lookup from the <code>java:comp/env</code> namespace, by defining them in the deployment descriptor, as specified by the Servlet 2.4 specification. Resource injection relies on J2SE 5.0 annotaions. J2SE 5.0 is a pre-requirement for Servlet 2.5.
</p>

<p>
<b>Injectable Classes</b>

<p>The classes that can be injected with external dependencies are,</p>

<p><li>Servlets</li><br />
<li>Filters</li><br />
<li>Various lifecycle and event listeners</li></p>

</p>

<p>

<p><b>Resource Types</b></p>

<p>The annotaions available for dependency injection are</p>

<p><li><i>@Resource</i>: This annotation is used to inject resource types that were broadly covered by <code>resource-ref</code>, <code>resource-env-ref</code> and <code>message-destination-ref</code> elements in the deployment descriptor. This will include datasources, JMS administered objects etc.</li><br />
<li><i>@Resources</i>: This annotation acts as a container for multiple @Resource annotations.</li><br />
<li><i>@EJB</i>: This annotaion provides the same functionality as <code>ejb-ref</code> and <code>ejb-local-ref</code> elements for injecting EJB references</li><br />
<li><i>@WebServiceRef</i>: This annotation is used for injecting web service references.</li><br />
<li><i>@InjectionComplete</i>: This is a method level annotation for the method to be called once all the dependencies are injected. For the ones familiar with Spring, this is similar to the <code>afterPopertiesSet</code> method on the <code>InitializingBean</code> interface.</li></p>

</p>

<p>
<b>Example</b>

<p>The snippet below shows a simple example of injecting a datasource into a Servlet,</p>

<p><code><br />
public class MyServlet extends HttpServlet {<br />
  @Resource(name="myDs") DataSource myDataSource;<br />
}<br />
</code></p>

<p>This injects a datasource by the JNDI name myDs into the field myDataSource. If the name attribute is not specified, the field name is treated as the JNDI name.<br />
</p></p>

<p>
<b>Improvements?</b>

<p>Would you want the resource injection mechanism to be extended to ay classes load by the web application classloader, rather than only those classes whose lifecycle are managed by the container. Would the Servlet specification require EJB 3 persistence contexts to be injectable to web application classes?<br />
</p></p>]]>

</content>
</entry>
<entry>
<title>Does Java need friends?</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/meeraj/archive/2005/08/does_java_need.html" />
<modified>2008-01-02T17:42:16Z</modified>
<issued>2005-08-21T12:20:07Z</issued>
<id>tag:weblogs.java.net,2005:/blog/meeraj/68.3131</id>
<created>2005-08-21T12:20:07Z</created>
<summary type="text/plain">The access modifiers currently supported in Java allows granting access to members within a class to members within the same class, members within the sub-classes, classes belonging to the same package and all the other classes through the private, protected, package and public visibility modifiers. However, in certain scenarios you may want to have more flexible visibility mechanisms.</summary>
<author>
<name>meeraj</name>

<email>meeraj@lycos.com</email>
</author>
<dc:subject>J2SE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/meeraj/">
<![CDATA[<p>
One of the stumbling blocks I have run into, in my few years of using Java is Java's lack of flexible access visibility mechanisms. The access mechanisms are strictly constrained within the semantics of private, package, protected and public access modifiers. However, in ceratin scenarios this can be a bit constraining.
</p>

<p>
A good example if often when you use light-weight domain modelling using Java. You woudln't want to expose the internal state of your domain objects to external entities. However, you are forced to add the so called public <em>getters</em> and <em>setters</em> to your private instance variables so that your persistence frameworks can set them or the view framework can get them. This is indeed an anti-pattern, that breaks one of the cornerstones of object orientation, i.e data encapsulation. These getters and setters are not part of the public behaviour of the entity you are modelling.

</p>

<p>
There are two solutions that some into my mind,
<br/>

<ul>A C++ style <em>friend</em> access mechansim, where you can specify arbitrary visibility enablement between classes. This means you can allow the internal state of your domain classes be accessed by only persistent and domain classes.</ul>

<ul>Allow the semantics of package and protected access to be extended to hierarchical packages. This means for example, classes in <em>com.acme.domain.persist</em> and <em>com.acme.domain.view</em> would have the same access permissions on the classes within <em>com.acme.domain</em> as the classes within the same package.</ul>
</p>

<p>
<strong>Note:</strong> Some persistence frameworks do enable private field level access. However, as soon as you deny <em>ReflectPermission </em>in a J2EE environment (recommended by the spec) you will start running into problems.
</p>]]>

</content>
</entry>
<entry>
<title>Rich Domain Model and Transparent Persistence</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/meeraj/archive/2004/07/rich_domain_mod.html" />
<modified>2008-01-02T17:42:16Z</modified>
<issued>2004-07-21T03:17:27Z</issued>
<id>tag:weblogs.java.net,2004:/blog/meeraj/68.1033</id>
<created>2004-07-21T03:17:27Z</created>
<summary type="text/plain">I have worked on quite a few enterprise systems built on the J2EE platform in the past few years (some in which I was actively involved in the design and some I worked on other people&apos;s design). I have always felt there was something not quite right in almost all of those systems. No matter however hard we tried, we ended up with systems that were not seamlessly object oriented across the various application layers. </summary>
<author>
<name>meeraj</name>

<email>meeraj@lycos.com</email>
</author>
<dc:subject>J2EE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/meeraj/">
<![CDATA[<p>I have worked on quite a few enterprise systems built on the J2EE platform in the past few years (some in which I was actively involved in the design and some I worked on other people's design). I have always felt there was something not quite right in almost all of those systems. No matter however hard we tried, we ended up with systems that were not seamlessly object oriented across the various application layers. An evident after effect of this was there were often redundant code and logic duplicated in the various application layers. One obvious example was the myriad of transfer objects that mimicked the underlying entities in terms of state. This caused a huge amount of coupling right from the database through the business layer to the user interface.</p>
 
<p>I used to think this was an inevitable by-product of distributed systems where it was not such a good idea to transport state and behaviour. However, I soon realised in most but not all of the systems, this was caused by the over-emphasis on use case analysis without significant attention to proper domain modelling. The system was seen as a black box monolith that accepted user requests and produced responses. This led to the design of a bunch of stateless services exchanging dump data between the invoker and the invoked. As a result, domain logic was often duplicated in the various application layers. </p>
 
<p>Couple of weeks ago, I started on this new project and have had the fortune to work with <a href="http://www.springframework.org/books.html" taget="_blank">Rod Johnson</a> (I always wanted to work with him since the first time I met him in a restaurant in Brick Lane three years ago). This project has brought a breath of fresh air into my experience with J2EE. Here we no longer think in terms of dump transfer objects and entity beans. Here we no longer have use cases as the sole design artefact. More than everything, we have a rich reusable domain model built using object-oriented paradigms like inheritance, composition, polymorphism and re-entrancy. And even more important the persistence of the domain layer is transparent using Hibernate. Our object layer doesn't remotely resemble the data layer. I am hugely impressed with <a href="http://www.hibernate.org" taget="_blank">Hibernate's</a> persistence capabilities (though there is scope for improvement as any other software; I had some difficulty mapping polymorphic collections).</p>
 
<p>I think with a proper attach/detach strategy, and transparent data versioning you could have a rich domain layer that can be seamlessly reused in the distributed process spaces of your application. After reading the early draft of EJB 3.0, I understand most of these stuff will be supported by entity EJBs. Anyway, it is a long way to go before the spec becomes final and vendors start supporting it. For the time being, we have some fantastic commercial and open source O/R mappers and JDO implementations, that will move us forward from the "old-school" J2EE of transfer objects and entity beans towards rich domain model and transparent persistence.</p>
]]>

</content>
</entry>
<entry>
<title>Generate or Handcraft?</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/meeraj/archive/2003/09/generate_or_han.html" />
<modified>2008-01-02T17:42:16Z</modified>
<issued>2003-09-03T11:21:47Z</issued>
<id>tag:weblogs.java.net,2003:/blog/meeraj/68.717</id>
<created>2003-09-03T11:21:47Z</created>
<summary type="text/plain">One irritating thing I used to find in my early years of programming was the 
amount of time I spent on handcrafting details. Over the years, slowly but 
steadily, I have learned the art of meta-programming and I would say it is 
now the best tool in my programming arsenal. 
</summary>
<author>
<name>meeraj</name>

<email>meeraj@lycos.com</email>
</author>
<dc:subject>Tools</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/meeraj/">
<![CDATA[<p>
One irritating thing I used to find in my early years of programming was the amount of time I spent on handcrafting details. Over the years, slowly but steadily, I have learned the art of meta-programming and I would say it is now the best tool in my programming arsenal. So what is meta-programming? It is programming using metadata. And what is metadata? It is data about data. 
For example, databases have always provided metadata information in terms of dictionaries and meta tables. Database metadata include, information about the tables in the database, indices on tables, procedures that are available etc. Similarly you can have metadata about your application. Whenever I start hand-coding details, I try to extract the details in terms of metadata and write a framework that can interpret the metadata.
</p>
<p>
One of the main disadvantages in handcrafting details is that details change frequently forcing you to make changes to your programs to capture the changes. The more changes you make manually, the more bugs you introduce in the system. In my experience hand-coded details create the most number of bugs in the system. So, how do you get around this? The answer is metadata!! You externalize the details from your code to metadata. Then have an abstract 
framework that can interpret the metadata. For this you can have a number of strategies like static code generation based on metadata or a more dynamic reflective framework that can interpret the metadata. This means the only place you introduce bugs is in the framework. A bug in the framework will be manifested in every single artefact of your system that uses the framework, which makes the bugs easier to find and fix.
</p>
<p>
J2EE introduced the art of meta-programming to the enterprise Java world. With deployment descriptors you externalize a huge amount of meta information from the code and you delegate the tasks of interpreting the meta information to the containers. This was further enhanced by the 
introduction of great tools like XDoclet that used doclet based metadata to extract more details out of the code. Then came tools like Middlegen that generated your entity beans from the metadata in the database. If I look back to around four years ago on how I wrote entity beans and how I write them now, I would say it has been a quantum leap. This doesn't need to stop there. In my current project we used fastlane readers backed by stored procedures for bulk reads. All our fastlane readers are generated using a custom Ant task and Velocity based templates driven by metadata in the database. The next step would be to capture your domain logic in terms of  metadata (you can even have a custom domain language) and drive your business components off that meta information. Less code you write, less bugs you have and more maintainable your system is.
</p>
<p>
Some of the advantages I have found on using meta-programming are,
<ul>
<li>It is easy to find and fix bugs</li>
<li>You spend less time with details</li>
<li>Your system is more adaptable to changes</li>
<li>You spend less time on repetitive and redundant tasks</li>
<li>Your system is better designed as you spend more time in writing a robust framework and less time with the details</li>
</ul>
</p>

]]>

</content>
</entry>
<entry>
<title>@author: Bob the Builder</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/meeraj/archive/2003/08/author_bob_the.html" />
<modified>2008-01-02T17:42:16Z</modified>
<issued>2003-08-04T22:21:48Z</issued>
<id>tag:weblogs.java.net,2003:/blog/meeraj/68.622</id>
<created>2003-08-04T22:21:48Z</created>
<summary type="text/plain">Code that is not owned encourages poor coding practices that lead to totally un-maintainable code and ultimately utter anarchy. This isn&apos;t anything specific to our industry, whatever craft you do, it is extremely important to take pride in your work. It is important to let people know it is your piece of work. It is not about promoting finger pointing or blame culture. It is about having pride in your work. It is also a mark of responsibility. It is about taking ownership and having the motivation to produce better results. </summary>
<author>
<name>meeraj</name>

<email>meeraj@lycos.com</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/meeraj/">
<![CDATA[<p>
In our current project we have the entire development team working in a big conference room to promote pair programming and better communication within the team. One interesting thing we have in this room is a big plasma screen displaying team WIKI. The page that is displayed most of the time is the results of continuous build, integration and test. This page mainly displays a series of matrices showing the results of various tools like JCSC, Ckeckstyle and JDepend. We also display the team scoreboard displaying the ten worst and best components along with the authors, based on the above matrices.
</p>
<p>
One of the JCSC violations we used to have highly frequently, pretty early in the project was missing @author tag in the JavaDoc comments. This caused us a huge amount problem for tracking where poor code was being originated and often involved going back to CVS and check who wrote a particular bit of code. This made us enforce a standard that every single class in the system had to have an @author tag.
</p>
<p>
The result of this was amazing. Developers started working meticulously in writing better code to make sure that their names didn't appear in the "Hall of Shame" ;-). They also started having pride in their work and with pride came responsibility. In a couple of weeks the quality ratings based on the measurements started increasing, there were more unit tests being run, all the classes started having proper JavaDoc comments and the code quality started increasing significantly.
</p>
<p>
Code that is not owned encourages poor coding practices that lead to totally un-maintainable code and ultimately utter anarchy. This isn't anything specific to our industry, whatever craft you do, it is extremely important to take pride in your work. It is important to let people know it is your piece of work. It is not about promoting finger pointing or blame culture. It is about having pride in your work. It is also a mark of responsibility. It is about taking ownership and having the motivation to produce better results. 
</p>
]]>

</content>
</entry>

</feed>