<?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/"
	>

<channel>
	<title>Techie-Gyan &#187; coding</title>
	<atom:link href="http://www.techiegyan.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techiegyan.com</link>
	<description></description>
	<lastBuildDate>Fri, 25 Nov 2011 05:37:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Spring Framework 3.0 &#8211; Core</title>
		<link>http://www.techiegyan.com/2011/09/19/spring-framework-3-0-core/</link>
		<comments>http://www.techiegyan.com/2011/09/19/spring-framework-3-0-core/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 12:19:40 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://www.techiegyan.com/?p=1875</guid>
		<description><![CDATA[Spring Framework &#8211; Core View more presentations from Dmitry Noskov]]></description>
			<content:encoded><![CDATA[<div style="width:425px" id="__ss_8403168"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/analizator/spring-framework-core" title="Spring Framework - Core" target="_blank">Spring Framework &#8211; Core</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/8403168" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/analizator" target="_blank">Dmitry Noskov</a> </div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.techiegyan.com/2011/09/19/spring-framework-3-0-core/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Application Events &#8211; Spring framework</title>
		<link>http://www.techiegyan.com/2011/04/08/using-application-events-spring-framework/</link>
		<comments>http://www.techiegyan.com/2011/04/08/using-application-events-spring-framework/#comments</comments>
		<pubDate>Fri, 08 Apr 2011 18:25:31 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[basics]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.techiegyan.com/?p=1700</guid>
		<description><![CDATA[Spring Application contexts support a simple form of event publishing and subscription. This event mechanism can not be compared with other message queues and JMS like systems but can be useful for certain use cases like following: 1. Sending async email: While executing a user registration flow, system may want to send and email and [...]]]></description>
			<content:encoded><![CDATA[<p>Spring Application contexts support a simple form of event publishing and subscription. This event mechanism can not be compared with other message queues and JMS like systems but can be useful for certain use cases like following:</p>
<p>1. Sending async email: While executing a user registration flow, system may want to send and email and sending this email should not stop the registration process to complete so it requires an asynchronous way to do that. Application Event can help in this situation.<br />
2. Auditing application actions: Another use case where you do not want to stop the execution of main thread and want to audit activities in an async way.</p>
<p>I am trying to list classes you will need to use your own Application Events and handle them:</p>
<p><strong>a) Your custom event :</strong> UserEvent, AbstractEvent. AbstractEvent is an abstract class which can be extended based on requirement. As you can see in the code, Event Id is used to call its super class which is ApplicationEvent class of Spring framework. Another variable eventContext is used to carry context parameters to the handler of event(Check different constructors of UserEvent). </p>
<pre class="brush: java; title: ; notranslate">
public class UserEvent extends AbstractEvent {
        public UserEvent(String eventId, Object eventContext) {
		super(eventId, eventContext);
	}
        public UserEvent(String eventId, User user, String tPassword) {
		super(eventId, new HashMap());
		Map&lt;String, Object&gt; params = (Map&lt;String, Object&gt;) this.getEventContext();
		params.put(&quot;user&quot;, user);
		params.put(&quot;tPassword&quot;, tPassword);
	}
}

public abstract class AbstractEvent extends ApplicationEvent {

        protected String eventId;
	protected Object eventContext;

	public AbstractEvent(String eventId, Object eventContext) {
		super(eventId);
		this.eventId = eventId;
		this.eventContext = eventContext;
	}

	public String getEventId() {
		return eventId;
	}

	public Object getEventContext() {
		return eventContext;
	}

	public Object getContextParams(String paramName){
		if(! (eventContext!= null &amp;&amp; eventContext instanceof Map)){
			return null;
		}
		return ((Map)eventContext).get(paramName);
	}
}
</pre>
<p><strong>b) Publish your custom event :</strong> You will like to publish your custom event generally from the flow of execution e.g. in this case UserService or RegistrationService. Spring gives a facility to make your class able to publish Application events by implementing ApplicationEventPublisherAware interface. </p>
<p>By implementing ApplicationEventPublisherAware, you need to implement setApplicationEventPublisher function and Spring will automatically call set function to inject ApplicationEventPublisher instance. This instance can be used for publishing the event.</p>
<p>This basically invokes all listeners waiting for this kind of Event in a separate thread to make it async.</p>
<pre class="brush: java; title: ; notranslate">
public class RegistrationService implements ApplicationEventPublisherAware{
        protected ApplicationEventPublisher applicationEventPublisher;
        public static final String Event_RegisterUser = &quot;registerUser&quot;;

        public void registerUser(User u) {
                .......
                .......
                try {
				applicationEventPublisher.publishEvent(new UserEvent(Event_RegisterUser, u));
			}
			catch(Exception e) {
				logger.error(e.getMessage(), e);
			}
                ..........
                ..........
        }
        public void setApplicationEventPublisher(
			ApplicationEventPublisher applicationEventPublisher) {
		this.applicationEventPublisher = applicationEventPublisher;
	}
}
</pre>
<p><strong>c) Handle your custom event :</strong> An event listener would be required to handle the event published by the service and handle it. By implementing ApplicationListener, class has to implement onApplicationEvent function where it gets the Event object with eventId and eventContext.</p>
<pre class="brush: java; title: ; notranslate">
public class UserEventListener implements ApplicationListener&lt;UserEvent&gt; {
        public void onApplicationEvent(UserEvent event) {
                String eventId = event.getEventId();
                User user = (User) event.getContextParams(&quot;user&quot;);
                String tempPassword = (String) event.getContextParams(&quot;tPassword&quot;);
                //Do your handling like send an email to newly added User
        }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.techiegyan.com/2011/04/08/using-application-events-spring-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spring 3 &#8211; Synopsis, all modules</title>
		<link>http://www.techiegyan.com/2011/03/09/spring-3-synopsis-all-modules/</link>
		<comments>http://www.techiegyan.com/2011/03/09/spring-3-synopsis-all-modules/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 10:44:28 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.techiegyan.com/?p=1603</guid>
		<description><![CDATA[Spring 3 View more presentations from André Faria Gomes]]></description>
			<content:encoded><![CDATA[<div style="width:425px" id="__ss_3005855"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/andrefaria/spring-3" title="Spring 3">Spring 3</a></strong> <object id="__sse3005855" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=spring3-100127102423-phpapp02&#038;stripped_title=spring-3&#038;userName=andrefaria" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse3005855" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=spring3-100127102423-phpapp02&#038;stripped_title=spring-3&#038;userName=andrefaria" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/andrefaria">André Faria Gomes</a> </div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.techiegyan.com/2011/03/09/spring-3-synopsis-all-modules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maven 2 &#8211; An overview</title>
		<link>http://www.techiegyan.com/2010/08/24/maven-2-an-overview/</link>
		<comments>http://www.techiegyan.com/2010/08/24/maven-2-an-overview/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 08:18:13 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[addon]]></category>
		<category><![CDATA[basics]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.techiegyan.com/?p=1490</guid>
		<description><![CDATA[Maven 2 features View more presentations from Angel Ruiz. Maven 2 in the real world View more presentations from carlo.bonamico.]]></description>
			<content:encoded><![CDATA[<div style="width:425px" id="__ss_816032"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/pakin318/Maven2-816032" title="Maven 2 features">Maven 2 features</a></strong><object id="__sse816032" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=Maven2-122835746311-phpapp02&#038;stripped_title=Maven2-816032" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse816032" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=Maven2-122835746311-phpapp02&#038;stripped_title=Maven2-816032" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/pakin318">Angel Ruiz</a>.</div>
</div>
<div style="width:425px" id="__ss_952797"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/carlo.bonamico/maven-2-in-the-real-world-presentation" title="Maven 2 in the real world">Maven 2 in the real world</a></strong><object id="__sse952797" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=javaday2009carlobonamicomaven203-1232952925826657-2&#038;stripped_title=maven-2-in-the-real-world-presentation" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse952797" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=javaday2009carlobonamicomaven203-1232952925826657-2&#038;stripped_title=maven-2-in-the-real-world-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/carlo.bonamico">carlo.bonamico</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.techiegyan.com/2010/08/24/maven-2-an-overview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Apache Commons</title>
		<link>http://www.techiegyan.com/2010/08/23/apache-commons/</link>
		<comments>http://www.techiegyan.com/2010/08/23/apache-commons/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 09:26:59 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[addon]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[basics]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://www.techiegyan.com/?p=1483</guid>
		<description><![CDATA[An overview of many commons libraries. Will try to cover the popular ones in separate posts. Apache Commons &#8211; Don\&#39;t re-invent the wheel View more presentations from tcurdt.]]></description>
			<content:encoded><![CDATA[<p>An overview of many commons libraries. Will try to cover the popular ones in separate posts.</p>
<div style="width:425px" id="__ss_762432"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/tcurdt/apache-commons-dont-reinvent-the-wheel-presentation" title="Apache Commons - Don\&#39;t re-invent the wheel">Apache Commons &#8211; Don\&#39;t re-invent the wheel</a></strong><object id="__sse762432" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=commons-1226968082756899-9&#038;stripped_title=apache-commons-dont-reinvent-the-wheel-presentation" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse762432" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=commons-1226968082756899-9&#038;stripped_title=apache-commons-dont-reinvent-the-wheel-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/tcurdt">tcurdt</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.techiegyan.com/2010/08/23/apache-commons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

