ConfusionableFuture in Java8

Code, Software - No Comments » - Posted on June, 9, 2015 at 2:19 am

We are making use of Java 8’s CompleteableFuture but I was getting very confused about what the difference between thenCompose, thenAccept and thenApply. Thankfully I work with smart people. Here is our discussion.

lw: It’s really simple…
thenCompose takes two promise actions and runs one after the other

readContentsFromAFile().thenCompose(contents -> doSomethingElse(contents))

would read the contents of a file then do something else, all async

me: where the `printContentsToScreen` returns a promise
lw: Yeah

lw: thenApply takes a promise action and a pure function and transforms the output of the promise using that function

readContentsFromAFile().thenApply(contents -> length(contents))

That makes a new promise action that reads the contents of a file and returns the length of it (notice there is only one promise action involved)

thenAccept takes a promise action and a non-promise procedure and runs the procedure non-async on the results e.g.

readContentsFromAFile().thenAccept(contents -> blockingPrintContentsToScreen(contents))

That makes a new promise action that reads the contents from a file asynchronously, then run the blocking print operation on the contents
The main point is that thenAccept only executes one promise then a normal java procedure

me: So

CompletableFuture<int> cf = readContentsFromAFile().thenApply(contents -> length(contents)); 

lw: Correct

me: Where as thenAccept returns CompletableFuture<void>

lw: Yes

me: and thenCompose is like `here, use this one`
So it’s like

CompletableFuture<Whatever> cf = something.thenCompose(contents -> asyncGetWhatever());

lw: Yeh. I prefer to think of `thenCompose` as chaining two promises together, so when the first one finishes it runs the next one

me: Got it, thanks.

I’m actually OK at Aquaponics

Aquaponics - 2 Comments » - Posted on November, 10, 2012 at 6:35 am

Someone recently came across my blog and related to me that I have a compendium of what NOT to do in an Aquaponics system. Since those posts oh so long ago I’ve improved immesurably, and only kill fish through stupidity rather than lack of knowledge (e.g. turning a pumps off and forgetting to turn them back on).

Here is a short video of my aquaponics system with the last of last years trout in them.

They’re quite big fish now (they were last years runts) – previously I’ve said “Trout Season Ends in December“, but last year’s summer was so unusually cold that I got my fish through without any supplementary cooling! Wow.

And if you want to see me doing a really bad job of gutting a fish, check out this one:

It would be comical if it weren’t so cruel. From the look on my face you can tell I don’t exactly enjoy the process. Worth watching even if it’s just to see the brilliant chicken coop/gutting bench that my wife built using our old kitchen cabinets & sink.


Introducing the “Nimble” Software Methodology

Software, Technology - 1 Comment » - Posted on October, 30, 2011 at 9:37 am

I had a comment from someone on a previous rant about the term agile, and it has spurred me on to tell you all about my first encounter with nimble software processes.

In my first job out of Uni I was working on a client site in another country on a project where the delivery date was set based on the owner’s birthday. So I probably should have run a mile based on that alone. But it was new and exciting and I didn’t know what to expect from the real world so I worked my 6 day weeks with 3 hour commute each day. We had a team with an experienced lead and 5 grads straight out of Uni, and the work environment was very unsettled (figuratively and literally, they were building the building around us). We were keen to employ some of the things we’d learned at Uni so we approached our team lead and said:

“The client is changing their mind all the time, instead of just hacking on code each time they do this we should employ some sort of agile process to manage it”.

To which he replied:

“Process is for stupid people, it’s for people who can’t manage themselves. We’re better than Agile, we’re … Nimble.”

And from that day forward any time someone has said they use a process when they are clearly using no process at all, or only the bits that mean they have to do less work, I have labelled them as using a Nimble methodology.

Dealing with the heat in aquaponics

Aquaponics - No Comments » - Posted on December, 8, 2010 at 8:17 am

Trout don’t like hot water, nigh, trout don’t even like warm water. From my experience somewhere around 25 degrees C and they start to struggle. It’s not actually the temperature that gets ’em, it’s the Dissolved Oxygen (DO) level. See as the temperature of the water rises, the saturation level of DO goes down. And trout are very finicky about their oxygen. So essentially it gets to the point where you just can’t get enough oxygen into the water for the trout to survive. So you have two options:

  • Harvest your trout. Last year I pulled them out from late November through to late December – I pulled the last lot out just before the xmas holidays.
  • Fight it tooth and nail (maybe your trout aren’t big enough and you want to get another month of growth in).

Assuming you’ve chosen the “fight it tooth and nail” path then there are a few things you can do.

  • Don’t pump during the day – you don’t need to. The ammonia level will rise very slightly if you don’t pump during the day, but it won’t affect the fish. Pump all night. If you are really worried about ammonia, use an air lift bio filter in the tank (see below). Essentially the growbeds are going to heat up your water, so don’t pump up to them. Your plants will survive.
  • Shade your tank as much as possible. For obvious reasons.
  • Put an old sheet on your tank, with a corner dipped in the water. This will wick the water out of your tank and evaporate. Evaporation is a cooling process – essentially what you’re trying to do is create a “bush refrigerator” or “Coolgardie Safe“. I’d go one step further and invest in another small fountain pump. During the day this pump is on and is pumping water up over your sheet and then running back into the tank. This will add extra oxygen as well as cooling the water.

I mentioned above a concept of “Air Lift Biofilter” – essentially it’s a couple of bubblers in a tube – as the air rises it pulls the water up with it, which in turns pulls water in from the bottom of the tube. So you get a bit of water movement by using the bubbler. Then what you do is you add a small amount of rocks, or some cut up poly pipe to the tube and the bacteria live on that in a nice highly oxygenated environment and do a bit of biofiltration. The water is pulled in through holes in the bottom of the pipe, and rises up through holes at the top.

Here’s a very low tech version which I threw together with scrap peices of PVC:

Apart from that, my trout are growing well, and the cool spring/summer has been kind to them – I haven’t actually had to apply any of the aforementioned techniques as yet, where as the guys over in Perth have all had to pull their trout out! Two more videos of them feeding:

And finally – the plants. This side has been pretty disappointing this year. I have been smashed by slaters, and then I had a nutrient deficiency so I sprayed with seasol, only TOO MUCH SEASOL AGAIN and burnt the crap out of my plants, and now hail. So things are a little sad (that is, I can actually see the media!). You can see what I’m up against in the photo below. A seed sprouts and has it’s leaves munched off…

And then I went and compounded the problem by putting too much seasol in my leaf feed mix and burnt the lettuce.

But most of  the lettuce bounced back really well (you can see the burnt edges of the leaves underneath those glossy ones on top).

A blog about trout and bacteria

Aquaponics - 2 Comments » - Posted on October, 22, 2010 at 12:37 am

So here in Canberra we’re pretty lucky in that we can grow trout. Well whats so special about trout? Apart from the fact that they grow quickly (9 months to plate size) and they’re delicious smoked, they are surface feeders. And what’s more, they’re aggressive surface feeders. What this means is that when you throw the food in, you’re likely to get wet.

Exhibit A:

Exhibit B (click it for a higher res image):

The violence at which they throw themselves at the food is really quite impressive. They’re certainly not like gold fish, hoping to pull something in by gobbling at the surface. When they come up, it is with great intent and purpose. They’re not just going to gulp and hope, they’ve picked a target and they’re going to smash it.

Whilst we’re on the aquaponics theme – I want to direct your attention to a truly amazing article on bacteria in the human body, and the wonderous ways in which nature uses bacteria (or does bacteria use nature?!). The article is here, and the reason it’s relevant is because bacteria is oh-so-important in aquaponics, because they’re the things which make the whole gig possible – Ammonia->Nitrite->Nitrate. The world has such “germ phobia” that it sickens me. We need bacteria more than it needs us. Oh the whole, it is natural, and necessary for our (and almost every other species’) survival.

I should also mention that I saw a Black Soldier Fly (BSF) the other day. So around October they appear in Canberra.

An Aquaponics Update

Aquaponics - 2 Comments » - Posted on October, 3, 2010 at 10:53 am

Ah, has it been so long? Sorry.

To bring you up to speed – I had a disaster around ANZAC day this year (6 months ago, I know) and I lost a bunch of fish. The weird thing is that I lost a bunch of fish at exactly the same time of year last year. So could be something seasonal? I think it’s more likely that I overstocked, and fell into the ol’ trap of “I want ’em to grow big so I’ll feed ’em heaps’ and of course overfed them which is the worst thing you can do in AP. I think what ended up doing the fish in, was that the fish food broke down into a fine paste kind of stuff and spread throughout the system. And then as it breaks down it consumes oxygen, and trout are VERY touchy about DO (Dissolved Oxygen). But that’s the thing with fish deaths – they don’t really tell you why they died.

It’s not all bad news! I have about 60 trout, and whats more, they survived an entire month without me. I was overseas (check out these videos of the norwegian fjords: Kayaking and the “liquid metal” water ), my father and a friend looked after the system – this entailed coming over on alternating days, and feeding the fish. Not too onerous.

So my fish survived, and here they are – about 1.5 months ago they looked like this:

And now:

So they’ve definitely grown. And it’s fantastic fun feeding them:

On the other side of the biological equation, the veggies are doing OK:

Above is some brightly coloured silvebeet, and below is russian red kale.

So why did I say things are going OK rather than fantastic? Well one of my growbeds has a big bare patch where I sprinkled in some seeds, and that’s a bit dissapointing. But I know why that’s happened. I have a slater problem, and the little bastards are eating everything, seeds, seedlings, my leek:

So what am I doing? “Flood ’em out”.

I raise the height of the standpipe so that the bed floods to above the height of the clay, and drown critters.

Edit: I should also mention that there is an Aquaponics open day at Alfred Deakin high on 9/10/10 – see capitalaquaponics for more details.

“Agile” considered redundant

Software - 2 Comments » - Posted on July, 29, 2010 at 7:38 am

I have many pet hates, one of them is the term “agile” when talking “agile software methodology” or “agile software process”. It’s not any of the actual processes that I dislike, it’s the use of the term “agile”. I think it’s overused to the point where it no longer means anything. When people talk about agile methodologies they contrast them with “traditional” methodologies, usually the waterfall methodology. This is where it starts to irk me – why is it that there are thousands of agile methodologies, and ONE non-agile methodology. And in fact if you made a process which was essentially lots of shorter waterfall methodologies you could probably pass it off as an agile process. So this is why I think the term “agile” is a completely redundant term.

Anything that is essentially an iterative methodology is labeled as agile. And because most processes are iterative due to the nature of projects (i.e. requirements change, regardless of software industry) pretty much every software process out there is agile. Which of course means that the “agile” is completely redundant and can be dropped and we can return to talking about processes, rather than agile processes.

I thought of an analogy which goes some way to explaining my distaste of the term “Agile”.

 <em>“Agile” is to software process what “award winning pies” is to a bakery. </em>

i.e. What bakery doesn’t have award winning pies?

Essentially any process, agile or not, has a series of steps to follow, and a bunch of techniques and tools which help software quality (e.g. pair programming) or some other software or project attribute (e.g. you measure earned value to predict completion time). If you take anything which is iterative and produces something, and then grab a bunch of these techniques, and give it a process metaphore (e.g. SCRUM has “sprints” etc) and you’ve got yourself a new agile process. No wait, let me take that back, you’ve got yourself a new process. We don’t need the term agile, because it doesn’t mean anything anymore.

Aquaponics in Space

Aquaponics, Ideas - 2 Comments » - Posted on June, 11, 2010 at 3:00 pm

Wow. What an interesting idea. At lunch today we had a really good discussion about this.

Firstly – why would you do it? Well you can grow some protein onboard your ship – you can’t exactly grow livestock so apart from protein in legumes etc this might be the only way.  Secondly, this is dirt free, so you don’t need to worry about dirt getting in your systems and cutting them to pieces.  Space ships are all about recirculation, this is a very low tech recirculation system.  The added bonus being that the plants scrub the air of carbon dioxide.

Space throws up a whole bunch of problems. Firstly, how would you do it? Well I’d do it by grabbing an asteroid that’s mostly water ice, and build a structure around it. You then add another module which has hydroponic trays full of plants.  The biofiltration is done by a barrels of “bioballs”, or possibly just by bacteria growing on the walls of the structures.

Do we need gravity? Maybe not, the plants will grow towards light, and the roots will grow towards water, but gravity is useful. For starters, how would you keep the water inside the grow trays? I think you’d be fighting a losing battle, but if you had gravity – it doesn’t need to be much, then at least the water will stay “down”, and can be made to flow along the bottom of the channel. Dunno how fish like zero gravity – they have a swim bladder which enables them to go up and down in the water column, so I guess we need SOME gravity. Maybe fish have fine enough control of their swim bladder to handle low grav?

I’m not fluid physicist, but so long as the fish tank was “full enough” then you wouldn’t have too many problems with the fish getting stuck in a bubble of air and expiring. Plus I think the fact that you’re in a gravity-less environment would mean that the fish “flipping” about would actually have some effect on the air/water around it and eventually it would find itself back in the water. A bit of gravity might help with this as well, maybe you could pressurise the sides of the tank so the water stays as a ball in the middle? I dunno, probably not possible.

The fish need oxygen in the water – this might be a problem. The plants provide oxygen, but whether they provide enough oxygen for the fish to consume is another questionable. (Aside: I wonder why astronauts don’t have a massive vat of algae to do their CO2 to O2?). We wouldn’t want the whole system to consume oxygen.

Apparently water ice asteroids in space have quite a bit of Ammonia in them. Sheesh, that’s exactly what an Aquaponics system excels at. So when the ice has melted down, you can run the system for a couple of months and it’ll consume the Ammonia (and the plants will grow! Hurrah!) and by the time you’re ready for fish, it’ll be all cycled because it’s consumed the Ammonia present in the ice asteroid, ready for the Ammonia produced by the fish. Maybe NASA should explore using this high Ammonia ice to grow plants without the fish as this could be done right now. By product is drinkable water or oxygen if you want to go to the effort of splitting H2O.

A spinning ship provides the slight gravity that you need, it also means that you can emulate night and day.

Heating is another issue, it’s cold up there.  I think you’d have to filter the sunlight – I think direct sunlight is very dangerous, and the plants would probably get smashed by it (that’s why our ozone layer is so important), so we might need to have some sort of filter there. But if we had that, we’d essentially already have a greenhouse. I suppose you could do everything with closed boxes and awesome insulation for your modules, and use growlights for the plants, but I like the idea of using the sun.

I suppose we really need to close the cycle a bit more – the fish would need to eat plants, maybe we could use plant waste and turn it into worms (or even the worms compost our bodily wastes ….). Otherwise you’re going to need to take up a whole bunch of food for the fish. Though if you’ve got carbon dioxide, water and sunlight, you should be able to grow food for fish like you can grow plants for humans. Maybe you’d need to create more of a food chain (i.e. watersnails which convert algae to protein, fish which eat the watersnails and grow).

I dunno  – there are probably a million flaws with the idea, but it’s very blue sky dreaming and I love that kind of thinking. Give it thirty years! “Every deep space ark ship should be fitted with an Aquaponics system, and for the best space Aquaponics systems around, you need to talk to the experts“.

Tip For AP N00bs

Aquaponics - 1 Comment » - Posted on March, 21, 2010 at 10:58 am

I’ve been doing AP for a couple of years now, so here’s a tip for people who are new to AP that will save you much heart ache. If your water ever gets a kind of “slick” on it that looks like this:

Then you should start to worry. This is caused by an overload of protein, which is a precursor to an overload of Ammonia, which is a precursor to lots of dead fish. So it’s a bad sign and should be heeded. Generally this is caused by overfeeding, and sure enough, on checking the bottom of the tank I noticed a buildup of uneaten food. Note that fish like trout and silver perch eat as the food falls, and once it’s touched the bottom generally goes untouched (maybe the fish have a 3 second rule?!). My problem is that my fish food is a little bit too small for them, so quite a lot makes it through the swarm and to the bottom.

Anyway, it’s easy to fix if you catch it at this stage. Vacuum the bottom of the tank (just siphon it out onto the beds where the worms will digest it), and turn your pump on so it’s cycling for 24 hours, this should digest the extra load and the system should return to normal. Oh, and stop feeding so much or make sure they eat it all as it falls.

Supplementary Feed

Aquaponics - No Comments » - Posted on February, 26, 2010 at 9:18 pm

So I went out to my worm farm the other day and opened the lid to this grotesque sight:

I know what you’re thinking – “eww maggots are in your compost”.

These are indeed maggots, but they are AWESOME maggots. Why? Because they’re Black Soldier Fly larvae (also known as Pheonix worm).  Below is a photo of the fly.

You’ve probably seen it around, they seem to be all over Australia. When they’re at the fly stage, their only concern is breeding and laying eggs. They have no mouthparts so they’re not the type of fly that comes into your house and buzzes around the kitchen scraps. They’re just not interested.

But the larvae. Well, they’re composting MACHINES. They will eat anything – which includes meat and citrus (something worms don’t abide by) – and turn all that compost into a rich source of protein – themselves. And here’s the kicker: they’re self harvesting.

What they do is grow from that small white stage, right up to a big brown stage like below:

Once they reach this stage, they head for a drier to environment so that they can pupate, so what you do is you put your bucket of scraps on a 45 degree angle, and the larvae get to this stage and then wriggle their way up and …. PLOP. They drop into your tank and are fish food. They are a fantastic source of protein and another step in “closing the loop”.

….Well that’s the theory anyway. I’m still yet to actually make a BSF harvester. You can buy commercial ones (e.g. BioPod) but they’re expensive. The Black Soldier Fly seems to arrive in Canberra in Summer (around December). I don’t think it can survive year round. Anyway, go do some searching – there’s plenty of info on them out in the wild, youtube has some good vids. The BackyardAquaponics Magazine Edition 5 contains an excellent article on BSFL (Black Soldier Fly Larvae). If you’re at all interested, buy this one (the whole magazine is excellent though).