I am using Logback to do most of my logging. I am using a third party library for some computation. Luckily the library uses slf4j, meaning it’s agnostic of the logging implementation.

The library caches two collections of items and depending on the circumstances the item I am looking for may be in any of the two collections. This is not important. What is important, is that the library for some reason logs an error if an item cannot be found in the first collection.

I wanted to get rid of this message because it was cluttering my logs. But I didn’t want to disable all logging from this specific class, because it may print some useful logs. I just wanted to get rid of this specific log. There is a way to do it Continue reading

Since Spring 3.2 it should be possible to use a qualifier in the “Async” annotation of a method, to indicate which specific executor to use. For example, I have the following class, that is supposed to collect the HTML from a website asynchronously:

HTMLFetcher Interface

TestHTMLFetcher Class

And the following excerpt from the context.xml file:

This didn’t work! I submitted 10 tasks to the executor and 10 thread, instead of 1 as I had instructed it had been created. I digged into the Spring code a bit and found the AnnotationAsyncExecutionInterceptor class that was doing tbe job of assigning tasks from methods annotated as async to executors. Putting  a breakpoint on its getExecutorQualifier method it became evident why it doesn’t work.

You need to annotate the interface method rather than the class with the:

annotation. In my example that is the getHTML method of the HTMLFetcher interface. It now works. I am not sure if it was done on purpose (i.e. if it’s part of the specification). I don’t have time to read the related documentation or search the Spring Jira. However, I would assume that the right place to put the annotation is the implementation. I may want to have two implementations of the same method, one decorated with “Async” that will be asynchronously executed and another without any annotation that will be synchronously executed.

Recently I’ve been playing around with a webbrowser control to automate my interaction with a website for testing purposes. I am using C# and DOT NET.

I found it a bit difficult to change the value of an HTML combobox (i.e. dropdown), but as it turns out it’s rather easy.I used the following code to change the value of a combobox named: “test” to the value 12.

This code was used for the following HTML:

Finally the following code was required to press the “Submit” button.
 

I recently wanted to get the usage of my CPU in C#. After searching the internet I found a way of doing it using the PerfomanceCounter class. I made a couple of changes and I created the following class, which seems to work.

Using the statement: SystemUtils.getCpuUsage() you should be able to get an integer number showing the CPU usage.

I tried using the Apache XMLConfiguration to save the settings of an application I am developing to XML format. When I used it with Java 1.5 it all worked perfectly; however if I tried using it with Java 1.6 I was getting the following exception.

After doing some search on google I found that this can be a problem with the xerces XML library (xercesImpl.jar). Checking the 3rd party libraries I am using in my project, I found a library that was using and distributing an earlier version of xercesImpl.jar.

I downloaded the latest version (2.91) of xercesImpl.jar from the Apache xerces project (http://xerces.apache.org/mirrors.cgi#binary) and replaced in the 3rd party library I was using the xercesImpl.jar file with the one I downloaded. Now everything seems to work fine, even in Java 1.6.  🙂

This is another script I found while cleaning up my hdd. Now, we all know that java .class files can be decompiled to (a version) of their source code. The first java decompiler out there is jad. I tried to decompile some of my class files using jad.exe, but I couldn’t find a way of decompiling multiple .class files at the same time. So instead of digging into the documentation, I decided to quickly create a script that allows me to decompile a number of .class files at the same time.

Here’s how it works! I created a VBScript that goes through a directory (and subdirectories) of .class files and creates a dos batch file. The dos batch file can now be used to run and actually decompile all the .class files!

The VBscript can be found under this link: Decompile_vbs.

You need to edit it and change the paths to the .class and source directories.

When you execute this file, it will create a dos batch file like this one: Example_decompile.batPlease note this batch file will be generated under the directory where jad.exe exists! You can now run this batch file, which will actually decompile the .class files.

I recently wanted to redirect the output of Log4j to a JTextPane, so as to output messages to the JTextPane using a different color depending on the severity.

I spent some time searching for information and I quickly put together a small example. The following screenshot shows the output.

screenshot.jpg

The source code is available here.

Alloy Analyzer v4.0 has been out for quite a while. Alloy v4.0 is an extension of the Alloy v 3.0 language (http://alloy.mit.edu/alloy4/quickguide/a4.html). More specifically parts of the concrete syntax of the language has changed (i.e. when invoking a predicate from within another predicate we now have to use brackets “pred1 [param1,param2,..]” instead of parentheses “pred 1(param1, param2,..)“. Also some of the properties of the language have changed (in MDA terms constraints on the metamodel, or well-formedness rules have changed). For example in Alloy 4 you are able to overload predicates, functions and fields. These are relatively small changes and it should be easy to accommodate them in UML2Alloy.

However, Alloy v4.0 has been developed from scratch and it is based on the kodkod model finder. The AST implementation has changed substantially and the convenience methods provided on the AST model elements are fine tuned for the Alloy compiler. For example Signature constructors are private and I couldn’t find a way to update the properties of Signatures (i.e. the Multiplicity of the Signature) after a Signature has been created.

Of course this is perfect if you have an Alloy model and you just want to parse, but not very convenient if you use an MDA approach to instantiate Alloy AST objects. For example in UML2Alloy you can change the Multiplicity of a Signature (i.e. change from set to some to enforce that some Signature instances will exist in the model). If you don’t have access to the Multiplicity attribute of the Signature class, after the object has been created, complicates the situation.

Moreover the AST class elements have been defined as final so there is no way you can override the Alloy v4.0 AST classes.

So, I spent almost 1 day evaluating the situation and trying to find a solution. One solution would be to create my own implementation of Alloy’s AST. Another would be to create wrapper classes of Alloy’s AST that will have pointers to the actual Alloy implementation.

Then I stepped back and thought about the siltation. Well, I already have a rather stable implementation that uses Alloy v3.0 AST. In Alloy v4.0 the AST has NOT changed. Just the concrete syntax. So the solution is easy.

Currently in UML2Alloy after the Alloy AST objects have been generated by SiTra, a visitor is used to create a text file that contains the Alloy model. So, all I have to do is use another visitor and override the methods that create the part of the model for which the concrete syntax has changed.

Today I finished a beta version of a simple java program that collects the statistics from a subversion repository. I have created a website for the program: http://www.freewebs.com/subvstats/

It currently works by checking the whole history of the repository, finding how many lines have been added/removed in each file by using the “svn diff” command and creating an HTML report.
A sample of the report can be found here: http://www.freewebs.com/subvstats/samplereport.html

The program should work for relatively small repositories. As soon as I have time I will document it more and generate more statistics. And yes, I am thinking of making it opensource, but not in its current state. I first need to find some time to document the code properly and have a stable version.

Keywords: Subversion, statistics, package, tool, program, software, java, subvstats.