Blog Archives

Optional Parameters another way.

I’ve always liked the way that in C++ and other languages you can have optional parameters and I’ve been messing around with ways to do it in JAVA, so I came up with a class that extends the HashMap and makes it quite a neat way of having optional parameters in code.

Here’s the class

package utilclasses;
import java.util.HashMap;
 * Another fine Java Class
 * @author paulc
public final class optional extends HashMap {
 optional(Object... objects) {
 public void put(Object... objects) {
 for (int i=0;i<objects.length;i=i+2) {
 Object key=objects[i];
 Object value=objects[i+1];


As you can see it has one routine called put that is called in the constructor that constructs the hash map, so it’s use in your code is pretty simple.

 opt(new optional("Name","John","Age",34,"Address","test"));
 private static void opt(optional y) {

Which produces the result:-


Note that the last result is null because optional parameter 22 has not been set.  Note however this will only work with Java 8. I’ve actually used their optional solution to create mine! Only that I really like the idea of just filling out key values so you can see in your code the variables.


Tungsten Replicator setting up and Gotchas

Tungsten Replicator site Clicky

So we have a big MYSQL server with mission critical data on it.

I want to replicate it accross to another MYSQL database, they are both ubuntu servers with Percona MYSQL database.

1. Preparation

Master – Install RUBY, JAVA,

Slave – Install RUBY, JAVA

edit the hosts files on both machines in etc/hosts and add the other servers in each one and reference the IP address – just makes things easier.

2. SSH

Make sure you set up SSH so that you can ssh from one server to the other WITHOUT using passwords.


make sure all ports required 10000,10001 are available (particularly problematical PLESK, WEBMIN a whole host of things like these ports) on all machines. One server actually had a PLESK tool on it even though plesk was not installed!!


make sure everything is set up and restore a backup of the database before you start.

5. Helper scripts

Set up your tungsten. You’ll need to edit to make sure your nodes are correct and USER_CONFIG as per the tungsten documentation. – put in the tungsten folder e.g. tungsten-replicator-2.1.0-343

VERBOSE=1 ./cookbook/install_master_slave ./cookbook/ (actually I renamed this to tungsten and did a chmod +x tungsten)

if [ "$1" == "help" ] || [ "$1" == "" ]; then
 echo "Commands"
 ls installs/cookbook/tungsten/tungsten-replicator/bin/
installs/cookbook/tungsten/tungsten-replicator/bin/$1 $2 $3 $4 $5

So you can type

./tungsten replicator status

To run commands.

Netbeans/Glassfish = Community

Very interestingly one of the things that the Sun folks asked at on the Second Life Meeting on Thursday night was what would make people come along? (it was packed out as it was).

Someone said “more free stuff”.

I then pointed out that actually, we get so much for free we need to be thinking about giving to the community not taking it.

For Free from Sun Microsystems and the Community

– Netbeans – FULL Java IDE that supports doing just about anything you want to do with a computer

– Glassfish – The most AWESOME application server ever

– The Java database tool – Even has its own small database system

– MYSQL (industry standard database) – Sun Microsystems are doing this.

– Updates and Support for Free

You try buying that lot from Mr Gates ad you will be spending a LOT of money. (£4000 for an enterprise version of .net for one developer with MSDE membership).

So here’s a call – to those who are learning and starting out – lets build community – join Second Life and come visit the Sun Microsystems islands where you can get involved with the Java Developers Group.

Promote Netbeans and Java within your own developer community (once you’ve got into it you will be doing it!).

Perhaps start a blog.

Oh and by the way don’t forget that Netbeans and Glassfish don’t just run on windows – you can get an UBUNTU linux box going in about an hour (if everything goes ok) and have a full office compatible system with a development environment and industry class SQL server (MYSQL) for free.

I have to say the folks at Sun Microsystems have been amazing as my company has been exploring the Java platform.

Good job guys. Onwards and Upwards