Redundant bonding of wireless and wired interfaces in Ubuntu.

Recently while attending a networking course which covered redundant multipathing for high availability systems I got to thinking – could this be applied to my wired / wireless network at home? The end result being that removing the wired network from my laptop by unplugging the cable would instantly fail over to my wireless connection. I’m sure many people are thinking “but gnome network manager already does that” well, not quite.

With redundant bonding or multi-pathing both interfaces are connected to the same network and put into a special group. These interfaces are constantly connected to the network and are ready to work, however only one of them is active at any one time. Should the active interface fail (such as a network cable being removed) the mac address, ip address and all other configuration is almost instantly assigned to one of the other available network interfaces. This allows you to continue working as if nothing had happened, songs playing from network shares will continue playing, instant messenger conversations will continue to work, downloads will not be interrupted… the list goes on.

It turns out that under Linux this works incredibly well, read on for details.

Requirements.

In terms of networking you must have your wired and wireless networks on the same physical network segment, in this post I am also assuming that your wireless network is setup and that you have knowledge of networking.
As for packages you will need to install the ifenslave package under ubuntu.

# apt-get install ifenslave-2.6

Step One.

Warning: if you follow the steps I’ve included here, reboot and anything goes wrong, I accept no responsibility – thanks.

Under Linux high availability and link aggregation is handled by the bonding module, this can be enabled by adding the following line to your /etc/modules configuration file.

bonding mode=1 miimon=100 downdelay=200 updelay=200

This will load the bonding module upon next boot, however, it can be loaded at any time using the modprobe command the options are as follows.

  • mode=1 – This enables the active backup mode, this will provide link level redundancy but it does not allow for any kind of link aggregation.
  • miimon=100 – This enables link level monitoring of the connection (the default value is 0 – which disables link monitoring). The value passed is the frequency in milliseconds that the link is checked. Link level monitoring only takes into account the physical connection, not if the network is correctly configured or not.
  • downdelay=200 – This is the delay in milliseconds before the link is marked as failed, it must be a multiple of miimon
  • updelay=200 – This is the delay in milliseconds before the link is marked as active, it must be a multiple of miimon

Step Two.

Next the bonding interface (bond0) must be configured, this can be done in the /etc/network/interfaces file an entry such as this needs to be added:

auto bond0
iface bond0 inet static
address 192.168.1.34
netmask 255.255.255.0
gateway 192.168.1.24
broadcast 192.168.1.255
post-up ifenslave bond0 eth0 eth1
post-up echo “eth1″ > /sys/class/net/bond0/bonding/primary
pre-down ifenslave -d bond0 eth0 eth1

The network address, netmask, gateway and broadcast should be configured for your network. This is the one single address that your machine will be known as, assuming that one of the connections to your laptop is available. You should be able to use dhcp to configure this interface, however I have chosen a static address.

  • ‘post-up ifenslave bond0 eth0 eth1′ – This line assigns my wired (eth1) and wireless (eth0) interfaces into my failover group bond0. You should replace these with the interfaces you want to use.
  • ‘post-up echo “eth1″ > /sys/class/net/bond0/bonding/primary’ – This line specifies a primary slave, that is if this interface is available it will always be used in preference to the others. In this case eth1 is my wired interface, this ensures that when I return to my desk and plug my network cable back in I will be using the faster ethernet network and not my slower wireless.
  • ‘pre-down ifenslave -d bond0 eth0 eth1′ – This line removes the eth0 and eth1 interfaces from the bond group when networking is stopped.

Step Three.

Now reboot for the settings to take effect. It is of course possible to do all of this without rebooting, one would simply perform the following steps:

  1. modprobe the bonding driver
  2. ifconfig the bonding interface
  3. add the default route for the bonding interface
  4. ifenslave the network devices
  5. set the primary bonding interface

To Test that everything is working simply ping a host on your local network then once its going unplug the wired interface it should fail over to the wireless interface without dropping any packets. You can then re-insert the network cable and instantly switch back to the wired interface.
Help, its not working.

I had a few problems getting this working, firstly ifenslave would assign the bonding interface the mac address of my wired interface. As part of my wireless network security I have mac filtering enabled, however, only the mac address of the wireless card was allowed. Adding the mac of the bonding interface to my mac filter list cleared up that problem.

My other problem involved gnome network applet, I believe that this process is called nm-monitor. This would attempt to reconfigure my wireless network or wired network whenever I removed the network cable to my laptop. This appeared to prevent the failover from working as quickly as it should have. killing off the nm-monitor fixed this little issue.

I’ve now been using this for roughly two weeks without any issues, being able to unplug my laptop and take it to another room of the house without having to even consider whats going to happen to my network has been a real step forward.

Posted in hardware, Linux, networking | 2 Comments

When Good Hard Drives Go Bad

Picture the scene, you return to your system and casually attempt to create a new file on one of your disks. Permission Denied. What?

  1. Check you’re logged in as the correct user – check
  2. Check that the user has write permissions – check

Following this you start to get a sinking feeling, something is not right. In fact, something is very wrong but you don’t know what that is just yet. Although, the situation feels vaguely farmilar. Without recalling why you decide to check if the partition you’re attempting to write to has been mounted read only. It has, your mind races and you check /var/log/messages for the worst.

ide: failed opcode was: unknown
end_request: I/O error, dev hdd, sector 61866003
Buffer I/O error on device hdd1, logical block 30933001
hdd: dma_intr: status=0×51 { DriveReady SeekComplete Error }
hdd: dma_intr: error=0×40 { UncorrectableError }, LBAsec= 63963157, high=3, low=1460081, sector=65011733

And now you realise why this felt so familiar, its because the same thing has happened to one of your disks at the beginning of summer three years in a row. You really should have made backups by now.

I’m sorry to say that this is a true story, three different branded disks in different systems in different houses all in different conditions. The only common factor is that these disks all ran 24/7 and were used as a ‘media repository’. Having been in this situation before I would like to share my experiences of simple disk recovery under Linux.
Step One.

Unmount the faulty disk (stop reading this, do it now). Forget about reading from it, forget writing to it and whatever happens do not fsck the faulty disk. Running fsck against a disk with physical errors will only make the problem worse. I recommend that you disconnect the disk and store it somewhere safe.
Step Two.

Buy/locate/steal/borrow a replacement disk, as you’re going to need somewhere to copy your data to. You should then connect both disks, you new disk and the faulty disk to your system. If possible try to get them on separate IDE buses, I’ve had one disk fail which created IDE bus resets when reading from it. This had a negative effect on all disks on the same IDE bus (including the good disk I was copying to). Format your new disk and check that its working, do not store anything important on it just yet as it will be overwritten.

It should also be noted that if you have a disk or array which is already in-use but has enough free space available, then you can write an image of your damaged disk to this space. The disk image can then be fscked and mounted via a loop back mount. The exact details of this method are not covered here but it should be easy to adjust the methods described here.
Step 3.

Install GNU DD Rescue onto your system ( http://www.gnu.org/software/ddrescue/ddrescue.html ) the package name under Debian / ‘bunty (Ubuntu) is gddrescue. This is possibly one of the most useful data recovery tools I’ve used. It is dd designed with data recovery in mind, it will allow you to read directly from the disk ignoring any errors which may exist in the file system. The website lists its most important features but most importantly to us its very easy to use and fully automatic. Once you’ve read the manual page for dd rescue its time to start on recovering your data.
Step 4.

Make sure that both your old faulty disk and your new disk are unmounted, once that is done invoke dd rescue.

# ddrescue /dev/hdd1 /dev/hdc1 /logfile

In this example, /dev/hdd1 is my old faulty disk (the source) and /dev/hdc1 is my new disk (the target) the /logfile will create a log file which dd rescue can use to resume its recovery should you need to stop it for any reason. This will take some time so sit back and wait, the output from dd rescue is very clear. It will keep you informed as to how much data it has copied, how much is unreadable and how many errors have occoured.

For my most recent disk failure on a 250 Gigabyte drive ddrescue was able to read all but ~2 Megabytes of data. Which is really quite fantastic when you consider that with the faulty disk mounted read only I was unable to copy any files without producing hundreds of errors.
Step 5.

The moment of truth, dd rescue has read all it can read and now its time to fsck the new disk.

# fsck -C /dev/hdc1

This will run fsck with a handy progress bar, If you’re very lucky fsck will complete without complaining and you have successfully rescued all of your data. If you’re not so lucky (as I have been this time) you may have suffered some fairly nasty file system corruption, fsck will go through asking you if you would like to fix the errors. You should make a note of which files have gone and let fsck do its thing, there may be better ways to handle this, if there are I would love to hear them. If you have only suffered damage to the file system structure and your actual data files are okay then you will end up with a load of files in the lost+found directory. Simply put these are files which exist on disk but no longer have a file name (and other things) associated with them, so fsck will move them into the lost+found directory.
Step 6.

Thats it really, you should have most or all of your data back, unless you’ve been really unlucky. Now is the time to create a backup plan, do it now while the fear is still in you. Otherwise six months down the line you’ll be thinking to yourself, “nahh disk failure wont happen to me (again)”.
It should be noted that there are variations on this method, if anyone knows of any better ways to handle a failed disk please let me know, I’d love to know if there are any steps or tools I’ve missed out upon.

Posted in hardware, Linux | 1 Comment

Tarte Aux Iain

Introduction

Its Sunday afternoon here in Paris, I’m feeling what could be described as boredom mixed with hunger, boreger no hungdom maybe. When I feel like this it is often time to cook something. As it is Sunday, the shops are mainly closed so I will have to get creative with what I have in the fridge.

I may subconsciously plan for afternoons like these as I appear to have all of the ingredients to make “Tarte aux Iain” or “Iain’s Tarte”. If you wish to make Tarte aux Iain you need the following ingredients:

Ingredients

tarte-ingredients

  • 2 x Oeufs De Poules (Eggs of a Chicken)
  • 1 x Pate Brisee (Short Crust Pastry)
  • 3 x Champignon de Paris (Button Mushrooms)
  • 1 x Lait (Deme-ecreme UHT) (Semi Skimmed UHT Milk)
  • 1 x Emmental Rape Fromage (Emmental Ripe Cheese (grated))
  • 1 x Creme Fraiche (Creme Fraiche)
  • 1 x Lardons de Nature (Little bits of bacon chopped into cubes)
  • 1 x Pivoron Vert (Green Pepper)
  • Pepper, Herbs & Garlic

This serves roughly 2 – 4 people depending on the size and appetite of the people.

Of course, you don’t actually need all of these to make your own Tarte (Tarte Aux Vous). The base ingredients are the eggs, pastry, milk, cheese and creme fraiche. As for everything else, I recommend you include whatever you can find in your fridge.
Through mis-communication I have made tarte using Natural Yogurt instead of Creme Fraiche, it was an interesting experiment but not one that I would recommend you repeat. It should also be noted that you can use non UHT milk.

Utensils

  • 1 x Frying Pan
  • 1 x Baking Tray
  • 1 x Tiny French Electric Oven with built in hobs.
  • 1 x Mixing Bowl (not pictured)
  • 1 x Whisk (not pictured)

The tiny electric oven can be replaced with a larger standard oven if a tiny French electric oven is not available. Of course this detracts from the authenticity of the Tarte. The Oven should be pre-heated to roughly 220 Degrees oC.

tarte-oven-pan-tray-oil.jpg

The Oil

In the above picture you can see my oil, its called “4 Huiles” or “4 Oils” in English, it is advertised
to have the following four properties.

Forme – Fitness and Health
Equilibre – Balance, Equilibrium
Bien-Etre – Well-Being
Plaisir – Pleasure

If only the oil in England had these properties we would all be much healthier, balanced and pleasured. From that list I think it should be obvious why I have chosen the 4 oils, you can of course use whatever type of oil is available (I’d actually recommend a nice olive oil if you have one available). The oil is to be used when frying the ingredients later on.

Vegetable / Meat Preparation

All of the vegetables and meat that you plan to put in your Tarte should be chopped in into small cubes. As my Lardons Au Nature come pre chopped I wont need to chop those. The Vegetables should look something like this when you’re finished with them.

tarte-chopped.jpg

The Tarte Mixture

This is relatively simple to create, you are aiming to create a liquid which has just moved from being thick to one which is runny. As I’ve never made this using measurements you will just have to do this by eye.

Step one, crack two eggs into the mixing bowl and add your creme fraiche. I put in roughly two and a half mounded dessert (large) spoon fulls into the mixture here.

tarte-eggs_creme_bowl.jpg

Step two, add the milk, again how much is to be done by eye. Remember that you need to fill your baking tray with enough of this mixture that it just covers your chopped meat and vegetables. You can add some pepper and seasoning here to taste if you wish.

tarte-eggs_creme_milk_bowl.jpg

Step Three, Whisk it all up! There should be no lumps of creme fraiche or egg when you are finished just a white runny mixture.

tarte-mixed-bowl.jpg

Cook The Vegetables and Meat.

All of the ingredients should be pre-cooked before you put them in to your tarte, I find it easiest to fry everything (making use of my 4 oils) until they’re done. If you like you can also throw in some pepper and herbs here, I believe I also put some chopped garlic into
this tarte.
garlic_pepper

lardons_vegies_pan

Preparing The Tray

Step One, Line your tray with something to stop it from sticking, I have used butter but you could also use grease proof paper. Now take your round short crust pastry and attempt to put it into a rectangular pan (not as easy as you might think). Finally prick the pastry all over with a fork.

pastry_and_dish

Step Two, Put your vegetable and meat mixture into the tray, spread it as evenly as possible throughout the tray.

pastry_and_stuff

Step Three, Pour your tarte mixture that you pre paired earlier into the tray.

pastry_stuff_milk

Step Four, Cover everything in the tray with massive amounts of grated cheese, once this is done your tarte should be ready for the tiny electric oven.

ready_for_oven

The End Product

You should put the tarte in the pre-heated oven for roughly 40 minutes, Generally you can judge when the tarte is ready by the colour of the cheese on the top. If its gone golden brown all over then the tarte should be ready.

Your end product might look something like this, although this picture does not do it justice.
end_product_tarte

The tarte can be eaten hot or cold, it works well with salad and boiled new potatoes. Enjoy!

Posted in Cooking, France, nontech | Leave a comment

Fifty Things an Englishman may learn about Paris (or France)

After living in Paris for over six months there are many new things that I have had to learn. The language being only the most obvious but there are far more interesting oddities which slowly expose themselves to you over time. The author Stephen Clarke has written several fantastic books on this subject which I highly recommend. All of the points in this list are related to something I have experienced while living here, its far from a definitive guide but its at least a start. With that being said, onto the list which is in no particular order.

  1. Traffic Lights are merely a suggestion
  2. Pointing at drivers is an effective way to make them stop
  3. Queuing is for people who have time to waste
  4. An Englishman should learn French
  5. Speaking bad French is worse than speaking English
  6. Bribery is the most effective way to get things done
  7. Shrugging is a highly effective form of communication
  8. Being on time for a (work) meeting is like turning up to a party two hours early
  9. Meetings are not for working, they are a chance to see your friends
  10. Deadlines, schedules and time have no bearing on anything – ever
  11. 9am often means 2pm or 2:45pm if it was a nice lunch
  12. The first hour of the day is devoted purely to greeting everyone in the office
  13. The third hour is devoted to a coffee break
  14. A good lunch should last until 3:30pm
  15. Public transport in Paris is outstanding if not a little crowded
  16. The metro is practically free
  17. Going outside Paris by public transport is an ill founded idea
  18. Alcohol in supermarkets costs very little
  19. You may need a small loan to buy a round of drinks in a Pub
  20. Everyone must go on holiday at the same time
  21. Street markets are fantastic, though a little off putting at first
  22. After eating a ‘well done’ steak you should still be able to mop the blood up on your plate with some bread
  23. A rare steak is cold (read: raw) on the inside with the outside lightly seared
  24. Steak Tartare is available in all restaurants which serve burgers
  25. If someone on the street randomly asks you if you speak English say ‘non’
  26. ‘Quick’ is not a French fast food restaurant, its Belgian, the French do not have ANY fast food restaurants
  27. Nearly all McDonald’s restaurants in Paris have free wifi internet access
  28. The Belgians are to the French what the Welsh are to the English
  29. The only good Belgian film is ‘Man Bites Dog’
  30. Indian food in France is generally not spicy
  31. Walk 500m in any direction and you will end up next to a metro station
  32. Beware of tourists for they travel in packs
  33. The Montparnasse Tower and the Effiel Tower can be used as navigation beacons when the metro has closed and you are very drunk.
  34. You are unlikely to witness a single act of physical violence while in Paris
  35. Most English kitchens are large, so large in fact they have an entire room devoted to them.
  36. The inefficiency of business is a point of national pride
  37. Legal contracts in France are incredibly complex
  38. Train doors may open before the train has stopped
  39. It is very easy to wonder onto a construction site in the middle of the street
  40. Construction workers appear to follow no safety rules at all
  41. Dogs crap everywhere
  42. There is an army of men in green who wash away the dog turds
  43. Most French over-the-counter drugs are double the strength of the English name brand equivalent
  44. Christmas decorations often last until February
  45. There is very little Christmas music in shops
  46. French popular music is beyond awful (Diams must be forced never to produce any more music)
  47. Real books do not feature cover illustrations
  48. Not topping up your mobile phone results in you losing your number
  49. Just because you have been seated in a restaurant does not mean you will get served.
  50. Waiters are not referred to as ‘Garçon’

Maybe some more another time…

Posted in France, nontech | Leave a comment

Console gaming on a remote X display

I have recently ended up in a situation where creating something like this (see diagram) would allow me to play my Game Cube on my laptop display before I finalise my purchase of a nice new LCD display for my desktop system.
Game Cube -> Tv Card -> Linux Box (no display) -> 100Base-t Network -> Laptop (with display)

gamecube-to-laptop

Playing a console game over a remote X display is slightly more challenging than simply watching TV. With TV you can capture your video and audio input, compress it, send it over the network in a nice format and decompress it at the other end. Sure, you’ll be watching TV that is maybe one second to a minute behind whats actually being broadcast but its in sync and it looks good. If you’re attempting to play a game in a similar fashion even 500ms (1/2 a second) delay would make most console games totally un-playable, with this in mind I set about console gaming over remote X with ssh.
It should be noted that:

  1. While attempting this I had no access to the internet, just to whatever documentation came with my debian / ubuntu installs
  2. My desktop runs debian testing and my laptop runs ubuntu edgy eft
  3. If you just want the solution, skip down to Attempt 4.

Attempt 1 – tvtime

Usually when playing Game Cube on a local display attached to my desktop I use a fantastic application called tvtime, To run this I SSH’ed from my laptop to my desktop with X display forwarding and compression enabled:

iain@laptop ~> ssh -X -C -o CompressionLevel=9 desktop

iain@desktop ~> tvtime

Unfortunately for me tvtime does not appear to work via X display forwarding, it appears to be looking for an xvideo port to connect to and fails upon startup, most likely tvtime was not designed for this.

Attempt 2 – xawtv

Xawtv is a tried and tested linux tv viewing tool, its almost

guaranteed to work and it did:

iain@laptop ~> ssh -X -C -o CompressionLevel=9 desktop

iain@desktop ~> xawtv -remote

<meta content="StarOffice 7 (Solaris Sparc)" name="GENERATOR" /><meta content="20061124;15040900" name="CREATED" /><meta content="16010101;0" name="CHANGED" />After re-sizing xawtv to a fairly tiny window of roughly 320x240px the output was in real time, with practically no<br /> <style>!-- @page { size: 8.27in 11.69in; margin: 0.79in } P { margin-bottom: 0.08in } --></style> <p><span lang="en-GB"> perceivable</span> delay. Next I attempted to set xawtv to full screen, a big mistake. It upped the resolution of the tv window to 1024x768 (the resolution of my laptop display) and attempted to pipe all 786432 pixels per frame uncompressed across the network in real time, nice. The end result being a slide-show about 5 seconds behind real time, completely unplayable.</p> <p><strong>Attempt 3 - ffmpeg, mplayer, pipes & a network (madness)<br /> </strong></p> <p>After the failure of xawtv I had determined that the bottleneck was the network. I could see from my network / cpu utilisation graphs that the cpu was hardly getting used and the network was pegged at 100% usage. This made me think of compressing the video "on the fly" and then sending it over the network to my laptop - due to the latency involved in encoding this was not my greatest idea but getting it to work was an interesting experiment.</p> <p>It was obvious that I needed to keep the latency as low as possible, this meant getting as few components in my encoding -> network -> decoding chain as possible. After the reading of some man pages I realised that <a href="http://ffmpeg.mplayerhq.hu/">ffmpeg</a> and <a href="http://www.mplayerhq.hu/">mplayer</a> could encode and play from standard input / output, this sent the unix geek in me a little bit crazy. Even though the sane voice in my head was saying "this is stupid, its never going to work as you want it" but the unix geek in me simply retorted with "but wouldn't it be cool if it worked!". In the end unix geek won, it was a sad moment for my sanity.</p> <p>Some time and many many command line arguments later, it was working. By using ssh keys to avoid any input on my part I had managed to redirect the standard output of a remote ffmpeg command over ssh and into the standard input of mplayer, the command looks something like this...</p> <blockquote><p>iain@laptop ~> ssh desktop "/home/iain/src/ffmpeg-0.4.9-pre1/ffmpeg -vd /dev/video0 -an -f mpeg1video -aspect 4:3 -tvstd pal - 2> /dev/null" | mplayer -</p></blockquote> <p><meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE" /><title /><meta content="StarOffice 7 (Solaris Sparc)" name="GENERATOR" /><meta content="20061124;15040900" name="CREATED" /><meta content="16010101;0" name="CHANGED" />Now, be warned this does actually work (as it should, of course) infact for standard tv this works really well, although its probably easier for one to use the ffserver tool which is bundled with ffmpeg (I did'nt for a number of reasons which I wont go into now). For playing games, it still does'nt work, there's a constant 1/2 second or so delay. I assume this is how much ffmpeg needs in its buffer to encode the stream before sending it. I attempted a number of different codecs and resolutions; an mpeg2 transport stream at a dvd like resolution looks<br /> <style> <!-- @page { size: 8.27in 11.69in; margin: 0.79in } P { margin-bottom: 0.08in } --</style> <p>particularly lovely but still suffers from the same delay.</p> <p><strong>Attempt 4 - mplayer, or what should really have been Attempt 3</strong></p> <p>After reading the <a href="http://www.mplayerhq.hu/">mplayer</a> manual (the parts useful to me anyway) I noticed that mplayer could play from <a href="http://www.linuxtv.org/">v4l2 (video for linux)</a> devices. Hoping that it would employ a more intelligent technique than xawtv when displaying in full screen mode I set about configuring mplayer. It is fairly easy to configure and work with once you've found the relevant options, I opted to put the options in a config file (usually located in ~/.mplayer/config) instead of typing them each time I wanted to use a v4l device. The entry in the config file looks something like this:</p> <blockquote><p>tv=driver=v4l2:input=2:width=256:height=192:device=/dev/video0:normid=1:noaudio=1:fps=30</p></blockquote> <p>As you can see, that's going to play at a fairly small resolution (256x192) and limit the fps to 30 with no audio. The steps to run this are fairly similar to xawtv:</p> <blockquote><p>iain@laptop ~> ssh -X -C -o CompressionLevel=9 desktop</p> <p>iain@desktop ~> mplayer tv://</p></blockquote> <p>After mplayer had started and expecting the worst I tapped 'f' to put mplayer into full screen mode. Shockingly it worked, some how mplayer appears to get the remote x server to stretch the image to full screen size, keeping the source resolution fixed. This method works really well, I played about with some higher resolutions but the delay increased too much, 256x192 appears to be a happy medium. After several hours of gaming I'm happy to say that it is possible to play console games on a remote X display</p> </div><!-- .entry-content --> <div class="entry-utility"> <span class="cat-links"> <span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> <a href="http://blog.buttermountain.co.uk/category/hacks/" title="View all posts in hacks" rel="category tag">hacks</a>, <a href="http://blog.buttermountain.co.uk/category/linux/" title="View all posts in Linux" rel="category tag">Linux</a>, <a href="http://blog.buttermountain.co.uk/category/v4l/" title="View all posts in v4l" rel="category tag">v4l</a> </span> <span class="meta-sep">|</span> <span class="comments-link"><a href="http://blog.buttermountain.co.uk/2006/11/24/console-gaming-on-a-remote-x-display/#comments" title="Comment on Console gaming on a remote X display">1 Comment</a></span> </div><!-- .entry-utility --> </div><!-- #post-## --> <div id="post-10" class="post-10 post type-post status-publish format-standard hentry category-france category-nontech"> <h2 class="entry-title"><a href="http://blog.buttermountain.co.uk/2006/11/13/disabled-parking/" title="Permalink to Disabled Parking" rel="bookmark">Disabled Parking</a></h2> <div class="entry-meta"> <span class="meta-prep meta-prep-author">Posted on</span> <a href="http://blog.buttermountain.co.uk/2006/11/13/disabled-parking/" title="3:16 pm" rel="bookmark"><span class="entry-date">November 13, 2006</span></a> <span class="meta-sep">by</span> <span class="author vcard"><a class="url fn n" href="http://blog.buttermountain.co.uk/author/admin/" title="View all posts by iain">iain</a></span> </div><!-- .entry-meta --> <div class="entry-content"> <p>In France it is wise not to break the law and park in spaces which are reserved for the disabled. Unlike in England where someone may simply park in the disabled parking space and hope that they will not get fined.</p> <p>These clever people appear to have avoided breaking the law but some how missed the point.</p> <p>Note: all the cars in this picture have been parked in the same position overnight, the picture was taken at about 2pm</p> <p><a class="imagelink" title="disabled-parking.jpg" href="http://blog.buttermountain.co.uk/wp-content/uploads/2006/11/disabled_parking.jpg"> </a> <a class="imagelink" title="disabled-parking.jpg" href="http://blog.buttermountain.co.uk/wp-content/uploads/2006/11/disabled_parking.jpg" /></p> <div style="text-align: center"><a class="imagelink" title="disabled-parking.jpg" href="http://blog.buttermountain.co.uk/wp-content/uploads/2006/11/disabled_parking.jpg"><img width="449" height="560" id="image9" alt="disabled-parking.jpg" src="http://blog.buttermountain.co.uk/wp-content/uploads/2006/11/disabled_parking.jpg" /></a></div> </div><!-- .entry-content --> <div class="entry-utility"> <span class="cat-links"> <span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> <a href="http://blog.buttermountain.co.uk/category/france/" title="View all posts in France" rel="category tag">France</a>, <a href="http://blog.buttermountain.co.uk/category/nontech/" title="View all posts in nontech" rel="category tag">nontech</a> </span> <span class="meta-sep">|</span> <span class="comments-link"><a href="http://blog.buttermountain.co.uk/2006/11/13/disabled-parking/#respond" title="Comment on Disabled Parking">Leave a comment</a></span> </div><!-- .entry-utility --> </div><!-- #post-## --> <div id="post-8" class="post-8 post type-post status-publish format-standard hentry category-apache category-code category-xml-rpc"> <h2 class="entry-title"><a href="http://blog.buttermountain.co.uk/2006/11/06/accessing-persistent-objects-with-apache-ws-xmlrpc-30-a-documented-example/" title="Permalink to Accessing Persistent Objects with Apache ws-xmlrpc 3.0 – A Documented Example" rel="bookmark">Accessing Persistent Objects with Apache ws-xmlrpc 3.0 – A Documented Example</a></h2> <div class="entry-meta"> <span class="meta-prep meta-prep-author">Posted on</span> <a href="http://blog.buttermountain.co.uk/2006/11/06/accessing-persistent-objects-with-apache-ws-xmlrpc-30-a-documented-example/" title="11:28 am" rel="bookmark"><span class="entry-date">November 6, 2006</span></a> <span class="meta-sep">by</span> <span class="author vcard"><a class="url fn n" href="http://blog.buttermountain.co.uk/author/admin/" title="View all posts by iain">iain</a></span> </div><!-- .entry-meta --> <div class="entry-content"> <p><strong>Introduction</strong></p> <p>A common use case for an xml-rpc based application server would be one which involves the use of one or more persistent objects. Without any kind of persistence a server handling xml-rpc requests will either be ineffective or inefficient.</p> <p>Accessing Persistent objects in an exposed method/user handler with Apache xml-rpc 3.0 is a process involving several layers of redirection. This can be difficult for anyone who is not familiar with the ws-xmlrpc 3.0 code base. The purpose of this document is to provide a working example using the standalone servlet server which can assist people new to ws-xmlrpc 3.0.</p> <p><strong>Before We Begin</strong></p> <p>For those of you who are just interested in the source code to this example, that can be found here: <a id="p7" href="http://blog.buttermountain.co.uk/wp-content/uploads/2006/11/ws-xmlrpc-30-buttermountain-example.zip">ws-xmlrpc-3.0-buttermountain-example.zip</a></p> <p>This document and the code has been created with the help of the ws-xmlrpc FAQ examples and the help of the Apache ws-xmlrpc mailing list.</p> <p>It is assume that you have read the examples on the Apache ws-xmlrpc website and are familiar with the Java programming language.</p> <p>Finally, I recommend that you open up the source code and read through the sample code with this document.</p> <p><strong>In The Beginning There Was Nothing</strong></p> <p>Before you even begin starting to write your handler methods (the methods which will be exposed via xml-rpc), you must first collect the required libraries and setup the correct directory structure. The directory structure I have opted for looks something like this:</p> <p>org/buttermountain/xmlrpc/server<br /> org/buttermountain/xmlrpc/client<br /> org/buttermountain/pobject<br /> javax<br /> lib</p> <p>The javax directory contains all of the Sun servlet classes and the lib directory contains all of the Apache ws-xmlrpc 3.0 jar’s and the Apache ws jar’s that they depend upon.</p> <p>As for the other directories, xmlrpc/server contains all of our server files, xmlrpc/client contains a sample java ws-xmlrpc client. Finally, the pobject directory contains our very simple persistent object class.</p> <p><strong>User Handler Methods</strong></p> <p>When creating an xml-rpc server you will need to create a class which has its methods exposed via xml-rpc. With Apache ws-xmlrpc 3.0 this is done by creating two classes, one which is your interface (ExposedMethodsInterface.java) and one which is the implementation of this interface (ExposedMethodsImplementation.java).</p> <p>The interface will merely define the methods, their inputs and return data types. For a method to be exposed via xml-rpc it must be public and have a return type that is not void, here is the example interface code</p> <p>public interface ExposedMethodsInterface {<br /> public void init(Pobject pobject);<br /> public boolean setString(String string);<br /> public String getString();<br /> }</p> <p>Three methods have been defined, firstly the init() method is a non exposed method which we will call from one of our extended classes to pass our persistent object in (much more on this later). The ‘get and set’ methods are public and will be exposed via xml-rpc, hopefully you can imagine what is going on in the underlying implementation, if not take a look at the ‘ExposedMethodsImplementation.java’<br /> file provided in the example code.</p> <p><strong>A Sample Persistent Object</strong></p> <p>The persistent object for this example is incredibly simple, it exists solely to keep this example simple. The code is so short that I will include it here:</p> <p>public class Pobject {<br /> private String storedString = “”;<br /> public synchronized void setString(String string){<br /> storedString = string;<br /> }<br /> public synchronized String getString(){<br /> return storedString;<br /> }<br /> }</p> <p>As you can see, all it does is store a string and then allows the programmer the ability to ‘get and set’ the string.</p> <p><strong>Here lies the problem</strong></p> <p>Someone who is not familiar with the ws-xmlrpc 3.0 tool-kit may be thinking:</p> <blockquote><p>“Why do I even need an object like this? surely something as simple as a string could be stored in my handler class?”</p></blockquote> <p>This is where the problem begins, the user handler classes are completely stateless, up-to the point that a new instance of the handler class is created to handle each individual xml-rpc request. After the request is completed the handler instance is disposed of – never to be used again.</p> <p><strong>A solution to the problem</strong></p> <p>To get around this problem, one can call methods of the handler class after it has been initialised and just before it handles an xml-rpc request. Once one has the required knowledge this is a relatively simple task. However, judging by my experience and messages on the Apache xml-rpc mailing list, there is some confusion regarding how one can do this.</p> <p>To access methods of the handler class in this way, three of the ws-xmlrpc classes must be extended and the correct methods within them must be overridden / extended. In the sample code there is another class which has been extended (AuthenticationHandler by BmAuthHandler.java) This includes another example from the ws-xmlrpc FAQ which explains how to enable basic HTTP authentication. I have left this in to provide a more complete example.</p> <p>The classes call each other in the following Hierarchy:</p> <p>ServletServer</p> <p>|____> XmlRpcServlet<br /> |____> RequestSpecificProcessorFactoryFactory<br /> |____> Can make calls to user handler methods.\</p> <p>We will be extending the XmlRpcServlet class and the RequestSpecificProcessorFactoryFactory class. It is within the XmlRpcServlet that your persistent objects will be initialised, it is within the RequestSpecificProcessorFactoryFactory class that you will make calls to your handler methods.</p> <p><strong>Your very own ‘ServletServer’</strong></p> <p>Making use of the ServletWebServer class is very simple and is the starting point of your standalone Apache ws-xmlrpc 3.0 server. The ServeletServer class merely initialises your servlet (in this case one that we have extended ourselves) and then starts up the servlet web server on the specified port. See the file:<br /> ‘org/buttermountain/xmlrpc/server/ServletServer.java’ for details.</p> <p><strong>Extending the XmlRpcServlet</strong></p> <p>The XmlRpcServlet is persistent, it is only initialised once (when using ServletServer, I have not tested this with anything else (such as TomCat)). This class is extended within ‘org/buttermountain/xmlrpc/server/BmXmlRpcServlet.java’. It is here that the example persistent<br /> object (Pobject) class is initialised:</p> <p>private Pobject pobject = new Pobject();</p> <p>Within BmXmlRpcServlet The methods ‘isAuthenticated’ and ‘XmlRpcHandlerMapping’ are used to handle basic HTML authentication, you may ignore those for the purposes of this example. The method that we are interested in is the newPropertyHandlerMapping method. Is is<br /> within this method that we initialise our next (and final) extended class the BmProcessorFactory which extends the RequestSpecificProcessorFactoryFactory class.</p> <p><strong>Extending the RequestSpecificProcessorFactoryFactory</strong></p> <p>The RequestSpecificProcessorFactoryFactory is an incredibly long variable name, my extended version of this class uses a much shortened name ‘BmProcessorFactory’ it can be found here ‘org/buttermountain/xmlrpc/server/BmProcessorFactory.java’. It is within this class<br /> that you can actually call methods on your handler class.</p> <p>I have implemented the ProcessorFactory in the following way, the initialisation method for this class takes in our persistent object from the XmlRpcServlet. The getRequestProcessor() method is then overridden, it is in this method that we make calls to our handler methods.</p> <p>If you remember the ExposedMethodsInterface class had a method called ‘init()’ which took an object of type Pobject. The implementation for this method looks like this:</p> <p>public void init(Pobject pobject){<br /> this.pobject = pobject;<br /> }</p> <p>The variable ‘pobject’ is declared in the main body of the class allowing it to be accessible from all of the methods. This method is called from the BmProcessorFactory in the following way:<br /> ExposedMethodsInterface proc = (ExposedMethodsInterface)<br /> super.getRequestProcessor(pClass, pRequest);<br /> proc.init(pobject);<br /> return proc;</p> <p>Finally in that one line ‘proc.init(pobject)’ you can pass the persistent object to your handler class. It would be here that you could call any other methods you may want to on your handler method, one thing you must make sure is that all of your handler classes implement an init() method in the same way. Any handler classes which do not will throw an XmlRpcException and refuse to work.</p> <p><strong>Pulling it all together</strong></p> <p>Before the xml-rpc server can be run you must create a mapping file, this file creates a mapping between exposed method names and method names local to java. The included file to handle this is called ‘XmlRpcServlet.properties’ and looks like this:</p> <p>ExposedMethodsInterface=org.buttermountain.xmlrpc.server.ExposedMethodsImplementation<br /> org.buttermountain.xmlrpc.server.ExposedMethodsInterface=org.buttermountain.xmlrpc.server.ExposedMethodsImplementation</p> <p>The default location of this file is ‘org/apache/xmlrpc/webserver/XmlRpcServlet.properties’, However, I have overridden this location in the newXmlRpcHandlerMapping method of our BmXmlRpcServlet class.</p> <p><strong>Starting the xmlrpc server</strong></p> <p>The source I’ve included has a file listing the relative classpath (./classpath) and another file listing all of the source files (./sourcefiles).</p> <p>Under Linux the following steps can be taken to compile and execute the code (assuming that java/javac are in your $PATH)</p> <p>user@host $ ~/xmlrpc-example> export CLASSPATH=`cat classpath`<br /> user@host $ ~/xmlrpc-example> javac @sourcefiles<br /> user@host $ ~/xmlrpc-example> java org/buttermountain/xmlrpc/server/ServletServer<br /> 04-Nov-2006 21:16:06 org.apache.xmlrpc.webserver.XmlRpcServlet log<br /> INFO: init</p> <p>If you’ve not changed anything the Apache ws-xmlrpc server should now be running on localhost port 5555</p> <p><strong>Testing the example server</strong></p> <p>To make things even easier I’ve included two clients, one written in Java (ProxyClient.java) which is code taken from the Apache ws-xmlrpc client FAQ and one written in Python. Both clients perform the same operations but set a different string. These two clients should prove to you that the xml-rpc server is working as intended.</p> <p>Under Linux (again) make sure you have started the server (as mentioned above), now in another terminal:</p> <p>user@host $ ~/xmlrpc-example> export CLASSPATH=`cat classpath`<br /> user@host $ ~/xmlrpc-example> python python_client/client.py<br /> The oldstring was: <<< note: the default string is ""<br /> setting string to: python xmlrpc client<br /> The string is now: python xmlrpc client</p> <p>user@host $ ~/xmlrpc-example> java org/buttermountain/xmlrpc/client/ProxyClient<br /> The oldstring was: python xmlrpc client<br /> setting string to: java xmlrpc client<br /> The string is now: java xmlrpc client</p> <p>Take a look at the source code of both those examples if you wish to see how they work in more detail, the output should look something like the above.</p> <p>Note: The client and server code should work under any operating system where Java & Apache ws-xmlrpc 3.0 are supported. The Python client should work under any operating system which supports Python.<br /> i.e the code should run on systems other than Linux.</p> <p><strong>Conclusion</strong></p> <p>I hope that this example will be useful to people attempting to use the Apache ws-xmlrpc 3.0 tools. If you have any questions / comments etc, please drop me an email.</p> <p>Thank you to the kind people of the Apache ws-xmlrpc mailing list who helped me get to a working solution and to the Apache ws-xmlrpc developers who have created a fantastic (although sometimes complicated) tool kit.</p> </div><!-- .entry-content --> <div class="entry-utility"> <span class="cat-links"> <span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> <a href="http://blog.buttermountain.co.uk/category/apache/" title="View all posts in Apache" rel="category tag">Apache</a>, <a href="http://blog.buttermountain.co.uk/category/code/" title="View all posts in code" rel="category tag">code</a>, <a href="http://blog.buttermountain.co.uk/category/xml-rpc/" title="View all posts in xml-rpc" rel="category tag">xml-rpc</a> </span> <span class="meta-sep">|</span> <span class="comments-link"><a href="http://blog.buttermountain.co.uk/2006/11/06/accessing-persistent-objects-with-apache-ws-xmlrpc-30-a-documented-example/#comments" title="Comment on Accessing Persistent Objects with Apache ws-xmlrpc 3.0 – A Documented Example">5 Comments</a></span> </div><!-- .entry-utility --> </div><!-- #post-## --> <div id="post-3" class="post-3 post type-post status-publish format-standard hentry category-junk"> <h2 class="entry-title"><a href="http://blog.buttermountain.co.uk/2006/09/01/welcome-to-the-butter-mountain/" title="Permalink to Welcome to the Butter Mountain" rel="bookmark">Welcome to the Butter Mountain</a></h2> <div class="entry-meta"> <span class="meta-prep meta-prep-author">Posted on</span> <a href="http://blog.buttermountain.co.uk/2006/09/01/welcome-to-the-butter-mountain/" title="3:15 pm" rel="bookmark"><span class="entry-date">September 1, 2006</span></a> <span class="meta-sep">by</span> <span class="author vcard"><a class="url fn n" href="http://blog.buttermountain.co.uk/author/admin/" title="View all posts by iain">iain</a></span> </div><!-- .entry-meta --> <div class="entry-content"> <p>As the title says, welcome! but I’m afraid that there’s not much here at the moment.</p> </div><!-- .entry-content --> <div class="entry-utility"> <span class="cat-links"> <span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> <a href="http://blog.buttermountain.co.uk/category/junk/" title="View all posts in junk" rel="category tag">junk</a> </span> <span class="meta-sep">|</span> <span class="comments-link"><a href="http://blog.buttermountain.co.uk/2006/09/01/welcome-to-the-butter-mountain/#respond" title="Comment on Welcome to the Butter Mountain">Leave a comment</a></span> </div><!-- .entry-utility --> </div><!-- #post-## --> <div id="nav-below" class="navigation"> <div class="nav-previous"></div> <div class="nav-next"><a href="http://blog.buttermountain.co.uk/" >Newer posts <span class="meta-nav">→</span></a></div> </div><!-- #nav-below --> </div><!-- #content --> </div><!-- #container --> <div id="primary" class="widget-area" role="complementary"> <ul class="xoxo"> <li id="search" class="widget-container widget_search"> <form role="search" method="get" id="searchform" action="http://blog.buttermountain.co.uk/" > <div><label class="screen-reader-text" for="s">Search for:</label> <input type="text" value="" name="s" id="s" /> <input type="submit" id="searchsubmit" value="Search" /> </div> </form> </li> <li id="archives" class="widget-container"> <h3 class="widget-title">Archives</h3> <ul> <li><a href='http://blog.buttermountain.co.uk/2008/10/' title='October 2008'>October 2008</a></li> <li><a href='http://blog.buttermountain.co.uk/2008/09/' title='September 2008'>September 2008</a></li> <li><a href='http://blog.buttermountain.co.uk/2008/05/' title='May 2008'>May 2008</a></li> <li><a href='http://blog.buttermountain.co.uk/2008/04/' title='April 2008'>April 2008</a></li> <li><a href='http://blog.buttermountain.co.uk/2008/03/' title='March 2008'>March 2008</a></li> <li><a href='http://blog.buttermountain.co.uk/2007/10/' title='October 2007'>October 2007</a></li> <li><a href='http://blog.buttermountain.co.uk/2007/09/' title='September 2007'>September 2007</a></li> <li><a href='http://blog.buttermountain.co.uk/2007/05/' title='May 2007'>May 2007</a></li> <li><a href='http://blog.buttermountain.co.uk/2007/03/' title='March 2007'>March 2007</a></li> <li><a href='http://blog.buttermountain.co.uk/2006/11/' title='November 2006'>November 2006</a></li> <li><a href='http://blog.buttermountain.co.uk/2006/09/' title='September 2006'>September 2006</a></li> </ul> </li> <li id="meta" class="widget-container"> <h3 class="widget-title">Meta</h3> <ul> <li><a href="http://blog.buttermountain.co.uk/wp-login.php">Log in</a></li> </ul> </li> </ul> </div><!-- #primary .widget-area --> </div><!-- #main --> <div id="footer" role="contentinfo"> <div id="colophon"> <div id="site-info"> <a href="http://blog.buttermountain.co.uk/" title="Butter Mountain" rel="home"> Butter Mountain </a> </div><!-- #site-info --> <div id="site-generator"> <a href="http://wordpress.org/" title="Semantic Personal Publishing Platform" rel="generator">Proudly powered by WordPress.</a> </div><!-- #site-generator --> </div><!-- #colophon --> </div><!-- #footer --> </div><!-- #wrapper --> </body> </html>