maandag 16 augustus 2010

Extreme Feedback from the Nebula: The Oscilloscope



Extreme Feedback
When I was reading the Hudson manual a few days ago, I came across a section called "Extreme Feedback" where people are experimenting with feedback from the build system. Devices vary from cute bears to traffic lights and actual smell emitters.

Now I am looking for an genuine hospital heartbeat monitor to top all that. If you find one, let me know.


Until that time ...
We are currently building a new software machine that is based on OSGi services. Some of these services are really important and without them the machine will not run. For example, there is the Store service to persist and retrieve data. I don't know why but a few months ago I got this idea that a dashboard with some heartbeat monitors would be a nice way to a) impress our customers and b) to get immediate feedback in case one of the services would die.

After playing around for a few hours on a sunny Sunday when I should really not sit behind my computer, the first version of the OSGilloscope was born. I especially liked the name, but changed it later. The first version was slow as a snail and consumed all of my CPU and I had to tinker quite a bit to be able to run many scopes without problems.

After adding a few nice options, including sound (Heartbeat, Flatline, ..) I asked the Nebula guys if they wanted to have it, and they did!

I have included the scope into the Nebula Examples view. If you want to take a look please follow these five easy steps:

1. Start Eclipse with a new workspace
2. Create a java project
3. Create a file called widget.psf and load it with this content
4. Right click on the file and select "Import Project Set ..."
5. Open the nebula.product file from the example project and press "Launch an Eclipse Application"

After this is done, open the Oscilloscope tab and play around with the options. It is a lot of fun.

How to use the scope
If you want to use the widget please look at the included snippets project. You can just launch each snippet as a Java application. The widget comes with a special abstract OscilloscopeDispatcher class that keeps the animation running if you call the dispatch() method.

It does that by putting a request on the Display queue with a delay of 10-n milliseconds. The higher the delay, the slower the scope will run. You can specify the delay by implementing the getDelayLoop() method.

Off course, the scope wants to display a value. You get an opportunity to put a value in the scope every "Pulse". The value of the pulse can be specified by implementing the getPulse() method. If the pulse is 60 and the delay loop is 20 then every 1200 milliseconds something can be displayed in the scope. This can be a single value which will spike the scope by calling the getOscilloscope().setValue(int) method or

it can be a value series by calling the getOscilloscope().setValues(int[]) method. e.g. the Oscilloscope.HEARTBEAT field will draw a heartbeat like shape. The aforementioned method can lose values if you overflow the stack. The stack is circular meaning that if you push too many values in the method then the tail will overwrite the top.

If you want to draw something in "real time" then the pulse must be set to one. This will give you the opportunity to input a value every cycle.

Alternatively you can register a listener that gets notified if the stack is empty. An example of this can be found in Snippet4.

Please give it a spin. All feedback is appreciated, even extreme feedback.