2010-11-17
So I thought ...
... that I was about to start up this site again. But, to no avail. There has been so much to do and more is on its way. Don't get me wrong, it has been a very exciting time and there is more, much more, to look forward to.
2010-03-09
Started up again ...
Yes, I've started blogging again. Well, see how much time I've got on my hands to do so. The latest projects has had very tight schedules, so there hasn't been much time left for activities like blogging end such. As I am attending EclipseCon for the first time, I might take the opportunity to do some "reporting". We'll see.
2008-12-08
Native code, JNI
Recently I posted on how to incorporate native code in OSGi bundles. Well, some questions surface now and then, particularly "then" nowadays (thanks to the recent posting), regarding the actual native code production.
To start with there is a good tutorial on the subject provided by Sun. Secondly, and probably a bit harder to obtain, is a very good book on the subject: Essential JNI - Java Native Interface, by Rob Gordon (ISBN 0-13-679895-0). It seems to have gone out of print. That is a pity as it is considered one of the best books on the subject. It explains all parts of JNI well, and it has very good examples.
But, how do you get about dealing with native code? What pitfalls are there? Rules of Thumb? Here is a check list for you, hope it is of help when you are about to select the path ahead:
Despite what I say (write) in the bullets above I am an advocate of JNI. Every Java assignment I've had has involved some work using JNI - there has been no exceptions so far. JNI is a powerful technology and correctly used it will leverage your project.
To start with there is a good tutorial on the subject provided by Sun. Secondly, and probably a bit harder to obtain, is a very good book on the subject: Essential JNI - Java Native Interface, by Rob Gordon (ISBN 0-13-679895-0). It seems to have gone out of print. That is a pity as it is considered one of the best books on the subject. It explains all parts of JNI well, and it has very good examples.
But, how do you get about dealing with native code? What pitfalls are there? Rules of Thumb? Here is a check list for you, hope it is of help when you are about to select the path ahead:
- When do I need to employ JNI? Answer: Never!
Well, in 99,9 % of the cases you are better off not using JNI. I.e. native code does not always execute faster - running Java code in the HotSpot JVM can actually be equally as fast or sometimes even faster! Further; check to see if there is another solution, open source maybe, that does what you need. They might have fixed the interfacing chore for you... - Ok, but you've got some legacy stuff on your hands. Now do you need JNI? Yes, maybe, but there might be other techniques you can employ. Have you checked pipes, shared memory or sockets? Please keep in mind that loading a shared library into a process space might crash the process if some piece of code in the library crashes. You are outside the Java Sandbox, but still within the same process space. The other techniques mentioned have the library execute in a separate process, then you have a problem of checking liveliness instead.
- You are about to interface and use COM-components or ActiveX Controls on Windows. Required to learn everything about COM, DCOM, ActiveX, etc? No, not really. Ok, knowledge is no burden, as every abstraction leaks you should at least learn the basics on COM. For the interfacing problem, as mentioned before, somebody else has already taken care of the JNI part you in this case: e.g. the COM - Java Bridge JACOB, and others...
- You are still here? Ok, maybe JNI is the solution for you. Are there any pitfalls? Oh yes! There are plenty, in most cases we are talking about writing code in C or C++ here. As some of you already are aware of, it is much easier to create code that will malfunction in C/C++ than Java! Do not get me wrong here; C and C++ are perfectly ok languages too, it just that you have to take more aspects into consideration and be careful of pointers, casts, void*, etc.
Then, there is loading of the library, on Linux/Unix check your LD_LIBRARY_PATH, om Win32 the PATH variable. That also goes for those libraries your library depends on. - Other considerations:
- Strings - in Java a String instance is an object, needs to be converted on the native side using the special GetStringUTFChars function. It is released using the ReleaseStringUTFChars whendone with.
- Exceptions - if calling Java code from the native side, under some circumsances you need to check for possible exceptions thrown, or you might run into trouble.
- If you are into C++, using the bridge design pattern can be a powerful approach; Java classes are mirrored on the native side implementation in the C++ classes. Have them comminucate through JNI.
Despite what I say (write) in the bullets above I am an advocate of JNI. Every Java assignment I've had has involved some work using JNI - there has been no exceptions so far. JNI is a powerful technology and correctly used it will leverage your project.
2008-12-06
Christmas beers and ales sampling
A couple of days ago we had a small gathering to sample some of the beers and ales for this Christmas. We had a good time and there where a number of tasty beers. 13 to be precise (Magnus took notes, so I'm not fully responsible...):
- Stone Old Guardian (USA, 11,26%, 70 cl) Full, some bitterness - Nice!
- Saint Landelin (France, 6,8%, 75 cl) sweet, artificial flat tase, everybody poured this one in the drain!
- Samuel Adams Winter lager (USA, 5,6 %, 35,5 cl) good likable taste, most everything in it, not that full taste, goes good with the food. A favorite!
- N'Ice Chouffe (Belgium, 10%, 75 cl) Nice full taste, typical Belgian, maybe a bit of sweetness. Long after-taste.
- Token Julefröjd (Sweden, 4,9 %, 50 cl) Strong taste of coffee, sour, no bitterness at all! Is this really beer - disappointment! This brewery usually does much much better.
- Jämtlands Julöl (Sweden, 6,5 %, 50 cl) Ok, we're back in business! Precisely right on bitterness and sweeness, well balanced, goes very well with the food on the table. Very nice!
- Gouden Carolous Chritmas (Belguim, 10,5 5, 33 cl) Ohhh! this one is really good! Precise balance in bitterneess, sweetness, dryness, etc. Full, nice taste, long full after-taste. Maybe the best ale tonight?
- Nøgne Ø God jul (Norway, 8,5%, 50 cl) Some notes of coffee, a litle bit of bitterness, quite good. We like it.
- Dugges Rudolf Ren Ale (Sweden, 7%, 50 cl) Chemical, acrid taste. What is this.?.. no, it is no favorite of ours.
- Corsendonk Christmas Ale (Belguim, 8,5 %, 25 cl) Nice, not so full as Gouden Caroulus or Chouffe, but as it is slightly "thinner" it probably goes well will the stuff on the Christmans table. Why the weird size (25 cl) of the bottle??
- Gulden Draak Vintage (Belguim, 7,5 %, 33 cl) The chock of the evening. Gulden Drrak is a favorite, i.e. the regular Gulden Draak. What this is we don't know. Magnus Baught it while in Belguim. Well, it wont be purchased again, it has a sour acrid vinegar tone, really a disappointment.
- Regal Christmas (Belguim, 8,1 %, 33 cl) Nice full taste, a tone of spice. Very very nice!
- Gordon Xmas (Belguim, 8,8%, 33 cl) Almost as the previous, slightly different tone, long after-taste.
Ok, how did we rate them? The order after some discussion, we came to the following conclusion:
- Gouden Carolous Christmas
- Regal Chrsitmas
- >Gordon Xmas
- Jämtlands Julöl
- N'Ice Chouffe
- Stone Old Guardian
- Nøgne Ø God Jul
- Samuel Adams Winter Lager
- Corsendonk Christmas Ale
After that there where really none we liked. So we did not grade them... Further, there are of course several good ones we haven't tried yet, e.g. Nils Oscar Julöl and Kalas Julöl, Wisby Julöl, Anchor Christmas Ale, etc.
Etiketter:
beer ale christmas sampling tasting palate
2008-12-04
Bundle-NativeCode in the OSGi manifest
OSGi is a pretty straight forward and quite easy to use technology. As long as you are doing the thing Java programming language. But, what happens when you start to involve other implementations, i.e. native code (most often compiled C/C++ source). On Windows these libraries are known as Dynamic Link Libraries, or DLL for short. Linux and Unix clones are called shared object libraries and has the .so suffix.
What about Mac OS X? Well, there is also so-files, but I've also encountered so called dynlib:s. Anyhow, do not despair, all these are nicely handled by OSGi. I.e. an OSGi framework will happily load these libraries into the JVM process space and thus make them available to whatever Java class that is about to call them. If you are about to produce some native code, check out the tutorial at Sun.
Ok, you have your Java class defining the native methods, generated the .h-file from it and done the mandatory HelloWorld thing on the native side, also got the System.loadLibrary call right and everything. It works all nice and peachy.
So, now what? How to get it to work encapsulated within an OSGi bundle? as you've got all teh basic stuff in place, it is pretty much a walk in the park. Well, all you actually need is to declare your newly created native library in the bundle manifest and also declare which library goes with which operating system. Yes, you can bundle several libraries for various operating systems in the same bundle and the framework load the correct one depending on the declaration in the manifest.
So how does this portion of the manifest look like? Here is a simple example of declaring a DLL (Windows) named "mylib", located in a directory named "lib":
Please note the placement of the semicolons (';'). That is quite important.
But; what if I've got several DLL:s, or libraries, in my project that need to go into the same bundle? Well, that is not a problem. What you need to keep in mind is the placements of the semicolons.
So, expanding the above simple example with two DLL:s (mylib1 and mylib2) for the same platform it will look like this:
Ok, everything is nice and peachy. Next iteration of the projects adds a whole bunch of requirements, one is regarding the support for yet another platform: Linux. Can I easily add that?
Sure! Produce the necessary native libraries for the new platform, add them into your project and finally - before launching the debugger - add some more lines to the manifest:
See the comma (',')? Each "block" is separated by a comma. As you also might have guessed by now is that fact that not only is it possible to qualify on operating system. You can also load different libraries depending on processor architecture, on the same operating system, and operating system version. Further, I haven't discussed another option that is quite powerful; the filter capability. It is also possible to qualify on basically anything, e.g. which windowing system is present and thus load an appropriate library dependent on that.
Maybe I'll discuss how to make use of the filter capability in a future posting. Anyhow, I do recommend that you download and read the OSGi specification from osgi.org, it is one of the best specifications when it comes to readability I've come across. The section on Bundle-NativeCode is very worth studying, it discusses the above and more ...
What about Mac OS X? Well, there is also so-files, but I've also encountered so called dynlib:s. Anyhow, do not despair, all these are nicely handled by OSGi. I.e. an OSGi framework will happily load these libraries into the JVM process space and thus make them available to whatever Java class that is about to call them. If you are about to produce some native code, check out the tutorial at Sun.
Ok, you have your Java class defining the native methods, generated the .h-file from it and done the mandatory HelloWorld thing on the native side, also got the System.loadLibrary call right and everything. It works all nice and peachy.
So, now what? How to get it to work encapsulated within an OSGi bundle? as you've got all teh basic stuff in place, it is pretty much a walk in the park. Well, all you actually need is to declare your newly created native library in the bundle manifest and also declare which library goes with which operating system. Yes, you can bundle several libraries for various operating systems in the same bundle and the framework load the correct one depending on the declaration in the manifest.
So how does this portion of the manifest look like? Here is a simple example of declaring a DLL (Windows) named "mylib", located in a directory named "lib":
.
.
Bundle-NativeCode: lib/mylib.dll ;
osname=Win32 ;
processor=x86
.
.
Please note the placement of the semicolons (';'). That is quite important.
But; what if I've got several DLL:s, or libraries, in my project that need to go into the same bundle? Well, that is not a problem. What you need to keep in mind is the placements of the semicolons.
So, expanding the above simple example with two DLL:s (mylib1 and mylib2) for the same platform it will look like this:
.
.
Bundle-NativeCode: lib/mylib1.dll ; lib/mylib2.dll ;
osname=Win32 ;
processor=x86
.
.
Ok, everything is nice and peachy. Next iteration of the projects adds a whole bunch of requirements, one is regarding the support for yet another platform: Linux. Can I easily add that?
Sure! Produce the necessary native libraries for the new platform, add them into your project and finally - before launching the debugger - add some more lines to the manifest:
.
.
Bundle-NativeCode: lib/mylib1.dll ; lib/mylib2.dll ;
osname=Win32 ;
processor=x86,
lib/libmylib1.so ; lib/libmylib2.so ;
osname=linux;
processor=x86
.
.
See the comma (',')? Each "block" is separated by a comma. As you also might have guessed by now is that fact that not only is it possible to qualify on operating system. You can also load different libraries depending on processor architecture, on the same operating system, and operating system version. Further, I haven't discussed another option that is quite powerful; the filter capability. It is also possible to qualify on basically anything, e.g. which windowing system is present and thus load an appropriate library dependent on that.
Maybe I'll discuss how to make use of the filter capability in a future posting. Anyhow, I do recommend that you download and read the OSGi specification from osgi.org, it is one of the best specifications when it comes to readability I've come across. The section on Bundle-NativeCode is very worth studying, it discusses the above and more ...
2008-12-03
The history of computer hardware
Reading Wired sometimes render some interesting things; like this one - The history of PC hardware. Fascinating stuff! And, it wasn't that long ago. I actually came across one those early mobile computers, with a detachable keyboard.
Further, I am searching the Internet for articles and pictures on the early versions of the AXE-telephone system, here is another story. I used work with it during the 80:s and 90:s. In the beginning the so called man-machine interface consisted of a number of teletype printer with paper. There could also be VT terminals sometimes. Anybody who could share any knowledge on where to find this stuff?
Further, I am searching the Internet for articles and pictures on the early versions of the AXE-telephone system, here is another story. I used work with it during the 80:s and 90:s. In the beginning the so called man-machine interface consisted of a number of teletype printer with paper. There could also be VT terminals sometimes. Anybody who could share any knowledge on where to find this stuff?
2008-12-01
Shopping at Wal-Mart can be dangerous
You've probably heard the saying "shop until you drop", but being like this!
People are so inclined to consume they care not for others. I've read somewhere, long ago, in a science fiction novel about a society where the rich where those who could afford to live a simple life. While, the poor where forced to consume. At the time I thought the story to be outrageous. But, everyday I see evidence that the author, whoever it is, where quite on spot. That's scary ...
Anybody out there who might know which author? I believe him (yes it's a he) to be one of the more famous American SF novelists.
People are so inclined to consume they care not for others. I've read somewhere, long ago, in a science fiction novel about a society where the rich where those who could afford to live a simple life. While, the poor where forced to consume. At the time I thought the story to be outrageous. But, everyday I see evidence that the author, whoever it is, where quite on spot. That's scary ...
Anybody out there who might know which author? I believe him (yes it's a he) to be one of the more famous American SF novelists.
2008-11-30
Want to get somewhere in life?
I am really amazed by how confused people get when I tell about my goal in life. Especially when they start to ask how. And, why I am not financially focused, a great deal of people seems to be aimed at acquiring as much monetary funds as possible. Well, nothing wrong in getting large amounts of money, on the contrary, I wouldn't say no to it.
But, as great many seems to believe they will be happy once they earn their first million, or so. The big new for those folks; there is no happiness in money, it will make you comfortable though.
What you have to do; you have to make up your mind of what you want. I'll repeat that: You have to make a decision of What You Want! Not what somebody else wants you to want, but what You really want. It can be anything, as long as it is important to you; may it be large amounts of money, may it be a new car, a certain position at your company, a relationship, the apartment/house you are looking for, more time on your hands, a trip to somewhere you've always wanted to go, write that book, start painting, writing music, etc.
But, how do I know what I want? If you do not have a clear picture, start to think about, dream about, use you imagination. If you encounter something that really fires you up - well, there you have it! Apparently that is something that stirs your emotions! That is important, it is much easier to set your goal if you feel strongly about it.
Now, when you know what you want - make a decision; when will yo acquire this of our desire? Do not worry about how. It will come you.
If you think about our goal, often, you are sort of re-programming your sub-conscious, i.e. you will both, eventually, consciously and unconsciously work toward your goal. Sounds simple enough? Well, keep in mind that things take time, you will achieve your goal - you have to make many small, and sometimes big, steps every day. The important thing here is to:
1. Make a decision on what you want
2. Once decided, start at once working towards it
3. Each and every day you will achieve something taking you closer to your goal
4. Never ever ever give up! You will run into hurdles, success is measured by how you handle them
... remember, winners learn from mistakes, hurdles, and then moves on. Losers, they just give up as soon as they run into trouble.
P.S. You might ask: Is this somehow related to computers? The answer is: Yes! Very much so! By repeatedly trying out new ways of solving a problem the computer will eventually "give up". We humans as more persistent and smarter than our machines. Well, at least for now ...
P.P.S There is no problem that can withstand the accumulated assault of sustained Thinking!
But, as great many seems to believe they will be happy once they earn their first million, or so. The big new for those folks; there is no happiness in money, it will make you comfortable though.
What you have to do; you have to make up your mind of what you want. I'll repeat that: You have to make a decision of What You Want! Not what somebody else wants you to want, but what You really want. It can be anything, as long as it is important to you; may it be large amounts of money, may it be a new car, a certain position at your company, a relationship, the apartment/house you are looking for, more time on your hands, a trip to somewhere you've always wanted to go, write that book, start painting, writing music, etc.
But, how do I know what I want? If you do not have a clear picture, start to think about, dream about, use you imagination. If you encounter something that really fires you up - well, there you have it! Apparently that is something that stirs your emotions! That is important, it is much easier to set your goal if you feel strongly about it.
Now, when you know what you want - make a decision; when will yo acquire this of our desire? Do not worry about how. It will come you.
If you think about our goal, often, you are sort of re-programming your sub-conscious, i.e. you will both, eventually, consciously and unconsciously work toward your goal. Sounds simple enough? Well, keep in mind that things take time, you will achieve your goal - you have to make many small, and sometimes big, steps every day. The important thing here is to:
1. Make a decision on what you want
2. Once decided, start at once working towards it
3. Each and every day you will achieve something taking you closer to your goal
4. Never ever ever give up! You will run into hurdles, success is measured by how you handle them
... remember, winners learn from mistakes, hurdles, and then moves on. Losers, they just give up as soon as they run into trouble.
P.S. You might ask: Is this somehow related to computers? The answer is: Yes! Very much so! By repeatedly trying out new ways of solving a problem the computer will eventually "give up". We humans as more persistent and smarter than our machines. Well, at least for now ...
P.P.S There is no problem that can withstand the accumulated assault of sustained Thinking!
2008-11-29
JavaOne call for papers & Christmas Ales
If you haven't noticed, the JavaOne call for papers opened November 19:th. It closes on December 19:th, so hurry up submitting those great ideas of yours! Myself, and some collegues, has so far come up with a couple. We'll see if the content team likes any of them.
Anyhow; it is during this time of year, the season, when the Christmas Ales show up. Actually, chistmas beers and ales are also released on the 19:th of November. Coincidence ..?..
Went out today and got myself a couple of nice ones, like Corsendonk Christmas Ale (having one while writing this post), Jämtlands Julöl (from northern Sweden - really good!), Tokens Julfröjd (from a microbrewery on Öland) and, of course, N'ice Chouffe - one of the best. Unfortunately the liquor store does not carry Gouden Carolous Chistmas any more, the very best one in my opnion.
While at JavaOne, don't miss Thirsty Bear, brewing their own beers and serving Spanish tapas (!).
Anyhow; it is during this time of year, the season, when the Christmas Ales show up. Actually, chistmas beers and ales are also released on the 19:th of November. Coincidence ..?..
Went out today and got myself a couple of nice ones, like Corsendonk Christmas Ale (having one while writing this post), Jämtlands Julöl (from northern Sweden - really good!), Tokens Julfröjd (from a microbrewery on Öland) and, of course, N'ice Chouffe - one of the best. Unfortunately the liquor store does not carry Gouden Carolous Chistmas any more, the very best one in my opnion.
While at JavaOne, don't miss Thirsty Bear, brewing their own beers and serving Spanish tapas (!).
Subscribe to:
Posts (Atom)