Wednesday, July 29, 2015

New MoVirt release - introduction of augmented reality

  I decided to date this post for MoVirt release and since release has been delayed this post is delayed too.

  But now 0.2 beta version of MoVirt is available to everyone, and I'm very happy about this because the main feature introduced in this version is my work on augmented reality! You can check how does it work in this video:

  Also you can download latest test build for Android from here if you are using oVirt or interested in virtualization. This is unsigned package, so you need to copy .apk file into your android device, enable "Unknown sources" in Settings and install .apk file.

  To prepare this release I've spent three weeks fixing various bugs, stability and usability issues along with refactoring and cleaning some parts of the code. And there were two "interesting" tasks which annoyed me a lot.

  The first task was about android synchronization. We noticed that automatic synchronization with oVirt server happens only once a day and this may be not very good behavior for monitoring software, because you can easily skip some important events if you are relying on notifications from moVirt. According to android SDK documentation:
When a network connection is available, the Android system sends out a message every few seconds to keep the device's TCP/IP connection open. This message also goes to the ContentResolver of each app. By calling setSyncAutomatically(), you can run the sync adapter whenever the ContentResolver receives the message.
"every few seconds", but this is not working in moVirt for some reason. People at says that android documentation misguiding in some topics especially about synchronization, and I found the only working solution is to enable periodic sync with fixed custom interval which is not recommended. There is one more solution (which is possibly the best) is to use push-notifications via GCM, but this is far-far future plans which requires modification also in oVirt server.

  The second task was about proper storing time in database. Since we have information at what time connection to server was lost and when was the last successful synchronization, we need to store this information in database to share between activities and sessions (detailed about necessity of using database in previous post). My first thought was to use java.sql.Timestamp class because it specially designed to store time and date in database. As I understand this class contains Unix Time which is UTC time and converts to properly formatted string to store in database.
public String toString()
Formats a timestamp in JDBC timestamp escape format. yyyy-mm-dd hh:mm:ss.fffffffff, where ffffffffff indicates nanoseconds.
Everything was looking fine until I realized that time in database stored in local time zone! And if you change time zone in your device it will show wrong time. Who in the world needs to store date and time in database in local time zone? And why does this Timestamp class do this conversion implicitly in toString() function with no obvious way to avoid this conversion? Ok, there are LOTS of other classes to work with time in java, and I decided to find some ready to use code snippets to store time as string in database in UTC... I've spent three days trying different solutions and all of them was wrong and shows the wrong time, because every class in Java performs implicit time zone conversion even if it is not needed and not obvious for this action. So I stopped to store time in database just as Unix Time and convert to string only while displaying and this seems to work.

1 comment: