Three years with Java Simon (3)

I should finish this series before it should be called “Four years with Java Simon” – but we still have some time. I’ll show you what possibilities callbacks brought to the Simon, but first I’d like to deal with our Webnode site.

It was three years back (January 13th, 2009) when I posted on our Webnode site that we need some better web for presentation than our project site on Google Code. But then we found we can’t post bunch of HTML files (Javadoc) on Webnode – and with mime-types SVN props we can do that on Google Code… oh, how quickly things change.

Webnode site could be good if Java Simon gained some bigger momentum on our side – more committers and contributors, people writing blogs or tutorials or success stories (or not so success stories too if they can help :-) ). But this did not happen and I felt as rather annoying obligation to update this site. Especially because the edit functionality is on a separate URL – editing a Wikipedia page or a blog post on WordPress is always just one click away – but not so on Webnode.

Three years later I decided to redirect javasimon.org on our Google+ page because it is so much easy to update, posting even very short posts is not inappropriate (which would be on a blog) and it’s just so much closer to my way of living on the Internet right now. I’ll go through javasimon.webnode.com and it will soon be a matter of past.

Last time I discussed some changes from version 1 to version 2. And to preserve the little from Webnode site that has any “historical” value I hereby copy one blog post covering just these differences:

Major changes in the core of the Java Simon v2
2009-01-28 14:30
While there are some important extensions to the Java Simon (JMX, Spring integration, etc.) there are a few important changes in the core part of the API that are probably even more important. If you’ve already managed to use Java Simon 1 I strongly suggest that you use version 2 even in its alpha stages. The thing is:

  • If your project is finished or close to finish (month or two) stay with version 1.
  • If your project continues and you’re just experimenting with Simon, definitely use version 2! There is v2-alpha1 which is basically rework of the v1 after a few changes in Stopwatch. If there is newer alpha out (check Featured Downloads on the right on our project page) take that one of course, because it contains more features from v2.
  • Version 2 is planned to be out during March or April 2009, which is really soon.

Now what are the changes and why we made them?

  • Important change happened in the Stopwatch. While in the v1 it contained various start/stop methods that took care of multi-threaded environment now it has only one start method and this start doesn’t return this anymore but it returns new Split object instead. You have to take care of the Split object, you have to take care of your multi-threading, you have to call stop method on the Split. This makes our code safer as the Stopwatch doesn’t contain internal maps that were prone to memore-leaks if client forgot to stop some split. Thanks to Erik van Oosten and his great Java Simon evaluation.
  • Based on the same post we changed sample methods so that they return Java Bean objects now instead of the field.
  • While in v1 you had to use SimonManager now you can use non-static Manager implementation directly. SimonManager still stays your favourite convenient class full of static methods, of course. ;-) This allows to have multiple separeated Simon hierarchies which may be handy in Java EE environment.
  • To provide some extensibility for the API we introduced Callback interface. This allows to hook onto various events and process these events in any way you want – to log them, send JMX notifications, whatever.

There are more features to come with version 2 and I covered only those in the core part of the API. Stay tuned, download, use, test, let us know what you think. :-)

Now let’s take a look at those Callbacks. Based on good-old Observer pattern, Callback is a listener that performs some actions on various events. First question was where the Callback should be registered – and we decided that Manager will hold its Callbacks. We didn’t want to scatter Callbacks across various Simons because typical usage would lead to a situation where many Simons call (and point to) the same Callback. We rather decided we will centralize Callback management on a Manager (that is per Manager of course) and bring some way how to filter events based on Simon name for instance.

Simple example of Simon is in our CallbackExample:

    SimonManager.callback().addCallback(new CallbackSkeleton() {
           public void onStopwatchStart(Split split) {
               System.out.println("\nStopwatch " + split.getStopwatch().getName() + " has just been started.");
           }

           public void onStopwatchStop(Split split) {
               System.out.println("Stopwatch " + split.getStopwatch().getName()
                   + " has just been stopped (" + SimonUtils.presentNanoTime(split.runningFor()) + ").");
           }
       });

       Stopwatch sw = SimonManager.getStopwatch(SimonUtils.generateName());
       sw.start().stop();

When you work with Simon (last two lines) you don’t care about Callbacks – they will be called. Their configuration can be based on some configuration and they should do whatever you want to hook on various Simon events.

BTW: If you use Java Simon 3.1 method onStopwatchStop is still called stopwatchStop. This is quite serious flaw and poor choice of method name on my part (and I’m terribly sorry for that). While this method doesn’t show it clearly, there was another method – clear (now onManagerClear). This method is called – as you may guess from the new name – when clear method on the manager is called. Let me explain composite callbacks first to show you the whole problem…

To add more callbacks to the manager is all right but if you want to filter Simons (by name, for instance) that fire an event on a Callback you actually need to do it in the event itself. Or wrap the Callback into another one – that is exactly what FilterCallback idea is all about. Another thing is that you may need to call various callbacks for the same filter – to group them – and that is what composite callback does – holds more callbacks (children) and relays the event to all of them. There is no interface CompositeCallback – instead all these methods are on Callback already, but they are not implemented in the CallbackSkeleton for instance (used in the example above). There is one implementation called CompositeFilterCallback – and you probably can guess what it does. It can hold more callbacks and call them when the common configured filter is passed. See CallbackFilteringExample for simple use case.

Now guess how people tried to remove callbacks from composite callback. It’s just a collection of callbacks after all, right? Ah, method “clear” must do exactly what I need here. But it didn’t. And if you didn’t implement this event method (which is not very common, but JmxRegisterCallback is nice example where it is very handy) it simply did nothing. There was method to remove one callback, but not all of them (this one was in SimonUtils). This is all finally fixed with version 3.2 – all names are much better and removeAllCallbacks is in the Callback interface.

JMX is nice example why we needed callbacks just as much as we wanted to offer them to our users. There are two ways how to access Simons via JMX – you can use single point MX bean, or let Simon instantiate MX beans per Simon. The latter however requires some actions when Simon is created, destroyed or the whole manager is cleared. I mentioned JmxRegisterCallback already – check how it’s done there. Now the Simon manager knows about Callback mechanism – but it doesn’t have to know about JMX – or anything else you want to drive by these events.

Split introduction and Callbacks are two very important changes that happened in version 2 – and these things are now well proven and will probably last (though some names can change as will happen in version 3.2 :-) ). Next time I’ll try to wrap up the rest of the story.

Open letter to Java Simon users

I bet there are people who are not on our mail group or watching Java Simon page on Google+. Roughly three years after the first official release we have another really good release.

I’m really proud about our newest Java Simon release (3.1.0) and I decided to share the mail written to javasimon@googlegroups.com also here on my blog:

Dear Java Simon users

Firstly – version 3.1.0 was released on New Year’s Day – more about it
on our project site:
http://code.google.com/p/javasimon/

We announced it also on our new stream on Google+ (it should be
available for non-google users too):
https://plus.google.com/b/115141838919870730025/115141838919870730025/posts/ZpmYGp9F2yp

Secondly – about Google+ – we decided to pull down our Webnode site
because it was a bit cumbersome to maintain and add new posts there.
Instead we are moving to the aforementioned Google+ page.

Direct link: https://plus.google.com/115141838919870730025/posts
Short link: http://gplus.to/javasimon
Or just use our domain! http://javasimon.org/ or http://www.javasimon.org/

This way it should be easier for us to post more often even smaller
facts about your favourite monitoring library. :-)

Thirdly – Happy New Year to you all, update and share your thoughts, I
feel very well about the last release. We’re working on 3.2 already,
with our new commiter (Gerald) we should be able to deliver simple
embeddable web console too, so there is a lot to be looking forward
to.

Best regards and wishes

Richard “Virgo” Richter

You are welcome – and encouraged – to add Google+ page into your circles of course. And once more – Happy New Year – as this is my first post here in 2012. :-)

2011 in review

If you blog on WordPress you probably got the mail too. :-) It was just lovely dot after the whole year on the Internet. Especially with sentences like “your writing has staying power”. That made my day. Here it goes – full of it is behind the link at the bottom:

The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog.

Here’s an excerpt:

The concert hall at the Syndey Opera House holds 2,700 people. This blog was viewed about 26,000 times in 2011. If it were a concert at Sydney Opera House, it would take about 10 sold-out performances for that many people to see it.

Click here to see the complete report.

PS: I forgot to mention that my wife’s blog about cooking – in Slovak only! – made three times bigger numbers. With only two new posts this year she reportedly sold out Medison Square Garden three times (I was rather compared to Sydney Opera – another nice touch of the report). :-)

Personal Log (4): Games I played in 2011

Last time I wrote “Personal Log” it was the end of 2009 and I wrapped it up in my post from more perspectives. Year 2011 was a good one (again), I started in a new job in January, our daughter Barbora was born in January – but even with these obligations (job and family) and a lot of additional work on Java Simon I still managed to play games. And to my surprise – quite a lot. :-) I’ll talk only about single-player games because I can’t engage into any serious multi-player with all the children around. :-)

So let’s start with the previous Christmas sales on Steam. I bought Mass Effect 2, King Arthur Pack, Railworks (now updated to Train Simulator 2012), Dragon Age: Origins, Crysis Complete, The Ball and Burnout Paradise. I even new I may not play some of them, but for the gamer it would be a sin not buy it when it’s so cheap. :-) I want to play The Ball just because it’s made by Hourences and the team of other great mappers/modders who had been around Unreal engine and Unreal Tournament quite some time – and the game is original too.

In the last few years Mass Effect may be my favourite franchise – it’s a great shooter and I even forgot it’s RPG. Not that I have anything against RPGs – on the contrary – lately I played more RPGs of various types to my own surprise. I stopped playing other games and first I had to go through Mass Effect 2 (twice, different gender, different specialization). While you don’t exactly save the galaxy in front of the whole council (dead or alive ;-) ) like in the first part, the continuation is probably more epic on the whole. Not that I didn’t have any gripes about the game, I can’t remember them now – but I can remember how great the game was. As I remember the VI announcing another customer in line from the first part I still have vivid memories of quite a lot of scenes from ME2. This game flows well and it’s getting bigger and bigger towards the end. If you like sci-fi RPGs (or even shooters and can survive a few dialogues) then this is an absolute must-have. ME1 was great, ME2 is greater, with less annoyances, more variability in scenery, more subplots and one really nasty boss at the end. Fun factor 5/5, frustration 0, length just right.

King Arthur was the game I spent the start of the year with (after ME2 that is). I was really surprised with the blend of the Heroes M&M turn-based strategy (on a map that reminded me good old Defender of the Crown) and RTS battles – this all spiced up by simple text-based quests and some economy. I was really surprised how playable the game was. In the middle of it I thought I will loose because opponents’ knights (heroes) started to be very strong while I underestimated the power of some spells, but somehow I managed to outmaneuver them in the end. If you like strategies, try it. On the RTS battlefield it’s often about you knowing how to play around key areas and you may destroy a few armies with a single one. Maybe hard-core players would object, but I – casual nearly-ex-gamer – appreciated this concept. Fun factor 4/5, frustration 0, length quite long as expected. Typical “just one more move and I’ll go to bed” game.

Batman: Arkham Asylum is a bit difficult story. I had troubles to save single player games originally – I even wanted to play cracked version because of the stupid Windows Live service. But I figured out the offline profile feature (hidden in an unbelievably stupid way) and then I started to play. Another serious issue – no way to change controls. I’m ESDF guy, I touch-type too. WASD drives me crazy and when I want to press 1, I always press ` (key to the left) – well… because I touch-type! Not to mention that one disabled guy told me how missing controls customization can render the game unplayable for them. But back to the game itself. The story, visuals and all was quite reminiscent of Bioshock (both Unreal 3 engine games, by the way). I liked special tactics Batman can use, detective mode, gargoyles, visuals – this all was very good. You were really in the middle of Batman’s story with may heroes I didn’t even know. :-) Boss fights were interesting, each of them a bit different. If you had any problem, game gave you some hints – I liked this as I’m less and less hard-core player and more and more a casual one. However here and there you played with different camera than over-the-shoulder and it made controls even more difficult (some boss fights mostly). You could take it as a minigame though. For one reason or the other I wasn’t so sucked into this game in the end, but I finished it after a few breaks (a few months mostly). Fun factor 4/5, frustration 3 (Windows Life + controls + camera), length just fine for me (progress meter counts also riddles, so you may probably end around 60% if you don’t care for the riddles). Recommended? Why not, but I don’t plan playing Arkham City.

In the middle of the year I suddenly got a strong need to play Half-Life 2 again – with both Episodes too, of course. As scripted this FPS is, it is simply great. Even the second run. I realized how many scenes in this game are simply so great. The river, first gravity-gun practice, “We don’t go to Ravenholm”, blocked bridge, Nova Prospect fight while waiting for Alyx, all those striders, Overwatch Nexus, Citadel… all of it! And then the Episodes – reactor hot-fix, run away to the station, fleeing the city, jumping over a broken bridge, Alyx down and up again, ambush in a homestead and amazing finale of the second episode. Without making any choices, without any active dialogues, the story is just great and I think I’ll probably have to go through it some other time again. Not to mention that it has great commentaries too – these just underline how well-thought this game is. Fun factor 5, frustration 0, length just fine – I even consider the main game quite long for a shooter, but I bet it’s short for others. :-)

I was nicely surprised by Anomaly Warzone Earth. Simple, arcadish, and as goes with turret defense – very addictive. The concept of playing against the turret defense is smart, it is spiced up with a lot of specific details on particular maps and while this game was shorter in overall, it was also cheaper as it is no AAA title. Still the production was surprisingly good and the whole game is just smooth. Worth a few bucks for killing a few evenings, really. Fun 5, frustration 0, length could be longer, but OK.

Frozen Synapse on the other hand was too much for me. You have to dedicate more time to this game, it’s not good for a casual player I’d say. I expected some kind of Laser Squad I remember from ZX Spectrum (or the horrible port on PC) – but then – I had much more time (and much less games) back then. However the concept is interesting but without going for a multiplayer it’s probably not worth it. Fun factor 3 (single player), frustration 0, length – no idea.

And then there’s The Elder Scrolls IV: Oblivion. I played Morrowind before, but after some time I just gave up. Maybe I chose more boring class, but I guess different class wouldn’t change my mind. Oblivion is more or less like Morrowind – but more fun. Both these games are BIG. A lot of locations, a lot of characters, a lot of quest. However I lost my goal after some time. Oblivion is far better from this perspective than Morrowind, not only because it’s newer. But still – after shutting a few Oblivion gates I started to loose my focus, I didn’t know where to go and what to achieve in this game. This game is very good and having less other games and more time I’d probably play it (and maybe I’ll return to it). System is better than in Morrowind, a bit simpler, leveling goes more naturally, movement around the world map is faster – this all makes the game great. But when I compare it with games like Witcher and Dragon Age Origins (which I’m playing now though I hardly started the story) it’s easy to get lost here. I like RPGs that lead the player a bit (or more) – Witcher, Dragon Age, Mass Effect – these are much better in this aspect. For Oblivion the fun factor is 4, frustration 0, length was too much for me. :-)

However, there is one easy way how to try a lot of games for little money. Wait a year or two and buy it during holidays sales if you’re not sure if you really want it. I remember buying Unreal Tournament 3 in metal case for quite a lot of money for my taste – and I was utterly disappointed by the game (though I loved UT99/2004). That’s why I hate to give anything more than 30 for a game I’m not sure of. Having Dragon Age 1 with all of the DLCs (another reason why to wait a bit) for 20 is much better deal then. I rather spend a lot of money on a lot of games risking I’ll not play a few of them than spending even more money on a few ones, half of them probably more or less disappointing.

And what were your favourite games in 2011? :-) Let me know, anonymous comments are allowed as well – as always.

Three years with Java Simon (2)

This is continuation of the previous post where we somehow got to version 1.0 – that was December 2008.

Working on our first version of Java Simon I learned a lot from my colleagues too. While we shared our views all the time on the OSS library we somehow did even better than on our common (resource limited) projects. We also knew that library must be even cleaner and better than some Information System developed once – often without proper support budget. One guy insisted on finals whenever possible (which I’m not fan of) and he also vigorously refactored methods with boolean flags – and I originally disliked this change. In Simon interface we had methods like:

Map<String, String> sample(boolean reset);

Now we have much cleaner two methods instead of using boolean parameter – not to mention that we have Sample object instead of Map used in early versions:

Sample sample();
Sample sampleAndReset();

Not that we don’t have any method with boolean flag – but the most prominent one is rather management one compared to sample methods:

void setState(SimonState state, boolean overrule);

Generally I don’t like using boolean flag parameters because they are hard to read when you see just plain code. If they are replaced with enums (where suitable) readability goes up instantly. If they are split to two methods – especially when one of them is rather default (like the sample without reset) – even better.

Working on an OSS library (or any other library – even a private one) you have to think way harder (or rethink more often) how to organize your interface, packages and all. I personally hate backward compatibility as an ultimate decision and we knew that we will change the interface here and there. If you want to upgrade then just go through your code and change those few things you have to change! Or don’t upgrade. (I’ll not go on about the whole myth of compatiblity and how often it is not completely true.)

That’s why we decided to release version 1.0 quite soon (December 2008, we started the project in August 2008) and find out what is missing. Version 2.0 followed quite quickly – in January 2009 we had the first alpha (quite stable though) and we decided to focus solely on this without any support for 1.0. The reason was that the Stopwatch behaviour changed quite a lot – for the better.

In 1.0 HalloWorld looked something like this:

SimonStopwatch stopwatch = SimonFactory.getStopwatch("org.javasimon.HelloWorld-stopwatch");
stopwatch.start();
System.out.println("Hello world, " + stopwatch);
stopwatch.stop();
System.out.println("Result: " + stopwatch);

Most important feature was that both start and stop were called on the Stopwatch. Now you may wonder what would happen if you started stopwatch twice and stopped it twice as well. It depended… though – honestly – I don’t remember exactly. Stopwatch had thread-local variable that remembered start timestamp (nanoseconds of course) and stop was expected to be called in the same thread. Double start and stop was illegal operation. Now this implied two serious limitations. The first was potential memory leak on the thread-local variable if you (client programmer) failed (or forgot) to stop the stopwatch. The second was that you couldn’t stop the stopwatch in a different thread.

This was troublesome design and happened to be resolved soon after 1.0 release. Our new HelloWorld looked (and still looks) like this:

Stopwatch stopwatch = SimonManager.getStopwatch("org.javasimon.examples.HelloWorld-stopwatch");
Split split = stopwatch.start();
System.out.println("Hello world, " + stopwatch);
split.stop();
System.out.println("Result: " + stopwatch);

Now the client programmer is fully responsible for working with the Split, there is no thread-local and the worst thing that may happen to the stopwatch is that its “actual” count will go up and up (and so indicate some problem with missing stops). Split will be garbage collected – unless stored by the programmer (his fault anyway ;-) ).

Another important features coming with 2.0 were JMX support (MX Bean) and Callbacks – these allowed programmer to hook on various events. But more about these in my next post, right?

Follow

Get every new post delivered to your Inbox.

Join 214 other followers