Showing posts with label Microproperties. Show all posts
Showing posts with label Microproperties. Show all posts

Feb 21, 2010

Reading Properties Files on Android (Investigation for microlog4android)

Today I have investigated the possibilities to read properties files on Android. In microlog4android there is no configuration possibilities via file as it is today. The microlog4android development team feels that we need to re-write the configuration from scratch. There are many reasons for this decision, for example there is the Properties class available on Android while in Java ME we use microproperties. These are my findings about properties files on Android.

My first thought was to use the SharedPreferences class. My brain picked up this idea while using the SharedPreferences in another project. The SharedPreferences is used to read/write preferences for an Android application. The preferences are stored in an xml file that is put in the private directory structure of an application. You could edit the file by pulling it from the device or emulator using adb pull. After editing it you push it back using the adb push command. If you are using the Android Eclipse plugin you could use the file browser to do the same trick. But this is cumbersome to pull/edit/push the file and I do not really like to use XML for storing properties.

But how do we do it in microlog? The properties are stored in a properties file that is put in the JAR or by setting properties in the JAD file. Both are easily edited in Eclipse without no need to pull/push the file. The same goes for NetBeans. The properties file is bundled with the jar. Why not do the same on Android? Time to Google again! I found out that there was primarily two ways of doing this:
  1. Using the AssetManager
  2. Reading a raw resource
To test this I created a simple Android project in Eclipse and copied two microlog properties files. One was put in the /assets directory while the other was put in the /res/raw directory. The first thing that happened was that Eclipse complained about the naming of micrologV2.properties that was put in the /res/raw directory. It was kind enough to inform me that only [0..9][a..z] was allowed. Changing the capital V to a lower case v was simple. Now time to do some coding. The code for reading using the AssetManager looked like this:

Resources resources = this.getResources();
AssetManager assetManager = resources.getAssets();

// Read from the /assets directory
try {
    InputStream inputStream = assetManager.open("microlog.properties");
    Properties properties = new Properties();
    properties.load(inputStream);
    System.out.println("The properties are now loaded");
    System.out.println("properties: " + properties);
} catch (IOException e) {
    System.err.println("Failed to open microlog property file");
    e.printStackTrace();
}

The code is dead simple and thank God for the Properties class, although microproperties would do the trick. The second way to do it is as simple as the first approach. The code looks like this:

// Read from the /res/raw directory
try {
    InputStream rawResource = resources.openRawResource(R.raw.micrologv2);
    Properties properties = new Properties();
    properties.load(rawResource);
    System.out.println("The properties are now loaded");
    System.out.println("properties: " + properties);
} catch (NotFoundException e) {
    System.err.println("Did not find raw resource: "+e);
} catch (IOException e) {
    System.err.println("Failed to open microlog property file");
}

Notice that I omitted the code for getting the resources, since this was part of the first example. Both ways seems to be good. But what to choose? Using approach 1) has the following advantages from a microlog4android perspective:
  1. You are not limited to name your file with lower case letters only.
  2. It is possible to use a default file name if the user does not specify one.
But I probably will implement both solutions, since this gives the user a freedom to choose where to put the file. What do you think? Is there any other solutions that I have missed out?

Oct 14, 2009

Microlog Development $$$

I have often wondered how many hours I have spent on Microlog. It is countless hours of fun and sometimes frustration. But it is definitely worth it. I guess my wife beg to differ :) Anyway; there is a site called ohloh. This site collects data from the Internet about open source projects. It analyzes the code for a lot of things. For example it checks how well documented the code is. Another interesting metrics is the calculated development cost. Here is a list of the projects that I am involved in:
  • Microlog - $ 435,348
  • Microproperties - $ 2,955
  • Microinstall - $ 12,018
  • Voxtr - $ 29,963
Interesting reading. Please notice these figures are not only due to my work, but due to other peoples hard work as well. But is these values realistic or not? What do you think?

Apr 16, 2009

Microlog Recent Updates

It feels like I have spent ages on re-factoring the Microlog code. When I look in the rear mirror I see two things that has caused the slow progress. First of all there has been a lot of hard decisions that has been made. For example, how should the setup of the logging hierarchy work like? Should I use the same approach that is used in Log4j or should I invent a new and clever way? The answer is that I used the Log4j way, but adopted it to Microlog. The second problem has been the lack development time. Not much to say about that, Microlog is a project that I do on my spare time. Last but not least, everythings seems to take more time than originally planned.

But what has happened? The biggest change must be the new configuration. The configuration has been centralized and I use dependency injection to inject my properties into Microlog. The properties are fetched using Microproperties. This is in fact the first project where I have used Microproperties. This is good since I managed to improve the Microproperties source code along the way. I have spent many hours writing tests for the logging hierarchy and improving the code along the way. As always, I have commited the source code very often. As such the code in the source repository is very much in flux. Do not expect the API to be stable for yet a couple of weeks.

The coming days I plan to adopt all the Appender classes to comply to the new configuration. A nice side effect is that the code will be smaller. Also I will test out the HttpAppender. It is implemented as it is now, but not tested against a server. This is a much awaited feature. I am really looking forward to make this code available for all Microlog lovers.

Please be patient! I am certain that the new version of Microlog will be worth waiting for.

Mar 8, 2009

Microlog & Microproperties Updates

This weekend I decided to start the replacement of the old Microlog configuration with the new one; Microproperties. Ironically this work was to copy the file reading part from Microlog to Microproperties. When this was done and tested, I decided to do a new Microproperties release. This is the new V0.2.0 release. When this was done I added Microproperties V0.2.0 to Microlog.

However this weekend is approaching its end and I decided to do the first snapshot release of V2.0.0, before continuing my work. The Android extension is included in this release. My hope is that developers who prefer the Log4j API will find Microlog for Android an interesting alternative. Please download and try it out!

Feb 28, 2009

Microlog the Next Generation

Developing Microlog for the last couple of weeks has been like working with a strait jacket. A lot of the requested features would break the compatibility. Thus I had to postpone these requests and only implement simple features with low priority. On the other hand I wanted the V1.1.0 release to be really stable. This has been very frustrating. Yesterday I decided to release V1.1.0 in order to start my work on Microlog the next generation (V2.0).

The most important new features for Microlog V2.0 are
  • Client identification
  • New configuration
  • Re-send functionality
  • Improved packaging
The client identification is needed when you have several mobile client logging to the same server. To analyze the logs it is important to be able to identify each client with an unique id. I have not yet decided how the id will be generated. Perhaps the IMEI number? I will have to think about this a little bit more before deciding.

The configuration of Microlog is kind of old fashioned as it is today. Each appender and formatter is responsible for pulling its properties from the properties classes. A much more modern way ought to be dependency injection. Another problem today is that you have a dependency to the MIDlet class. One must remember that Microlog is possible to run in any CLDC environment, not just with the MIDP profile. In such situations it not possible use the properties classes that is used today, but you have to do the setup programatically. I plan to use the Microproperties classes as the default configuration option. However it should be possible to use any dependency injection framework like fallme.

All appenders that log to a server has no recovery function. Let us assume that a MIDlet logs and then crashes. When the MIDlet starts again it should try to re-send the log to the server. Another scenario is that the connection to the server is lost. The logging should continue and try to re-send when the connection is established again. It is all about making remote logging more robust.

Improved packaging is actually not a new feature, but I think it is an important thing to implement. The packaging of Microlog is a little bit confusing. There are many sub projects within Microlog, each with its own deliverable. My guess is that this could confuse any new user of Microlog.

Of course this list is subject to changes, but these are the main ideas as of today. This will give you some idea what is in store for you. Stay tuned for more information about the development of Microlog the next generation. Meantime you could download the all new fresh version of Microlog.

Nov 8, 2008

How I Created the Microsuite Website with Google Sites

I have been thinking about creating the Microsuite website for a long time. In fact it was several months ago that I registered the domain microsuite.org. The thing is that it does not amuse me very much to create websites. The latest couple of months has been filled with a lot of more interesting stuff. It has been very hard for me to prioritize between all the projects that I am involved in. There are still a lot of work with Microlog, there are many ideas that I want to try out for Microinstall, and I also want to be an active part of the Voxtr project. So on, and so fourth.

Just the other day I ran across Google Sites. It is a service that is built on top of a wiki software, formerly known as JotSpot. But you do not need to know any HTML at all :) At least that is what they claim on the Google site information pages. So this seemed like a perfect choice for me. I already knew what information I wanted to put on the site, so it was merely some hard work that was ahead of me. My experience it that computer related stuff does not always takes the time you wish it would do. Most of the time it takes much longer than expected, at least when you try something new. To my surprise this was an exception. I spent only one evening creating the first version. Rather nice!

For those of you that has not visited the Microsuite website, I can tell you a little bit about what it is. The Microsuite is a collection of the Micro projects that I am involved in. To this date they are; Microlog, Microinstall & Microproperties. Microlog is a logging tool for Java ME developers. Microinstall consists of some small classes that makes it easy to distribute your MIDlet(s). The Microproperties project has not yet delivered any code, but the intention is to create a good properties framework for Java ME. The plan is to create the code from scratch, with some inspiration from the properties classes found in Microlog. Please visit the Microsuite website to find out more about the different projects that are part of Microsuite.