<?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>lstierneyltd &#187; How to&#8217;s</title>
	<atom:link href="http://lstierneyltd.com/blog/category/development/how-tos/feed/" rel="self" type="application/rss+xml" />
	<link>http://lstierneyltd.com/blog</link>
	<description>Yet another development blog</description>
	<lastBuildDate>Thu, 02 Sep 2010 18:04:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Display Version in Android Application</title>
		<link>http://lstierneyltd.com/blog/development/display-version-in-android-application/</link>
		<comments>http://lstierneyltd.com/blog/development/display-version-in-android-application/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 10:09:11 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[How to's]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=181</guid>
		<description><![CDATA[I was looking for a way to display the Version on the splash screen of my Android app, more specifically, the &#8220;versionName&#8221; as defined in the application&#8217;s AndroidManifest.xml
After A LOT of looking I discovered PackageInfo, which is a Java API to all of the info held in the manifest.
Armed with this information is was easy [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for a way to display the Version on the splash screen of my Android app, more specifically, the &#8220;versionName&#8221; as defined in the application&#8217;s AndroidManifest.xml</p>
<p>After A LOT of looking I discovered <a href="http://developer.android.com/reference/android/content/pm/PackageInfo.html" target="_blank">PackageInfo</a>, which is a Java API to all of the info held in the manifest.</p>
<p>Armed with this information is was easy to produce the following:</p>
<pre class="brush: plain;">
private void displayVersionName() {
    String versionName = &quot;&quot;;
    PackageInfo packageInfo;
    try {
        packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    	versionName = &quot;v &quot; + packageInfo.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    TextView tv = (TextView) findViewById(R.id.versionNameTextView);
    tv.setText(versionName);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/display-version-in-android-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Log4j Nested Diagnostic Contexts (NDC)</title>
		<link>http://lstierneyltd.com/blog/development/log4j-nested-diagnostic-contexts-ndc/</link>
		<comments>http://lstierneyltd.com/blog/development/log4j-nested-diagnostic-contexts-ndc/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 18:31:57 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[How to's]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[log4j]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=118</guid>
		<description><![CDATA[Introduction and Problem
Log4j is a brilliant set of libraries which provides good &#8220;out of the box&#8221; logging capabilities.
Sometimes however, in multi-threaded environments (for example web apps), it can be hard to decipher the interleaved messages from the various clients

e.g.
Client A logs something
Client B logs something
Client A logs something
Client C logs something
Client A logs something
Client A [...]]]></description>
			<content:encoded><![CDATA[<h4>Introduction and Problem</h4>
<p>Log4j is a brilliant set of libraries which provides good &#8220;out of the box&#8221; logging capabilities.</p>
<p>Sometimes however, in multi-threaded environments (for example web apps), it can be hard to decipher the interleaved messages from the various clients<br />
<code><span id="more-118"></span></code><br />
e.g.</p>
<p>Client A logs something<br />
Client B logs something<br />
Client A logs something<br />
Client C logs something<br />
Client A logs something<br />
Client A logs something<br />
Client B logs something<br />
Client A logs something</p>
<p>Getting hard to read already!</p>
<h4>Solution</h4>
<p>Luckily for us Log4j has a built in solution to this common problem: Nested Diagnostic Contexts.</p>
<p>To quote the API doc &#8220;A Nested Diagnostic Context, or NDC in short, is an instrument to distinguish interleaved log output from different sources. Log output is typically interleaved when a server handles multiple clients near-simultaneously. </p>
<p>Interleaved log output can still be meaningful if each log entry from different contexts had a distinctive stamp. This is where NDCs come into play&#8230;.&#8221; </p>
<p><a href="http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/NDC.html">http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/NDC.html</a></p>
<p>The simple example below applies NDC to a Message Driven Bean (MDB):</p>
<h4>Sample Java Code</h4>
<pre>
package test.controller;

import javax.jms.Message;
import javax.jms.MessageListener;

import org.apache.log4j.Logger;
import org.apache.log4j.NDC;

public class Log4jDiagnosticContextSetter implements MessageListener {

    private static final Logger LOG = Logger.getLogger(Log4jDiagnosticContextSetter.class);

    private MessageListener messageListener;

    public void onMessage(Message message) {
        boolean loggingContextIsSet = addLoggingContextData(message);

        try {
            messageListener.onMessage(message); // the bean does its stuff
        }
        finally {
            if (loggingContextIsSet){
                removeLoggingContextData();
            }
        }
    }

    private boolean addLoggingContextData(Message message) {
        if (!LOG.isInfoEnabled())
            return false;

        try {
            NDC.push(getUniqueRef());
        }
        catch (Exception e) {
            LOG.error("Error pushing identifier onto Log4J NDC stack.", e);

            return false;
        }

        return true;
    }

    private void removeLoggingContextData() {
        try {
            while (NDC.getDepth() != 0) {
                NDC.pop();
            }
        }
        catch (Exception e) {
            LOG.error("Error popping message ID off of Log4J NDC stack.", e);
    }

    private String getUniqueRef() {
        // some way to get a unique reference
    }
}
</pre>
<h4>Sample Log Output</h4>
<p>You can see here in the example log output the result of the NDC push code above (in this case &#8220;98765432&#8243; is the unique identifier)</p>
<pre>
[02/06/2010 12:49:34:883 BST] [MessageListenerThreadPool : 0] DEBUG AuditServiceListener [98765432] - Processing message
[02/06/2010 12:49:34:883 BST] [MessageListenerThreadPool : 0] DEBUG ServiceMsgProcessor  [98765432] - Starting processing of XML request. Request=(<someMessage></someMessage>)
[02/06/2010 12:49:34:883 BST] [MessageListenerThreadPool : 0] DEBUG RequestUnmarshaller  [98765432] - Unmarshalling XML request payload to object.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/log4j-nested-diagnostic-contexts-ndc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Quartz to schedule tasks in Spring</title>
		<link>http://lstierneyltd.com/blog/development/use-quartz-to-schedule-tasks-in-spring/</link>
		<comments>http://lstierneyltd.com/blog/development/use-quartz-to-schedule-tasks-in-spring/#comments</comments>
		<pubDate>Fri, 07 May 2010 16:47:56 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[How to's]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[quartz]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=87</guid>
		<description><![CDATA[Quartz is a full-featured, open source job scheduling service that can be integrated with, or used along side virtually any Java EE or Java SE application.
In this simple example (notionally checking Twitter for updates) we integrate it with Spring.

Spring Config

&#60;bean name="checkTwitterForUpdates"
  class="org.springframework.scheduling.quartz.JobDetailBean"&#62;

       &#60;property name="jobClass" value="test.twitterReader" /&#62;
&#60;/bean&#62;

&#60;bean id="cronTwitterUpdateCheckTriggerBean"
  [...]]]></description>
			<content:encoded><![CDATA[<p>Quartz is a full-featured, open source job scheduling service that can be integrated with, or used along side virtually any Java EE or Java SE application.</p>
<p>In this simple example (notionally checking Twitter for updates) we integrate it with Spring.<br />
<code><span id="more-87"></span></code></p>
<h4>Spring Config</h4>
<pre>
&lt;bean name="checkTwitterForUpdates"
  class="org.springframework.scheduling.quartz.JobDetailBean"&gt;

       &lt;property name="jobClass" value="test.twitterReader" /&gt;
&lt;/bean&gt;

&lt;bean id="cronTwitterUpdateCheckTriggerBean"
  class="org.springframework.scheduling.quartz.CronTriggerBean"&gt;

       &lt;property name="jobDetail" ref="checkTwitterForUpdates" /&gt;
       &lt;!-- Run every day at noon --&gt;
       &lt;property name="cronExpression" value="0 0 12 * * ?" /&gt;
&lt;/bean&gt;

&lt;bean id="scheduler"
  class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt;

       &lt;property name="triggers"&gt;
           &lt;list&gt;
               &lt;ref bean="cronTwitterUpdateCheckTriggerBean" /&gt;
           &lt;/list&gt;
       &lt;/property&gt;
&lt;/bean&gt;
</pre>
<p>You may just want to call a method on an existing object (perhaps a business object). We can use MethodInvokingJobDetailFactoryBean to do just this:</p>
<p> Often you just need to invoke a method on a specific object. Using the MethodInvokingJobDetailFactoryBean you can do exactly this:</p>
<pre>
&lt;bean id="jobDetail"
  class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt;
    &lt;property name="targetObject" ref="someBusinessObject"/&gt;
    &lt;property name="targetMethod" value="someMethod"/&gt;
&lt;/bean&gt;
</pre>
<h4>Java</h4>
<pre>
package twitter;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

public class twitterReader extends QuartzJobBean {
    protected void executeInternal(JobExecutionContext ctx)
      throws JobExecutionException {

      // Like whatever.......
    }
}
</pre>
<h4>Libraries</h4>
<p>You can get get Quartz <a href="http://www.quartz-scheduler.org/">here</a></p>
<p>You may also need:<br />
<a href="http://www.slf4j.org/">Simple Logging Facade for Java (SLF4J)</a> and</p>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/use-quartz-to-schedule-tasks-in-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Quickly Setup Subversion Server on Linux (Ubuntu)</title>
		<link>http://lstierneyltd.com/blog/development/how-to-quickly-setup-subversion-server-on-linux-ubuntu/</link>
		<comments>http://lstierneyltd.com/blog/development/how-to-quickly-setup-subversion-server-on-linux-ubuntu/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 19:55:35 +0000</pubDate>
		<dc:creator>lawrence</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[How to's]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://lstierneyltd.com/blog/?p=49</guid>
		<description><![CDATA[Installation
First of all you&#8217;ll need to see if you&#8217;ve got Subversion installed. Check this article on how to query installed packages or just try executing:
% svn help
If you haven&#8217;t got Subversion installed then:
% apt-get install subversion
Users and Groups
% addgroup subversion
% usermod -a -G subversion yourUser
Create Repository
% svnadmin create /path/to/repository
Configure Repository
% chgrp -R subversion /path/to/repository
% chmod [...]]]></description>
			<content:encoded><![CDATA[<h4>Installation</h4>
<p>First of all you&#8217;ll need to see if you&#8217;ve got Subversion installed. Check <a href="http://lstierneyltd.com/blog/development/tips/show-and-search-list-of-installed-packages-ubuntu/">this article</a> on how to query installed packages or just try executing:</p>
<pre>% svn help</pre>
<p>If you haven&#8217;t got Subversion installed then:</p>
<pre>% apt-get install subversion</pre>
<h4>Users and Groups</h4>
<pre>% addgroup subversion
% usermod -a -G subversion yourUser</pre>
<h4>Create Repository</h4>
<pre>% svnadmin create /path/to/repository</pre>
<h4>Configure Repository</h4>
<pre>% chgrp -R subversion /path/to/repository
% chmod -R g+rws /path/to/repository
% vi /path/to/repository/conf/svnserve.conf

Edit/uncomment the following lines:

anon-access = none
auth-access = write
password-db = passwd

% vi /path/to/repository/conf/passwd

Add the following line:

yourUser = yourSecretPassword</pre>
<h4>Start Subversion Server as Daemon</h4>
<pre>svnserve -d</pre>
<h4>Troubleshooting</h4>
<p>You will need sudo or root access (unless you want to see a lot of permission denied errors!)<br />
If you see this error (when using Windows SVN client):</p>
<pre>
Can’t move
‘..\..\.svn\entries’ to ‘..\..\.svn\entries’:
The file or directory is corrupted and unreadable.
</pre>
<p>Then try excluding the local directory from the Windows Indexer.</p>
]]></content:encoded>
			<wfw:commentRss>http://lstierneyltd.com/blog/development/how-to-quickly-setup-subversion-server-on-linux-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
