tag:blogger.com,1999:blog-32377240057446424702020-11-17T09:20:39.926+00:00Captain Debug's BlogJava tips, observations, bugs and problems from the world of Spring, Weblogic, Oracle, MySQL and many other technologies...Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.comBlogger390125tag:blogger.com,1999:blog-3237724005744642470.post-18689413480132143312017-10-22T17:24:00.002+01:002017-10-22T17:29:36.812+01:00Mocking in GoI was recently asked to help out on a project with the aim of recommending how to implement some additional event handling functionality. I had a look through the source code and suggested a change to an existing interface implementation, plus a few other bits and pieces; all pretty straightforward or so I thought. Later, one of the developers said to me that he&#39;d rather not change that particular piece of code as it was a crucial piece of code and he didn&#39;t know what else might break if it were changed. And that&#39;s when the alarm bells started ringing, it was a deeply worrying statement.<br><br>One of the things I believe is that you should always have the confidence to take software apart and change, redevelop and fix any part of it you like. The thing that gives you this confidence are unit tests; if you screw up a change the tests will fail and you&#39;ll know that you&#39;ve made a mistake and you can fix things. Unit tests also mean that, when you&#39;ve moved on, other developers can also have the confidence to take your software apart.<br><br>Given this statement I had to find out what was going on, so I did a review of the software and uncovered the fact that there weren&#39;t many unit tests, in fact some areas didn&#39;t have any at all... but they did have a number of integration tests. Strange. What was going on? <br>Were they just poor programmers? Didn&#39;t they realise that you can write unit tests in Go? Were the developers so naive that they thought that they didn&#39;t need tests? <a href="/2017/10/mocking-in-golang.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com3tag:blogger.com,1999:blog-3237724005744642470.post-44524670721734943872014-07-28T09:00:00.000+01:002014-07-28T09:00:00.522+01:00Default Methods: Java 8's Unsung HerosA few weeks ago I wrote a blog saying that developers learn new languages because they&#39;re cool. I still stand by this assertion because the thing about Java 8 is it&#39;s <i>really</i> cool. Whilst the undoubted star of the show is the addition of Lambdas and the promotion of functions to first class variables, my current favourite is default methods. This is because they&#39;re such a neat way of adding new functionality to existing interfaces without breaking old code. <br><br>The implementation is simple: take an interface, add a concrete method and attach the keyword <tt>default</tt> as a modifier. The result is that suddenly all existing implementations of your interface can use this code. In this first, simple example, I’ve added default method that returns the version number of an interface<sup>1</sup>. <br><br><div class="java"><code class="java"><span class="java4">public interface </span><span class="java10">Version </span><span class="java8">{<br><br>  </span><span class="java14">/**<br>   * Normal method - any old interface method:<br>   * <br>   * </span><span class="java11">@return </span><span class="java14">Return the implementing class&#39;s version<br>   */<br>  </span><span class="java4">public </span><span class="java10">String version</span><span class="java8">()</span><span class="java10">;<br><br>  </span><span class="java14">/**<br>   * Default method example.<br>   * <br>   * </span><span class="java11">@return </span><span class="java14">Return the version of this interface<br>   */<br>  </span><span class="java4">default </span><span class="java10">String interfaceVersion</span><span class="java8">() {<br>    </span><span class="java4">return </span><span class="java5">&#34;1.0&#34;</span><span class="java10">;<br>  </span><span class="java8">}<br><br>}</span></code></div><br>You can then call this method on any implementing class.<a href="/2014/07/default-methods-java-8s-unsung-heros.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com1tag:blogger.com,1999:blog-3237724005744642470.post-57163764068563109282014-06-18T09:00:00.000+01:002014-06-18T21:00:44.609+01:00The Simple Story ParadoxI’ve recently been following the <a href="http://martinfowler.com/articles/is-tdd-dead/" target="new">#isTDDDead</a> debate between Kent Beck (@kentbeck), David Heinemeier Hansson (@dhh), and Martin Fowler (@martinfowler) with some interest. I think that it’s particularly beneficial that ideas, which are often taken for granted, can be challenged in a constructive manner. That way you can figure out if they stand up to scrutiny or fall down flat on their faces.<br><br>The discussion began with @dhh making the following points on TDD and test technique, which I hope I’ve got right. Firstly, the strict definition of TDD includes the following:<br><ol><li>TTD is used to drive unit tests</li><li>You can’t have collaborators</li><li>You can’t touch the database</li><li>You can’t touch the File system</li><li>Fast Unit Tests, complete in the blink of an eye.</li></ol>He went on to say that you therefore drive your system’s architecture from the use of mocks and in that way the architecture suffers damage from the drive to isolate and mock everything, whilst the mandatory enforcement of the &#39;red, green, refactor’ cycle is too prescriptive. He also stated that a lot of people mistake that you can’t have confidence in your code and you can’t deliver incremental functionality with tests unless you go through this mandated, well paved road of TDD.<a href="/2014/06/the-simple-story-paradox.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com2tag:blogger.com,1999:blog-3237724005744642470.post-29551745337027485132014-05-27T09:00:00.000+01:002014-05-27T23:22:32.878+01:00Is it Imperative that you learn Functional Programming with Java 8?<br><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-20d7UNDGU7w/U34EskGsIYI/AAAAAAAAA_U/YxVVSpPMWRE/s1600/Screen+Shot+2014-05-22+at+15.07.05.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-20d7UNDGU7w/U34EskGsIYI/AAAAAAAAA_U/YxVVSpPMWRE/s200/Screen+Shot+2014-05-22+at+15.07.05.png"></a></div>I&#39;ve recently been taking look at Java 8 and have got hold of <a href="http://www.manning.com/urma/" target="new">&quot;Java 8 In Action&quot; published by Manning</a>. The first thing that struck me is how one of Java 8&#39;s unique sales propositions is functional programming; functions are now first class variables, you can pass them around your code as you would an <tt>int</tt> or a <tt>String</tt>. This is a big change.<br><br>It seems that functional languages have become more popular in recent years and there are no end of them to choose from. Modern <a href="http://en.wikipedia.org/wiki/List_of_programming_languages_by_category#Functional_languages" target="new">function programming language examples</a> include Clojure, JavaScript, Scala, and even Erlang, invented in the late 1980s, has made a come back.<br><br>So, why is there this change in direction? You could probably come up with several reasons, but we’ll begin with the premise that industry best practise changes over time and even the most popular languages will one day fall out of favour. I imagine that if you&#39;re young enough there will be a day when you&#39;ll look back and say &quot;remember when we used to use Java”? Before looking at why there is this change, let’s reflect on how we got here by stepping back to the 1980s...<a href="/2014/05/is-it-imperative-that-you-learn.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com3tag:blogger.com,1999:blog-3237724005744642470.post-81176106297596258492014-05-07T09:00:00.000+01:002014-05-07T09:00:02.264+01:00Tracking Exceptions - Part 6 - Building an Executable JarIf you’ve read the previous five blogs in this series, you’ll know that I’ve been building a Spring application that runs periodically to check a whole bunch of error logs for exceptions and then email you the results. <br><br>Having written the code and the tests, and being fairly certain it’ll work the next and final step is to package the whole thing up and deploy it to a production machine. The actual deployment and packaging methods will depend upon your own organisation&#39;s processes and procedures. In this example, however, I’m going to choose the simplest way possible to create and deploy an executable JAR file. The first step was completed several weeks ago, and that’s defining our output as a JAR file in the Maven POM file, which, as you’ll probably already know, is done using the packaging element:<a href="/2014/05/tracking-exceptions-part-6-building.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com1tag:blogger.com,1999:blog-3237724005744642470.post-7893469821379441872014-04-23T09:00:00.000+01:002014-04-23T09:00:02.953+01:00Tracking Exceptions - Part 5 - Scheduling With Spring<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-9uuLHobIOGY/U1T-v-91WEI/AAAAAAAAA94/i4QqJ88H5nc/s1600/Screen+Shot+2014-04-21+at+12.12.34.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-9uuLHobIOGY/U1T-v-91WEI/AAAAAAAAA94/i4QqJ88H5nc/s200/Screen+Shot+2014-04-21+at+12.12.34.png"></a></div>It seems that I&#39;m finally getting close to the end of this series of blogs on Error Tracking using Spring and for those who haven’t read any blogs in the series I’m writing a simple, but almost industrial strength, Spring application that scans for exceptions in log files and then generates a report. From the first blog in the series, these were my initial requirements:<br><ol><li>Search a given directory and its sub-directories (possibly) looking for files of a particular type.</li><li>If a file is found then check its date: does it need to be searched for errors?</li><li>If the file is young enough to be checked then validate it, looking for exceptions.</li><li>If it contains exceptions, are they the ones we’re looking for or have they been excluded?</li><li>If it contains the kind of exceptions we’re after, then add the details to a report.</li><li>When all the files have been checked, format the report ready for publishing.</li><li>Publish the report using email or some other technique.</li><li>The whole thing will run at a given time every day</li></ol>This blog takes a look at meeting requirement number 8: <i>&quot;The whole thing will run at a given time every day&quot;</i> and this means implementing some kind of scheduling.<a href="/2014/04/tracking-exceptions-part-5-scheduling.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com1tag:blogger.com,1999:blog-3237724005744642470.post-20560688321293620522014-04-08T09:00:00.000+01:002014-04-09T20:19:12.092+01:00Tracking Exceptions - Part 4 - Spring's Mail SenderIf you&#39;ve read any of the previous blogs in this series, you may remember that I&#39;m developing a small but almost industrial strength application that searches log files for exceptions. You may also remember that I now have a class that can contain a whole bunch of results that will need sending to any one whose interested. This will be done by implementing my simple <tt>Publisher</tt> interface shown below.<br><br><div class="java"><code class="java"><span class="java4">public interface </span><span class="java10">Publisher </span><span class="java8">{<br><br>  </span><span class="java4">public </span><span class="java10">&lt;T&gt; </span><span class="java9">boolean </span><span class="java10">publish</span><span class="java8">(</span><span class="java10">T report</span><span class="java8">)</span><span class="java10">;<br></span><span class="java8">}</span></code></div><br>If you remember, the requirement was:<br><br><pre class="pre_text">7 . Publish the report using email or some other technique.<br></pre><br>In this blog I’m dealing with the concrete part of the requirement: sending a report by email.<a href="/2014/04/tracking-exceptions-part-4-springs-mail.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com0tag:blogger.com,1999:blog-3237724005744642470.post-60917513540578479932014-03-26T09:00:00.000+00:002014-03-26T09:00:00.468+00:00Error Tracking Reports - Part 3 - Strategy and Package Private<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-qf2ajo7TFLo/Uy20acNuLJI/AAAAAAAAA9I/uljQDOmQdPY/s1600/IMG_0742.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-qf2ajo7TFLo/Uy20acNuLJI/AAAAAAAAA9I/uljQDOmQdPY/s200/IMG_0742.jpg"></a></div>This is the third blog in a series that&#39;s loosely looking at tracking application errors. In this series I’m writing a lightweight, but industrial strength, application that periodically scans application log files, looking for errors and, if any are found, generates and publishes a report. <br><br>If you’ve read the <a href="/2014/03/tracking-application-exceptions-with.html" target="new">first blog</a> in the series you may remember that I initially said that I needed a <tt>Report</tt> class and that “if you look at the code, you won’t find a class named Report, it was renamed Results and refactored to create a Formatter interface, the TextFormatter and HtmlFormatter classes together with the Publisher interface and EmailPublisher class”. This blog covers the design process, highlighting the reasoning behind the refactoring and how I arrived at the final implementation.<br><br>If you read on, you may think that the design logic given below is somewhat contrived. That’s because it is. The actual process of getting from the <tt>Report</tt> class to the <tt>Results</tt> class, the <tt>Formatter</tt> and <tt>Publisher</tt> interfaces together with their implementations probably only took a few seconds to dream up; however, writing it all down took some time. The design story goes like this...<a href="/2014/03/error-tracking-reports-part-3-strategy.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com0tag:blogger.com,1999:blog-3237724005744642470.post-6750650590489899092014-03-11T09:00:00.000+00:002014-03-11T09:00:03.789+00:00Tracking Exceptions With Spring - Part 2 - Delegate PatternIn <a href="/2014/03/tracking-application-exceptions-with.html" target="new">my last blog</a>, I started to talk about the need to figure out whether or not your application is misbehaving in it&#39;s production environment. I said that one method of monitoring your application is by checking its log files for exceptions and taking appropriate action if one is found. Obviously, log files can take up hundreds of megabytes of disk space and it&#39;s impractical and really boring to monitor them by hand.<br><br>I also said that there were several ways of automatically monitoring log files and proposed a Spring based utility that combs log files daily and sends you an email if / when it finds any exceptions.<br><br>I only got as far as describing the first class: the <tt>FileLocator</tt>, which will search a directory and it&#39;s sub-directories for log files. When it finds one, it passes it to the <tt>FileValidator</tt>.<a href="/2014/03/tracking-exceptions-with-spring-part-2.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com1tag:blogger.com,1999:blog-3237724005744642470.post-44907689069360741172014-03-03T09:00:00.000+00:002014-03-03T09:00:00.956+00:00Tracking Application Exceptions With SpringA few weeks ago a colleague asked me to spend a week doing a support role as he needed cover whilst he took a well earned holiday and he couldn&#39;t find anyone else. As I&#39;d just completed a particularly complex coding project and was feeling a little burnt out, I said &#39;yes&#39;; after all the change would do me good.<br><br>Part of the job consisted of monitoring a collection of fairly critical backed processes, to see how well they were performing and whether or not they were going wrong.<br><br>We developers spend a lot of time and energy adding logging to our application in order to prove that it&#39;s working okay and to figure out what went wrong when an exception occurs. These log files are often used to tell us how well, or badly, our application is performing on a daily basis.<br><br><div class="aside">I&#39;m ignoring other techniques such as adding probes to your application by whatever method you choose, such as HTTP or JMX. These provide immediate information on your application rather than the second level monitoring under discussion here.<br></div><br>There are at least three ways of monitoring log files:<a href="/2014/03/tracking-application-exceptions-with.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com3tag:blogger.com,1999:blog-3237724005744642470.post-78419438152898631372014-02-03T09:30:00.000+00:002014-02-03T19:51:55.894+00:00Optimising Your ApplicationContextThere’s a problem with Spring, it’s been there for some time and I’ve come across it in a number of projects. It’s nothing to do with Spring, or the Guys at Spring, it’s down to Spring’s users like you and me. Let me explain… In the old days of Spring 2 you had to configure your Application Context by hand, manually creating an XML configuration file that contained all your bean definitions. The down side of this technique was that it was time-consuming to create these XML files and then, you had the headache of maintaining this increasingly complex file. I seem to remember that at the time, it was known as “Spring Config Hell”. On the upside, at least you had a central record of everything that was loaded into the context. Bowing to demand and the popular notion that annotations were the way to go, Spring 3 introduced a whole raft of stereotyping classes such as <tt>@Service</tt>, <tt>@Component</tt>, <tt>@Controller</tt> and <tt>@Repository</tt> together with an addition to the XML configuration file of the <tt>&lt;context:component-scan/&gt;</tt> element. This made, from a programming point of view, things a lot simpler and is a hugely popular way of constructing Spring contexts.<br><br>There is, however, a downside to using Spring annotations with wild abandon<a href="/2014/02/optimising-your-applicationcontext.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com1tag:blogger.com,1999:blog-3237724005744642470.post-19870717950501054002014-01-02T09:00:00.000+00:002014-01-02T09:00:03.168+00:00Publish and Subscribe with Hazelcast<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-RxzAckfG_Yg/UrclRXjo5II/AAAAAAAAA7c/nIfdnsTdjBk/s1600/IMG_0662.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="150" src="http://2.bp.blogspot.com/-RxzAckfG_Yg/UrclRXjo5II/AAAAAAAAA7c/nIfdnsTdjBk/s200/IMG_0662.jpg" width="200"></a></div>A few weeks ago I wrote a blog on <a href="/2013/10/getting-started-with-hazelcast.html" target="new">getting started with Hazelcast</a> describing how ludicrously simple it is to create distributed maps, lists and queues. At the time I mentioned that Hazelcast does quite a few other things besides. This blog takes a quick look at another of Hazelcast’s features: its broadcast messaging system based on the <a href="http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern" target="new">Publish/Subscribe pattern</a>. This takes the usual format where by the message sender app <i>publishes</i> messages on a certain topic. The messages aren&#39;t directed at any particular client, but can be read by any client that registers an interest in the topic.<br><a href="/2014/01/publish-and-subscribe-with-hazelcast.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com3tag:blogger.com,1999:blog-3237724005744642470.post-80921945997155590342013-12-05T09:00:00.000+00:002014-02-01T13:59:40.535+00:00Investigating Memory Leaks Part 2 - Analysing the Problem<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-5Ao90MLxF9s/UpsM1sGk8WI/AAAAAAAAA48/nVDiVRxHnF8/s1600/Screen+Shot+2013-11-11+at+09.02.00.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-5Ao90MLxF9s/UpsM1sGk8WI/AAAAAAAAA48/nVDiVRxHnF8/s200/Screen+Shot+2013-11-11+at+09.02.00.png"></a></div>The <a href="/2013/11/investigating-memory-leaks-part-1.html" target="new">first blog</a> in this mini-series looked at creating a very leaky sample application, so that we can investigate techniques for solving heap based problems on server applications. It demonstrates the big problem with the Producer-Consumer pattern, namely that the consumer code has to be able to remove items from the queue at least as fast, if not faster than, the producer. The blog ended with me starting the sample code and sitting back whilst it leaked enough memory away to investigate. It’s now time to do that investigation.<br><br>If you read <a href="/2013/11/investigating-memory-leaks-part-1.html" target="new">part 1 of this blog</a>, you’ll know that the leaky code is part of an application<sup>1</sup> that records stock/share orders in a dummy database using the Producer Consumer pattern. The sample code has been written to contain a very obvious flaw, namely that the <tt>OrderRecord</tt> can’t keep up with the <tt>OrderFeed</tt>. This means that the <tt>Order</tt> queue gets bigger and bigger until finally, the application runs out of heap space and falls over. The thing is, looking at my simple code, the problem should be obvious, but what if you&#39;ve never seen the code before and it&#39;s huge, complex industrial strength code, plus there&#39;s no simple monitoring thread to keep an eye on the queue size or other internals? What do you do then?<a href="/2013/12/investigating-memory-leaks-part-2.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com2tag:blogger.com,1999:blog-3237724005744642470.post-91667172619058753812013-11-27T09:00:00.000+00:002013-12-08T17:21:20.911+00:00Investigating Memory Leaks Part 1 - Writing Leaky Code<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-gjAW9_AHst8/UpB_eeXvItI/AAAAAAAAA4Y/0qOh0bNruMM/s1600/Screen+Shot+2013-11-11+at+08.57.22.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-gjAW9_AHst8/UpB_eeXvItI/AAAAAAAAA4Y/0qOh0bNruMM/s200/Screen+Shot+2013-11-11+at+08.57.22.png"></a></div>I found this little problem the other day: there’s this server that runs for a while and then falls over. It’s then restarted by its startup script and the whole process repeats itself. This doesn&#39;t sound that bad as it isn&#39;t business critical although there is a significant loss of data, so I decided to take a closer look and to find out exactly what&#39;s going wrong. The first thing to note is that the server passes all it&#39;s unit tests and a whole bunch of integration tests. It runs well in all test environments using test data, so what&#39;s going wrong in production? It&#39;s easy to guess that in production it&#39;s probably under a heavier load than test, or than had been allowed for in its design, and therefore it&#39;s running out of resources, but what resources and where? That&#39;s the tricky question.<a href="/2013/11/investigating-memory-leaks-part-1.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com0tag:blogger.com,1999:blog-3237724005744642470.post-69099621401226732042013-10-30T09:00:00.000+00:002013-11-02T18:31:16.901+00:00Getting Started with HazelcastIn July I wrote a <a href="/2013/07/erlang-for-java-developers.html#.UmFeCGTk8jc" target="new">blog</a> introducing erlang to Java developers, highlighting some of the similarities and differences between the two languages. The erlang virtual machine has a number of impressive, built-in features, one of which is that they are location independent and can talk to each other. This means that that data can be synchronised between VMs by writing very few lines of code. This is really good news if you have a networked cluster of servers all doing the same thing. <br><br>You could argue that there&#39;s something lacking in the JVM if it can&#39;t even perform the most basic interprocess communication; however, Java takes the opposite view, it has a basic VM and then layers different services on top as and when required. Whether this is right is a matter of opinion and I&#39;ll leave it as a subject for a future blog, because it seems that the Hazelcast Guys have solved the problem of JVMs talking to each other; which is the point of this blog.<br><br><h3>So, what is Hazelcast? </h3><a href="/2013/10/getting-started-with-hazelcast.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com0tag:blogger.com,1999:blog-3237724005744642470.post-1918508080938196802013-09-25T18:32:00.000+01:002013-09-25T18:32:00.710+01:00Tomcat's Graceful Shutdown with Daemons and Shutdown Hooks<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-qphwtSUBH18/Uj8pp63Q4pI/AAAAAAAAAz4/IeDYu6PAlek/s1600/IMG_0577.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-qphwtSUBH18/Uj8pp63Q4pI/AAAAAAAAAz4/IeDYu6PAlek/s200/IMG_0577.jpg"></a></div>My last couple of blogs have talked about <a href="/2013/08/long-polling-tomcat-with-spring.html#.UjXZj2R4apY" target="new">long polling</a> and <a href="/2013/09/long-polling-with-spring-32s.html#.UjXZq2R4apY" target="new">Spring&#39;s <tt>DeferredResult</tt> technique</a> and to demonstrate these concepts I&#39;ve shoehorned the code from my <a href="/2013/02/the-producer-consumer-pattern-is-ideal.html#.UjXZ62R4apY" target="new">Producer Consumer project</a> into a web application. Although the code demonstrates the points made by the blogs it does contain a large number of holes in its logic. Apart from the fact that in a real application you wouldn&#39;t use a simple <tt>LinkedBlockingQueue</tt>, but would choose JMS or some other industrial strength messaging service, and the fact that only one user can get hold of the match updates, there&#39;s also the problem it spawns badly behaved threads that don&#39;t close down when the JVM terminates. <br><br>You may wonder why this should be a problem… <a href="/2013/09/tomcats-graceful-shutdown-with-daemons.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com4tag:blogger.com,1999:blog-3237724005744642470.post-73284501161446106442013-09-06T11:51:00.000+01:002013-09-06T11:51:18.819+01:00Long Polling with Spring 3.2’s DeferredResult In our <a href="http://www.youtube.com/watch?v=OSaNWYHmUvI" target="new">last episode</a>, the CEO of <i>Agile Cowboys Inc</i> had just hired a Java/Spring consultant by giving him the Porsche that he originally bought for his girlfriend. Being upset by the loss of her prize Porsche, the CEO’s girlfriend has told his wife of their affair. His wife, after cutting up the CEO’s suites has filed for divorce. Meanwhile the CEO has implemented a new ‘casual’ dress code at the office and the Java/Spring consultant has just arrived back from a spin in his <i>new</i> Porsche and is sitting down at his desk about to fix the TV company’s software... If this doesn’t mean anything to you then take a look at <a href="/2013/08/long-polling-tomcat-with-spring.html#.UhsZ2xZ8vdk" target="new">Long Polling Tomcat With Spring</a>.<br><br>The Java/Spring Consultant has to fix the TV Company’s server resource problem before the next big game, and he knows he can do this by implementing Spring’s Deferred Result technique using the Servlet 3 specification as implemented on Tomcat 7<sup>1</sup><br><br>The first thing that the Java/Spring consultant does is to check<a href="/2013/09/long-polling-with-spring-32s.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com2tag:blogger.com,1999:blog-3237724005744642470.post-19316756796440014632013-08-21T09:30:00.000+01:002013-08-21T09:41:38.808+01:00Long Polling Tomcat with Spring<a href="http://wiki.answers.com/Q/What_does_oh_er_misses_mean" target="new">&quot;Ooh err Missus&quot;</a> as comedian <a href="http://en.wikipedia.org/wiki/Frankie_Howerd" target="new">Frankie Howerd</a> would have said, but enough of British innuendo and double entendre because Long Polling Tomcat isn&#39;t some kind of sexual deviance with next door&#39;s moggy, it&#39;s a technique (or more of a hack) that&#39;s been developed as a result of Steve Jobs&#39;s refusal to support <a href="http://edition.cnn.com/2011/11/09/tech/mobile/flash-steve-jobs" target="new">Adobe Flash Player on the iPhone and iPad</a>. The thing is, using Flash Player as part of a web application was a really good way of supporting the <a href="http://en.wikipedia.org/wiki/Publish–subscribe_pattern" target="new">Publish and Subscribe paradigm</a> as it was able to cater for those scenarios that require live updates, such as live stock prices, news updates and changes to betting odds, whereas straight forward HTTP, with its request/reply paradigm, is a good way of supporting static pages. A good number of companies put a lot of effort in to developing applications that used Flash in order to provide their users with realtime data. When Apple announced that iOS would not support Adobe Flash they were left high and dry without an iPhone solution and to get back into the mobile market I imagine that a good number of them went for long polling.<br><br>So, what is a <a href="http://en.wikipedia.org/wiki/Long" target="new">long</a> <a href="http://www.thefreedictionary.com/poll" target="new">poll</a>? Well, it isn&#39;t a tall guy from <a href="http://www.um.warszawa.pl/en" target="new">Warsaw</a>, the idea is to mimic the Publish and Subscribe pattern. The scenario goes like this:<a href="/2013/08/long-polling-tomcat-with-spring.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com1tag:blogger.com,1999:blog-3237724005744642470.post-50010384361821810902013-07-31T09:00:00.000+01:002013-08-03T15:19:37.806+01:00Erlang for Java DevelopersYou probably haven&#39;t noticed, but it&#39;s a couple of weeks since I last posted a blog. There is reason for this is that I&#39;ve ruptured my Soleus and my leg is in a plaster cast. Being immobile I thought that it would be a good idea to investigate something totally different - it was either that or watch day time TV and, even though reruns of Kojak and Magnum PI were tempting, investigating <a href="http://www.erlang.org" target="new">Erlang</a> came out tops.<br><br><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-9T9vv5UexpE/Ufa8r86hOqI/AAAAAAAAAyQ/JvkH6EEgIW4/s1600/erlang-logo.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-9T9vv5UexpE/Ufa8r86hOqI/AAAAAAAAAyQ/JvkH6EEgIW4/s1600/erlang-logo.png"></a></div>The thing to remember here is that this is not an <a href="http://learnyousomeerlang.com/content" target="new">Erlang tutorial</a>, the idea here is to examine a few of the similarities between Erlang and Java in order to try an provide a starting point for learning Erlang. If I&#39;ve made any howling mistakes, then hopefully someone with more Erlang experience will let me know.<br><br>When getting started, the first thing they tell you about Erlang is that it&#39;s a functional language; however, before you have apoplexy at the thought, it&#39;s such a well structured functional language that you&#39;d think you were dealing with objects.<a href="/2013/07/erlang-for-java-developers.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com1tag:blogger.com,1999:blog-3237724005744642470.post-38984880968726607302013-07-17T09:00:00.000+01:002013-07-17T09:00:00.710+01:00Getting Started With Spring’s MVC Test Framework - Part 2The <a href="/2013/07/getting-started-with-springs-mvc-test.html#.UeQrAxbFXZs" target="new">first blog</a> in this mini-series introduced the Spring MVC Test Framework and demonstrated its use in unit testing Spring MVC Controller classes as controllers rather then as POJOs. It’s now time to talk about using the framework for integration testing.<br><br>By ‘integration testing’ I mean loading the Spring context into the test environment so that the controller can work with its collaborators in ‘end to end’ tests.<a href="/2013/07/getting-started-with-springs-mvc-test_17.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com2tag:blogger.com,1999:blog-3237724005744642470.post-71780448803028801582013-07-09T09:00:00.000+01:002013-07-09T09:00:06.040+01:00Getting Started With Spring’s MVC Test Framework - Part 1Newly promoted to the main Spring framework is the Spring MVC Test Framework, which the Guys at Spring claim is a “first class JUnit support for testing client and server side Spring MVC code through a fluent API”<sup>1</sup>. In this and my next blog, I’m going to take a look at Spring’s MVC Test Framework and apply it to some of my existing sample code to figure out whether or not it does what it says on the tin.<br><br>The API has been designed with two ways of setting up server side tests. These are firstly, with a Spring context file and secondly, programmatically without a context file. The Guys at Spring refer to the programatic method as ‘standalone’ mode.<br><br>Setting tests up programmatically <a href="/2013/07/getting-started-with-springs-mvc-test.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com1tag:blogger.com,1999:blog-3237724005744642470.post-64748521280215028632013-07-02T09:00:00.000+01:002013-07-02T21:53:45.372+01:00Auditing a Spring MVC Webapp with AspectJ. Part 2Now, this is the blog you want to read if you&#39;re interested in creating a Spring MVC Webapp that uses Aspect Oriented Programming (AOP) in the form of Aspectj&#39;s <tt>@Aspect</tt> and <tt>@Before</tt> annotations to audit a user&#39;s visit to a screen. <br><br>As I said in <a href="/2013/06/auditing-spring-mvc-webapp-with-aspectj.html" target="new">my last blog</a> auditing a user’s visits to a screen is one of those few cross-cutting concerns that Aspect Oriented Programming (AOP) solves very well. The idea in the case of my demo code, is that you add an annotation to the appropriate controllers and every time a user visits a page, then that visit is recorded. Using this technique you can construct a picture of the most popular screens and therefore the most popular chunks of functionality in your application. Knowing these details makes it easier to decide where to aim your development effort as it doesn’t pay to develop those chunks of your application that hardly anyone ever uses.<br><br>For the demo-code I created a simple Spring MVC application that has two screens: a home page and a help page. On top of this I’ve created a simple annotation: <tt>@Audit</tt>, which is used to mark a controller as one that needs auditing (not all of them will, especially if you choose to audit function points rather than individual screens) and to tell the advice object the screen id. This I&#39;ve demonstrated in the snippet of code below:<a href="/2013/07/auditing-spring-mvc-webapp-with-aspectj.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com0tag:blogger.com,1999:blog-3237724005744642470.post-35446611406420481352013-06-28T13:32:00.000+01:002013-06-28T17:46:57.772+01:00Auditing a Spring MVC Webapp with AspectJ. Part 1 If you’re like me, then you’ll have those kinds of programming days where everything seems to go incredibly well. You write the code and the tests and it just works. And then and there are those other kinds of days, the really bad ones, where you know that everything you’ve written is as right as it can be and the code refuses to work: something is obviously wrong, but you’ve no idea what. I had one of these kinds of days when writing the code for this blog. The idea was to demonstrate how to use Spring and Aspectj to audit a user’s visits to a screen. <a href="/2013/06/auditing-spring-mvc-webapp-with-aspectj.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com0Barcelona, Spain41.3850639 2.173403499999949441.3850639 2.1734034999999494 41.3850639 2.1734034999999494tag:blogger.com,1999:blog-3237724005744642470.post-86596144816177217922013-06-13T09:00:00.000+01:002013-06-13T09:00:08.046+01:00Acceptance Criteria Should be ExecutableHaving covered the debacle at Backwater Bank inc, you would have thought that my last blog had said just about everything there is to say about Agile User Stories. Well, that turns out not to be the case. If you take a look at an example order a cheque book story from the Backwater Bank inc scenario, you&#39;ll see that includes some acceptance criteria:<br><br><div class="story">Title: Order Cheque Book<br>As a customer<br>I want to access my online account <br>So that I can order a new cheque book<br><br><u>Acceptance Criteria</u><br>1) The bank will only send out a cheque book if the customer is in credit.<br>2) The user can only request a cheque book if the bank has his/her complete address details.<br></div><br>...and acceptance criteria implies that there are tests associated with the story.<a href="/2013/06/acceptance-criteria-should-be-executable.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com1tag:blogger.com,1999:blog-3237724005744642470.post-69062899501901569962013-06-03T09:00:00.000+01:002013-06-04T07:56:40.265+01:00So, what's in a story?I don&#39;t know about you, but I always feel a little nervous when it comes to writing Agile stories. I often worry whether I&#39;m the best person to write them and if I&#39;ve got them right. The reason for the first worry is that the agile gospel says that the best stories are written by the customers whilst, the reason for the second worry is that my stories will be reviewed by a number of people including various project stake holders. All of which got me thinking: writing a story, how hard can it be? So, I took a good look around to see what advice others could offer.<br><br>Some of this advice was often vague such as that in<a href="/2013/06/so-whats-in-story.html#more">Read more »</a>Roger Hugheshttp://www.blogger.com/profile/07042290171112551665noreply@blogger.com3