<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:rawvoice="http://www.rawvoice.com/rawvoiceRssModule/"
>

<channel>
	<title>Solution Hacker &#187; annotation</title>
	<atom:link href="http://www.solutionhacker.com/tag/annotation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.solutionhacker.com</link>
	<description>This blog provides solutions for enterpreneurs!</description>
	<lastBuildDate>Mon, 06 Feb 2012 07:19:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=115</generator>
<!-- podcast_generator="Blubrry PowerPress/2.0.4" -->
	<itunes:summary>This blog provides solutions for enterpreneurs!</itunes:summary>
	<itunes:author>Solution Hacker</itunes:author>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.solutionhacker.com/wp-content/plugins/powerpress/itunes_default.jpg" />
	<itunes:subtitle>This blog provides solutions for enterpreneurs!</itunes:subtitle>
	<image>
		<title>Solution Hacker &#187; annotation</title>
		<url>http://www.solutionhacker.com/wp-content/plugins/powerpress/rss_default.jpg</url>
		<link>http://www.solutionhacker.com</link>
	</image>
		<item>
		<title>Java 5 Features &#8211; Enum and Annotation</title>
		<link>http://www.solutionhacker.com/implement-your-idea/design/java-5-features-enum-and-annotation/</link>
		<comments>http://www.solutionhacker.com/implement-your-idea/design/java-5-features-enum-and-annotation/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 19:01:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[tiger]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=244</guid>
		<description><![CDATA[<h2>Intent</h2>
<p>I want to summarize some new and interesting Java 5 features in this article and how they change the way I code.</p>
<h2>Enum</h2>
<p>I use int constants to make my life easier b/c it can avoid typo. However, it has several drawbacks:</p>
<ol>
    <li>Java doesn't provide namespace for int enum groups. I can either prefix my constant like ABC_ or using inner interfaces to organize it.</li>
    <li>It is compile-time constants. So you need to recompile once changed.</li>
    <li>No easy way to translate int enum constants into printable string during debugging.</li>
    <li>You cannot iterate over all the int enum easily.</li>
    <li>You need a way to validate the enum is an valid int</li>
</ol>
<p>Use new enum type in Java 5:</p>
<blockquote>
<p>public enum Apple {FUJI, PIPPIN, GRANNY_SMITH}</p>
</blockquote>
<p>Enum is full-fledged final class that export one instance for each enumeration constant via a public static final field.</p>
<ol>
    <li>Namespace is provided via the enum type name.</li>
    <li>You can reorder and add the enumeration constant without recompiling its client.</li>
    <li>You can translate enum into printable strings via toString() method.</li>
    <li>Enum type provides you values() method to iterate your enumeration constants (based on declaration order).</li>
    <li>Type-checking can be used for the validation check</li>
    <li>You can associate data with enum constant</li>
    <li>Enum is immutable, serializable and comparable.</li>
</ol>
<h2>EnumSet</h2>
<p>If elements of an enumerated types are used primarily in sets, it is traditional to use the int enum pattern, assigning a different power of 2 to each constant like READ = 1 &#60;&#60; 2, WRITE = 1 &#60;&#60;1, EXECUTE = 1 &#60;&#60; 0 to represent permissions per each entity in Unix. This representation lets you use the bitwise OR operation to combine several constants into a set, known as a bit field. The bit field representation also lets you perform set operations such as union and intersection efficiently using bitwise arithmetic. But bit fields have all the disadvantages of int enum mentioned above.</p>
<p>Now, java.util package provides the EnumSet to efficient represent sets of value drawn from single enum type. This class implements Set interface and internally use bit vector to represent set of values. For example, if you enum types has 64 values, the entire EnumSet can be represented as a single long, so its performance is comparable to the bit field.</p>
<p>The EnumSet class provides three benefits a normal set does not:</p>
<ol>
    <li>Various creation methods that simplify the construction of a set based on an Enumeration</li>
    <li>Guaranteed ordering of the elements in the set based on their order in the enumeration constants are declared</li>
    <li>Performance and memory benefits not nearly possible with a regular set implementation</li>
</ol>
<h2>Annotation</h2>
<p>An annotation is a new language feature introduced in J2SE 5.0. Simply put, annotations allow developers to mark classes,                         methods, and members with secondary information that is not part of the operating code.You can see annotation is a way to extend Java language.</p>
<p>Before annotation from Java 5, you may use naming patterns to indicate that some program elements like method demanded special treatment by a tool or a framework. Like JUnit required its users to name the test methods with the pattern like testXXX(). It works but with some big disadvantages:</p>
<ol>
    <li>Typo problem</li>
    <li>It doesn't provide a way to associate parameter values with program elements.</li>
</ol>
<p>Annotation can solve this problem. To use it, you can:</p>
<ol>
    <li>Create you own marker annotation (<strong>@interface</strong> is the keyword) or parametized annotation. You can annotate the annotation (ie. meta-annotation). Example: @Retention and @Target. And marker annotation has no parameter associated with it.</li>
    <li>Annotate the program elements</li>
    <li>Write processor to handle your annotated code. Generally, annotations never change the semantics of the annotated code, but enable it for special treatment by tools. Now, the metadata of Method carries additional info for your job. You can use <strong>Method's isAnnotationPresent() </strong>to check if a method is annotated by certain annotation type. If you annotation carried parameter, you can use<strong> Method's getAnnotation()</strong> to get the Annotaton object and use <strong>value()</strong> to obtain the parameter.</li>
</ol>
<h2>Reference</h2>
<p>Below are some related articles I feel useful:</p>
<ol>
    <li><a class="linkification-ext" href="http://www.javalobby.org/java/forums/t16967.html" title="Linkification: http://www.javalobby.org/java/forums/t16967.html">http://www.javalobby.org/java/forums/t16967.html</a></li>
    <li><a href="http://www.ibm.com/developerworks/library/j-annotate1/">Annotation in Tiger - Part 1 Meta-Annotation</a></li>
    <li><a href="http://www.ibm.com/developerworks/library/j-annotate2.html">Annotation in Tiger - Part 2 Custom Annotation</a></li>
</ol>
<p>&#160;</p>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<h2>Intent</h2>
<p>I want to summarize some new and interesting Java 5 features in this article and how they change the way I code.</p>
<h2>Enum</h2>
<p>I use int constants to make my life easier b/c it can avoid typo. However, it has several drawbacks:</p>
<ol>
<li>Java doesn&#8217;t provide namespace for int enum groups. I can either prefix my constant like ABC_ or using inner interfaces to organize it.</li>
<li>It is compile-time constants. So you need to recompile once changed.</li>
<li>No easy way to translate int enum constants into printable string during debugging.</li>
<li>You cannot iterate over all the int enum easily.</li>
<li>You need a way to validate the enum is an valid int</li>
</ol>
<p>Use new enum type in Java 5:</p>
<blockquote>
<p>public enum Apple {FUJI, PIPPIN, GRANNY_SMITH}</p>
</blockquote>
<p>Enum is full-fledged final class that export one instance for each enumeration constant via a public static final field.</p>
<ol>
<li>Namespace is provided via the enum type name.</li>
<li>You can reorder and add the enumeration constant without recompiling its client.</li>
<li>You can translate enum into printable strings via toString() method.</li>
<li>Enum type provides you values() method to iterate your enumeration constants (based on declaration order).</li>
<li>Type-checking can be used for the validation check</li>
<li>You can associate data with enum constant</li>
<li>Enum is immutable, serializable and comparable.</li>
</ol>
<h2>EnumSet</h2>
<p>If elements of an enumerated types are used primarily in sets, it is traditional to use the int enum pattern, assigning a different power of 2 to each constant like READ = 1 &lt;&lt; 2, WRITE = 1 &lt;&lt;1, EXECUTE = 1 &lt;&lt; 0 to represent permissions per each entity in Unix. This representation lets you use the bitwise OR operation to combine several constants into a set, known as a bit field. The bit field representation also lets you perform set operations such as union and intersection efficiently using bitwise arithmetic. But bit fields have all the disadvantages of int enum mentioned above.</p>
<p>Now, java.util package provides the EnumSet to efficient represent sets of value drawn from single enum type. This class implements Set interface and internally use bit vector to represent set of values. For example, if you enum types has 64 values, the entire EnumSet can be represented as a single long, so its performance is comparable to the bit field.</p>
<p>The EnumSet class provides three benefits a normal set does not:</p>
<ol>
<li>Various creation methods that simplify the construction of a set based on an Enumeration</li>
<li>Guaranteed ordering of the elements in the set based on their order in the enumeration constants are declared</li>
<li>Performance and memory benefits not nearly possible with a regular set implementation</li>
</ol>
<h2>Annotation</h2>
<p>An annotation is a new language feature introduced in J2SE 5.0. Simply put, annotations allow developers to mark classes,                         methods, and members with secondary information that is not part of the operating code.You can see annotation is a way to extend Java language.</p>
<p>Before annotation from Java 5, you may use naming patterns to indicate that some program elements like method demanded special treatment by a tool or a framework. Like JUnit required its users to name the test methods with the pattern like testXXX(). It works but with some big disadvantages:</p>
<ol>
<li>Typo problem</li>
<li>It doesn&#8217;t provide a way to associate parameter values with program elements.</li>
</ol>
<p>Annotation can solve this problem. To use it, you can:</p>
<ol>
<li>Create you own marker annotation (<strong>@interface</strong> is the keyword) or parametized annotation. You can annotate the annotation (ie. meta-annotation). Example: @Retention and @Target. And marker annotation has no parameter associated with it.</li>
<li>Annotate the program elements</li>
<li>Write processor to handle your annotated code. Generally, annotations never change the semantics of the annotated code, but enable it for special treatment by tools. Now, the metadata of Method carries additional info for your job. You can use <strong>Method&#8217;s isAnnotationPresent() </strong>to check if a method is annotated by certain annotation type. If you annotation carried parameter, you can use<strong> Method&#8217;s getAnnotation()</strong> to get the Annotaton object and use <strong>value()</strong> to obtain the parameter.</li>
</ol>
<h2>Reference</h2>
<p>Below are some related articles I feel useful:</p>
<ol>
<li><a class="linkification-ext" href="http://www.javalobby.org/java/forums/t16967.html" title="Linkification: http://www.javalobby.org/java/forums/t16967.html">http://www.javalobby.org/java/forums/t16967.html</a></li>
<li><a href="http://www.ibm.com/developerworks/library/j-annotate1/">Annotation in Tiger &#8211; Part 1 Meta-Annotation</a></li>
<li><a href="http://www.ibm.com/developerworks/library/j-annotate2.html">Annotation in Tiger &#8211; Part 2 Custom Annotation</a></li>
</ol>
<p>&#160;</p>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/implement-your-idea/design/java-5-features-enum-and-annotation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powerful combination: JMX + Annotation + AOP</title>
		<link>http://www.solutionhacker.com/implement-your-idea/scale-your-website/powerful-combination-jmx-spring-aop/</link>
		<comments>http://www.solutionhacker.com/implement-your-idea/scale-your-website/powerful-combination-jmx-spring-aop/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 06:30:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scale]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[AOP]]></category>
		<category><![CDATA[aspectj]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[cross-cutting concern]]></category>
		<category><![CDATA[interceptor]]></category>
		<category><![CDATA[JMX]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[proxy-based]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=215</guid>
		<description><![CDATA[<h2>What is AOP?</h2>
<p>AOP is a way to <strong>modularize</strong> cross-cutting concerns. Ok, what does "modularize" really mean? Modularization is the encapsulation of a unit of functionality. It is exactly what "Class" is doing in OO world. How about "cross-cutting concerns"? Basically it means any functionalities that span multiple modules/ classes. They include <strong>Transaction</strong> <strong>Management</strong>, <strong>Security</strong>, <strong>Caching</strong>, <strong>Performance Monitoring </strong>and etc. To understand how AOP works, we first look at the common terms in this area:</p>
<ol>
    <li><strong>Join point</strong> - An identifiable point in the execution of a program like method invocation, exception thrown.</li>
    <li><strong>Pointcut</strong> - Program construct that selects join points and collects context at those points. AspectJ has a rich pointcut expression language!</li>
    <li><strong>Advice</strong> - Code to be executed at a join point that has been selected by a pointcut.</li>
</ol>
<p>To me, I found it easier to understand these terms if I consider<strong> join point</strong> as event generated point in code, <strong>pointcut </strong>as a way to define what events to be captured and <strong>advice </strong>as event handler.</p>
<p>AOP is indeed a powerful way to factor out system or infrasturcture-related code from the business oriented code. Typically, we use it to take care of transaction, security and profiling aspects. But it doesn't stop you putting creativity in this domain. With a bit more creativity, you can also do the following::</p>
<ol>
    <li><strong>Exception translation</strong> - checked to runtime</li>
    <li><strong>Catch ConcurrencyFailureExceptions</strong> and transparently retry if an idempotent operation fails with, for example, a deadlock loser exception.</li>
</ol>
<p><!--more--></p>
<h2>How I use Spring AOP in my project?</h2>
<p>I have been told to report the elapsed time for all calls to the database. If I don't know how to use AOP, I may end up putting code to measure time for every JDBC calls. It ends up <strong>tangling</strong> performance monitoring code with my main line business logic and the same logic will be <strong>scattered everywhere</strong> in my data access code. Bad!! That is why we need to know how to factor out the performance monitoring code into an <strong>aspect </strong>like below:</p>
<p style="text-align: center;"><img alt="" style="width: 541px; height: 163px;" src="http://www.solutionhacker.com/wp-content/uploads/image/aspectCode1.JPG" /></p>
<p>Here we use <strong>AspectJ annotation approach</strong> to implement the aspect. "Around" is to intercept start and end of any repository method. Here is what states in Spring 2.5 reference:</p>
<blockquote>
<p>Spring 2.0 introduces a simpler and more powerful way of writing       custom aspects using either a <a title="6.3.&#160;Schema-based AOP support" href="http://static.springframework.org/spring/docs/2.5.x/reference/aop.html#aop-schema">schema-based       approach</a> or the <a title="6.2.&#160;@AspectJ support" href="http://static.springframework.org/spring/docs/2.5.x/reference/aop.html#aop-ataspectj">@AspectJ annotation       style</a>. Both of these styles offer fully typed advice and use of       the AspectJ pointcut language, while still using Spring AOP for       weaving.</p>
</blockquote>
<p>If you use <strong>AspectJ annotation</strong>, you need to put <strong>&#60;aop:aspectj-autoproxy/&#62;</strong> in your application-context.xml. The limitation of Spring proxy-based AOP is that it is limited to method invocation interception. To get around that, you can use AspectJ syntax in your pointcut expression. You don't need to build the application with ajc (the AspectJ compiler) even you are using AspectJ syntax. Spring AOP can also understand @AspectJ aspects. I strong suggest you use Annotation driven AOP because it is cleaner and simplier. Working with AOP, I have faced 2 questions.</p>
<ol>
    <li>How to select the methods that I want to intercept without hardcoding the method or package name in my pointcut expression. So, my aspect or pointcut doesn't contain application specific information - Look into annotation and AOP section.</li>
    <li>How to turn on and off AOP without restarting the web application? I would use <strong>JMX</strong>. Look into "What is JMX" section.&#160;</li>
</ol>
<h2>Annotation and AOP</h2>
<p><strong>Annotation </strong>provides a better way other than code signature for selecting join point that leads to creating loosely coupled aspect. In fact, you can see annotation as another signature of a method in other dimension. And a method can have multiple annotations and each concern just bother its own annotation. It is called <strong>multidimensional signature space</strong>. For example,</p>
<blockquote>
<p>@Authentication("bankOperation")<br />
@Transactional(REQUIRED)<br />
public void credit(){...}</p>
</blockquote>
<p><strong>Pointcut </strong>uses annotation to capture join points. For example:</p>
<blockquote>
<p>execution(@Transactional * *.*(..)) Execution of a method annotated as Transactional<br />
execution((@Trasactional *) *.*(..)) Execution of a method that returns object annotated as Transactional<br />
execution(* (@Transactional *).*(..)) Execution of a method defined for type annotated as Transactional</p>
</blockquote>
<p>Selection can use <strong>Annotation types</strong> and <strong>Annotation values</strong>.&#160; What is more, annotation values can be used in Advice implementation.</p>
<p>Here is a great <a href="http://www.parleys.com/display/PARLEYS/Home#talk=2097291;slide=1;title=Leveraging%20Annotations%20with%20AOP">video</a> from Parleys that talked about "Leveraging Annotation with AOP". I have included some key points Ramnivas made here:</p>
<ul>
    <li>Write you pointcut in a smart way to avoid annotation mess. Try to use naming and package convention to help you. For example, if you want to write app log for all public facing service method, you can use "public" with package name containing "service" wildcard to help you.</li>
    <li>If you really need to use annotation like <strong>@Transaction</strong> that designer has no way to define the pointcut beforehand, use annotation to describe <strong>what the join point is</strong> but not how to handle it. So, your transaction aspect only need to worry annotation @Transaction and decouple from the application.</li>
    <li>You can piggyback annotation. For example, you can make all entities auditable via <strong><span style="color: rgb(51, 153, 102);">declare @type: @Entity *: @Auditable;&#160;</span></strong></li>
</ul>
<h2><strong>How does Spring AOP work internally?</strong></h2>
<p>The magic behind AOP is the concept of Proxy/ Decorator/ Interceptor/ Filter pattern. To me, all those patterns are conceptually the same. They all try to present itself as target object (thru implementing the same interface), intercept method call and execute injected logics. And you can have more than one interceptors invoked in series. In Spring AOP, there is one thing we need to pay attention:</p>
<p>However, once the call has finally reached the target object, ...any method calls that it may make on itself, such as 	<tt class="methodname">this.bar()</tt> or <tt class="methodname">this.foo()</tt>, are going to be 	invoked against the <span class="emphasis"><em><tt class="literal">this</tt></em></span> reference, and <span class="emphasis"><em>not</em></span> 	the proxy. This has important implications. It means that self-invocation is <span class="emphasis"><em>not</em></span> 	going to result in the advice associated with a method invocation getting a chance to execute. To handle this, either you refactor your code such that the self-invocation does not happen (best approach) or you make self invocation call thru proxy like&#160;<strong>((Pojo) AopContext.currentProxy()).bar()</strong> (invasive approach b/c it totally couples your code to Spring AOP, <span class="emphasis"><em>and</em></span> it makes the class     itself aware of the fact that it is being used in an AOP context, which flies in the face of AOP. Avoid using it).</p>
<p><em>However, it must be noted that AspectJ does not have this self-invocation issue because it is 	not a proxy-based AOP framework.</em></p>
<h2>What is JMX?</h2>
<p>In short, it is a way to enable management and monitoring of Java applications over a generic API. JMX has a simple architecture that contains <strong>instrumentation </strong>level, <strong>agent </strong>level and <strong>distribution service </strong>level. In instrumentation layer, we register MBean to the MBeanServer. In simple term, In simple term, <strong>MBean </strong>is a&#160; JavaBean with defined management interface that exposes attributes and operations to the world. <strong>MBeanServer </strong>acts as a <strong>broker </strong>to decouple communication among application MBeans and/or remote clients.</p>
<p><img alt="" style="width: 473px; height: 327px;" src="http://www.solutionhacker.com/wp-content/uploads/image/jmxaArchitecture2.JPG" /></p>
<h2>Combine AOP and JMX</h2>
<p>AOP is statically defined and intercept at the runtime. It is hard to take this out or add another aspect in after you start your machine. However, with JMX, you can enable and disable it via skipping the aspect code. <img src="../../../../../wp-includes/images/smilies/icon_cool.gif" alt=":cool:" onclick="grin(':cool:');" /> On the other hand, you can also use JMX to configure and report SLA metrics like configure thresholds and send notifications of violations. That sounds very interesting to me. There are other interesting usages mentioned in the Parley's video as well:</p>
<ol>
    <li><strong>Service blocking</strong> - throw an exception if particular service you don't want to user to use it for a period of time esp during maintenance time.</li>
    <li><strong>Caching management</strong> - I am currently using interceptor pattern and IoC to intercept dao method calls for cache lookup.&#160;</li>
</ol>
<h2>Reference</h2>
<ol>
    <li><a href="http://developers.sun.com/learning/javaoneonline/2007/pdf/TS-1106.pdf">JavaOne 07 - JMX, AOP and Spring (Nice Presentation)</a></li>
    <li><a href="http://www.parleys.com/display/PARLEYS/Home#talk=2097315;slide=3;title=Spring%20AOP%20and%20JMX">Parley's AOP and JMX (Video)</a></li>
    <li><a href="http://www.infoq.com/articles/Simplifying-Enterprise-Apps">Simplifying Enterprise Applications with Spring 2.0 and AspectJ</a></li>
    <li><a href="http://www.infoq.com/articles/Orchestration-Oleg-Zhurakousky">Workflow Orchestration Using AOP</a></li>
    <li><a href="http://www.ibm.com/developerworks/java/library/j-aopwork10/index.html">Performance Monitoring with AOP and JMX</a></li>
</ol>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<h2>What is AOP?</h2>
<p>AOP is a way to <strong>modularize</strong> cross-cutting concerns. Ok, what does &#8220;modularize&#8221; really mean? Modularization is the encapsulation of a unit of functionality. It is exactly what &#8220;Class&#8221; is doing in OO world. How about &#8220;cross-cutting concerns&#8221;? Basically it means any functionalities that span multiple modules/ classes. They include <strong>Transaction</strong> <strong>Management</strong>, <strong>Security</strong>, <strong>Caching</strong>, <strong>Performance Monitoring </strong>and etc. To understand how AOP works, we first look at the common terms in this area:</p>
<ol>
<li><strong>Join point</strong> &#8211; An identifiable point in the execution of a program like method invocation, exception thrown.</li>
<li><strong>Pointcut</strong> &#8211; Program construct that selects join points and collects context at those points. AspectJ has a rich pointcut expression language!</li>
<li><strong>Advice</strong> &#8211; Code to be executed at a join point that has been selected by a pointcut.</li>
</ol>
<p>To me, I found it easier to understand these terms if I consider<strong> join point</strong> as event generated point in code, <strong>pointcut </strong>as a way to define what events to be captured and <strong>advice </strong>as event handler.</p>
<p>AOP is indeed a powerful way to factor out system or infrasturcture-related code from the business oriented code. Typically, we use it to take care of transaction, security and profiling aspects. But it doesn&#8217;t stop you putting creativity in this domain. With a bit more creativity, you can also do the following::</p>
<ol>
<li><strong>Exception translation</strong> &#8211; checked to runtime</li>
<li><strong>Catch ConcurrencyFailureExceptions</strong> and transparently retry if an idempotent operation fails with, for example, a deadlock loser exception.</li>
</ol>
<p><span id="more-215"></span></p>
<h2>How I use Spring AOP in my project?</h2>
<p>I have been told to report the elapsed time for all calls to the database. If I don&#8217;t know how to use AOP, I may end up putting code to measure time for every JDBC calls. It ends up <strong>tangling</strong> performance monitoring code with my main line business logic and the same logic will be <strong>scattered everywhere</strong> in my data access code. Bad!! That is why we need to know how to factor out the performance monitoring code into an <strong>aspect </strong>like below:</p>
<p style="text-align: center;"><img alt="" style="width: 541px; height: 163px;" src="http://www.solutionhacker.com/wp-content/uploads/image/aspectCode1.JPG" /></p>
<p>Here we use <strong>AspectJ annotation approach</strong> to implement the aspect. &#8220;Around&#8221; is to intercept start and end of any repository method. Here is what states in Spring 2.5 reference:</p>
<blockquote>
<p>Spring 2.0 introduces a simpler and more powerful way of writing       custom aspects using either a <a title="6.3.&#160;Schema-based AOP support" href="http://static.springframework.org/spring/docs/2.5.x/reference/aop.html#aop-schema">schema-based       approach</a> or the <a title="6.2.&#160;@AspectJ support" href="http://static.springframework.org/spring/docs/2.5.x/reference/aop.html#aop-ataspectj">@AspectJ annotation       style</a>. Both of these styles offer fully typed advice and use of       the AspectJ pointcut language, while still using Spring AOP for       weaving.</p>
</blockquote>
<p>If you use <strong>AspectJ annotation</strong>, you need to put <strong>&lt;aop:aspectj-autoproxy/&gt;</strong> in your application-context.xml. The limitation of Spring proxy-based AOP is that it is limited to method invocation interception. To get around that, you can use AspectJ syntax in your pointcut expression. You don&#8217;t need to build the application with ajc (the AspectJ compiler) even you are using AspectJ syntax. Spring AOP can also understand @AspectJ aspects. I strong suggest you use Annotation driven AOP because it is cleaner and simplier. Working with AOP, I have faced 2 questions.</p>
<ol>
<li>How to select the methods that I want to intercept without hardcoding the method or package name in my pointcut expression. So, my aspect or pointcut doesn&#8217;t contain application specific information &#8211; Look into annotation and AOP section.</li>
<li>How to turn on and off AOP without restarting the web application? I would use <strong>JMX</strong>. Look into &#8220;What is JMX&#8221; section.&#160;</li>
</ol>
<h2>Annotation and AOP</h2>
<p><strong>Annotation </strong>provides a better way other than code signature for selecting join point that leads to creating loosely coupled aspect. In fact, you can see annotation as another signature of a method in other dimension. And a method can have multiple annotations and each concern just bother its own annotation. It is called <strong>multidimensional signature space</strong>. For example,</p>
<blockquote>
<p>@Authentication(&#8220;bankOperation&#8221;)<br />
@Transactional(REQUIRED)<br />
public void credit(){&#8230;}</p>
</blockquote>
<p><strong>Pointcut </strong>uses annotation to capture join points. For example:</p>
<blockquote>
<p>execution(@Transactional * *.*(..)) Execution of a method annotated as Transactional<br />
execution((@Trasactional *) *.*(..)) Execution of a method that returns object annotated as Transactional<br />
execution(* (@Transactional *).*(..)) Execution of a method defined for type annotated as Transactional</p>
</blockquote>
<p>Selection can use <strong>Annotation types</strong> and <strong>Annotation values</strong>.&#160; What is more, annotation values can be used in Advice implementation.</p>
<p>Here is a great <a href="http://www.parleys.com/display/PARLEYS/Home#talk=2097291;slide=1;title=Leveraging%20Annotations%20with%20AOP">video</a> from Parleys that talked about &#8220;Leveraging Annotation with AOP&#8221;. I have included some key points Ramnivas made here:</p>
<ul>
<li>Write you pointcut in a smart way to avoid annotation mess. Try to use naming and package convention to help you. For example, if you want to write app log for all public facing service method, you can use &#8220;public&#8221; with package name containing &#8220;service&#8221; wildcard to help you.</li>
<li>If you really need to use annotation like <strong>@Transaction</strong> that designer has no way to define the pointcut beforehand, use annotation to describe <strong>what the join point is</strong> but not how to handle it. So, your transaction aspect only need to worry annotation @Transaction and decouple from the application.</li>
<li>You can piggyback annotation. For example, you can make all entities auditable via <strong><span style="color: rgb(51, 153, 102);">declare @type: @Entity *: @Auditable;&#160;</span></strong></li>
</ul>
<h2><strong>How does Spring AOP work internally?</strong></h2>
<p>The magic behind AOP is the concept of Proxy/ Decorator/ Interceptor/ Filter pattern. To me, all those patterns are conceptually the same. They all try to present itself as target object (thru implementing the same interface), intercept method call and execute injected logics. And you can have more than one interceptors invoked in series. In Spring AOP, there is one thing we need to pay attention:</p>
<p>However, once the call has finally reached the target object, &#8230;any method calls that it may make on itself, such as 	<tt class="methodname">this.bar()</tt> or <tt class="methodname">this.foo()</tt>, are going to be 	invoked against the <span class="emphasis"><em><tt class="literal">this</tt></em></span> reference, and <span class="emphasis"><em>not</em></span> 	the proxy. This has important implications. It means that self-invocation is <span class="emphasis"><em>not</em></span> 	going to result in the advice associated with a method invocation getting a chance to execute. To handle this, either you refactor your code such that the self-invocation does not happen (best approach) or you make self invocation call thru proxy like&#160;<strong>((Pojo) AopContext.currentProxy()).bar()</strong> (invasive approach b/c it totally couples your code to Spring AOP, <span class="emphasis"><em>and</em></span> it makes the class     itself aware of the fact that it is being used in an AOP context, which flies in the face of AOP. Avoid using it).</p>
<p><em>However, it must be noted that AspectJ does not have this self-invocation issue because it is 	not a proxy-based AOP framework.</em></p>
<h2>What is JMX?</h2>
<p>In short, it is a way to enable management and monitoring of Java applications over a generic API. JMX has a simple architecture that contains <strong>instrumentation </strong>level, <strong>agent </strong>level and <strong>distribution service </strong>level. In instrumentation layer, we register MBean to the MBeanServer. In simple term, In simple term, <strong>MBean </strong>is a&#160; JavaBean with defined management interface that exposes attributes and operations to the world. <strong>MBeanServer </strong>acts as a <strong>broker </strong>to decouple communication among application MBeans and/or remote clients.</p>
<p><img alt="" style="width: 473px; height: 327px;" src="http://www.solutionhacker.com/wp-content/uploads/image/jmxaArchitecture2.JPG" /></p>
<h2>Combine AOP and JMX</h2>
<p>AOP is statically defined and intercept at the runtime. It is hard to take this out or add another aspect in after you start your machine. However, with JMX, you can enable and disable it via skipping the aspect code. <img src="../../../../../wp-includes/images/smilies/icon_cool.gif" alt=":cool:" onclick="grin(':cool:');" /> On the other hand, you can also use JMX to configure and report SLA metrics like configure thresholds and send notifications of violations. That sounds very interesting to me. There are other interesting usages mentioned in the Parley&#8217;s video as well:</p>
<ol>
<li><strong>Service blocking</strong> &#8211; throw an exception if particular service you don&#8217;t want to user to use it for a period of time esp during maintenance time.</li>
<li><strong>Caching management</strong> &#8211; I am currently using interceptor pattern and IoC to intercept dao method calls for cache lookup.&#160;</li>
</ol>
<h2>Reference</h2>
<ol>
<li><a href="http://developers.sun.com/learning/javaoneonline/2007/pdf/TS-1106.pdf">JavaOne 07 &#8211; JMX, AOP and Spring (Nice Presentation)</a></li>
<li><a href="http://www.parleys.com/display/PARLEYS/Home#talk=2097315;slide=3;title=Spring%20AOP%20and%20JMX">Parley&#8217;s AOP and JMX (Video)</a></li>
<li><a href="http://www.infoq.com/articles/Simplifying-Enterprise-Apps">Simplifying Enterprise Applications with Spring 2.0 and AspectJ</a></li>
<li><a href="http://www.infoq.com/articles/Orchestration-Oleg-Zhurakousky">Workflow Orchestration Using AOP</a></li>
<li><a href="http://www.ibm.com/developerworks/java/library/j-aopwork10/index.html">Performance Monitoring with AOP and JMX</a></li>
</ol>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/implement-your-idea/scale-your-website/powerful-combination-jmx-spring-aop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Annotated Charting</title>
		<link>http://www.solutionhacker.com/data-intelligence/report/flex-annotated-charting/</link>
		<comments>http://www.solutionhacker.com/data-intelligence/report/flex-annotated-charting/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 23:02:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Report]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[google finance]]></category>
		<category><![CDATA[line chart]]></category>
		<category><![CDATA[range selector]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=201</guid>
		<description><![CDATA[<p>Recently, I want to extend the LineChart in Flex. I want to have line chart with event annotated like Google Finance.</p>
<div align="center"><a href="http://meutzner.com/examples/flex_finance/Flex_Finance_Step5.html" target="_blank">  <img border="0" alt="" src="http://meutzner.com/examples/flex_finance/flex_finance.jpg" /></a></div>
<div align="center">&#160;</div>
<div style="text-align: left;">First of all, I googled the Net to see whether anyone had already done it. It was even better if I could find any open source project related to this. Below are the interesting things I found:</div>
<ol>
    <li><a href="http://www.djindexes.com/DJIA110/learning-center/">Dow Jone Interactive Chart </a>(commerical - it is exactly what I am looking for)</li>
    <li><a href="http://demo.quietlyscheming.com/InteractiveBubble/InteractiveBubble.html">Interactive Bubble Chart</a> (open - although it is not exactly want I want, but if I believe the code can benefit me if I need to customize line chart. <img src="../../../../../wp-includes/images/smilies/icon_cool.gif" alt=":cool:" onclick="grin(':cool:');" /> I may just need to draw the interactive small bubble on the line to get my job done!)</li>
    <li>This <a href="http://demo.quietlyscheming.com/ChartSampler/app.html">demo </a>gives you tons of chart samples. They are all great example although none of them satisfy my current need.</li>
    <li>This <a href="http://www.stretchmedia.ca/blog/index.cfm/2007/3/28/Chart-Milestones-using-annotationElements">demo </a>is close to what I want. From this demo, I notice I can use "<strong>annotationElement</strong>" to draw on top of the data series. However, the trick is to convert the data points to pixel coordinate in order for me to draw something that can move along with the graph even someone stretches it. To make thing easier, Ely Greenfield has created <strong>DataDrawingCanvas </strong>that helps us draw on the chart with only data points specified instead of pixel coordinates. This class extends the <strong>ChartElement </strong>like <strong>AnnotationElement </strong>does (<a href="http://www.quietlyscheming.com/blog/charts/easy-custom-charts/">blog</a>). That is amazing!! Thanks!!! <img onclick="grin(':smile:');" alt=":smile:" src="../../../../../wp-includes/images/smilies/icon_smile.gif" /></li>
    <li><a href="http://meutzner.com/examples/flex_finance/Flex_Finance_Step5.html">Google Finance Chart</a> (It is exactly what I want. I wonder I can get the source of it)<br />
    <ul>
        <li>I have found the blog and <a href="http://meutzner.com/examples/flex_finance/Flex Finance PPT.ppt">powerpoint </a>of this sample (1/7/2009)</li>
        <li>Google uses the Flash/ JavaScript integrate kit to get it works (<a href="http://www.mikechambers.com/blog/2006/03/21/google-finance-flash-ajax-integration/">blog</a>) - I heard that it is very nice combination of Flash and AJAX. This is similar to <a href="http://www.measuremap.com/">MeasureMap</a>'s use of the kit.</li>
        <li>It is open source example!!! (<a href="http://www.meutzner.com/blog/attachments/360/srcview/index.html">code</a>). Thanks for Brendan Meutzner!!</li>
        <li>Brendan also shows us how he created his demo in 5 steps to help us understand how to build it ourselves.</li>
        <li><a href="http://www.meutzner.com/blog/attachments/360/Flex_Finance_Step1.html">Step 1</a>, <a href="http://www.meutzner.com/blog/attachments/360/Flex_Finance_Step2.html">Step 2</a>, <a href="http://www.meutzner.com/blog/attachments/360/Flex_Finance_Step3.html">Step 3</a>, <a href="http://www.meutzner.com/blog/attachments/360/Flex_Finance_Step4.html">Step 4</a>, <a href="http://www.meutzner.com/blog/attachments/360/Flex_Finance_Step5.html">Step 5</a> - enjoy!!</li>
    </ul>
    </li>
</ol>
<h2>Reference</h2>
<p>Useful resources:</p>
<ol>
    <li><a href="http://tv.adobe.com/#vi+f15384v1024">Data Visualization by Tom Gonzalez</a>. (Tom created an open source visualization framework named Axiis. It looks great. Once I get a chance, I will dig into it) - 7/31/2009</li>
    <li><a href="http://www.onflex.org/ACDS/BuildingAFlexComponent.pdf">Building a Flex Component</a> by Ely GreenField</li>
    <li><a href="http://www.adobe.com/devnet/flex/articles/components_separation.html">Create component and enforce separation of concern</a></li>
    <li><a href="http://www.edwardtufte.com/tufte/">http://www.edwardtufte.com/tufte/ </a>(Edward Tufte - famous guy in data visualization)</li>
    <li><a href="http://www.insideria.com/2008/03/image-manipulation-in-flex.html">http://www.insideria.com/2008/03/image-manipulation-in-flex.html</a> (Image Manipulation)</li>
</ol>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<p>Recently, I want to extend the LineChart in Flex. I want to have line chart with event annotated like Google Finance.</p>
<div align="center"><a href="http://meutzner.com/examples/flex_finance/Flex_Finance_Step5.html" target="_blank">  <img border="0" alt="" src="http://meutzner.com/examples/flex_finance/flex_finance.jpg" /></a></div>
<div align="center">&#160;</div>
<div style="text-align: left;">First of all, I googled the Net to see whether anyone had already done it. It was even better if I could find any open source project related to this. Below are the interesting things I found:</div>
<ol>
<li><a href="http://www.djindexes.com/DJIA110/learning-center/">Dow Jone Interactive Chart </a>(commerical &#8211; it is exactly what I am looking for)</li>
<li><a href="http://demo.quietlyscheming.com/InteractiveBubble/InteractiveBubble.html">Interactive Bubble Chart</a> (open &#8211; although it is not exactly want I want, but if I believe the code can benefit me if I need to customize line chart. <img src="../../../../../wp-includes/images/smilies/icon_cool.gif" alt=":cool:" onclick="grin(':cool:');" /> I may just need to draw the interactive small bubble on the line to get my job done!)</li>
<li>This <a href="http://demo.quietlyscheming.com/ChartSampler/app.html">demo </a>gives you tons of chart samples. They are all great example although none of them satisfy my current need.</li>
<li>This <a href="http://www.stretchmedia.ca/blog/index.cfm/2007/3/28/Chart-Milestones-using-annotationElements">demo </a>is close to what I want. From this demo, I notice I can use &#8220;<strong>annotationElement</strong>&#8221; to draw on top of the data series. However, the trick is to convert the data points to pixel coordinate in order for me to draw something that can move along with the graph even someone stretches it. To make thing easier, Ely Greenfield has created <strong>DataDrawingCanvas </strong>that helps us draw on the chart with only data points specified instead of pixel coordinates. This class extends the <strong>ChartElement </strong>like <strong>AnnotationElement </strong>does (<a href="http://www.quietlyscheming.com/blog/charts/easy-custom-charts/">blog</a>). That is amazing!! Thanks!!! <img onclick="grin(':smile:');" alt=":smile:" src="../../../../../wp-includes/images/smilies/icon_smile.gif" /></li>
<li><a href="http://meutzner.com/examples/flex_finance/Flex_Finance_Step5.html">Google Finance Chart</a> (It is exactly what I want. I wonder I can get the source of it)
<ul>
<li>I have found the blog and <a href="http://meutzner.com/examples/flex_finance/Flex Finance PPT.ppt">powerpoint </a>of this sample (1/7/2009)</li>
<li>Google uses the Flash/ JavaScript integrate kit to get it works (<a href="http://www.mikechambers.com/blog/2006/03/21/google-finance-flash-ajax-integration/">blog</a>) &#8211; I heard that it is very nice combination of Flash and AJAX. This is similar to <a href="http://www.measuremap.com/">MeasureMap</a>&#8216;s use of the kit.</li>
<li>It is open source example!!! (<a href="http://www.meutzner.com/blog/attachments/360/srcview/index.html">code</a>). Thanks for Brendan Meutzner!!</li>
<li>Brendan also shows us how he created his demo in 5 steps to help us understand how to build it ourselves.</li>
<li><a href="http://www.meutzner.com/blog/attachments/360/Flex_Finance_Step1.html">Step 1</a>, <a href="http://www.meutzner.com/blog/attachments/360/Flex_Finance_Step2.html">Step 2</a>, <a href="http://www.meutzner.com/blog/attachments/360/Flex_Finance_Step3.html">Step 3</a>, <a href="http://www.meutzner.com/blog/attachments/360/Flex_Finance_Step4.html">Step 4</a>, <a href="http://www.meutzner.com/blog/attachments/360/Flex_Finance_Step5.html">Step 5</a> &#8211; enjoy!!</li>
</ul>
</li>
</ol>
<h2>Reference</h2>
<p>Useful resources:</p>
<ol>
<li><a href="http://tv.adobe.com/#vi+f15384v1024">Data Visualization by Tom Gonzalez</a>. (Tom created an open source visualization framework named Axiis. It looks great. Once I get a chance, I will dig into it) &#8211; 7/31/2009</li>
<li><a href="http://www.onflex.org/ACDS/BuildingAFlexComponent.pdf">Building a Flex Component</a> by Ely GreenField</li>
<li><a href="http://www.adobe.com/devnet/flex/articles/components_separation.html">Create component and enforce separation of concern</a></li>
<li><a href="http://www.edwardtufte.com/tufte/">http://www.edwardtufte.com/tufte/ </a>(Edward Tufte &#8211; famous guy in data visualization)</li>
<li><a href="http://www.insideria.com/2008/03/image-manipulation-in-flex.html">http://www.insideria.com/2008/03/image-manipulation-in-flex.html</a> (Image Manipulation)</li>
</ol>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/data-intelligence/report/flex-annotated-charting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

