Asynchronous notifications from the server to the browser - perfect

This is why I love Wicket Java Web UI framework.

It provides all the power of the latest JavaScript and browser capabilities without ever having to write any code in that crazy, non type safe, interpreted JavaScript language ;)

Wicket components have all of the required JavaScript embedded within them meaning a Java developer of any skill level can simply instantiate a few components, add them to a page and bang! - too easy.

So about asynchronous notifications...

The 'status update' problem

Often within a web app the user will invoke some operation that can take some time. The page or part of it needs to be updated to reflect the new status after the operation has completed.

To do this developers, traditionally, have had to do one of these:

  • Make a request to the server which the server delays responding to until the operation has completed. This is inviting bad karma to your web server because it ties up a connection and the number of connections in a web/app server are not infinite. What's worse, in many application servers tying up a connection also ties up a thread - which consumes much more resources than merely tying up a connection.
  • Start up a poller in JavaScript which regularly polls the server to get the status on the operation. When the operation is complete the poller is disabled and the relevant panel(s) on the page are updated. This option has a latency issue: for example if you set the polling period to 2 seconds then the user might have to wait for up to 2 seconds after the operation has completed before they see the update. You can make the polling period very small but this solution will not scale well as with thousands of users all hammering the server with update requests may place too much burden on the server.

A better solution

Quite a long time ago a technology called "Web sockets" was introduced which allows for the server to asynchronously notify a client (browser) of a change of state. e.g. the completion of an operation or an update of the value of a stock.

Wicket provides a very simple "wrapper" for Web sockets which allows the developer to add Web socket support to their app without writing a single line of JavaScript code - it can all be done in Java - the clever Wicket devs have done all the hard JavaScript coding yards for us, once again! (Thank you guys!)

Here is an example of an asynchronously updated graph:


Here is a tutorial on how to write an Web sockets app using Wicket:


Comments

Popular posts from this blog

Java package name structure and organization - best practice and conventions

Classic software engineering mistakes: To Greenfield or Refactor Legacy code?

How to reset MySQL 8 root password on CentOS 7 and 8