<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Java on despatches</title><link>https://icle.es/tags/java/</link><description>Recent content in Java on despatches</description><generator>Hugo</generator><language>en</language><lastBuildDate>Wed, 18 Mar 2026 20:33:52 +0000</lastBuildDate><atom:link href="https://icle.es/tags/java/index.xml" rel="self" type="application/rss+xml"/><item><title>Limit Java Memory Globally</title><link>https://icle.es/2024/07/26/limit-java-memory-globally/</link><pubDate>Fri, 26 Jul 2024 11:18:35 +0100</pubDate><guid>https://icle.es/2024/07/26/limit-java-memory-globally/</guid><description>&lt;p>Java can be greedy with RAM. By default, it grabs up to half your system memory,
which is fine for servers—but annoying on a dev machine.&lt;/p>
&lt;p>You can tame this by setting:&lt;/p>
```bash
export JAVA_TOOL_OPTIONS="-Xmx1G"
```
&lt;p>I dropped this into my .bashrc, and it instantly reduced background memory
pressure. One gig is plenty for most compile-and-run tasks during development.&lt;/p></description><content:encoded><![CDATA[<p>Java can be greedy with RAM. By default, it grabs up to half your system memory,
which is fine for servers—but annoying on a dev machine.</p>
<p>You can tame this by setting:</p>
```bash
export JAVA_TOOL_OPTIONS="-Xmx1G"
```
<p>I dropped this into my .bashrc, and it instantly reduced background memory
pressure. One gig is plenty for most compile-and-run tasks during development.</p>
]]></content:encoded></item><item><title>Microservices vs Monolith: Real World Tradeoffs</title><link>https://icle.es/2024/07/17/microservices-vs-monolith-real-world-tradeoffs/</link><pubDate>Wed, 17 Jul 2024 09:48:25 +0100</pubDate><guid>https://icle.es/2024/07/17/microservices-vs-monolith-real-world-tradeoffs/</guid><description>&lt;p>When starting a new backend system for a contract I was on, one of the early
decisions I had to make was whether to lean into a monolith or adopt a
microservices approach. While common wisdom offers strong opinions on both ends
of the spectrum, in reality, the choice often hinges on organizational
constraints as much as on technical purity.&lt;/p>
&lt;h3 id="reactive-vs-traditional-spring-web">Reactive vs Traditional Spring Web&lt;/h3>
&lt;p>I began by reviewing
&lt;a href="https://filia-aleks.medium.com/microservice-performance-battle-spring-mvc-vs-webflux-80d39fd81bf0">performance comparisons&lt;/a>
between Spring MVC and WebFlux. Reactive Web generally comes out ahead in
benchmarks, but that doesn’t tell the whole story.&lt;/p></description><content:encoded><![CDATA[<p>When starting a new backend system for a contract I was on, one of the early
decisions I had to make was whether to lean into a monolith or adopt a
microservices approach. While common wisdom offers strong opinions on both ends
of the spectrum, in reality, the choice often hinges on organizational
constraints as much as on technical purity.</p>
<h3 id="reactive-vs-traditional-spring-web">Reactive vs Traditional Spring Web</h3>
<p>I began by reviewing
<a href="https://filia-aleks.medium.com/microservice-performance-battle-spring-mvc-vs-webflux-80d39fd81bf0">performance comparisons</a>
between Spring MVC and WebFlux. Reactive Web generally comes out ahead in
benchmarks, but that doesn’t tell the whole story.</p>
<p>In our use case—web notifications—the benefit of reactive patterns depends
heavily on how data is delivered. If we were polling, the advantage would be
limited. However, with Server-Sent Events (SSE), Spring’s support aligns
directly with Reactive Web, making WebFlux the more appropriate choice for this
part of the system.</p>
<h3 id="the-deployment-constraint">The Deployment Constraint</h3>
<p>Ideally, I would have started with a monolith: a single deployable artifact
combining both the Kafka Streams logic and the API. This option would have
simplified initial development and allowed us to iterate quickly. But at the
client, the platform does not allow deploying a Kafka Streams app and an API
within the same Kubernetes deployment.</p>
<p>This effectively rules out a true monolith, even for a prototype.</p>
<h3 id="options-considered">Options Considered</h3>
<h4 id="shared-library-with-thin-deployments">Shared Library with Thin Deployments</h4>
<p>A middle ground was to build the core logic in a shared library and have
lightweight deployments wrap around it. This would allow the streams app and the
API to share code without needing to make HTTP calls between them.</p>
<p>The downside: these services are no longer independently deployable. But given
our team size and velocity goals, this compromise might be acceptable.</p>
<h4 id="full-microservices">Full Microservices</h4>
<p>Another option was to separate the services entirely:</p>
<ul>
<li><strong>Streams service</strong> (Kafka, plus domain-specific logic)</li>
<li><strong>Web API</strong> (for delivering notifications)</li>
<li><strong>Subscription API</strong> (managing notification subscriptions)</li>
</ul>
<p>This adheres more closely to the single responsibility principle, especially as
we move from PoC to MVP. However, it adds deployment and coordination overhead.</p>
<h4 id="application-profiles">Application Profiles</h4>
<p>A third hacky option was to control which parts of the app run using
environment-based profiles. For example, we could disable Kafka in dev or use
conditional beans to keep deployments clean. While not ideal long-term, it
offers flexibility for early stages.</p>
<h3 id="conclusion">Conclusion</h3>
<p>Constraints matter. While I lean toward monoliths for rapid delivery in small
teams, platform limitations forced a hybrid approach. We intend to evolve into
microservices over time, but only when the benefits clearly outweigh the cost.</p>
<p>Have you faced similar deployment constraints that shaped your architecture? I&rsquo;d
love to hear how you navigated them.</p>
]]></content:encoded></item><item><title>List of Installed Programs on Windows from java</title><link>https://icle.es/2019/03/17/list-of-installed-programs-on-windows-from-java/</link><pubDate>Sun, 17 Mar 2019 15:13:53 +0000</pubDate><guid>https://icle.es/2019/03/17/list-of-installed-programs-on-windows-from-java/</guid><description>&lt;p>I was recently in need of a way to pick up the list of installed software on a
windows computer from Java. It was shrouded in a veil a mystery. There did not
seem to be a functional call that I could make, which makes sense since Java is
cross-platform and there is not universal way to pick up all the installed
packages on an OS.&lt;/p>
&lt;p>In fact, picking up all the installed packages on Windows seems be a bit
cryptic. There are API calls you can make and I considered JNI. I suspect this
might be a superior solution, but I haven't tried it and I read that it may be
slow.&lt;/p></description><content:encoded><![CDATA[<p>I was recently in need of a way to pick up the list of installed software on a
windows computer from Java. It was shrouded in a veil a mystery. There did not
seem to be a functional call that I could make, which makes sense since Java is
cross-platform and there is not universal way to pick up all the installed
packages on an OS.</p>
<p>In fact, picking up all the installed packages on Windows seems be a bit
cryptic. There are API calls you can make and I considered JNI. I suspect this
might be a superior solution, but I haven't tried it and I read that it may be
slow.</p>
<p>After much research, I came across
<a href="https://github.com/mavenlin/ListPrograms">ListPrograms.</a> My initial thought was
to link to it using JNI. However, it seemed simple enough to warrant a rewrite
in Java if I could access the registry somehow.</p>
<p>This is where <a href="https://github.com/java-native-access/jna">JNA</a> and the
<a href="https://java-native-access.github.io/jna/4.2.0/com/sun/jna/platform/win32/Advapi32Util.html">Advapi32Util</a>
class came in handy.</p>
<p>It didn't take me long to put together a quick replica of behaviour. I skipped
out the part about user installed programs because it isn't relevant for me
(yet).</p>
<p>I also missed out issues which will be around when running it as part of a 32bit
VM within a 64bit OS.</p>
<p>You can find <a href="https://github.com/drone-ah/JavaListApps">JavaListApps at GitHub</a></p>
]]></content:encoded></item><item><title>What I learnt developing a small JavaFX App</title><link>https://icle.es/2018/06/26/what-i-learnt-developing-a-small-javafx-app-wip/</link><pubDate>Tue, 26 Jun 2018 11:18:38 +0000</pubDate><guid>https://icle.es/2018/06/26/what-i-learnt-developing-a-small-javafx-app-wip/</guid><description>&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;p>This is a collection of the things I learnt developing a simple JavaFX app over
the last month or two. My background is very much in Java EE with decades of
experience building high end, high-performance ticketing systems. This means
that my expectation from a development environment is relatively high. There are
many optional components in here that I find worthwhile setting up at the start,
but are not necessary&lt;/p></description><content:encoded><![CDATA[<h1 id="introduction">Introduction</h1>
<p>This is a collection of the things I learnt developing a simple JavaFX app over
the last month or two. My background is very much in Java EE with decades of
experience building high end, high-performance ticketing systems. This means
that my expectation from a development environment is relatively high. There are
many optional components in here that I find worthwhile setting up at the start,
but are not necessary</p>
<h2 id="tools">Tools</h2>
<h3 id="maven">Maven</h3>
<p>One of the most useful tools I have found while working with Java is maven. If
maven isn't a part of your build, have a look at it and re-evaluate that. I
have no doubt that maven has saved me hundreds, if not thousands of hours over
the last few years.</p>
<h3 id="javafx-scene-builder">JavaFX Scene Builder</h3>
<p>While this one has a bunch of issues and serious limitations, it can still be a
helpful tool. It helped me get a handle on the components available and placing
items.</p>
<h1 id="libraries">Libraries</h1>
<h2 id="testing">Testing</h2>
<p>I use <strong>junit5,</strong> but there are other options like test-ng which are equally
good. I use **Mockito **for mocking, but there are many other options like
PowerMock, JMockit, EasyMock, etc.</p>
<p>For UI Testing, you can use <strong>TestFX.</strong> I don't like UI work, so haven't done
much work with this.</p>
<pre><code>    org.junit.platform
    junit-platform-launcher
    1.2.0
    test


    org.junit.jupiter
    junit-jupiter-engine
    5.2.0
    test


    org.junit.vintage
    junit-vintage-engine
    5.2.0
    test



    org.mockito
    mockito-core
    2.18.3
    test
</code></pre>
<h2 id="logging">Logging</h2>
<p>I can&rsquo;t live without logging in any application. It can make troubleshooting
much easier, particularly when you&rsquo;ve deployed your app. <strong>log4j2</strong> is the main
logging framework out there. You can choose another one if you like, but I
strongly recommend having and using one.</p>
<pre><code>    org.apache.logging.log4j
    log4j-slf4j-impl
    2.11.0


    org.apache.logging.log4j
    log4j-api
    2.11.0


    org.apache.logging.log4j
    log4j-core
    2.11.0
</code></pre>
<h2 id="dependency-injection">Dependency Injection</h2>
<p>If you have working the Java EE Environment, you have almost certainly come
across
<a href="https://en.wikipedia.org/wiki/Inversion_of_control">Inversion of Control</a>, 
particularly in the form
of <a href="https://en.wikipedia.org/wiki/Dependency_injection">Dependency Injection</a>. I
love dependency injection. It helps with decoupling components and with testing.
I looked at various frameworks including
<a href="https://google.github.io/dagger/">Dagger 2</a>, <a href="https://spring.io/">Spring</a>,
<a href="https://github.com/google/guice">Guice</a>.</p>
<h3 id="dagger">Dagger</h3>
<p>The fully static (compile time) nature of Dagger 2 means that it doesn't gel
well with JavaFX which is very dynamic.</p>
<h3 id="spring">Spring</h3>
<p>I had worked with Spring many years ago and didn't want to tangle with a
behemoth for a small project. There are many components and loads of
functionality in spring and if you building a large and complex project, it
might be worth it.</p>
<h3 id="google-guice">Google Guice</h3>
<p>Google Guice is the framework that I ended up going with. It does have some
dependencies like Guava, but as it turned out, I Guava comes in handy for JavaFX
anyway. We don't need an entry in the pom.xml for this because of the following
dependency.</p>
<h2 id="gluon-ignite">Gluon Ignite</h2>
<p><a href="https://gluonhq.com/labs/ignite/">Gluon Ignite</a> was released by gluon labs to
integrate Dependency Injection frameworks with JavaFX. In other words, it ties
in the DI framework with the FXMLLoader so that it will load the correct
controller instances. Since I am using Guice, I needed the ignore-guice module.
If you add this into your pom.xml, it will also pull in google guice. Easy eh?
;)</p>
<pre><code>    com.gluonhq
    ignite-guice
    1.0.2
</code></pre>
<p>If you don't want to add another dependency, you could take a look at the code
in this module. It's fairly straightforward to integrate that manually into
your app. It's just easier to add in the dependency and let it do the magic</p>
<h2 id="event--publisher--subscriber-framework">Event / Publisher / Subscriber Framework</h2>
<p>It is likely that you will need an event framework or a publisher/subscriber
framework. The nature of GUI design and work is that it is an easy and simple
solution for a number of problems you will come across. Fortunately, we already
have an
<a href="https://github.com/google/guava/wiki/EventBusExplained">event framework</a> in
place within <a href="https://github.com/google/guava">Guava</a> which is a dependency of
Google Guice.</p>
<h2 id="project-lombok">Project Lombok</h2>
<p>Don't you love adding in a getter and a setter for each field? When you change
your fields, don't you love going in and updating all the getters and setters?
How about defining the long, pita to type types with generics of variables that
you are assigning from a method call? I mean the compiler can't possibly figure
that out by itself, right? How about writing out the toString, equals and
hashCode for each class? What do you mean no, you don't? You don't love these
tedious repetitive tasks of development? Good! You will love
<a href="https://projectlombok.org/setup/eclipse">Lombok.</a> Unfortunately, with Lombok,
it's not as simple as adding it into your pom.xml. Check out the install
instructions on their website for you IDE etc. You also need it in your pom.xml.</p>
<pre><code>    org.projectlombok
    lombok
    1.18.0
    provided
</code></pre>
<p>There is some controversy around Lombok. There is a
<a href="https://stackoverflow.com/questions/3852091/is-it-safe-to-use-project-lombok">good post on stackoverflow that covers some of these things in a reasonable fashion</a>.</p>
<h2 id="apache-commons">Apache Commons</h2>
<p>Last but certainly not least, we have
<a href="https://commons.apache.org/">apache commons</a>. This is a collection of libraries
rather than a single one. You know all those bits of code you write over and
over. Chances are that there is something in here that does it better and in a
simpler way.</p>
<h2 id="persistence">Persistence</h2>
<p>TBC</p>
<h1 id="packaging">Packaging</h1>
<p>TBC</p>
]]></content:encoded></item><item><title>Directed Acyclic Graphs and Executing Tasks in Order (and in Parallel) Based on Dependencies</title><link>https://icle.es/2011/11/07/directed-acyclic-graphs-and-executing-tasks-in-order-and-in-parallel-based-on-dependencies-1107/</link><pubDate>Mon, 07 Nov 2011 23:44:36 +0000</pubDate><guid>https://icle.es/2011/11/07/directed-acyclic-graphs-and-executing-tasks-in-order-and-in-parallel-based-on-dependencies-1107/</guid><description>&lt;p>A little while ago, there was a requirement to write a tool that could take a
number of tasks each with a set of dependencies and execute them in parallel
while taking the dependencies into account.&lt;/p>
&lt;p>The tasks themselves were meant for data migration but that is not particularly
relevant. We were writing a number of tasks which all had a set of dependencies
(some of the tasks did not have any dependencies or the process could of course
never start).&lt;/p>
&lt;p>It was assumed that there were no cyclic dependencies (which would be error in
this particular case anyway)&lt;/p>
&lt;p>Bearing in mind that this was a quick and dirty tool for use three times, some
of the bits in here could do with tidying up.&lt;/p>
&lt;p>Each task was defined to implement the following interface&lt;/p>
```java
 public interface Task extends Runnable {

 public String getName();

 public Set getDependencies();

 }
```</description><content:encoded><![CDATA[<p>A little while ago, there was a requirement to write a tool that could take a
number of tasks each with a set of dependencies and execute them in parallel
while taking the dependencies into account.</p>
<p>The tasks themselves were meant for data migration but that is not particularly
relevant. We were writing a number of tasks which all had a set of dependencies
(some of the tasks did not have any dependencies or the process could of course
never start).</p>
<p>It was assumed that there were no cyclic dependencies (which would be error in
this particular case anyway)</p>
<p>Bearing in mind that this was a quick and dirty tool for use three times, some
of the bits in here could do with tidying up.</p>
<p>Each task was defined to implement the following interface</p>
```java
    public interface Task extends Runnable {

        public String getName();

        public Set getDependencies();

    }
```
<p>It should all be self explanatory. Extending the Runnable interface ensure that
we can pass it into threads and other relevant bits of code. The getDependencies
is expected to return the name of the tasks that it depends on.</p>
<p>The basic task runner which I describe below does not check if the task
described in any list of dependencies actually exist. If an non-existing
dependency is defined, it will likely just throw a Null Pointer Exception. I
wrote this a long time ago, so don&rsquo;t actually remember.</p>
<p>The BasicTaskRunner which we used to run the tasks implemented the TaskRunner
Interface</p>
```java
    public interface TaskRunner {

        public boolean addTask(Task task);

        public boolean prepare();

        public boolean start();

        public void waitToComplete();
    }
```
<p>The <code>addTask</code> method simply added it to a map from String -&gt; Task and threw an
exception in the event of a duplicate task being added in.</p>
```java
       @Override
        public synchronized boolean addTask(Task task) {
            LOG.info("Adding task: " + task.getName());

            if (tasks.put(task.getName(), task) != null) {
                throw new RuntimeException("Task with same name already exists: " + task.getName());
            }

            return true;
        }
```
<p>the prepare method just calls a method to buildGraph. This uses the jGrapht
library to build a
<a href="http://en.wikipedia.org/wiki/Directed_acyclic_graph" title="Directed Acyclic Graph">Directed Acyclic Graph</a></p>
```java
       private boolean buildGraph() {

            LOG.info("Building DAG of tasks");
            graph = new SimpleDirectedGraph(DefaultEdge.class);

            LOG.info("Adding tasks");

            for (Task task: tasks.values()) {
                graph.addVertex(task);
            }

            LOG.info("Adding Relationships");

            for (Task task: tasks.values()) {

                if (task.getDependencies() != null) {
                    for (String depend: task.getDependencies()) {

                        Task dependOnTask = tasks.get(depend);

                        LOG.info("Adding relationship between " + task.getName() + " and " + dependOnTask.getName());
                        graph.addEdge(dependOnTask, task);

                    }
                }
            }

            return true;
        }
```
<p>So we create a simple directed graph, loop through the tasks, then each of its
dependencies to create an edge, which we then add to the graph. Simple stuff
really.</p>
<p>the start method, which actually executes the task is as follows:</p>
```java
       public boolean start() {

            int cpus = Runtime.getRuntime().availableProcessors();

            executor = new ThreadExecutor(cpus, 60, new LinkedBlockingQueue());

            numTasks = graph.vertexSet().size();
            LOG.info("Starting... Num Tasks: " + numTasks);
            startTime = System.currentTimeMillis();

            scheduleTasks();

            return true;

        }
```
<p>As a basic algorithm, we pick up the number of available processors and use that
many threads. scheduleTasks is a pseudo-recursive function whose role is to add
the currently executable list of tasks into the executor to execute.</p>
```java
       private void scheduleTasks() {
            if (graph.vertexSet().size() == 0) {
                executor.shutdown();
            }

            synchronized (graph ) {
                Iterator iter = new TopologicalOrderIterator(graph);
                Set executing = new HashSet();

                while(iter.hasNext()) {

                    Task task = iter.next();
                    //System.out.println(task.getName());
                    if (graph.incomingEdgesOf(task).size() == 0 && !executing.contains(task)) {
                        executor.execute(task);
                        executing.add(task);
                    }

                }
            }

        }
```
<p>If there are no tasks left to execute, we shut the executor down. All being
well, we add every single task in the graph that has no dependencies to be
executed. The threadpool ensures that any tasks that cannot currently be
executed are queued.</p>
<p>We use a custom version of the threadpool as follows:</p>
```java
       private class ThreadExecutor extends ThreadPoolExecutor {

            public ThreadExecutor(int corePoolSize, long keepAliveSeconds, BlockingQueue workQueue) {
                super(corePoolSize, corePoolSize, keepAliveSeconds, TimeUnit.SECONDS, workQueue);
            }

            @Override
            protected void afterExecute(Runnable runTask, Throwable e) {
                super.afterExecute(runTask, e);

                if (e == null) {
                    completed((Task) runTask);
                } else {
                    failed((Task) runTask, e);
                }
            }

        }
```
<p>The main purpose of this is to use the completed and failed callbacks to ensure
that on complete, dependent tasks can be executed. On fail, we ensure that
dependent tasks are not executed. The code currently does not allow for tasks
that are left behind and will hang indefinitely after executing all tasks it
can.</p>
```java
       public void completed(Task t) {
            LOG.info("Completed Task: " + t.getName());

            synchronized (graph) {
                graph.removeVertex(t);
            }

            long timeTaken = (System.currentTimeMillis() - startTime);
            int tasksComplete = numTasks - graph.vertexSet().size();

            long timePerTask = timeTaken/tasksComplete;

            long totalTime = timePerTask * numTasks;
            long timeToComplete = timePerTask * graph.vertexSet().size();

            LOG.info(" ## Tasks left: " + graph.vertexSet().size()
                   + " ## Elapsed: " + timeTaken/1000
                   + " ## Est. Total " + totalTime/1000
                   + " ## E.T.A : " + timeToComplete/1000);

            scheduleTasks();
        }

        public void failed(Task t, Throwable e) {
            LOG.fatal("Failed Task: " + t.getName(), e);
            scheduleTasks();
        }
```
<p>On completion of a task, we simply remove the task from the graph. The frees up
all its dependencies to be executed. We add these tasks into the list by calling
scheduleTasks again. There is nothing more for us to do when a task fails except
to schedule any other tasks that can be executed. In theory, this call is
redundant since any tasks that could be executed before the failure are already
in the queue. Any tasks that can be completed on the completion of another item
will be initiated on the completion of that task.</p>
<p>I hope the above makes sense and has been helpful. The code for the full class
including further logging statements follows. Please bear in mind that this was
hacked together over a couple of hours for something that was to be executed a
grand total of three times.</p>
```java
    public class BasicTaskRunner implements TaskRunner {

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

        private Map tasks = new HashMap();

        private DirectedGraph graph;

        private ThreadExecutor executor;

        @Override
        public synchronized boolean addTask(Task task) {
            LOG.info("Adding task: " + task.getName());

            if (tasks.put(task.getName(), task) != null) {
                throw new RuntimeException("Task with same name already exists: " + task.getName());

            }

            return true;
        }

        @Override
        public boolean prepare() {

            LOG.info("Preparing task runner. Num Tasks: " + tasks.size());

            buildGraph();

            return false;
        }

        private boolean buildGraph() {

            LOG.info("Building DAG of tasks");
            graph = new SimpleDirectedGraph(DefaultEdge.class);

            LOG.info("Adding tasks");

            for (Task task: tasks.values()) {
                graph.addVertex(task);
            }

            LOG.info("Adding Relationships");

            for (Task task: tasks.values()) {

                if (task.getDependencies() != null) {
                    for (String depend: task.getDependencies()) {

                        Task dependOnTask = tasks.get(depend);

                        LOG.info("Adding relationship between " + task.getName() + " and " + dependOnTask.getName());
                        graph.addEdge(dependOnTask, task);

                    }
                }
            }

            return true;
        }

        public void waitToComplete() {
            try {
                executor.awaitTermination(3, TimeUnit.DAYS);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        private long startTime;
        private int numTasks;

        @Override
        public boolean start() {

            int cpus = Runtime.getRuntime().availableProcessors();

            executor = new ThreadExecutor(cpus, 60, new LinkedBlockingQueue());

            numTasks = graph.vertexSet().size();
            LOG.info("Starting... Num Tasks: " + numTasks);
            startTime = System.currentTimeMillis();

            scheduleTasks();

            return true;

        }

        private void scheduleTasks() {
            if (graph.vertexSet().size() == 0) {
                executor.shutdown();
            }

            synchronized (graph ) {
                Iterator iter = new TopologicalOrderIterator(graph);
                Set executing = new HashSet();

                while(iter.hasNext()) {

                    Task task = iter.next();
                    //System.out.println(task.getName());
                    if (graph.incomingEdgesOf(task).size() == 0 && !executing.contains(task)) {
                        executor.execute(task);
                        executing.add(task);
                    }

                }
            }

        }

        public void completed(Task t) {
            LOG.info("Completed Task: " + t.getName());

            synchronized (graph) {
                graph.removeVertex(t);
            }

            long timeTaken = (System.currentTimeMillis() - startTime);
            int tasksComplete = numTasks - graph.vertexSet().size();

            long timePerTask = timeTaken/tasksComplete;

            long totalTime = timePerTask * numTasks;
            long timeToComplete = timePerTask * graph.vertexSet().size();

            LOG.info(" ## Tasks left: " + graph.vertexSet().size()
                   + " ## Elapsed: " + timeTaken/1000
                   + " ## Est. Total " + totalTime/1000
                   + " ## E.T.A : " + timeToComplete/1000);

            scheduleTasks();
        }

        public void failed(Task t, Throwable e) {
            LOG.fatal("Failed Task: " + t.getName(), e);
            scheduleTasks();
        }

        private class ThreadExecutor extends ThreadPoolExecutor {

            public ThreadExecutor(int corePoolSize, long keepAliveSeconds, BlockingQueue workQueue) {
                super(corePoolSize, corePoolSize, keepAliveSeconds, TimeUnit.SECONDS, workQueue);
            }

            @Override
            protected void beforeExecute(Thread thread, Runnable runTask) {
                super.beforeExecute(thread, runTask);

                Task task = (Task) runTask;

                LOG.info("Starting task: " + task.getName());
            }

            @Override
            protected void afterExecute(Runnable runTask, Throwable e) {
                super.afterExecute(runTask, e);

                if (e == null) {
                    completed((Task) runTask);
                } else {
                    failed((Task) runTask, e);
                }
            }

        }

    }
```]]></content:encoded></item><item><title>Java Object Size In Memory</title><link>https://icle.es/2011/04/25/java-object-size-in-memory/</link><pubDate>Mon, 25 Apr 2011 15:58:00 +0000</pubDate><guid>https://icle.es/2011/04/25/java-object-size-in-memory/</guid><description>&lt;p>Anyone who has worked with java in a high end application will be well aware of
the double edged sword that is java garbage collection. When it works - it is
awesome but when it doesn&amp;rsquo;t - it is an absolute nightmare. We work on a
ticketing system where it is imperative that the system is as near real-time as
possible. The biggest issue that we have found is the running of memory in the
JVM which causes a stop the world garbage collection. This then results in
cluster failures since an individual node is inaccessible for long enough that
it is kicked out of the cluster.&lt;/p>
&lt;p>There are various ways to combat this issue and the first instinct would be
suggest that there is a memory leak. After eliminating this as a possibility,
the next challenge was to identify where the memory was being taken up. This
took some time and effort and the hibernate second level cache was identified.
We were storing far too much in the second level cache.&lt;/p>
&lt;p>This is another double edged sword. The hibernate second level cache is
absolutely imperative to a high performance system. It does however, come with a
price. The cache needs to be managed carefully to ensure that balance between
performance and memory requirements.&lt;/p></description><content:encoded><![CDATA[<p>Anyone who has worked with java in a high end application will be well aware of
the double edged sword that is java garbage collection. When it works - it is
awesome but when it doesn&rsquo;t - it is an absolute nightmare. We work on a
ticketing system where it is imperative that the system is as near real-time as
possible. The biggest issue that we have found is the running of memory in the
JVM which causes a stop the world garbage collection. This then results in
cluster failures since an individual node is inaccessible for long enough that
it is kicked out of the cluster.</p>
<p>There are various ways to combat this issue and the first instinct would be
suggest that there is a memory leak. After eliminating this as a possibility,
the next challenge was to identify where the memory was being taken up. This
took some time and effort and the hibernate second level cache was identified.
We were storing far too much in the second level cache.</p>
<p>This is another double edged sword. The hibernate second level cache is
absolutely imperative to a high performance system. It does however, come with a
price. The cache needs to be managed carefully to ensure that balance between
performance and memory requirements.</p>
<p>To this end, it was important to be able to identify what was taking up all the
memory in the cache. Each object might only take a couple of hundred bytes, but
with our second level cache set to store hundreds of thousands of items, this
quickly takes up hundreds of megabytes. With the metadata of the cache, this
could easily hike it up near a gigabyte of memory usage. This gets substantially
worse with cache evictions and the adding of new items into the cache.</p>
<p>The correct way to resolve this is to identify specific object types that
&ldquo;overload&rdquo; the cache. i.e. items that have an large number of instances stored
in the cache. Identifying classes that store a large number of items is easy
enough - we just traverse the cache and count up the number of items. However,
there might be a class that stores a smaller number of items but take a sizeable
amount of memory. For this reason, it is important to understand the object
sizes in memory as well.</p>
<p>If you have ever tried to find a way to identify object sizes, you will know
that this is no easy task. You can calculate to some degree of accuracy the size
of an object based on the data it stores but this is a manual process.</p>
<p>The only real way to get this information is to use a java agent and use that to
calculate a more accurate memory usage. For this purpose, we used the
<a href="http://www.javamex.com/classmexer/" title="ClassMexer Java Profiling Agent">classmexer agent</a>
which requires a simple installation step of adding the following parameter to
java <code>-javaagent:classmexer.jar</code>. You can then figure out the memory utilisation
of an object by calling</p>
```java
MemoryUtil.deepMemoryUsageOf(objectInstance)
```
<p>You can also pass in a collection of objects:</p>
```java
MemoryUtil.deepMemoryUsageOfAll(objectInstanceCollection)
```
<p>This was the simple part.</p>
<p>Traversing the node structure of jboss cache and collating a collection
statistics with regards to the number of each type of object and its memory
utilisation was a little more interesting.</p>
<p>I will cover this separately</p>]]></content:encoded></item><item><title>Android - Parcel data to pass between Activities using Parcelable classes</title><link>https://icle.es/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/</link><pubDate>Mon, 26 Apr 2010 21:46:31 +0000</pubDate><guid>https://icle.es/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/</guid><description>&lt;p>Passing data between activities on android is unfortunately, not as simple as
passing in parameters. What we need to to do is tag these onto the intent. If
the information we need to pass across is a simple object like a String or
Integer, this is easy enough.&lt;/p>
```java
String strinParam = "String Parameter";
Integer intParam = 5;

Intent i = new Intent(this, MyActivity.class);
i.putExtra("uk.co.kraya.stringParam", stringParam);
i.putExtra("uk.co.kraya.intParam", intParam);

startActivity(i);
```</description><content:encoded><![CDATA[<p>Passing data between activities on android is unfortunately, not as simple as
passing in parameters. What we need to to do is tag these onto the intent. If
the information we need to pass across is a simple object like a String or
Integer, this is easy enough.</p>
```java
String strinParam = "String Parameter";
Integer intParam = 5;

Intent i = new Intent(this, MyActivity.class);
i.putExtra("uk.co.kraya.stringParam", stringParam);
i.putExtra("uk.co.kraya.intParam", intParam);

startActivity(i);
```
<p>Passing in custom objects is a little more complicated. You could just mark the
class
as <a href="http://java.sun.com/javase/6/docs/api/java/io/Serializable.html">Serializable</a>
and let Java take care of this. However, on the android, there is a serious
performance hit that comes with using Serializable. The solution is to
use <a href="http://developer.android.com/reference/android/os/Parcelable.html">Parcelable</a>.</p>
```java
package uk.co.kraya.android.demos.Parcelable;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * @author Shriram Shri Shrikumar
 *
 * A basic object that can be parcelled to
 * transfer between objects
 *
 */
public class ObjectA implements Parcelable {

    private String strValue;
    private Integer intValue;

    /**
     * Standard basic constructor for non-parcel
     * object creation
     */
    public ObjectA() { ; };

    /**
     *
     * Constructor to use when re-constructing object
     * from a parcel
     *
     * @param in a parcel from which to read this object
     */
    public ObjectA(Parcel in) {
        readFromParcel(in);
    }

    /**
     * standard getter
     *
     * @return strValue
     */
    public String getStrValue() {
        return strValue;
    }

    /**
     * Standard setter
     *
     * @param strValue
     */
    public void setStrValue(String strValue) {
        this.strValue = strValue;
    }

    /**
     * standard getter
     *
     * @return
     */
    public Integer getIntValue() {
        return intValue;
    }

    /**
     * Standard setter
     *
     * @param intValue
     */
    public void setIntValue(Integer intValue) {
        this.intValue = intValue;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

        // We just need to write each field into the
        // parcel. When we read from parcel, they
        // will come back in the same order
        dest.writeString(strValue);
        dest.writeInt(intValue);
    }

    /**
     *
     * Called from the constructor to create this
     * object from a parcel.
     *
     * @param in parcel from which to re-create object
     */
    private void readFromParcel(Parcel in) {

        // We just need to read back each
        // field in the order that it was
        // written to the parcel
        strValue = in.readString();
        intValue = in.readInt();
    }

    /**
     *
     * This field is needed for Android to be able to
     * create new objects, individually or as arrays.
     *
     * This also means that you can use use the default
     * constructor to create the object and use another
     * method to hyrdate it as necessary.
     *
     * I just find it easier to use the constructor.
     * It makes sense for the way my brain thinks ;-)
     *
     */
    public static final Parcelable.Creator CREATOR =
        new Parcelable.Creator() {
            public ObjectA createFromParcel(Parcel in) {
                return new ObjectA(in);
            }

            public ObjectA[] newArray(int size) {
                return new ObjectA[size];
            }
        };

}
```
<p>The intricacies of the class is described in the code above. There is now one
more special case. What if you have an object that references another object.
Clearly, they would both need to be Parcelable, but how would be integrate them.
ObjectB shows a parcelable embedded in another parcelable&hellip;</p>
```java
package uk.co.kraya.android.demos.Parcelable;

import android.os.Parcel;
import android.os.Parcelable;

public class ObjectB implements Parcelable {

    private ObjectA obj;
    private Long longVal;

    public ObjectB() { ; }

    public ObjectA getObj() {
        return obj;
    }

    /**
     *
     * Constructor to use when re-constructing object
     * from a parcel
     *
     * @param in a parcel from which to read this object
     */
    public ObjectB(Parcel in) {
        readFromParcel(in);
    }

    public void setObj(ObjectA obj) {
        this.obj = obj;
    }

    public Long getLongVal() {
        return longVal;
    }

    public void setLongVal(Long longVal) {
        this.longVal = longVal;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

        // The writeParcel method needs the flag
        // as well - but thats easy.
        dest.writeParcelable(obj, flags);

        // Same as in ObjectA
        dest.writeLong(longVal);
    }

    /**
     *
     * Called from the constructor to create this
     * object from a parcel.
     *
     * @param in parcel from which to re-create object
     */
    private void readFromParcel(Parcel in) {

        // readParcelable needs the ClassLoader
        // but that can be picked up from the class
        // This will solve the BadParcelableException
        // because of ClassNotFoundException
        obj = in.readParcelable(ObjectA.class.getClassLoader());

        // The rest is the same as in ObjectA
        longVal = in.readLong();
    }

    /**
     *
     * This field is needed for Android to be able to
     * create new objects, individually or as arrays.
     *
     * This also means that you can use use the default
     * constructor to create the object and use another
     * method to hyrdate it as necessary.
     *
     * I just find it easier to use the constructor.
     * It makes sense for the way my brain thinks ;-)
     *
     */
    public static final Parcelable.Creator CREATOR =
        new Parcelable.Creator() {
            public ObjectB createFromParcel(Parcel in) {
                return new ObjectB(in);
            }

            public ObjectB[] newArray(int size) {
                return new ObjectB[size];
            }
        };
}
```
<p>When writing the parcel, we need to pass in the flags - which is easy enough.
When reading the parcel, we need the classloader, which can be picked up from
destination class of the parcelable. Again easy!</p>
<p>Finally, passing a parcelable object to an intent</p>
```java
ObjectA obj = new ObjectA();

// Set values etc.

Intent i = new Intent(this, MyActivity.class);
i.putExtra("com.package.ObjectA", obj);

startActivity(i);
```
<p>Almost too easy - right?</p>
<p>and to read the values,</p>
```java
public class MyActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle b = getIntent().getExtras();
        ObjectA obj =
            b.getParcelable("com.package.ObjectA");
    }

}
```
<p>It it was any easier - we&rsquo;d all be out of a job ;-)</p>]]></content:encoded></item><item><title>Android - Multi-line Select List</title><link>https://icle.es/2010/04/19/android-multi-line-select-list/</link><pubDate>Mon, 19 Apr 2010 23:37:54 +0000</pubDate><guid>https://icle.es/2010/04/19/android-multi-line-select-list/</guid><description>&lt;p>It turns out that it is surprisingly easy to add a multi line select list to the
UI. There are four main parts to it. The layout file, a subclass to the adapter,
the activity and of course the data itself.&lt;/p>
&lt;p>Lets start with the data. For the sake of this demo, lets use a simple contact
list:&lt;/p>
```java
package uk.co.kraya.android.demos.MultiLineList.domain;

public class Contact {

 private String firstName;

 private String lastName;

 private String mobile;

 public String getFirstName() {
 return firstName;
 }

 public void setFirstName(String firstName) {
 this.firstName = firstName;
 }

 public String getLastName() {
 return lastName;
 }

 public void setLastName(String lastName) {
 this.lastName = lastName;
 }

 public String getMobile() {
 return mobile;
 }

 public void setMobile(String mobile) {
 this.mobile = mobile;
 }

}
```</description><content:encoded><![CDATA[<p>It turns out that it is surprisingly easy to add a multi line select list to the
UI. There are four main parts to it. The layout file, a subclass to the adapter,
the activity and of course the data itself.</p>
<p>Lets start with the data. For the sake of this demo, lets use a simple contact
list:</p>
```java
package uk.co.kraya.android.demos.MultiLineList.domain;

public class Contact {

    private String firstName;

    private String lastName;

    private String mobile;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

}
```
<p>Some straightforward fields and getters/setters</p>
<p>Next, we need an Adapter. For this one, we will use
a <a href="http://developer.android.com/reference/android/widget/ArrayAdapter.html">ArrayAdapter</a>.
We will extend it so that we can override
the <a href="http://developer.android.com/reference/android/widget/Adapter.html#getView%28int,%20android.view.View,%20android.view.ViewGroup%29">getView method.</a></p>
```java
package uk.co.kraya.android.demos.MultiLineList.domain.adapters;

import java.util.List;

import uk.co.kraya.android.demos.MultiLineList.domain.Contact;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TwoLineListItem;

public class ContactArrayAdapter extends ArrayAdapter {

    private final int resourceId;

    public ContactArrayAdapter(Context context, int textViewResourceId, List objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Contact c = getItem(position);

        // if the array item is null, nothing to display, just return null
        if (c == null) {
            return null;
        }

        // We need the layoutinflater to pick up the view from xml
        LayoutInflater inflater = (LayoutInflater)
                        getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        // Pick up the TwoLineListItem defined in the xml file
        TwoLineListItem view;
        if (convertView == null) {
            view = (TwoLineListItem) inflater.inflate(resourceId, parent, false);
        } else {
            view = (TwoLineListItem) convertView;
        }

        // Set value for the first text field
        if (view.getText1() != null) {
            view.getText1().setText(c.getFirstName() + " " + c.getLastName());
        }

        // set value for the second text field
        if (view.getText2() != null) {
            view.getText2().setText("mobile: " + c.getMobile());
        }

        return view;
    }

}
```
<p>The key bit here is the getView method. We pick up
the <a href="http://developer.android.com/reference/android/view/LayoutInflater.html">LayoutInflater</a>
which we can use to pick up the view that defines
the <a href="http://developer.android.com/reference/android/widget/TwoLineListItem.html">TwoLineListItem</a>
view. This allows us to use two different snippets of text as part of the list.
We then pick up the each of
the <a href="http://developer.android.com/reference/android/widget/TextView.html">TextView</a>
items and set the text against them. The formatting of these item are defined in
the xml file.</p>
<p>The TwoLineListItem class also defines a placeholder for the selectedIcon. Check
the documentation for more info.</p>
<p>The xml file for the layout goes as follows:</p>
```xml
<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView android:id="@android:id/text1"
        android:layout_marginTop="1dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15sp"
        android:textStyle="bold" />

    <TextView android:id="@android:id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@android:id/text1"
        android:layout_alignLeft="@android:id/text1"
        android:paddingBottom="4dip"
        android:includeFontPadding="false"
        android:textSize="15sp"
        android:textStyle="normal" />

</TwoLineListItem>
```
<p>As you can see, we are just defining a TwoLineListItem element with two embedded
TextItems. Tthe android:id parts are important. It ensures that the getText1()
and getText2() methods work as expected!</p>
<p>Finally, we have the activity. In fact, we will be using a
<a href="http://developer.android.com/reference/android/app/ListActivity.html">ListActivity</a>
as follows:</p>
```java
package uk.co.kraya.android.demos.MultiLineList;

import java.util.ArrayList;
import java.util.List;

import uk.co.kraya.android.demos.MultiLineList.domain.Contact;
import uk.co.kraya.android.demos.MultiLineList.domain.adapters.ContactArrayAdapter;
import android.app.ListActivity;
import android.os.Bundle;

public class MultiLineListDemo extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ContactArrayAdapter(this, R.layout.main, getContacts()));
    }

    private List getContacts() {

        List contacts = new ArrayList();

        Contact c;

        c = new Contact();
        c.setFirstName("Shriram");
        c.setLastName("Shrikumar");
        c.setMobile("07777777777");

        contacts.add(c);

        c = new Contact();
        c.setFirstName("John");
        c.setLastName("Doe");
        c.setMobile("MOBILE.NUMBER");

        contacts.add(c);

        return contacts;

    }
}
```
<p>getContacts clearly just creates a couple of contacts for the sake of the demo.
its the setListAdapter that is the key here. It creates a new
ContactArrayAdapter that we have written, passes in the context (which is just
the current activity), a resource ID and a List of items to display.</p>
<p>Run it and you should see something like:</p>
<p>
  <img src="/assets/2010/04/multilineselectdemo.png" alt="">

</p>
<p>So easy when you know how. I believe could use a View or a ViewGroup as needed
instead of the TwoLineListItem but I shall leave that to you to discover.</p>
<p>I have included all the files that I created/modified but if you want the whole
project tarred up, just drop me a note ;-)</p>]]></content:encoded></item><item><title>Database Systems Compared</title><link>https://icle.es/2009/03/10/database-systems-compared/</link><pubDate>Tue, 10 Mar 2009 16:00:21 +0000</pubDate><guid>https://icle.es/2009/03/10/database-systems-compared/</guid><description>&lt;p>My first experiences of a computer started with
&lt;a href="http://en.wikipedia.org/wiki/DBase" title="Dbase on Wikipedia">DBase III+&lt;/a>which is
now &lt;a href="http://www.dbase.com/" title="dBASE">dBASE&lt;/a>, then went on to
&lt;a href="http://en.wikipedia.org/wiki/FoxPro_2" title="Foxpro 2 on Wikipedia">Foxpro&lt;/a>, now
&lt;a href="http://msdn.microsoft.com/en-us/vfoxpro/bb190288.aspx" title="Microsoft Visual Foxpro">Microsoft Visual Foxpro&lt;/a>.&lt;/p>
&lt;p>I have since used:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="http://www.filemaker.co.uk/" title="Filemaker Pro">Filemaker Pro&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://office.microsoft.com/en-us/access/default.aspx" title="Microsoft Access">Microsoft Access&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" title="Microsoft SQL Server">Microsoft SQL Server&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://www.mysql.com/" title="MySQL">MySQL&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://www.postgresql.org/" title="PostgreSQL">PostgreSQL&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://www.sqlite.org/" title="SQLite">SQLite&lt;/a> and&lt;/li>
&lt;li>&lt;a href="http://hsqldb.org/" title="HSQLDB">HSQLDB&lt;/a>.&lt;/li>
&lt;/ul>
&lt;p>I have not yet used:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="http://www.ibm.com/software/data/db2/" title="IBM DB2">IBM DB2&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://www.oracle.com/index.html" title="Oracle">Oracle&lt;/a>.&lt;/li>
&lt;/ul>
&lt;p>&lt;a href="http://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems" title="Compare DB Systems">Wikipedia has a list of database systems&lt;/a>.&lt;/p></description><content:encoded><![CDATA[<p>My first experiences of a computer started with
<a href="http://en.wikipedia.org/wiki/DBase" title="Dbase on Wikipedia">DBase III+</a>which is
now <a href="http://www.dbase.com/" title="dBASE">dBASE</a>, then went on to
<a href="http://en.wikipedia.org/wiki/FoxPro_2" title="Foxpro 2 on Wikipedia">Foxpro</a>, now
<a href="http://msdn.microsoft.com/en-us/vfoxpro/bb190288.aspx" title="Microsoft Visual Foxpro">Microsoft Visual Foxpro</a>.</p>
<p>I have since used:</p>
<ul>
<li><a href="http://www.filemaker.co.uk/" title="Filemaker Pro">Filemaker Pro</a>,</li>
<li><a href="http://office.microsoft.com/en-us/access/default.aspx" title="Microsoft Access">Microsoft Access</a>,</li>
<li><a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" title="Microsoft SQL Server">Microsoft SQL Server</a>,</li>
<li><a href="http://www.mysql.com/" title="MySQL">MySQL</a>,</li>
<li><a href="http://www.postgresql.org/" title="PostgreSQL">PostgreSQL</a>,</li>
<li><a href="http://www.sqlite.org/" title="SQLite">SQLite</a> and</li>
<li><a href="http://hsqldb.org/" title="HSQLDB">HSQLDB</a>.</li>
</ul>
<p>I have not yet used:</p>
<ul>
<li><a href="http://www.ibm.com/software/data/db2/" title="IBM DB2">IBM DB2</a>,</li>
<li><a href="http://www.oracle.com/index.html" title="Oracle">Oracle</a>.</li>
</ul>
<p><a href="http://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems" title="Compare DB Systems">Wikipedia has a list of database systems</a>.</p>
<p>Having worked with this range of database systems and having done copious
amounts of research into DB2, Oracle and other DB systems I have not mentioned,
I like answering the age old questions. Which is the best database system?</p>
<p>Ah! if only it was that simple. There is no database system that is appropriate
for any given requirement. But then, if you have been in the technology sector
long enough, you would already know that. It's all about using the right tool
for the job.</p>
<p>I separate these systems into two broad categories and Oracle. There are the
Desktop based database systems:</p>
<ul>
<li>DBase</li>
<li>Foxpro</li>
<li>SQLite</li>
<li>HSQLDB</li>
<li>Filemaker Pro</li>
<li>Microsoft Access</li>
<li>MySQL</li>
</ul>
<p>DBase, FoxPro, Filemaker Pro and Microsoft Access are essentially a GUI frontend
that has a database backing.</p>
<p>Access is the best choice for this purpose under the majority of circumstances.
Filemaker Pro is relevant in some. The usual reason to use DBase or FoxPro is
simply that the developer is used to it. This is not a good enough reason.</p>
<p>I have used DBase III+ for developing an office management suite back in 1994. I
have since used Filemaker Pro to develop a simple contact management database in
1998, Microsoft Access to develop a patient management system for a clinic.</p>
<p>SQLite, HSQLDB and MySQL are database engines that are to be utilised by popping
a frontend on top; sometimes the frontend is Microsoft Access. Microsoft Access
can also be used for its database engine.</p>
<p>Access is usually the worst choice for this except as a stopgap. There are
exceptions to this. One is for a web frontend if the site is not too busy and
its running on a microsoft platform. You don't have to go to the hassle of
installing anything on the server. The drivers will take care of it all.</p>
<p>HSQLDB becomes an obvious choice for a light java based application and SQLite
for any other lightweight applications.</p>
<p>MySQL is substantially more powerful and scales a lot better. I include it in
this section because it is a server grade database system that can also work
well in a desktop environment.</p>
<p>I have used Access for several web based systems and I have used HSQLDB for unit
testing hibernate and for a quick and dirty MP3 library that linked into
<a href="http://musicbrainz.org/" title="Musicbrainz">musicBrainz</a>. I have used SQLite in
passing to be utilised by open source products.</p>
<p>I have used MySQL with an Access frontend as a management suite for a website as
well.</p>
<p>And we have the server based database systems:</p>
<ul>
<li>MySQL</li>
<li>Microsoft SQL Server</li>
<li>IBM DB2</li>
<li>PostgreSQL</li>
</ul>
<p>MySQL was used as the backed database system for the edFringe.com website. This
was the perfect choice since the most important requirement was speed.
Particuarly with the Query Cache and Master Slave replication, MySQL was the
best choice.</p>
<p>SQL Server was used as the backend system for an online course for the Scottish
Enterprise around 1999/2000. While MySQL would have been a good choice this, it
was not of production quality at the time.</p>
<p>We have also used Ms SQL Server for an insurance company since all the
infrastructure was based on Windows and PostgreSQL did not have a viable Windows
version at the time.</p>
<p>We use PostgreSQL for megabus. While speed is absolutely critical, it is a
ticketing system which means that transactionality is absolutely critical.</p>
<p>While MySQL now has transactionality with innodb, it is still nowhere near as
good as the transactionality provided by PostgreSQL through MVCC (Multi-version
Concurrency Control). We could have used Ms SQL Server but the cost savings are
dramatic.</p>
<p>To summarise, each system has a specific use, specific strengths and weaknesses
and which should be used is highly dependent on what it is to be used for. I am
hopeful that the summary of what we have used each of these systems for us
useful in determining which one is best placed to solve any specific problem :-D</p>
<p>We have not yet used Oracle and it was a strong contender for megabus but the
serious heavyweight functionality provided by Oracle comes at a price and it is
not yet a cost effective option.</p>]]></content:encoded></item><item><title>Eclipse TPTP on Ubuntu (64bit)</title><link>https://icle.es/2008/12/28/eclipse-tptp-on-ubuntu-64bit/</link><pubDate>Sun, 28 Dec 2008 18:15:45 +0000</pubDate><guid>https://icle.es/2008/12/28/eclipse-tptp-on-ubuntu-64bit/</guid><description>&lt;p>I run ubuntu 64 bit (technically, I run an ubuntu 64bit vserver which I access
from ubuntu 32 bit but thats not really relevant).&lt;/p>
&lt;p>In the open source world, I expect that all things which are accessible as 32bit
are also accessible and 64bit and ubuntu makes it automagic enough that
everything just works. Yes, I run into problems with closed source software like
Flash Player (recently resolved with flash player 10) and the Java Plugin but
that is another story. I use Eclipse and wanted to do some performance analysis
and benchmarking to find a bottleneck and installed the TPTP plugin; and ran
into a problem. It just didn&amp;rsquo;t work.&lt;/p></description><content:encoded><![CDATA[<p>I run ubuntu 64 bit (technically, I run an ubuntu 64bit vserver which I access
from ubuntu 32 bit but thats not really relevant).</p>
<p>In the open source world, I expect that all things which are accessible as 32bit
are also accessible and 64bit and ubuntu makes it automagic enough that
everything just works. Yes, I run into problems with closed source software like
Flash Player (recently resolved with flash player 10) and the Java Plugin but
that is another story. I use Eclipse and wanted to do some performance analysis
and benchmarking to find a bottleneck and installed the TPTP plugin; and ran
into a problem. It just didn&rsquo;t work.</p>
<p>To resolve it, I turned to google&hellip; In this instance, it turned out to be a
distraction and a red-herring. It lead me in the direction of installing
libstdc++2.10-glibc2.2_2.95.4-27_i386.deb which was difficult at best since
there was only a 32bit version of the package and that wasn&rsquo;t even in the
standard repository.</p>
<p>In the end, digging deeper, I found that it simply missed the following shared
object libstdc++.so.5.</p>
<p>All I had to do was install libstdc++5:</p>
```bash
sudo aptitude install libstdc++5
```
<p>and it worked&hellip; :-D</p>
<p>Now, I think that ACServer which Eclipse uses to do TPTP should not link to an
outdated library but that is another issue&hellip;</p>
]]></content:encoded></item><item><title>Hibernate Domain Model Testing</title><link>https://icle.es/2008/12/23/hibernate-domain-model-testing/</link><pubDate>Tue, 23 Dec 2008 22:14:42 +0000</pubDate><guid>https://icle.es/2008/12/23/hibernate-domain-model-testing/</guid><description>&lt;p>One of my pet peeves with Hibernate has always been how difficult it was to test
it. I want to test the persistence of data, loading the data back and any
specific funtionality with the domain model.&lt;/p>
&lt;p>Simple? NO! The main problem was the management of the data set. I had set up,
in the past fairly interesting classes to test the functionality using
reflection, and injecting the data from the classes themselves through the data
provider mechanism of &lt;a href="http://testng.org/d" title="TestNG">TestNG&lt;/a>. However, this was
error prone and clunky at best. It also made dependency management of data quite
cumbersome.&lt;/p>
&lt;p>With a view to resolving this, I also looked at
&lt;a href="http://dbunit.sourceforge.net/" title="DbUnit">DbUnit&lt;/a>,
&lt;a href="http://unitils.org/" title="Unitils">unitils&lt;/a> and
&lt;a href="http://ejb3unit.sourceforge.net/" title="Ejb3Unit">Ejb3Unit&lt;/a>. They all did some
things that I liked but lacked some functionality that was important.&lt;/p></description><content:encoded><![CDATA[<p>One of my pet peeves with Hibernate has always been how difficult it was to test
it. I want to test the persistence of data, loading the data back and any
specific funtionality with the domain model.</p>
<p>Simple? NO! The main problem was the management of the data set. I had set up,
in the past fairly interesting classes to test the functionality using
reflection, and injecting the data from the classes themselves through the data
provider mechanism of <a href="http://testng.org/d" title="TestNG">TestNG</a>. However, this was
error prone and clunky at best. It also made dependency management of data quite
cumbersome.</p>
<p>With a view to resolving this, I also looked at
<a href="http://dbunit.sourceforge.net/" title="DbUnit">DbUnit</a>,
<a href="http://unitils.org/" title="Unitils">unitils</a> and
<a href="http://ejb3unit.sourceforge.net/" title="Ejb3Unit">Ejb3Unit</a>. They all did some
things that I liked but lacked some functionality that was important.</p>
<p>This led me to write a simple testing infrastructure. The goal was
straightforward.</p>
<ul>
<li>I need to be able to define data in a CSV (actually it was seperated by the
pipe character |, so PSV) based on entities.</li>
<li>The framework should automatically persist the data (and fail on errors)</li>
<li>It should test that it can load all that data back</li>
<li>It should run as many automated tests on the DOM as possible.</li>
</ul>
<p>The framework uses the CSV files to read the data for each of the classes (using
the excellent <a href="http://supercsv.sourceforge.net/" title="SuperCsv">SuperCsv</a> library).
It needs an Id field for internal reference. As long as the id&rsquo;s match within
the CSV files for the relationships, it will be persisted correctly into the
database even when the persisted id&rsquo;s are different.</p>
<p>For example, I could have a Contact.csv with 5 records (ids 1 through 5) and a
Company.csv with 3 records (ids 1 through 3).</p>
<p>The Contact.csv records can map to the id specified in the Company.csv file and
when the records get persisted, they will be associated correctly, even if the
id&rsquo;s in the database end up being different.</p>
<p>The framework also looks for the CSV file which has the same name as the class
within the location defined within the configuration file. This means that as
long as the filename matches the class name, the data loading is automatic.</p>
<p>For simple classes, the Test case is as simple as:</p>
```java
public class CompanyTest extends DOMTest<Company> {

public CompanyTest() { super(Company.class); } }
```
<p>The system (with the help of testNG) is also easily flexible to define object
model dependencies. Just override the persist method (which just calls the
super.persist) and define the groups to be persist and <code>&lt;object&gt;.persist</code></p>
<p>in this particular case, it would be</p>
```java
@override
@Test(groups={"persist", "Company.persist"}
public void persist() {
    super.persist();
}
```
<p>For all dependent classes, I then depend on the Company.persist group (For the
ContactTest class for example, since it needs to link to the Company object)</p>
<p>You can specify OneToOne and ManyToOne relationships with just the CSV files -
just defining the field name and the id of the object to pull in.</p>
<p>ManyToMany is more complex and requires an interim object to be created within
the test section. If the Contact to Company relationship above was ManyToMany,
we would create a ContactCompany class with just the two fields - Contact &amp;
Company, then create a csv file with three fields, id, Contact, &amp; Company. The
framework currently always needs an id field.</p>
<p>You would then need to write a method within the ContactTest or CompanyTest(I
use the owning side) to read the CSV file in and pump the data. This process is
a little bit complex just now.</p>
<p>With an appropriate amount of test data, you are able to write a test suite that
can consistently test your domain model. More importantly, you can configure it
to drop the database at the start of each run so that once the tests are
complete, you have a database structure and data than can be used for testing of
higher level components (EJB/Spring/UI/WebApp)</p>
<p>We currently use this framework to test the domain model as well as distribute a
data set for development and testing of the higher tier functionalities.</p>
<p>For the future, there are several additional features this framework needs:</p>
<ul>
<li>It currently needs the setters/getters &amp; constructors to be public. This needs
to be FIXED</li>
<li>Refactor the ManyToMany Relationship code to make it easier and simpler to
test and pump data</li>
<li>See if we can ensure that additional tests which data is done within a
transaction and rolled back so that the database is left in the &ldquo;CSV Imported&rdquo;
state on completion of tests</li>
<li>Easier Dependency management if possible</li>
</ul>
<p>This framework is still inside the walls of Kraya, but once the above issues are
resolved and it is in a releasable state, it will be published into the open
source community. If you are interested in getting a hold of it, email me and
I&rsquo;ll provide you with the latest version.</p>
<p>The easier and quicker it is to test, the more time we can spend on writing
code&hellip; :-) The higher the coverage of the tests, the more confident you can be
of your final product.</p>
<p>To more testing&hellip;</p>]]></content:encoded></item><item><title>Design</title><link>https://icle.es/2008/12/12/design/</link><pubDate>Fri, 12 Dec 2008 16:42:37 +0000</pubDate><guid>https://icle.es/2008/12/12/design/</guid><description>&lt;p>Admitting to being a techie - I have often overlooked design. In fact, I have
often explained to (potential) clients, using the analogy of a ferrari that we
make the engine and everything else work while somebody else makes it look
gorgeous. For me, how something looks was largely irrelevant - as long as it
worked well.&lt;/p>
&lt;p>This explains why, for a long time, I used a fairly bland desktop environment.
My desktop itself was just pure black with no wallpaper. Ironically, I would
remove all the icons, so it would be pure black and nothing else.&lt;/p></description><content:encoded><![CDATA[<p>Admitting to being a techie - I have often overlooked design. In fact, I have
often explained to (potential) clients, using the analogy of a ferrari that we
make the engine and everything else work while somebody else makes it look
gorgeous. For me, how something looks was largely irrelevant - as long as it
worked well.</p>
<p>This explains why, for a long time, I used a fairly bland desktop environment.
My desktop itself was just pure black with no wallpaper. Ironically, I would
remove all the icons, so it would be pure black and nothing else.</p>
<p>This should have tipped me off on my own desire for design. I thought my desire
for black stemmed from the &ldquo;good old&rdquo; days of DOS when the screen was black and
my love for the linux terminal. As an aside, I used to reconfigure the terminal
windows in X to have a white on black background as well - so much better for
the eyes. In fact, I still don&rsquo;t understand why everyone uses a white background
for terminals and such like. Paper was white because that was easier. There is
really no reason for the screen to be white too&hellip;</p>
<p>Now, this was before I bumped into
<a href="http://www.enlightenment.org/" title="Beauty at your fingertips">Enlightenment</a> (at
this time, it was E16) and to put it bluntly, I was captivated. This was
absolutely gorgeous. Fairly unusable since I was used to
<a href="http://www.gnome.org/" title="The Free Software Desktop Project">GNOME</a> and of course
Microsoft Windows. I thoroughly enjoyed this until it became more of a
distraction&hellip;</p>
<p>I ended up reconfiguring GNOME to be prettier - in fact, I had the Mac OS X
theme for a while which I enjoyed.</p>
<p>I then dabbled with E17 and it was absolutely gorgeous - E16 paled in
comparison. I ran into a bug where some java applications would jump a few
pixels when changing the decorations. This was a real pain since I was
developing a Java application at the time. I spent an entire day trying to &ldquo;fix&rdquo;
this before I realised that it was E17 screwing it up and not my code&hellip; :-(</p>
<p>More recently, I thoroughly enjoyed
<a href="http://compiz.org/" title="A Compositing Window Manager">Compiz</a> with the shaky
windows and such like - I just always wished that I could actually throw a
window and watch the momentum carry it that extra distance.</p>
<p>Nevertheless, this bridged the gap enough to E17 to keep me happy for a little
while.</p>
<p>Last week, I dabbled with E17 again to see if the issue with Java was resolved.
To my surprise E17 had changed more or less completely - it was bridging the gap
between a window manager and a full fledged Desktop environment.</p>
<p>However, there was a problem. It looked like I couldn&rsquo;t get it back to its old
glory of absolutely fantastic graphics without some effort in configuration. One
other issue I ran into was that maximising a screen would fill it up across both
my monitors. Another thing I could configure but then, it all seemed like too
much effort.</p>
<p>E17 gives me the feeling that this is where user interfaces will end up - it
automates so many of the things that makes it quicker to do anything. However,
it still lacks some of the &ldquo;basics&rdquo;.</p>
<p>E17 is a very good example of a UI that tries to conform to what I call the
&ldquo;<a href="https://icle.es/2008/12/12/invisible-interface/" title="Invisible Interface">Invisible Interface</a>&rdquo;
which I will be writing about later.</p>
<p>To bring it all back to now, I found it a hassle to go through all the available
themes for WordPress for the Company Blog as well as my own.</p>
<p>I used to take great pleasure in going through dozens or hundreds of themes and
picking ones that I liked but after doing it a few times (for Firefox,
Thunderbird, my phone, GNOME, GDM and my flat), it gets a bit repetitous.</p>
<p>Now, for a wish. A website that pulls in all the different themes for all over
the world for everything. A one-stop-theme shop. Here, I could go through and
pick a general theme that I liked and download it for all the applications, my
phone(s), mp3 players (and of course, taking it to the next level, all the
gadgets at my flat).</p>
<p>That gives my life more uniformity. Perhaps this is something that Designers
could take on&hellip; Say Hugo Boss, and design something that even matches your
clothes, shoes, hair - everything.</p>
<p>That way, you could have your own unique branding&hellip; and while you are at it
link it into Gravatars and you are also instantly recognisable</p>
<p>Now for the issue of privacy - I think I best leave that for another day.</p>
]]></content:encoded></item></channel></rss>