<?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; java</title>
	<atom:link href="http://www.techiegyan.com/category/java/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>An Introduction To Android</title>
		<link>http://www.techiegyan.com/2010/10/24/an-introduction-to-android/</link>
		<comments>http://www.techiegyan.com/2010/10/24/an-introduction-to-android/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 19:32:02 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://www.techiegyan.com/?p=1531</guid>
		<description><![CDATA[An Introduction To Android View more presentations from natdefreitas.]]></description>
			<content:encoded><![CDATA[<div style="width:425px" id="__ss_1046655"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/natdefreitas/an-introduction-to-android" title="An Introduction To Android">An Introduction To Android</a></strong><object id="__sse1046655" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=an-introduction-to-androidwithnffinal-1235051497625329-1&#038;stripped_title=an-introduction-to-android&#038;userName=natdefreitas" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse1046655" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=an-introduction-to-androidwithnffinal-1235051497625329-1&#038;stripped_title=an-introduction-to-android&#038;userName=natdefreitas" 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/natdefreitas">natdefreitas</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.techiegyan.com/2010/10/24/an-introduction-to-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add Server address on page &#8211; Troubleshooting Load Balanced cluster</title>
		<link>http://www.techiegyan.com/2010/10/13/add-server-address-on-page-troubleshooting-load-balanced-cluster/</link>
		<comments>http://www.techiegyan.com/2010/10/13/add-server-address-on-page-troubleshooting-load-balanced-cluster/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 09:29:14 +0000</pubDate>
		<dc:creator>Aditya</dc:creator>
				<category><![CDATA[debug]]></category>
		<category><![CDATA[identity]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.techiegyan.com/?p=1527</guid>
		<description><![CDATA[It is actually about a trick that can be used in a particular type of environment. When you are running your application in multi-server environment with load balancers enabled to distribute the load, you may require to know which server is serving the request in certain error situations. One very probable scenario is that during [...]]]></description>
			<content:encoded><![CDATA[<p>It is actually about a trick that can be used in a particular type of environment. When you are running your application in multi-server environment with load balancers enabled to distribute the load, you may require to know which server is serving the request in certain error situations.</p>
<p>One very probable scenario is that during the maintenance processes some thing is missed on some server(s). This may cause random issues to the user of the application as requests are distributed and can reach any server.This trick can be used to figure out which server is serving your page. Here i am adding the code which we used recently in our JSP pages to figure it out. </p>
<pre class="brush: java; title: ; notranslate">&lt;%@page import=&quot;java.net.InetAddress;&quot; %&gt;
&lt;%String ip = &quot;&quot;;
  String hostName = &quot;&quot;;
try{
    InetAddress inetAddress = InetAddress.getLocalHost();
    ip = inetAddress.getHostAddress();
	hostName = inetAddress.getHostName();
}catch(Exception e){}
%&gt;
&lt;div style=&quot;display:none;&quot;&gt; Server IP address : &lt;%out.print(ip);%&gt; &lt;br/&gt;
Server Host Name : &lt;%out.print(hostName);%&gt; &lt;br/&gt;
&lt;/div&gt;
</pre>
<p>As you do not want to show this to user, you can add a hidden div element at the end of the page which can contain server address and server name by which you can differentiate servers. This can be accessed by viewing the page source (most of the browsers provide this option on right-click.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techiegyan.com/2010/10/13/add-server-address-on-page-troubleshooting-load-balanced-cluster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

