<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7414681341906437667</id><updated>2011-11-27T15:30:22.805-08:00</updated><category term='Swing'/><category term='AOP'/><category term='scripting'/><category term='VisualVM'/><category term='Open source'/><category term='OSGi'/><category term='Java'/><category term='Chameleon project'/><category term='Heap analysis'/><title type='text'>Just an ordinary Java blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>19</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-1059606607173353319</id><published>2010-03-07T12:59:00.000-08:00</published><updated>2010-03-07T14:22:40.827-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VisualVM'/><title type='text'>VisualVM and JFreeChart</title><content type='html'>&lt;div style="text-align: justify;"&gt;I work in an European project in which we are developing a set of &lt;a href="https://visualvm.dev.java.net/"&gt;VisualVM&lt;/a&gt; plugins to construct a management application. It's the same principle I've used on the &lt;a href="http://ordinaryjava.blogspot.com/2009/06/visualvm-osgi-plugin.html"&gt;VisualVM OSGi plugin&lt;/a&gt;: a set of MBeans in the application, and a nice GUI in the VisualVM side that uses JMX to access the MBeans.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;We used JFreeChart to visualize (in the VisualVM) data captured by sensors (in the managed application). &lt;/div&gt;&lt;div style="text-align: justify;"&gt;I had some minor problems for using JFreeChart due to class loading that I detail next.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Importing JFreeChart the wrong way&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;If you create a regular Netbeans Module project you won't be able to import libraries. So you need to create a Module Suite (File &gt; New Project &gt; Netbeans Module &gt; Module Suite), and then add the Module project of you plugin to that Module Suite (see picture below).&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_RRFIUjuwzn4/S5QWxwL_zII/AAAAAAAAAyY/Bo-xbb6Cnlw/s1600-h/addexistingmodule.JPG"&gt;&lt;img src="http://1.bp.blogspot.com/_RRFIUjuwzn4/S5QWxwL_zII/AAAAAAAAAyY/Bo-xbb6Cnlw/s320/addexistingmodule.JPG" border="0" alt="" id="BLOGGER_PHOTO_ID_5446002893402393730" style="text-align: justify;display: block; margin-top: 0px; margin-right: auto; margin-bottom: 10px; margin-left: auto; cursor: pointer; width: 232px; height: 225px; " /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt; Then, you can go right click the project, select Properties &gt; Libraries and get the below pop up window to add your library.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 238); -webkit-text-decorations-in-effect: underline; "&gt;&lt;img src="http://2.bp.blogspot.com/_RRFIUjuwzn4/S5QXj3l0vMI/AAAAAAAAAyg/4S9bUpilS74/s320/addlibrary.JPG" border="0" alt="" id="BLOGGER_PHOTO_ID_5446003754383228098" style="text-align: justify;display: block; margin-top: 0px; margin-right: auto; margin-bottom: 10px; margin-left: auto; cursor: pointer; width: 320px; height: 234px; " /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span"  style="color:#0000EE;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); "&gt;What I initially did was importing in two separate steps. First the JFreeChart library, and then JCommons which is necessary for JFreeChart. After executing my code I got a &lt;i&gt;java.lang.ClassNotFoundException: org.jfree.date.MonthConstants. &lt;/i&gt;Weird. Everything was imported. Well, aparently we had some classloading visibility issues here.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;As previously described, I had configured the following dependencies:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;MyModule -&gt; JFreeChart&lt;/div&gt;&lt;div style="text-align: justify;"&gt;MyModule -&gt; JCommons&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Doing it the right way (well, at least in a way that works)&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Adding the libraries two steps gives me two Library Wrapper Modules, which will belong to the same Module Suite. But when I added both libraries at once (resulting in just one Library Wrapper Module) and tried executing the JFreeChart code, my chart appeared and I had no longer a ClassNotFoundException. Thus, the depencency became:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;MyModule -&gt; {JFreeChart, JCommons}&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span"  style="color:#0000EE;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); "&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div&gt;I believe the above issues are the same for any other Netbeans RCP application when trying to use JFreeChart.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Just to have a sample of the nice charts that you can add, here goes a screenshot with some example charts. Library download and more info at the &lt;a href="http://www.jfree.org/"&gt;JFreeChart website&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_RRFIUjuwzn4/S5QXx1sB-OI/AAAAAAAAAyo/xpUsAQdHwck/s1600-h/chartsvisualvm.JPG"&gt;&lt;img src="http://3.bp.blogspot.com/_RRFIUjuwzn4/S5QXx1sB-OI/AAAAAAAAAyo/xpUsAQdHwck/s400/chartsvisualvm.JPG" border="0" alt="" id="BLOGGER_PHOTO_ID_5446003994390558946" style="display: block; margin-top: 0px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-align: center; cursor: pointer; width: 400px; height: 366px; " /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-1059606607173353319?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/1059606607173353319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=1059606607173353319' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/1059606607173353319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/1059606607173353319'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2010/03/visualvm-and-jfreechart.html' title='VisualVM and JFreeChart'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_RRFIUjuwzn4/S5QWxwL_zII/AAAAAAAAAyY/Bo-xbb6Cnlw/s72-c/addexistingmodule.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-4908091760700326977</id><published>2009-11-22T14:40:00.000-08:00</published><updated>2009-11-22T15:04:20.386-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Chameleon project'/><category scheme='http://www.blogger.com/atom/ns#' term='VisualVM'/><title type='text'>VisualVM OSGi Plugin available at the plugins center</title><content type='html'>&lt;div style="text-align: justify;"&gt;The VisualVM OSGi plugin has become part of the &lt;a href="http://wiki.chameleon.ow2.org/"&gt;OW2 Chameleon project&lt;/a&gt;, which tries to deliver a set of pluggable components for OSGi frameworks, allowing to create sorts of lightweight OSGi-based application servers with just the needed functionality. The VisualVM OSGi plugin was the initial step for a set of &lt;a href="https://visualvm.dev.java.net/"&gt;VisualVM&lt;/a&gt; plugins that will be provided in the Chameleon project.&lt;br /&gt;&lt;br /&gt;Recently Jiri Sedlacek and Tomas Hurka have proposed to add a link to the OSGi plugin in the &lt;a href="https://visualvm.dev.java.net/uc/release12/updates.xml.gz"&gt;VisualVM 1.2 plugins center&lt;/a&gt;. Now you can install the plugin  from the &lt;a href="https://visualvm.dev.java.net/download.html"&gt;VisualVM&lt;/a&gt; 1.2 or above, in the menu Tools &gt; Plugins. Don'f forget to download and install the appropriate OSGi bundle  in your OSGi application (this is how the plugin will get the info about the OSGi application).&lt;br /&gt;Detailed installation instructions can be found on the &lt;a href="http://wiki.chameleon.ow2.org/xwiki/bin/view/Main/AdminTools"&gt;plugin page&lt;/a&gt; in Chameleon's wiki&lt;br /&gt;&lt;br /&gt;Many thanks to my thesis advisor, Didier Donsez, for the idea of the plugin.&lt;br /&gt;Thanks to Clément Escoffier, for inviting the VisualVM OSGi Plugin to the Chameleon project.&lt;br /&gt;Thanks to Jiri and Tomas for all the tips, testing and for adding the plugin to the VisualVM plugins center, and thanks in advance for anyone who would eventually use the tool and hopefully provide any comments for improving it.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-4908091760700326977?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/4908091760700326977/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=4908091760700326977' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/4908091760700326977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/4908091760700326977'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2009/11/visualvm-osgi-plugin-available-at.html' title='VisualVM OSGi Plugin available at the plugins center'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-5078854159952869624</id><published>2009-10-16T13:45:00.000-07:00</published><updated>2009-10-16T14:26:13.419-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><title type='text'>Meeting of the OSGi users group France</title><content type='html'>&lt;div style="text-align: justify;"&gt;The 9&lt;span style="font-size:85%;"&gt;th&lt;/span&gt; meeting of the OSGi users group France took place today, at the &lt;a href="http://www.grenoble-universites.fr/"&gt;Grenoble University Campus&lt;/a&gt;. People from different places in France have attended. The central theme of the talks was about &lt;span style="font-style: italic;"&gt;isolation&lt;/span&gt;, mostly concentrated in recent research efforts. In the morning we had three talks:&lt;br /&gt;&lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Laurent Daynès&lt;/span&gt;, researcher from &lt;a href="http://www.sun.com/"&gt;Sun Microsystems&lt;/a&gt; at Grenoble, gave the talk “Lightweight Isolation with a multi-tasking JVM” where he talked about motivations for multitasking, lightweight isolation in the JVM (obviously! It is the presentation's title), &lt;a href="http://jcp.org/en/jsr/detail?id=121"&gt;Java Isolates&lt;/a&gt;, the Multitasking Virtual Machine (MVM) and a lot of interesting stuff concerning isolation.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Nicolas Geoffray&lt;/span&gt;, a fresh PhD from &lt;a href="http://www.upmc.fr/"&gt;Université Paris 6&lt;/a&gt;, presented the "I-JVM: a Java Virtual Machine for Component Isolation in OSGi", which he developed during his thesis under the co-direction of Gaël Thomas who was also there. He shows how he implemented lightweight Java Isolates in the VM level, and how he associated them with OSGi bundles allowing the safe termination and fine grained resource control of bundles.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Kiev Gama &lt;/span&gt;(sounds familiar to me...) presented the initial efforts of my PhD’s first year, under the direction of &lt;a href="http://membres-liglab.imag.fr/donsez/"&gt;Didier Donsez&lt;/a&gt;, in the talk entitled "Towards Dynamic Component Isolation in a Service Oriented Platform". In our work we provide a sort of fault contained sandbox for OSGi components by means of Java Isolates.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;In the afternoon, four more talks:&lt;br /&gt;&lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;My ex-labmate on the &lt;a href="http://www-adele.imag.fr/"&gt;Adèle team&lt;/a&gt; &lt;span style="font-weight: bold;"&gt;Clément Escoffier&lt;/span&gt;, from &lt;a href="http://www.akquinet.de/"&gt;Akquinet&lt;/a&gt; and leader of the &lt;a href="http://ipojo.org/"&gt;iPOJO project&lt;/a&gt;, presented directly from Berlin via &lt;a href="http://www.dimdim.com/"&gt;DimDim &lt;/a&gt;the talk "Chapter 4.2, Verse 138 : The Framework Multiplication". The RFC 138 is an ongoing specification at the OSGi alliance for allowing different OSGi framework instances to be hosted as nested frameworks isolated from each other. Although it addresses more issues, the basis for this specification seems to be quite similar to what Stéphane Frénot and Yvan Royon did a few years ago with V-OSGi (V for Virtual) by virtualizing different OSGi platform instances on one framework.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Stéphane Frénot&lt;/span&gt;, professor from &lt;a href="http://www.insa-lyon.fr/"&gt;INSA Lyon&lt;/a&gt;, presented the ROCS (Remote OSGi Caching Service) which targets resource constrained devices allowing OSGi applications to load classes from a remote cache, saving space on the device's persistent memory.&lt;/li&gt;&lt;li&gt;Next, &lt;span style="font-weight: bold;"&gt;Pierre Parrend&lt;/span&gt;, researcher from &lt;a href="http://www.fzi.de/"&gt;FZI Karlsruhe&lt;/a&gt;, in another live broadcasted session via DimDim talked about "Software Security Models for Service-Oriented Programming", where he presents different security threats that may be presented by OSGi bundles. He showed also how we a hardened OSGi can be implemented.&lt;/li&gt;&lt;li&gt;&lt;span&gt;Another ex-member of my team, &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Mikaël Désertot&lt;/span&gt;, professor from &lt;a href="http://www.univ-valenciennes.fr/"&gt;Université de Valenciennes&lt;/a&gt;, presented "Vehicular network: The VESPA use case" where OSGi is used in a vehicular project.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;Well, I must admit that during this last presentation I could not pay too much attention because I was showing to Nicolas Le Sommer and Laurent Daynès a snippet for crashing a JVM. During my presentation in the morning I had mentioned that and told everyone to try it home, but Nicolas had the initiative to try it already in the afternoon :)&lt;br /&gt;&lt;br /&gt;Here is the snippet that crashes the JVM, taken from &lt;a href="http://stackoverflow.com/questions/65200/how-do-you-crash-a-jvm"&gt;here&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;public class Crash {&lt;br /&gt;public static void main(String[] args) {&lt;br /&gt;  Object[] o = null;&lt;br /&gt;  while (true) {&lt;br /&gt;     o = new Object[] {o};&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Nicolas tried the above code which crashed the Sun JVM. However the GNU Classpath and IBM JVMs did not crash…&lt;br /&gt;&lt;br /&gt;Laurent tested it in his machine, also crashing the Sun JVM. He debugged it quickly and could precise that it happened when a full GC took place, but someone needs to fix it :)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The presentation abstracts and slides can be found &lt;a href="http://france.osgiusers.org/Meeting/200910"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-5078854159952869624?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/5078854159952869624/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=5078854159952869624' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/5078854159952869624'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/5078854159952869624'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2009/10/meeting-of-osgi-users-group-france.html' title='Meeting of the OSGi users group France'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-1970378015275470908</id><published>2009-06-16T02:51:00.000-07:00</published><updated>2009-06-19T14:31:09.890-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><category scheme='http://www.blogger.com/atom/ns#' term='VisualVM'/><title type='text'>VisualVM OSGi plugin</title><content type='html'>I wrote a simple OSGi management console as a VisualVM plugin, based on a concept similar to the OSGi JConsole plugin that my advisor asked me to do last year.&lt;br /&gt;&lt;div style="text-align: justify;"&gt;In this post I will describe the main steps for constructing the OSGi bundle and the VisualVM plugin, including the usage of a table from the JFluid API (so you plugin can look pretty much like the standard VisualVM stuff) and how simple it is to use JMX from your VisualVM plugin.&lt;br /&gt;&lt;br /&gt;If you want to skip the development steps, you can install and try the plugin by &lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/visualvm/"&gt;downloading the built sfuff here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;If you want to check the step-by-step, please continue reading.&lt;br /&gt;&lt;br /&gt;There is not too much advanced stuff here, but there are three pre-requisites for a complete understanding of this post:&lt;br /&gt;- A minimum of familiarity with VisualVM plugin development (You may want to try the &lt;a href="http://blogs.sun.com/geertjan/entry/getting_started_extending_visualvm"&gt;Hello VisualVM plugin&lt;/a&gt; before)&lt;br /&gt;- Basic JMX knowledge (JMX Tutorial &lt;a href="http://java.sun.com/docs/books/tutorial/jmx/index.html"&gt;here&lt;/a&gt;)&lt;br /&gt;- Basic &lt;a href="http://www.osgi.org/"&gt;OSGi&lt;/a&gt; knowledge (This main purpose of the plugin is not very useful to you if you don’t use OSGi, but you still can check out the JMX + VisualVM stuff).&lt;br /&gt;&lt;br /&gt;I’ll show in this post:&lt;br /&gt;- Brief description of the plugin functionality&lt;br /&gt;- How I used Netbeans to create an OSGi bundle exposing some management functionality via JMX&lt;br /&gt;- An overview of how I developed VisualVM plugin to access the JMX stuff above for accessing/managing OSGi applications&lt;br /&gt;- Some of my findings that I’ve think useful to describe here&lt;br /&gt;&lt;br /&gt;What I’ve used to develop, build and run the code show here:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Java 1.6&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.netbeans.org/downloads/"&gt;Netbeans 6.5&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://felix.apache.org/"&gt;Apache Felix&lt;/a&gt; (you can use another OSGi distribution like &lt;a href="http://www.eclipse.org/equinox"&gt;Equinox&lt;/a&gt;, &lt;a href="http://www.knopflerfish.org/"&gt;Knopflerfish&lt;/a&gt;) &lt;/li&gt;&lt;li&gt;&lt;a href="https://visualvm.dev.java.net/download.html"&gt;VisualVM 1.1.1&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt; &lt;span style="font-weight: bold;"&gt;1. Plugin Functionality Overview&lt;br /&gt;&lt;/span&gt;This plugin can be an alternative to the OSGi consoles that exist, or yet another toy for your VisualVM plugin set.&lt;br /&gt;The functionality of the plugin (screenshot below) is simple:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Listing of all bundles in an OSGi application &lt;/li&gt;&lt;li&gt;Installation of bundles&lt;/li&gt;&lt;li&gt;Perform a start/stop/update/uninstall in a bundle from a list &lt;/li&gt;&lt;li&gt;Visualize bundle information (Manifest headers, list of services, navigate through bundle contents).&lt;/li&gt;&lt;/ul&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_RRFIUjuwzn4/SjvJb4G9mnI/AAAAAAAAAcE/ouaarLHwLec/s1600-h/plugininspectingglassfish.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 279px;" src="http://2.bp.blogspot.com/_RRFIUjuwzn4/SjvJb4G9mnI/AAAAAAAAAcE/ouaarLHwLec/s400/plugininspectingglassfish.jpg" alt="" id="BLOGGER_PHOTO_ID_5349090463187835506" border="0" /&gt;&lt;/a&gt;&lt;span style="font-weight: bold;"&gt;2. Accessing OSGi via JMX&lt;br /&gt;&lt;/span&gt;In order to have a plugin in another process (the VisualVM) to access the OSGi platform, we needed to expose some interfaces for that. JMX is an easy way to expose management interfaces for Java applications, and there is built-in support in the VisualVM for using it.&lt;br /&gt;&lt;br /&gt;In this section I describe the development of the OSGi bundle that exposes this funcionality.&lt;br /&gt;&lt;br /&gt;I created a Netbeans project as a Java class library (I have called mine OSGiJMX)&lt;br /&gt;- Next I needed to reference a jar with the OSGi classes.&lt;br /&gt;- Right click on the project, go to project properties &gt; libraries &gt; add libraries, I needed to create a new one pointing to the felix.jar which contained the needed OSGi API&lt;br /&gt;- OSGi bundles need special manifest attributes. So I’ve added my own manifest to src/META-INF/MANIFEST.MF with the following content:&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;Manifest-Version: 1.0&lt;br /&gt;Bundle-Version: 1.0.0&lt;br /&gt;Bundle-Name: JMX OSGi&lt;br /&gt;Bundle-Description: A JMX OSGi Example&lt;br /&gt;Bundle-ManifestVersion: 2&lt;br /&gt;Bundle-Vendor: Kiev Gama&lt;br /&gt;Bundle-SymbolicName: osgijmx&lt;br /&gt;Bundle-Activator: osgijmx.impl.Activator&lt;br /&gt;Import-Package: org.osgi.framework,javax.management&lt;br /&gt;Export-Package: osgijmx, osgijmx.impl&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;- I needed to change the project ant build file so it would use my manifest instead of the default one. On the files tab of your project (usually on the left side of the Netbeans IDE), open the build.xml&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;import file="nbproject/build-impl.xml"/&amp;gt;&lt;br /&gt;&amp;lt;!--ADD LINE BELOW --&amp;gt;&lt;br /&gt;&amp;lt;property name="manifest.file" value="src/META-INF/MANIFEST.MF"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Basic operations should be made available via JMX MBeans, so our VisualVM plugin can access information concerning an executing OSGi platform and its bundles.&lt;br /&gt;The MBean that my advisor provided me for the JConsole plugin previously mentioned could be used, but it was a single MBean instance that mixed bundles and platform methods. At that time a friend from my lab suggested to create an MBean for each bundle instance. That’s what I finally did now. So, I’ve defined two MXBean interfaces:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;One for the OSGi Platform methods (kinda like a proxy to BundleContext which gives access to the OSGi platform)&lt;/li&gt;&lt;li&gt;Another for bundle related methods (worked like a proxy to a Bundle instance).&lt;/li&gt;&lt;/ul&gt;The code for the interfaces:&lt;br /&gt;&lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/visualvm/OSGiJMX/src/osgijmx/BundleMXBean.java"&gt;BundleMXBean&lt;/a&gt; and &lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/visualvm/OSGiJMX/src/osgijmx/OSGiPlatformMXBean.java"&gt;OSGiPlatformMXBean&lt;/a&gt;&lt;br /&gt;The code of their implementation:&lt;br /&gt;&lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/visualvm/OSGiJMX/src/osgijmx/impl/BundleMXBeanImpl.java"&gt;BundleMXBeanImpl&lt;/a&gt; and &lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/visualvm/OSGiJMX/src/osgijmx/impl/OSGiPlatformMXBeanImpl.java"&gt;OSGiPlatformMXBeanImpl&lt;/a&gt;&lt;br /&gt;the bundle &lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/visualvm/OSGiJMX/src/osgijmx/impl/Activator.java"&gt;Activator&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The OSGiPlatformMXBean will hold a list to all Bundle MXBean instances (thanks to &lt;a href="http://weblogs.java.net/blog/emcmanus/archive/2006/06/intermxbean_ref.html"&gt;Eammon McManus’ blog&lt;/a&gt;).&lt;br /&gt;OSGi is a dynamic platform: bundles can change their state, new services may arrive, etc. So, this JMX bundle should listen to Bundle events in order to add or remove the bundle MBeans in case of bundle installation or uninstallation, respectively, as well as notify (via JMX) any changes of bundle state so the VisualVM plugin GUI could be updated and always have consistent information. Currently the code does not have JMX notification of service events (a temporary workaround would be select/deselect the bundle from the list so its services list would be updated).&lt;br /&gt;&lt;br /&gt;If you’ve followed all the steps you can build the project and test the bundle (or maybe download it from &lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/visualvm/"&gt;here&lt;/a&gt;).&lt;br /&gt;Run Felix, and type start &lt;path&gt;&lt;pathtoosgijmxbundle&gt;.&lt;br /&gt;If you start JConsole and connect it to Felix, you should be able to visualize all tof our OSGi MBeans in the MBeans tab.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3. OSGi VisualVM Plugin Development&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;   &lt;/span&gt;The VisualVM plugin will depend on the JMX interfaces of the project described on the previous section, so it would need to be built and deployed with the plugin as well. My choice was to create a Module Suite, for aggregating the library and the VVM plugin.&lt;br /&gt;&lt;br /&gt;So, you'll end up with four Netbeans projects:&lt;br /&gt;&lt;/pathtoosgijmxbundle&gt;&lt;/path&gt;&lt;ul&gt;&lt;li&gt;&lt;path&gt;&lt;pathtoosgijmxbundle&gt;The OSGi bundle from previous step&lt;/pathtoosgijmxbundle&gt;&lt;/path&gt;&lt;/li&gt;&lt;li&gt;The Module Suite (just an umbrella project for the two below)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;A library wrapper for the OSGi bundle&lt;/li&gt;&lt;li&gt;The VisualVM plugin&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;path&gt;&lt;pathtoosgijmxbundle&gt;&lt;span style="font-style: italic;"&gt;3.1 Steps for creating the  Module Suite:&lt;/span&gt;&lt;br /&gt;-New Project &gt; Netbeans Modules &gt; Module Suite&lt;br /&gt;&lt;br /&gt;&lt;/pathtoosgijmxbundle&gt;&lt;/path&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_RRFIUjuwzn4/SjvYcC7gGpI/AAAAAAAAAcc/z6OhLtSEG7Q/s1600-h/modulesuite1.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 264px;" src="http://2.bp.blogspot.com/_RRFIUjuwzn4/SjvYcC7gGpI/AAAAAAAAAcc/z6OhLtSEG7Q/s400/modulesuite1.jpg" alt="" id="BLOGGER_PHOTO_ID_5349106958766971538" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;- Next, choose the target Netbeans platform (in our case is VisualVM 1.1.1)&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_RRFIUjuwzn4/SjvYcBC4DII/AAAAAAAAAck/T3O3xwU4umU/s1600-h/modulesuite2.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 268px;" src="http://2.bp.blogspot.com/_RRFIUjuwzn4/SjvYcBC4DII/AAAAAAAAAck/T3O3xwU4umU/s400/modulesuite2.jpg" alt="" id="BLOGGER_PHOTO_ID_5349106958261030018" border="0" /&gt;&lt;/a&gt; &lt;span style="font-style: italic;"&gt;3.2 Creating the Library Wrappper module&lt;br /&gt;&lt;br /&gt;- &lt;/span&gt;Choose a Netbeans Project &gt; Library Wrapper Module&lt;br /&gt;- Select the libraries (the jar files) to be wrapped. In this case I've wrapped the OSGiJMX.jar and the felix.jar in the same module.&lt;span style="font-style: italic;"&gt; &lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_RRFIUjuwzn4/Sjvbj--31WI/AAAAAAAAAcs/VjZLfRE8P2Q/s1600-h/librarywrapper2.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 286px;" src="http://4.bp.blogspot.com/_RRFIUjuwzn4/Sjvbj--31WI/AAAAAAAAAcs/VjZLfRE8P2Q/s400/librarywrapper2.jpg" alt="" id="BLOGGER_PHOTO_ID_5349110393681204578" border="0" /&gt;&lt;/a&gt;- In the next step you must indicate which Module Suite will contain your wrapped library (as indicated in the figure below). Then you can go to the next and final step where you define your codebase.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_RRFIUjuwzn4/SjvbjzzhQBI/AAAAAAAAAc0/8RfguUC-CWU/s1600-h/librarywrapper3.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 283px;" src="http://2.bp.blogspot.com/_RRFIUjuwzn4/SjvbjzzhQBI/AAAAAAAAAc0/8RfguUC-CWU/s400/librarywrapper3.jpg" alt="" id="BLOGGER_PHOTO_ID_5349110390680797202" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;3.3 Creating the VisualVM Plugin&lt;/span&gt; &lt;path&gt;&lt;pathtoosgijmxbundle&gt;&lt;br /&gt;&lt;br /&gt;- Create a new project &gt; Netbeans modules &gt; Module&lt;br /&gt;- Important: Choose the module suite create before, so your plugin module will be able to resolve the classes of the wrapped library under the same Module Suite (but we still need to configure that)&lt;br /&gt;&lt;br /&gt;&lt;/pathtoosgijmxbundle&gt;&lt;/path&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_RRFIUjuwzn4/Sjvsjio7l7I/AAAAAAAAAc8/5kiEKl_0FZQ/s1600-h/vvmplugin2.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 283px;" src="http://3.bp.blogspot.com/_RRFIUjuwzn4/Sjvsjio7l7I/AAAAAAAAAc8/5kiEKl_0FZQ/s400/vvmplugin2.jpg" alt="" id="BLOGGER_PHOTO_ID_5349129077770655666" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;After this step was finished, I've created a module installer:&lt;br /&gt;- Right click on the plugin project, New &gt; Module Installer&lt;br /&gt;- I've named it installer and added the code that follows&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;public class Installer extends ModuleInstall {&lt;br /&gt;@Override&lt;br /&gt;public void restored() {&lt;br /&gt;&lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/visualvm/OSGiJMXVVMPlugin/src/osgijmx/vvm/BundlesViewProvider.java"&gt;BundlesViewProvider&lt;/a&gt;.initialize();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;Besides the Installer and the BundlesViewProvides, the other classes for the VVM plugin were:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/visualvm/OSGiJMXVVMPlugin/src/osgijmx/vvm/BundlesView.java"&gt;BundlesView&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/visualvm/OSGiJMXVVMPlugin/src/osgijmx/vvm/BundlesViewProvider.java"&gt;BundlesTableModel&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-style: italic;"&gt;Dependencies&lt;/span&gt;&lt;br /&gt;After this, we would need to add the module dependencies concerning the imported types. Right click on the project &gt; Properties &gt; Libraries. Then you select the dependencies (check the  "Show non-API modules" on the pop-up dependency window)  listed in the figure below:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_RRFIUjuwzn4/SjvymROFNHI/AAAAAAAAAdE/yJL6Fjtx1PI/s1600-h/plugindependencies.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 356px;" src="http://4.bp.blogspot.com/_RRFIUjuwzn4/SjvymROFNHI/AAAAAAAAAdE/yJL6Fjtx1PI/s400/plugindependencies.jpg" alt="" id="BLOGGER_PHOTO_ID_5349135721704010866" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;At this point, trying to run/build the plugin gives the following error:&lt;br /&gt;&lt;br /&gt;"The module osgijmx.vvm is not a friend of &lt;visual-vm-path&gt;\profiler3\modules\org-netbeans-lib-profiler-ui.jar"&lt;br /&gt;&lt;br /&gt;We can solve this by editing the JFluid module dependency and setting it as an "Implementation Version"&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_RRFIUjuwzn4/Sjvymr9zSBI/AAAAAAAAAdM/vSR9AabNtSc/s1600-h/implementationdependency.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 375px;" src="http://3.bp.blogspot.com/_RRFIUjuwzn4/Sjvymr9zSBI/AAAAAAAAAdM/vSR9AabNtSc/s400/implementationdependency.jpg" alt="" id="BLOGGER_PHOTO_ID_5349135728883484690" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;path&gt;&lt;pathtoosgijmxbundle&gt;Ok, but why depend on the JFluid-UI classes?&lt;br /&gt;Well, these are the classes used for developing the pretty Visual VM built-in plugins. So, in order to get our plugin to look similar &lt;/pathtoosgijmxbundle&gt;&lt;/path&gt;&lt;/visual-vm-path&gt;&lt;visual-vm-path&gt;&lt;path&gt;&lt;pathtoosgijmxbundle&gt;to them we used the JFluid-UI. &lt;/pathtoosgijmxbundle&gt;&lt;/path&gt;&lt;/visual-vm-path&gt;The result can be seen in the table on the figure below where we inspect Fuji.&lt;br /&gt;&lt;br /&gt;&lt;visual-vm-path&gt;&lt;path&gt;&lt;pathtoosgijmxbundle&gt; &lt;/pathtoosgijmxbundle&gt;&lt;/path&gt;&lt;/visual-vm-path&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_RRFIUjuwzn4/Sjv2R2P2E-I/AAAAAAAAAdU/5Zg7H14vYKk/s1600-h/fuji.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 341px;" src="http://3.bp.blogspot.com/_RRFIUjuwzn4/Sjv2R2P2E-I/AAAAAAAAAdU/5Zg7H14vYKk/s400/fuji.jpg" alt="" id="BLOGGER_PHOTO_ID_5349139768912778210" border="0" /&gt;&lt;/a&gt;Here's the code for creating the table (JExtendedTable from JFluid UI):&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;        bundleTable = new JExtendedTable(tableModel);&lt;br /&gt;bundleTable.setBorder(BorderFactory.createEmptyBorder());&lt;br /&gt;&lt;br /&gt;bundleTable.setRowSelectionAllowed(true);&lt;br /&gt;bundleTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);&lt;br /&gt;bundleTable.setGridColor(UIConstants.TABLE_VERTICAL_GRID_COLOR);&lt;br /&gt;bundleTable.setSelectionBackground(UIConstants.TABLE_SELECTION_BACKGROUND_COLOR);&lt;br /&gt;bundleTable.setSelectionForeground(UIConstants.TABLE_SELECTION_FOREGROUND_COLOR);&lt;br /&gt;bundleTable.setShowHorizontalLines(UIConstants.SHOW_TABLE_HORIZONTAL_GRID);&lt;br /&gt;bundleTable.setShowVerticalLines(UIConstants.SHOW_TABLE_VERTICAL_GRID);&lt;br /&gt;bundleTable.setRowMargin(UIConstants.TABLE_ROW_MARGIN);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Using JMX from a VisualVM plugin&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;The usage of JMX was straightforward, without any problems. From our DataSourceView the Application instance can be used to retrieve the MBeanServerConnection:&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;public BundlesView(Application application) {&lt;br /&gt;super(application, "OSGi", new ImageIcon(Utilities.loadImage(IMAGE_PATH, true)).getImage(), 60, false);&lt;br /&gt;mbs = JmxModelFactory.getJmxModelFor(application).getMBeanServerConnection();&lt;br /&gt;...&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;After that, the MBeanServerConnection can be used to retrieve a proxy to the MXBean&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;ObjectName objName = new ObjectName("osgijmx:type=framework");&lt;br /&gt;OSGiPlatformMXBean osgiProxy = JMX.newMXBeanProxy(mbs, objName, OSGiPlatformMXBean.class);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;The invocations of the methods were ok, but I had some problems with a MXBean method that returned &lt;/span&gt;&lt;/span&gt;&lt;visual-vm-path&gt;&lt;path&gt;&lt;pathtoosgijmxbundle&gt;a Map[]&lt;string, string=""&gt; :&lt;br /&gt;&lt;span style="font-style: italic;"&gt;java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;But I still had errors changing the return type to a Map&lt;string,map&gt;&lt;string,string&gt;&lt;string,map&gt;&lt;string,string&gt; of Map.&lt;br /&gt;Surely issues with JMX’s Open type translation. The above methods did not work called from my proxy (any help from JMX experts would be great…), but the Map&lt;string,string&gt; getBundleHeaders() did work…&lt;br /&gt;&lt;br /&gt;I tried using an MBeanServerConnection.getAttribute and it did work. However it obliged me to navigate through TabularData instead of a java.util.Map, just the way JConsole does.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Building and deploying&lt;br /&gt;&lt;/span&gt;Inside the Netbeans we can run the plugin, but if we want to deploy it in the VVM  we need to build the nbm files. Just right click the Module suite project, and hit Create NBMs.&lt;br /&gt;Going to the updates folder of the Module Suite project we can find the two generated files.&lt;br /&gt;For their deployment on the VVM, the steps are the same from&lt;/string,string&gt;&lt;/string,string&gt;&lt;/string,map&gt;&lt;/string,string&gt;&lt;/string,map&gt;&lt;/string,&gt;&lt;/pathtoosgijmxbundle&gt; &lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/visualvm/"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I've tested it just in Felix-based applications like Glassfish and Fuji, and it worked fine.&lt;br /&gt;&lt;br /&gt;For deploying in Glassfish the OSGi bundle with the JMX probes:&lt;br /&gt;&lt;br /&gt;GLASSFISH_HOME\bin\asadmin deploy --type osgi YOUR_PATH\OSGiJMX.jar&lt;br /&gt;&lt;br /&gt;This is it. Maybe a long post, but this is the end of it...&lt;br /&gt;&lt;br /&gt;Suggestions for new features are welcome, as well as source code for doing so.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;References:&lt;/span&gt;&lt;br /&gt;&lt;a href="https://visualvm.dev.java.net/api-quickstart.html"&gt;Getting Started Extending the Visual VM &lt;/a&gt;&lt;br /&gt;&lt;a href="http://java.sun.com/docs/books/tutorial/jmx/index.html"&gt;JMX Tutorial&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.osgi.org/javadoc/r4v41/index.html"&gt;OSGi Javadoc&lt;/a&gt;&lt;br /&gt;&lt;a href="http://weblogs.java.net/blog/emcmanus/archive/2006/06/intermxbean_ref.html"&gt;Inter-MXBean references&lt;/a&gt;&lt;br /&gt;&lt;/path&gt;&lt;/visual-vm-path&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-1970378015275470908?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/1970378015275470908/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=1970378015275470908' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/1970378015275470908'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/1970378015275470908'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2009/06/visualvm-osgi-plugin.html' title='VisualVM OSGi plugin'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_RRFIUjuwzn4/SjvJb4G9mnI/AAAAAAAAAcE/ouaarLHwLec/s72-c/plugininspectingglassfish.jpg' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-6326740182625068762</id><published>2009-02-12T08:39:00.000-08:00</published><updated>2009-08-16T00:12:31.142-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><category scheme='http://www.blogger.com/atom/ns#' term='scripting'/><title type='text'>A scripting bundle for OSGi</title><content type='html'>&lt;div style="text-align: justify; color: rgb(0, 0, 0);"&gt;I've wrapped the &lt;a href="http://code.google.com/p/scriptconsole4j/"&gt;scriptconsole4j&lt;/a&gt; as an &lt;a href="http://www.osgi.org/"&gt;OSGi &lt;/a&gt;bundle (tested in &lt;a href="http://felix.apache.org/"&gt;Apache Felix&lt;/a&gt; 1.4.0 and &lt;a href="http://www.eclipse.org/equinox"&gt;Equinox&lt;/a&gt; 3.4.0).&lt;br /&gt;&lt;br /&gt;This console is a simple GUI that allows using the JSR-223 compatible scripting languages available in you Java 6 VM. The Rhino Engine (Javascript) is available by default.&lt;br /&gt;&lt;br /&gt;If you want to execute scripts accessing the OSGi framework to retrieve services in &lt;span style="font-style: italic;"&gt;adhoc&lt;/span&gt; scripts, you may find this version of the scriptconsole4j tool useful. When the bundle is started a scripting window is automatically displayed. Upon bundle termination, the window is disposed and vice-versa.&lt;br /&gt;&lt;br /&gt;How to use it:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Just &lt;a href="http://scriptconsole4j.googlecode.com/files/scriptconsole4j-osgi-0.2.jar"&gt;download it&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Install it on your favorite OSGi framework&lt;/li&gt;&lt;li&gt;Start the bundle&lt;/li&gt;&lt;li&gt;And its ready to be used&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;You can, for example, register listeners to framework objects:&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  var o = new Object();&lt;br /&gt;  o.bundleChanged = function(e) {&lt;br /&gt;      message = "An event happened to bundle "&lt;br /&gt;                + e.getBundle().getBundleId();&lt;br /&gt;      output.println(message);&lt;br /&gt;      //Writing in the standard output&lt;br /&gt;      java.lang.System.out.println(message);&lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt;  ctx.addBundleListener(new org.osgi.framework.BundleListener(o));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Since the bundle uses DynamicImport-Package, you can use it with any exported class, so you can dynamically implement and register services:&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;var o = new Object();&lt;br /&gt;o.sayHello = function() { java.lang.System.out.println("closed")};&lt;br /&gt;  &lt;br /&gt;r = new com.foo.HelloServerService(o);&lt;br /&gt;//registering the service in the OSGi Service Registry&lt;br /&gt;ctx.registerService("foo.BarService",r,null);&lt;br /&gt;//retrieving the service instance&lt;br /&gt;service = ctx.getService(ctx.getServiceReference("foo.BarService"));&lt;br /&gt;service.myMethod();&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;Take a look at the &lt;a href="http://www.mozilla.org/rhino/scriptjava.html"&gt;Rhino page&lt;/a&gt; showing how to use Java from Javascript, and use your imagination for the scripts that may help you.&lt;br /&gt;&lt;br /&gt;Recently I needed the scripting functionality in OSGi on a Java 5 Virtual Machine, which does not come with the JSR-223. I've removed the JSR-223 dependant stuff from the scriptconsole4j and embedded the beanshell core with it. It worked fine but without dynamic class generation. I guess by adding the bsh-classgen it "would"  work. Since we are running on OSGi, classloading is always an issue when dynamically generating stuff...&lt;br /&gt;I'll test it and leave it available soon (I hope so).&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-6326740182625068762?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/6326740182625068762/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=6326740182625068762' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/6326740182625068762'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/6326740182625068762'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2009/02/scripting-bundle-for-osgi.html' title='A scripting bundle for OSGi'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-3114633489094601545</id><published>2009-01-14T07:36:00.000-08:00</published><updated>2009-01-14T07:57:31.307-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Withdrawn JSRs</title><content type='html'>I've checked the status of &lt;a href="http://jcp.org/en/jsr/detail?id=277"&gt;JSR-277&lt;/a&gt;, which was &lt;a href="http://neilbartlett.name/blog/2008/12/08/hope-fear-and-project-jigsaw/"&gt;announced as being halted&lt;/a&gt; by Sun, but its status did not change to withdrawn. That makes sense, since it was announced as temporarily halted.&lt;br /&gt;So I went to check the list of all &lt;a href="http://jcp.org/aboutJava/communityprocess/withdrawn.html"&gt;withdrawn JSRs&lt;/a&gt;, just for curiosity, and the number surprised me:  52. A lot of those were concerning &lt;a href="http://java.sun.com/products/jain/"&gt;JAIN&lt;/a&gt; (which I haven't heard of until now). Some of the JSRs had comments like "withdrawn at the request of the submitter".&lt;br /&gt;&lt;br /&gt;If you look at the number of &lt;a href="http://jcp.org/en/jsr/all"&gt;all JSRs&lt;/a&gt; (355) we can do simple math and find that 15% of all JSRs have been withdrawn. It is true that they vary a lot in size, as there are umbrella JSRs that have a lot of stuff behind and we have some successful efforts that are heavyweight. Also, among that list there are "spinoffs", like the &lt;a href="http://jcp.org/en/jsr/detail?id=8"&gt;JSR-8&lt;/a&gt; which originated &lt;a href="http://www.osgi.org"&gt;OSGi&lt;/a&gt;. But, is 15% a high rate or considering the fact that standardization is a complex effort that involves people from different organizations which may have different interests,  could we say that it is a fairly acceptable percentage ?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-3114633489094601545?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/3114633489094601545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=3114633489094601545' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/3114633489094601545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/3114633489094601545'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2009/01/withdrawn-jsrs.html' title='Withdrawn JSRs'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-5699147879614194079</id><published>2008-11-24T13:45:00.000-08:00</published><updated>2008-11-25T04:09:57.589-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='AOP'/><title type='text'>Can AOP be some sort of elegant workaround?</title><content type='html'>&lt;a style="color: rgb(0, 0, 0);" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_RRFIUjuwzn4/SSswCIGFiII/AAAAAAAAAUs/U68bAWUVC5g/s1600-h/woolweaving.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 200px; height: 133px;" src="http://3.bp.blogspot.com/_RRFIUjuwzn4/SSswCIGFiII/AAAAAAAAAUs/U68bAWUVC5g/s200/woolweaving.jpg" alt="" id="BLOGGER_PHOTO_ID_5272360601858181250" border="0" /&gt;&lt;/a&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;In the pursuit of problem solving (or at least trying to) in my research, I guess I am taking AOP as a strategy to give me what I don't have. Maybe I am becoming too addicted to pointcuts...&lt;/span&gt; &lt;div style="text-align: justify; color: rgb(0, 0, 0);"&gt;&lt;br /&gt;I have used Aspect Oriented Programming for intercepting method calls to the OSGi framework and for adding my "concerns". These interceptions allowed me to, mainly, add hooks to service registration and retrieval. I think the good thing is that the solution was elegant enough and enabled portability accross different OSGi implementations, since the aspects targeted the API. The bad thing is that it does not rely in a standard mechanism supported by the platform, and it needs an additional building step (i.e. weaving the framework).&lt;br /&gt;&lt;br /&gt;After taking a look at the &lt;a href="http://www.osgi.org/download/osgi-4.2-early-draft.pdf"&gt;draft OSGi spec 4.2&lt;/a&gt;, I've checked the Service Registry Hooks with the hope that my weaved hooks could be replaced by a standard mechanism. They have exactly proposed the hooks I wanted but sadly that alternative solution had been rejected. The hooks they will provide still do not allow me to do what I need. I'll still be doing the AOP trick...&lt;br /&gt;&lt;br /&gt;I just can think of more pointcuts to add to my future solutions/attempts in order to have other types of hooks. As I said previously, this approach is useful to avoid changing the source code of a chosen OSGi implementation. There are lots of people in the research area who usually customize an OSGi impl to their needs (I still see recent articles talking about customizations of &lt;a href="http://forge.objectweb.org/projects/oscar/"&gt;OSCAR&lt;/a&gt;). One disadvantage is that if you touch the source code directly, you're stuck with a given version which makes it difficult to follow the evolution of the chosen impl. (either Equinox, KF or Felix). You would need constant effort for merging/synchronization your branch with the current version. I believe they could avoid that by doing the AOP trick as well. However, sometimes (like while writing this) I am not sure if this a true elegant solution or if I've just found a nice and powerful workaround for adding my hooks to the OSGi core.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-5699147879614194079?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/5699147879614194079/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=5699147879614194079' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/5699147879614194079'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/5699147879614194079'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/11/can-aop-be-some-sort-of-elegant.html' title='Can AOP be some sort of elegant workaround?'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_RRFIUjuwzn4/SSswCIGFiII/AAAAAAAAAUs/U68bAWUVC5g/s72-c/woolweaving.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-770746498061948421</id><published>2008-09-18T09:21:00.000-07:00</published><updated>2008-09-18T12:21:39.124-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><category scheme='http://www.blogger.com/atom/ns#' term='Open source'/><title type='text'>How to open source an OSGi targeted tool?</title><content type='html'>&lt;div style="text-align: justify; color: rgb(0, 0, 0);"&gt;I was working on a &lt;a href="http://membres-liglab.imag.fr/kiev.gama/dev/osgi/servicecoroner/"&gt;tool&lt;/a&gt; (with a funny name, or a ridiculous name if you will) for the diagnosis of stale references in the OSGi platform. It was part of my master thesis at &lt;a href="http://www.ujf-grenoble.fr/"&gt;Grenoble 1 university&lt;/a&gt;. The tool has been presented in an &lt;a href="http://www.osgi.org/wiki/uploads/CommunityEvent2008/26_Gama-Donsez.pdf"&gt;OSGi event&lt;/a&gt; in june, and in an &lt;a href="http://ordinaryjava.blogspot.com/2008/09/exclusive-osgi-session-at-euromicro.html"&gt;academic conference&lt;/a&gt; in the beginning of this month. Among our “future plans” is to open source this tool. I am starting the PhD in the same university, and this tool will not be my main activity. I will have plenty of other things to do also. However we would like to continue evolving it.&lt;br /&gt;&lt;br /&gt;But, I have several questions for all this process of releasing such a thing as open source. Maybe an inner self crisis!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1. Is this tool useful to anyone?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This tool is no rocket science and it does not cure problems, it only points a few of them.&lt;br /&gt;&lt;br /&gt;My first thought is that the thing is useless, because I will always have the thought that what I’ve coded sucks and I could have done better…&lt;br /&gt;&lt;br /&gt;But, if we do not make it available for the developer community it will surely be useless, since it would not be accessible to others. We never know if any a brave (and maybe a little insane) person would like to help evolving that.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. How (and where) to do open source it?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Initially I may think to put it in sourceforge or google code. But my thesis advisor says it would be useless and without a good visibility for the target audience: developers of OSGi based applications. I agree. I’ve made available a small “useless” &lt;a href="http://code.google.com/p/scriptconsole4j/"&gt;scripting console&lt;/a&gt; at google code, but the &lt;a href="http://code.google.com/p/scriptconsole4j/"&gt;download count&lt;/a&gt; is insignificant, thus nobody is using it. We can imagine that a more specific project would fall into oblivion.&lt;br /&gt;&lt;br /&gt;So, my thesis advisor, who is a committer in an Open Source OSGi implementation, has contacted its project leader. The guy said ok, but no more open source progress for our tool after that. I am not sure if : 1- he was just being polite and said ok; or 2- he is so busy that he can’t get into too much details on all mail that he receives. We also have not insisted since other stuff came up.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3. What if the code is not ready yet?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I am sure it is not ready. I feel like I’m leaving my house and while I'm not there people come in and see all the mess: dirt dishes, laundry, underwear in the floor. I would need to polish it. And after that, the project will no longer be “my house”, since it would belong to the community. Then the dirty laundry will be everyone's business.&lt;br /&gt;&lt;br /&gt;But, that leads to another question: when would it be ready for that? I guess the polishing is just removing the really ugly hardcoded stuff, a few bad practices (did I just said that?). The GUI is complicated for the end user to understand it. It would definitely need some good work. I confess that in a 5 month project, with a bunch of articles to read, and also the master’s thesis to write I’ve neglected in some software engineering and also human interaction practices. If anybody has never done that before, cast the first stone.&lt;br /&gt;Ah! Mavenization also. That's part of the polishing. For simplicity, I’ve used ant. Decent projects these days at least use maven for managing dependencies.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;4. What if they find bugs in my code?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Normal. Just open an issue. I am far away from being a bug free coder and I guess 99% of the developers out there are not bug free either.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5. When to do the open sourcing?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Good question. I guess ASAP before I have even less time for polishing the code.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;6. Volunteers for continuing the tool development?&lt;/span&gt;&lt;br /&gt;I believe we have at least one: me :)&lt;br /&gt;&lt;br /&gt;Well, these are basically my doubts that I share here in this post based on the little spark of dellusion that my master thesis result would be useful to someone.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-770746498061948421?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/770746498061948421/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=770746498061948421' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/770746498061948421'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/770746498061948421'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/09/how-to-open-source-osgi-targeted-tool.html' title='How to open source an OSGi targeted tool?'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-6084245062299155139</id><published>2008-09-05T08:10:00.000-07:00</published><updated>2008-09-05T08:12:33.490-07:00</updated><title type='text'>Exclusive OSGi session at Euromicro SEAA</title><content type='html'>&lt;div style="text-align: justify;"&gt;I was at the &lt;a href="http://seaa2008.isti.cnr.it/cfp"&gt;34th Euromicro conference on Software Engineering and Advanced Applications (SEAA)&lt;/a&gt; to present an article about the tool that we have developed for detecting stale references in OSGi applications.&lt;br /&gt;The conference had a session dedicated to OSGi  in the Component-Based Software Engineering Track. Somehow it shows the industry/academia recognition of the important role that OSGi plays in the development of component-based appplications.&lt;br /&gt;&lt;br /&gt;There were three articles presented in that session:&lt;br /&gt;&lt;ul&gt;&lt;li&gt; "Enhanced OSGi Bundle Updates to Prevent Runtime Exceptions"&lt;br /&gt;Premysl Brada&lt;/li&gt;&lt;li&gt; "Method for resource monitoring of OSGi-based software components"&lt;br /&gt;Tuukka Miettinen, Daniel Pakkala, Mika Hongisto&lt;/li&gt;&lt;li&gt; "Service Coroner: A Diagnostic Tool for locating OSGi Stale References"&lt;br /&gt;Kiev Gama, Didier Donsez&lt;/li&gt;&lt;/ul&gt; The other two presentations were pretty interesting. Each one of us showed little "hacks" for addressing some issues in the OSGi platform :)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-6084245062299155139?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/6084245062299155139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=6084245062299155139' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/6084245062299155139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/6084245062299155139'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/09/exclusive-osgi-session-at-euromicro.html' title='Exclusive OSGi session at Euromicro SEAA'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-4536607908833815948</id><published>2008-08-10T11:01:00.000-07:00</published><updated>2008-09-05T08:13:33.452-07:00</updated><title type='text'>Benchmarking the cost of dynamic proxies</title><content type='html'>I needed to quickly compare the cost of dynamic proxies versus direct access to objects, and also position it in relation to RMI. In theory we know that they add overhead, but how much? I just wanted more precise arguments to reinforce a rather obvious statement: “&lt;span style="font-style: italic;"&gt;Dynamic proxies are not that bad. Take RMI for example&lt;/span&gt;...” :)&lt;br /&gt;&lt;br /&gt;I could not find exact and up to date info saying that RMI is X times slower than direct method calls, nor dynamic proxies. In &lt;a href="http://www.javaperformancetuning.com/tips/j2ee_rmi.shtml"&gt;this link&lt;/a&gt; they’ve said that RMI is at least 1000 times slower than local calls. Since that appears to be some info from 2001, I imagine that we’ve had some nice optimizations in JVMs in the last 7 years.&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;I’ve changed a benchmark code that has been used in my lab, so I could have an approximate value of each method call in different approaches. &lt;a href="http://www.infoq.com/news/2008/08/java-benchmarking"&gt;This post&lt;/a&gt; (which actually points to &lt;a href="http://www.ibm.com/developerworks/java/library/j-benchmark1.html?ca=drs-"&gt;here&lt;/a&gt;) that I’ve just read this Sunday helped me a lot in adapting the code.&lt;br /&gt;&lt;br /&gt;My benchmark consisted of calling a million times a method in a given object which implements the tested "dummy" interface. The method was void with no parameters, and the implementation had just one line of code assigning an integer variable. The idea was to get the closest possible to the actual invocation time, with the minimum possible for method execution time.&lt;br /&gt;&lt;br /&gt;I’ve executed the benchmark a few times and I’ve always got the same minimum values for direct calls and dynamic proxy, respectively. However the minimum time for RMI calls varied a lot.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Dynamic proxies:&lt;/span&gt; 1.63 times slower than direct calls, which is not bad.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;RMI calls:&lt;/span&gt; At least 200 times slower.&lt;br /&gt;&lt;br /&gt;For info, here is my not so performing platform:&lt;br /&gt;JVM: Sun Hotspot/JRE 1.6.0 07.&lt;br /&gt;OS: Windows XP SP2.&lt;br /&gt;Hardware: Pentium 1.7 GHz 1GB RAM&lt;br /&gt;&lt;br /&gt;The cost of dynamic proxies surprised me. &lt;a href="http://www.ibm.com/developerworks/java/library/j-jtp08305.html"&gt;This article&lt;/a&gt; from developerWorks shows similar conclusions. I thought they would be more expensive. However, we are talking about a minimal overhead level here, as in actual usages of proxies we usually add more code for decoration, verifications, etc which would obviously lead to more than the 1.63 times that I’ve measured. Well, this info provided here cannot considered sufficient as more tests would need to be performed in order to be more precise.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-4536607908833815948?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/4536607908833815948/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=4536607908833815948' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/4536607908833815948'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/4536607908833815948'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/08/benchmarking-cost-of-dynamic-proxies.html' title='Benchmarking the cost of dynamic proxies'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-3379235486451675626</id><published>2008-07-20T23:47:00.000-07:00</published><updated>2008-07-22T09:04:52.433-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Swing'/><title type='text'>JSR 296 in coma ?</title><content type='html'>&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;I’ve been checking the upcoming features of Java 7 and found a cool detailed list &lt;a href="http://tech.puredanger.com/java7/"&gt;here&lt;/a&gt;. Also, some Java One 2008 &lt;a href="http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-6271.pdf"&gt;slides from Danny Coward’s presentation&lt;/a&gt; show a little on that too. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Among the &lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;JSRs &lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;mentioned in the first link, I already &lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;had checked &lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;some stuff from JSRs 277, 294, concerning Java Modules, JSR 284, concerning resource consumption and JSRs 295, 296 and 303 concerning Swing.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;I’ve known these swing-related JSRs since, more or less, they became available as JSRs. I had special interest on them at the time because I was working in a project where we needed a product built on top of a Rich Client Platform, to enable the development of plugins from third parties. The idea was to have a simple and pluggable structure. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;For us, Eclipse RCP was overkill so was the Netbeans platform. Spring RCP was in its initial stages. We’ve decided to go from scratch, using OSGi as the base for a pluggable architecture, and build our own straightforward RCP. The JSR 296 (Swing Application Framework) proposes most of what we needed (and developed) as a Swing foundation for our RCP:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;ul style="text-align: justify;" type="disc"&gt;&lt;li class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Resource management for &lt;a href="http://en.wikipedia.org/wiki/I18n"&gt;i18n&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Task services/monitoring&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Storage for session state &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Events/actions framework&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Managed application exiting (exit listeners), startup, shutdown&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;I can't say that this is a PCP (Poor Client Platorm). Maybe an ARCP (Almost Rich Client Platform). But, as I said, it does most of what we needed at that time. And I believe there are hundreds or thousands of other applications that don't need all the heavy richness provided by the RCPs.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;So I decided to take a look at JSR 296 (Swing Application Framework) to see what they have for us so far. I’ve downloaded it from the &lt;a href="https://appframework.dev.java.net/"&gt;project site&lt;/a&gt;. (You should also need to download the &lt;a href="https://swingworker.dev.java.net/"&gt;SwingWorker&lt;/a&gt; since they do not use the SwingWorker delivered with Java 6)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;      &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;span style="text-decoration: underline;"&gt;&lt;/span&gt;&lt;a href="http://java.sun.com/developer/technicalArticles/javase/swingappfr"&gt;This tutorial&lt;/a&gt; has good examples concerning the features of the JSR 296, &lt;o:p&gt;&lt;/o:p&gt; like the magic stuff for saving session state (components dimensioning, positioning, etc):&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;//The non-qualified getters below are inherited from the SingleFrameApplication class&lt;br /&gt;//&lt;br /&gt;//Saving session State&lt;br /&gt;getContext().getSessionStorage().save(getMainFrame(), sessionFile);&lt;br /&gt;&lt;/code&gt;&lt;code&gt;...&lt;br /&gt;//Restoring session State&lt;br /&gt;&lt;/code&gt;&lt;code&gt;getContext()&lt;/code&gt;&lt;code&gt;.getSessionStorage().restore(getMainFrame(), sessionFile);&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;      &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Lots of weeks of modelling and coding can be saved by using that framework.&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;br /&gt;There was a weird thing about the last available version: it was from November 2007. It seems that it is not evolving anymore. I’ve read a few months ago in blogs that I don’t recall, that some senior engineers from the Swing team were leaving Sun Microsystems. I could find this &lt;a href="http://almaer.com/blog/sun-is-bleeding-more-engineers-leave-as-javafx-is-pimped"&gt;blog entry&lt;/a&gt; mentioning some of them. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;The guys that took care of JSR 296 (Hans Muller) and 295 (Scott Violet) are gone. However, I think that there are no worries with JSR 295 and 303 which are just “standardizing” the concepts used in &lt;a href="http://www.jgoodies.com"&gt;JGoodies &lt;/a&gt;by Karsten Lentz, who is a member of both expert groups. But the JSR 296 is apparently a home grown implementation from Sun. The guy that was handling that is gone, and there are no new versions for 8 months.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Weird…  It appears that the project is in some sort of "coma". &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Don’t know if it will make it until Java 7&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-3379235486451675626?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/3379235486451675626/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=3379235486451675626' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/3379235486451675626'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/3379235486451675626'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/07/jsr-296-in-coma.html' title='JSR 296 in coma ?'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-5540774177374801387</id><published>2008-07-06T23:01:00.000-07:00</published><updated>2009-08-16T00:12:31.142-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OSGi'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='VisualVM'/><category scheme='http://www.blogger.com/atom/ns#' term='Heap analysis'/><category scheme='http://www.blogger.com/atom/ns#' term='scripting'/><title type='text'>Heap snapshot analysis and objects with different class versions</title><content type='html'>&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;I’ve been working lately on the detection of a particular problem, &lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;called stale references,&lt;/span&gt;&lt;span style="" lang="EN-GB"&gt; that may happen on OSGi based applications. It is a consequence of bad OSGi programming practices that may lead to memory retention and the utilization of inconsistent objects.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;As a part of the diagnosis process I need to analyze heap snapshots to find the referrers of services that have been unregistered. I’ve found some interesting stuff (at least for me) concerning memory inspection and classloading. Each module (bundle) in OSGi is provided with its own class loader instance. If you replace (update) a module during runtime, it will basically stop, refresh and restart; and get a new class loader. Objects and classes from the previous class loader must not be referenced anymore, and that previous CL is supposed to be “discarded” and GC’d.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;In our custom tool I was seeing that objects from “discarded” class loaders were still being referenced by other modules. However, when I used &lt;a href="http://java.sun.com/javase/6/docs/technotes/tools/share/jhat.html"&gt;JHat&lt;/a&gt; (either &lt;a href="http://ordinaryjava.blogspot.com/2008/04/hacking-jhat-api-to-integrate-it-to-my.html"&gt;embedded&lt;/a&gt; or standalone) to inspect the heap snapshots by performing queries like “&lt;span style="font-family: courier new;"&gt;select x from com.foo.TheClassOfTheReferencedObject&lt;/span&gt;” the result set listed only one object instance (from the running module) when I was supposed to get two instances (one loaded by the old class loader and other by the new one).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;      &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;I thought my tracking code was falsely accusing the service object from the old bundle version. After patiently and manually (maybe “stupidly”) verifying each class loader instance, I found the two different class loaders that referred to the same bundle ID, and could also found the “lost” object.&lt;br /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;After a few weeks I’ve tried to track the same problem with the heap inspection provided in the &lt;a href="https://visualvm.dev.java.net/"&gt;VisualVM&lt;/a&gt;. It worked like a charm! I could see all object instances of the same class name, no matter what class loader provided the object class. It does not have advanced queries like JHat, but in this case I only needed a filter to find the class instances that interest me.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;It’s a pity. JHat has powerful queries to analyze heap snapshots, but it can’t deal clearly with the same class names loaded by different class loaders (i.e. different versions of the same class). VisualVM has much more limited power that JHat, but allows to see attribute values, referrers and referring trees just like JHat. In addition, VisualVM deals with no problem with classes carrying the same name but loaded by different class loaders, and that what’s more interesting for me, at least for now.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-5540774177374801387?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/5540774177374801387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=5540774177374801387' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/5540774177374801387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/5540774177374801387'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/07/heap-snapshot-analysis-and-objects-with.html' title='Heap snapshot analysis and objects with different class versions'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-5420663289174299684</id><published>2008-06-16T12:46:00.000-07:00</published><updated>2008-06-16T12:49:50.043-07:00</updated><title type='text'>How can we developers (not the companies) do off-shore jobs ?</title><content type='html'>&lt;span style="" lang="EN-GB"&gt;Recently (actually just 40 minutes ago) I got an “almost certain” temporary home-office contract refused because I am overseas. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;&lt;br /&gt;Huh ?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;&lt;br /&gt;I’ll explain it… But skip to (2) if you’re in a hurry…&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;      &lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;(1) The company is located in &lt;st1:country-region st="on"&gt;&lt;st1:place st="on"&gt;Brazil&lt;/st1:place&gt;&lt;/st1:country-region&gt;, and some people who know my job (and apparently trust on it) wanted to hire me for a temporary home-office job in that company. No development services with them so far, but as a freelance trainer last year I’ve even taught Java classes in this company which is also a faculty and tech training school, so I’m not a complete stranger for them.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;I've quit my job 10 months ago and came to &lt;st1:place st="on"&gt;&lt;st1:country-region st="on"&gt;France&lt;/st1:country-region&gt;&lt;/st1:place&gt; to enroll in a computer science master’s degree. Ok so far. That's my choice. After knowing that some friends had done home-office for them, and since I was about to take summer vacations I’ve contacted them one month ago and said “hey if you need somebody for home-office development I’m here”. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Before leaving I left a legal representative in &lt;st1:country-region st="on"&gt;&lt;st1:place st="on"&gt;Brazil&lt;/st1:place&gt;&lt;/st1:country-region&gt; who can sign papers in my name, open bank accounts, etc. I’ve informed the company that I was going to be able to give legal receipts, invoices or whatever, which was what they have asked for.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;But their legal department said NO…&lt;br /&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;(2) To make this story shorter:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;&lt;span style="" lang="EN-GB"&gt;The receipt/invoice would be issued by the town hall of my home city in &lt;st1:country-region st="on"&gt;&lt;st1:place st="on"&gt;Brazil&lt;/st1:place&gt;&lt;/st1:country-region&gt; (this is the type of receipt they asked for)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="" lang="EN-GB"&gt;The money would be deposited in my bank account in &lt;st1:country-region st="on"&gt;&lt;st1:place st="on"&gt;Brazil&lt;/st1:place&gt;&lt;/st1:country-region&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="" lang="EN-GB"&gt;The job was going to be performed by a brazilian citizen with brazilian documents who would sign a contract with them, but with a TEMPORARY address in &lt;st1:country-region st="on"&gt;France&lt;/st1:country-region&gt; and a PERMANENT address in &lt;st1:country-region st="on"&gt;&lt;st1:place st="on"&gt;Brazil&lt;/st1:place&gt;&lt;/st1:country-region&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;        &lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;However, as I am not residing in the country, the legal department refused to issue the temporary contract.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;I have no clue how to deal with such situation. Neither these guys who contacted me have. They had good intention but the big guys said no…&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;My question is: how to deal with such issues related to off-shore jobs? Usually companies are hired to do off-shore. But what about people? Developers like me, like you.&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;Does anybody have ever faced similar situations? &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-5420663289174299684?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/5420663289174299684/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=5420663289174299684' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/5420663289174299684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/5420663289174299684'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/06/how-can-we-developers-not-companies-do.html' title='How can we developers (not the companies) do off-shore jobs ?'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-4992161581535655540</id><published>2008-06-02T23:10:00.000-07:00</published><updated>2008-06-02T23:46:01.632-07:00</updated><title type='text'>OSGi Community Event</title><content type='html'>&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;The second annual &lt;a href="http://www.osgi.org/CommunityEvent/HomePage"&gt;&lt;span class="wikiword"&gt;OSGi&lt;/span&gt; Community Event &lt;/a&gt;will take place next week (10-11 June), in &lt;st1:place st="on"&gt;&lt;st1:city st="on"&gt;Berlin&lt;/st1:city&gt;,  &lt;st1:country-region st="on"&gt;Germany&lt;/st1:country-region&gt;&lt;/st1:place&gt;. The event will have presentations and demos concerning both business and research projects.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;It is a little &lt;a href="http://www.osgi.org/CommunityEvent/Registration"&gt;expensive&lt;/a&gt;&lt;/span&gt;&lt;span style="" lang="EN-GB"&gt; &lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;(550 euros for non-members) but it is a good opportunity to business and research personnel gather together and exchange ideas and present results on OSGi technology usage.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-4992161581535655540?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/4992161581535655540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=4992161581535655540' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/4992161581535655540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/4992161581535655540'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/06/osgi-community-event.html' title='OSGi Community Event'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-5442264058300316987</id><published>2008-05-25T05:31:00.000-07:00</published><updated>2008-09-05T08:10:09.852-07:00</updated><title type='text'>More on the "OSGi hype"</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(0, 0, 0);" lang="EN-GB"&gt;I’ve seen more and more people talking about OSGi lately. Some are saying that we are going through “OSGi hype”…&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Well, I’ll talk about the OSGi hype here too :)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;a href="http://www.osgi.org/"&gt;OSGi &lt;/a&gt;is being around for almost ten years. Maybe it gained (more) momentum after &lt;a href="http://findarticles.com/p/articles/mi_m0ISJ/is_2_44/ai_n15399773/pg_1"&gt;Eclipse adopting it&lt;/a&gt; since version 3. I’m not sure, &lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;I have no "authority" to say that. T&lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;hat's just what I think as an outsider. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;A non-exhaustive list of OSGi advantages: no more classpath hell, modules life cycle, dynamic updates with no application reboots, package visibility, decoupling through services.&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="" lang="EN-GB"&gt;Several important organizations are seeing OSGi’s value and are investing on it. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);" lang="EN-GB"&gt;This guy posted a &lt;a href="http://www.pierocampanelli.info/articles/2006/11/15/osgi-and-open-source-ecosystem/"&gt;list of applications using OSGi&lt;/a&gt;. We can add &lt;a href="http://incubator.apache.org/sling/"&gt;Apache Sling&lt;/a&gt; , &lt;a href="http://servicemix.apache.org/SMX4KNL/why-does-servicemix-use-osgi.html"&gt;Apache ServiceMix&lt;/a&gt; and &lt;a href="https://fuji.dev.java.net/"&gt;Project Fuji &lt;/a&gt;to that list too, as well as &lt;a href="https://glassfish.dev.java.net/"&gt;Glassfish&lt;/a&gt;. I've worked as part of the team that developed a &lt;a href="http://www.cx65.de/News.600.0.html?&amp;amp;L=1&amp;amp;cHash=0fe134633d&amp;amp;tx_ttnews%5BbackPid%5D=196&amp;amp;tx_ttnews%5Btt_news%5D=658"&gt;now extinct product&lt;/a&gt; built on top of OSGi. There must be a lot of other not so popular stuff built with OSGi.&lt;/span&gt;    &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;Maybe some recent events caused all this hype:&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;ul style="color: rgb(0, 0, 0); text-align: justify;"&gt;&lt;li&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;a href="http://wiki.jonas.objectweb.org/xwiki/bin/view/Main/Overview"&gt;JOnAS&lt;/a&gt; 5 released as the first (I guess it was the first one) JEE application server to run on top of OSGi.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="" lang="EN-GB"&gt;Recently we’ve seen &lt;a href="http://weblogs.java.net/blog/ss141213/archive/2008/04/glassfish_v3_on.html"&gt;Glassfish using it&lt;/a&gt;.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;JBoss &lt;a href="http://www.jboss.org/community/interviews/ales_osgi.html"&gt;is talking about&lt;/a&gt; OSGi. &lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;li&gt;BEA (now Oracle) &lt;a href="http://dev2dev.bea.com/blog/gbrail/archive/2007/03/using_osgi_at_b.html"&gt;is using&lt;/a&gt; OSGi in its microservice architecture.  &lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;I guess OSGi has become the de facto module system for Java. It seems that &lt;a href="http://jcp.org/en/jsr/detail?id=277"&gt;JSR 277&lt;/a&gt; has a risk of falling into oblivion when it becomes released if it does not converge with OSGi. Since so many important announcements about OSGi adoption are taking place, we are seeing this “OSGi hype”.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;In my opinion, this is not hype. It is industry evolution. But those that still do not get it may see it only as hype.&lt;/span&gt;&lt;span style="" lang="EN-GB"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;      &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Technology hypes may sometimes lead to some naïve decisions like &lt;span style="font-style: italic;"&gt;“let’s use it because it’s a cool trend and everybody is using it. It's a new trend”&lt;/span&gt;. Maybe that was a &lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;naïve example too...&lt;br /&gt;&lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;Before choosing to use stuff like OSGi try to evaluate if it fits your needs. Get to know it better. Maybe taking a look at the docs in the &lt;a href="http://www.osgi.org/"&gt;OSGi alliance website&lt;/a&gt; or &lt;a href="http://www.google.fr/search?q=osgi+tutorial&amp;amp;ie=utf-8&amp;amp;oe=utf-8&amp;amp;aq=t&amp;amp;rls=com.google:fr:official"&gt;looking for tutorials&lt;/a&gt;. Decisions like this involve the architecture of your project.&lt;o:p&gt; &lt;/o:p&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Whoever tries to use OSGi must be careful with the sometimes steep learning curve. Try to take advantage of existing component models (OSGi declarative services, &lt;a href="http://gravity.sourceforge.net/servicebinder/"&gt;Service Binder&lt;/a&gt;, &lt;a href="http://springframework.org/osgi"&gt;Spring DM&lt;/a&gt;, &lt;a href="http://felix.apache.org/site/ipojo.html"&gt;iPOJO&lt;/a&gt;) that handle hard dynamic aspects, service location, dependency injection, and do all the dynamic voodoo magic. There was a time when all that stuff needed to be made by hand. You don’t need to do that anymore.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;        &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;There is some stuff that is painful in the beginning like “bundlizing” a jar. But constructing an OSGi compliant manifest may be simplified by automated stuff like a &lt;a href="http://felix.apache.org/site/maven-bundle-plugin-bnd.html"&gt;bundle plugin for maven&lt;/a&gt;. Well, there is plenty of stuff (like &lt;a href="http://www.ops4j.org/"&gt;here&lt;/a&gt;) to minimize efforts concerning OSGi development.&lt;span style=""&gt;  &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;I'm away from the market for almost a year and started (or continued, if you will) to do research that involves OSGi. Each time I see news about its adoption in industry I get even more motivated about my choice.&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;   &lt;/div&gt;&lt;p style="color: rgb(0, 0, 0); text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Even if you don’t buy the idea or if it is useless for you, it is worth taking a look. &lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;OSGi is not just a buzzword. &lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;Try to use it not because it is hype, check its benefits first.&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-5442264058300316987?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/5442264058300316987/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=5442264058300316987' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/5442264058300316987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/5442264058300316987'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/05/more-on-osgi-hype.html' title='More on the &quot;OSGi hype&quot;'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-751835753317128617</id><published>2008-05-14T14:16:00.000-07:00</published><updated>2008-07-22T09:05:58.571-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Do you know weak references? Have you ever used them?</title><content type='html'>&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;I’ve been using a lot of weak references lately. A couple of years ago I’ve read a &lt;a href="http://weblogs.java.net/blog/enicholas/archive/2006/05/understanding_w.html"&gt;blog entry&lt;/a&gt; that said that a lot of experienced Java developers did not know what they were. I’m glad I already knew it at the time I’ve read that :)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;I won’t go into details of weak references. I’ll just say that an object is not prevented to be garbage collected if it only has weak references pointing to it. You can get a nice overview &lt;a href="http://www.pawlan.com/Monica/refobjs/"&gt;here&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;In my current project I’m tracking garbage collection of special types of objects by using weak references. Maybe in another post I’ll provide more info on that.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;      &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Throughout my career I’ve used that nice resource of Java a few times. The most important ones that I can remember are:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="" lang="EN-GB"&gt;Weak Listeners&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="" lang="EN-GB"&gt;Memory Sensitive Caches&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;span style="font-weight: bold;"&gt;Weak Listeners&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Memory leaks are a painful problem that sometimes we don’t have a clue how to find them. I’ve worked in a desktop project where we had lots of instantiations of GUI panels, models, etc. That implied in a bunch of model listeners, property listeners, and so forth. We had a major memory leak due to a simple problem in most of the panels: objects from each created panel were being added as a listener of the model, but after the panel was discarded they did not remove themselves from the listeners list of the model. So, they kept being reference by the listeners list on the model and could not be garbage collected.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="" lang="EN-GB"&gt;A naïve example tries to illustrate that:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;public void setActivePanel() {&lt;br /&gt;MyPanel thePanel = new MyPanel();&lt;br /&gt;ApplicationModel.getInstance().addXYZListener(thePanel);&lt;br /&gt;this.activePanel = thePanel;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void releaseActivePanel() {&lt;br /&gt;this.activePanel = null;&lt;br /&gt;this.clearSelection();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;One solution was to provide a way to unsubscribe "thePanel" from the XYZListener list:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;public void releaseActivePanel() {&lt;br /&gt;ApplicationModel.getInstance().addXYZListener(this.activePanel);&lt;br /&gt;this.activePanel = null;&lt;br /&gt;this.clearSelection();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;      &lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;But.... you could also use weak references. They would avoid such problems. At the time I found &lt;a href="http://www.jroller.com/santhosh/entry/use_weak_listeners_to_avoid"&gt;good stuff &lt;/a&gt;that I’ve used as a reference.&lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;The only issue that I see in his solution is that we may have sometimes a bunch of empty WeakPropertyChangeListeners (pointing to null) when the referred object is GC’d. He provides a lazy approach for clean up. However, if you use your own &lt;a href="http://java.sun.com/javase/6/docs/api/java/lang/ref/ReferenceQueue.html"&gt;ReferenceQueue &lt;/a&gt;you can provide a thread that once in a while polls the queue and does the sweeping of listener lists. Or also you can use a WeakHashMap which does the dirty work of clean up.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;/div&gt;&lt;p style="font-weight: bold; text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Memory sensitive caches&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;There are several caching strategies (e.g. LRU, MRU) but this one is very simple. It caches everything, but when the system runs out of memory the cache is cleaned up.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Depending on the memory footprint of your system this strategy may be useless and your cache will not work really well.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;This memory sensitive cache relies on SoftReferences. They are special types of WeakReference which hang around for a while.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;The following class is not an optimal implementation of a cache, but it works…&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;public class ImageCache {&lt;br /&gt;private HashMap&amp;lt;String, SoftReference&amp;lt;ImageIcon&amp;gt;&amp;gt; map = new HashMap&amp;lt;String, SoftReference&amp;lt;ImageIcon&amp;gt;&amp;gt;();&lt;br /&gt;private static final String IMAGE_FOLDER = "/images/";&lt;br /&gt;&lt;br /&gt;public ImageIcon getImage(String imageFile) {&lt;br /&gt;ImageIcon icon = null;&lt;br /&gt;if (map.containsKey(imageFile)) {&lt;br /&gt;icon = map.get(imageFile).get();&lt;br /&gt;if (icon == null) {&lt;br /&gt;icon = cacheImage(imageFile);&lt;br /&gt;}&lt;br /&gt;} else {&lt;br /&gt;icon = cacheImage(imageFile);&lt;br /&gt;}&lt;br /&gt;return icon;&lt;br /&gt;}&lt;br /&gt;private ImageIcon cacheImage(String imageFile) {&lt;br /&gt;ImageIcon icon = new ImageIcon(this.getClass().getResource(&lt;br /&gt;imageFile));&lt;br /&gt;map.put(imageFile, new SoftReference&amp;lt;ImageIcon&amp;gt;(icon));&lt;br /&gt;return icon;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;Another cool stuff that can be done (although I've never done it in a "real life" project as I did with the other stuff) is to provide an alternative way to finalization using PhantomReferences. You can use them combined with a ReferenceQueue to provide your own finalization mechanism avoiding the error-prone finalize method. You could write your own finalizer thread :)&lt;br /&gt;&lt;/div&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;There is a good reference &lt;a href="http://www.ibm.com/developerworks/java/library/j-refs/"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p style="text-align: justify;" class="MsoNormal"&gt;I guess that it for the moment.&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-751835753317128617?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/751835753317128617/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=751835753317128617' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/751835753317128617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/751835753317128617'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/05/do-you-know-weak-references-have-you.html' title='Do you know weak references? Have you ever used them?'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-8523706557797633267</id><published>2008-04-23T07:21:00.000-07:00</published><updated>2008-09-18T11:14:44.617-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Open source'/><category scheme='http://www.blogger.com/atom/ns#' term='scripting'/><title type='text'>Scriptconsole4j: Embed a scripting console in your Java App.</title><content type='html'>&lt;span style="color: rgb(0, 0, 0);"&gt;Using scripting languages in Java became very easy. The JSR 223 standardizes the usage of scripting languages in the Java Platform; and Java 6 already ships with built-in support to JavaScript (Mozilla Rhino engine).&lt;/span&gt;&lt;br /&gt;&lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;If you need to embed a multi-language enabled scripting “visual console” to your application you may try the scriptconsole4j.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;I was developing a Java application where I needed to do some coding on the fly during runtime, change variable values, run snippets of code, etc.&lt;span style=""&gt;  &lt;/span&gt;So, I’ve created a simple scripting console to use on that application. I don’t know if something like that already existed, but my code and its usage are really simple. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;I’ve extracted the classes and made a few changes on it and created a separate reusable jar library (the scriptconsole4j). It is hosted at &lt;a href="http://code.google.com/p/scriptconsole4j/"&gt;http://code.google.com/p/scriptconsole4j/&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;There are two ways to use it:&lt;/span&gt;&lt;/p&gt;    &lt;ul style="color: rgb(0, 0, 0);"&gt;&lt;li&gt;&lt;span style="" lang="EN-GB"&gt;A JPanel with scripting functionality that can be embedded in another application (e.g. you can add a scripting window, or a scripting console to your app and access some of your application variables through the scripting window)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="" lang="EN-GB"&gt;A standalone frame that embeds the above scripting console (e.g. you can practice the scripting language of your choice with it)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;span style="color: rgb(0, 0, 0);" lang="EN-GB"&gt;This scripting console provides a standard output variable, but allows variables from your own application to be available through the scripting console.&lt;br /&gt;The combobox shows all available scripting engines on the running JVM. By default, Java 6 comes with JavaScript.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;a style="color: rgb(0, 0, 0);" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_RRFIUjuwzn4/SA9VhuZpSJI/AAAAAAAAAJ4/9HGWnIt56no/s1600-h/multiplescriptlangs.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_RRFIUjuwzn4/SA9VhuZpSJI/AAAAAAAAAJ4/9HGWnIt56no/s320/multiplescriptlangs.png" alt="" id="BLOGGER_PHOTO_ID_5192462933261109394" border="0" /&gt;&lt;/a&gt;&lt;span style="color: rgb(0, 0, 0);" lang="EN-GB"&gt;By doing the following as in the example, it is possible to add you custom(s) variable(s):&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;import scriptconsole4j.*;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;JFrame frame = new JFrame("[Scriptconsole4j] Default Window");&lt;br /&gt;//No textual description available. The console will just display the classname as info&lt;br /&gt;ScriptContextVariable myObjectVar = new ScriptContextVariable(new MyObject(),"myobj","");&lt;br /&gt;//The scripting panel can take several ScriptContextVariable as parameter&lt;br /&gt;ScriptingPanel panel = new ScriptingPanel(myObjectVar);&lt;br /&gt;frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;frame.setSize(400, 400);&lt;br /&gt;frame.add(panel);&lt;br /&gt;frame.setVisible(true);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;You can add any variable that you want and use it from the scripting panel. In the above code we add an object of type MyObject that will be available in the console with the alias of "myobj". There is no big deal here, since the JSR 223 allows context objects. However, we wrap it and put some additional info so other can see what are the variables that we intentionally want to let available to the console, and hopefully some (optional) textual description of it.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a style="color: rgb(0, 0, 0);" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_RRFIUjuwzn4/SA9Vh-ZpSKI/AAAAAAAAAKA/FvQ8YpXLZHA/s1600-h/scriptcustomvariable.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_RRFIUjuwzn4/SA9Vh-ZpSKI/AAAAAAAAAKA/FvQ8YpXLZHA/s320/scriptcustomvariable.png" alt="" id="BLOGGER_PHOTO_ID_5192462937556076706" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;   &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Other JSR 223 compliant engines of existing scripting languages are available at &lt;a href="http://scripting.java.net/"&gt;http://scripting.java.net &lt;/a&gt;.The download on that site provides the JSR 223 engines but it is still necessary to make additional downloads to the scripting libraries themselves.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Several improvements still need to be done in the console (e.g. ability to load scripts, script embelisher, undo support), but this little panel brought a lot of flexibility for me during development time of my apps.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;The first release can be downloaded &lt;a href="http://code.google.com/p/scriptconsole4j/downloads/list"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;I hope you can give it a try to see if it helps you too.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-8523706557797633267?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/8523706557797633267/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=8523706557797633267' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/8523706557797633267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/8523706557797633267'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/04/scriptconsole4j-embed-scripting-console.html' title='Scriptconsole4j: Embed a scripting console in your Java App.'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_RRFIUjuwzn4/SA9VhuZpSJI/AAAAAAAAAJ4/9HGWnIt56no/s72-c/multiplescriptlangs.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-894551937159530968</id><published>2008-04-02T16:05:00.001-07:00</published><updated>2008-07-22T09:05:47.811-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Heap analysis'/><title type='text'>"Hacking" JHat API to integrate it to my application</title><content type='html'>&lt;span style="color: rgb(0, 0, 0);"&gt;Those that already used jhat may say: "JHat API? I thought it was just a java tool that comes with JDK 6."&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;I'll explain.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);" lang="EN-GB"&gt;&lt;br /&gt;JHat (Java Heap Analysis Tool) is an experimental tool that comes with JDK 6. It can parse a heap dump file (HPROF format) and provide a simple http server (port 7000 as default) where we can execute queries in a simple SQL like language that has some predefined functions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);" lang="EN-GB"&gt;&lt;o:p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/o:p&gt;No big deal so far. All that is documented. A while ago I needed to integrate a memory inspection tool in a Java application that I was developing. I know there are few tools to do that externally but I wanted do memory inspection from a menu option in my application.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;    &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;Although jhat is available as a command line tool, actually its classes are in the tools.jar file. So, I thought I could try do integrate that with my app. I tried to google some javadocs on jhat. Couldn’t find it. The tool is experimental, I forgot that.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;Thanks to decompilers I could see how to start up the query engine. I extracted the code and could adapt it to my needs in my application.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;I’ve tried to write the examples in a more didactic method in order to be more understandable. I hope I’ve put it in an easy way.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;          &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;In order to run the example you would need an HPROF file.&lt;o:p&gt;&lt;/o:p&gt; There are some ways to obtain a heap dump. The easiest (I think) is to run jmap and get the file dump.&lt;/span&gt;&lt;!--[if !supportLists]--&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;Memory inspection done this way is not real time, since we are analyzing a snapshot of memory. But that helped me a lot. Remember that this is a heavy process that may consume lots of memory.&lt;br /&gt;&lt;/p&gt;&lt;ol style="color: rgb(0, 0, 0);"&gt;&lt;li&gt;Run jps to find out the PID of the Java application to take the memory snapshot&lt;/li&gt;&lt;li&gt;Now run: jmap –dump:fomat=b,file=myheapdump.bin &lt;pid&gt;&lt;/pid&gt;&lt;/li&gt;&lt;li&gt;Now: java JHatExample myheapdump.bin&lt;/li&gt;&lt;/ol&gt;    &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;In case of out of memory errors when running the example use the –Xmx option:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="color: rgb(0, 0, 0);" class="MsoNormal"&gt;&lt;span style="" lang="EN-GB"&gt;&lt;code&gt;java –Xmx512m JHatQueryExample myheapdump.bin&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; The example consists in three classes:&lt;/span&gt;&lt;br /&gt;&lt;ul style="color: rgb(0, 0, 0);"&gt;&lt;li&gt;JHatExample: The GUI code&lt;/li&gt;&lt;li&gt;JHatWrapper: A class that wraps the access to the jhat API&lt;/li&gt;&lt;li&gt;MyQueryVisitor: Implementation of the jhat’s ObjectVisitor interface that provides a call back method on the results of the query. &lt;/li&gt;&lt;/ul&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Running the code will show the following GUI:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="color: rgb(0, 0, 0);" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_RRFIUjuwzn4/R_SjXUOiNpI/AAAAAAAAAJA/Y_WeGkO3HIY/s1600-h/jhatwrapper.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_RRFIUjuwzn4/R_SjXUOiNpI/AAAAAAAAAJA/Y_WeGkO3HIY/s200/jhatwrapper.png" alt="" id="BLOGGER_PHOTO_ID_5184948691972273810" border="0" /&gt;&lt;/a&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;With the same query from the picture, if you click execute it will show all referrers to all instances of java.io.File.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Actually the way I print the result of the query is quite confusing...&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;If anybody ever happen to try to run the code, there is a good link on constructing queries in &lt;/span&gt;&lt;a style="color: rgb(0, 0, 0);" href="http://blogs.sun.com/sundararajan/entry/querying_java_heap_with_oql"&gt;Sundarajan's blog &lt;/a&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;with nice examples. The code I provided makes some calls to the javascript library that is provided with JHat.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;If you uncompress the tools.jar file you may find that library and the help page in:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;tools.jar\com\sun\tools\hat\resources\&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;The purpose of this code is to show the possibility to integrate jhat usage into your application. Normally it is used as a stand alone tool. The stand alone tool is ready to use, but is a side tool that you have to open. What I did in my app (not the one shown here) was to automate the memory dump via a Runtime.exec call to jmap, and then the resulting file was used as a parameter to instatiate the jhat engine.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Since jhat is an experimental tool, it may completely change or become unavailable on Java 7. Use it like I did at your own risk.&lt;br /&gt;&lt;br /&gt;Have fun playing with the code!&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;The GUI Code:&lt;/span&gt;&lt;br /&gt;&lt;pre style="color: rgb(0, 0, 0);"&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;import java.awt.*;&lt;br /&gt;import java.io.File;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;&lt;br /&gt;public class JHatExample extends JFrame {&lt;br /&gt;private JHatWrapper jhat;&lt;br /&gt;&lt;br /&gt;public JHatExample(JHatWrapper jhat) {&lt;br /&gt; super("JHat wrapper");&lt;br /&gt; this.jhat = jhat;&lt;br /&gt; initComponents();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;private void initComponents() {&lt;br /&gt; final JTextArea queryText = new JTextArea();&lt;br /&gt; JPanel buttonPanel = new JPanel();&lt;br /&gt; JButton executeBtn = new JButton("Execute");&lt;br /&gt; buttonPanel.add(executeBtn);&lt;br /&gt; this.add(new JScrollPane(queryText),BorderLayout.CENTER);&lt;br /&gt; this.add(buttonPanel,BorderLayout.SOUTH);&lt;br /&gt; executeBtn.addActionListener(new ActionListener() {&lt;br /&gt;  public void actionPerformed(ActionEvent e) {&lt;br /&gt;   try {&lt;br /&gt;    jhat.query(queryText.getText());&lt;br /&gt;   } catch (Exception e1) {&lt;br /&gt;    JOptionPane.showMessageDialog(JHatExample.this, "Error executing query");&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; });&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String[] args) throws Exception {&lt;br /&gt; if (args.length == 0 || ! new File(args[0]).exists()) {&lt;br /&gt;  System.out.println("The program must take a valid file path as parameter");&lt;br /&gt;  return;&lt;br /&gt; }&lt;br /&gt; JHatWrapper jhat = new JHatWrapper(args[0]);&lt;br /&gt; JHatExample frame = new JHatExample(jhat);&lt;br /&gt; frame.setSize(400,200);&lt;br /&gt; frame.setVisible(true);&lt;br /&gt; frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Now the wrapper class:&lt;/span&gt;&lt;br /&gt;&lt;pre style="color: rgb(0, 0, 0);"&gt;&lt;span style="font-size:85%;"&gt;&lt;code&gt;import java.io.*;&lt;br /&gt;import com.sun.tools.hat.internal.model.Snapshot;&lt;br /&gt;import com.sun.tools.hat.internal.oql.OQLEngine;&lt;br /&gt;import com.sun.tools.hat.internal.parser.HprofReader;&lt;br /&gt;import com.sun.tools.hat.internal.parser.PositionDataInputStream;&lt;br /&gt;&lt;br /&gt;public class JHatWrapper {&lt;br /&gt;private OQLEngine engine;&lt;br /&gt;&lt;br /&gt;public JHatWrapper(String s) throws Exception {&lt;br /&gt; PositionDataInputStream positiondatainputstream =&lt;br /&gt; new PositionDataInputStream(new BufferedInputStream(new FileInputStream(s)));&lt;br /&gt;  int l;&lt;br /&gt;  Snapshot snapshot;&lt;br /&gt;  l = positiondatainputstream.readInt();&lt;br /&gt;   //I "inferred" the meaning of the parameters below by comparing the decompiled code&lt;br /&gt;//and jhat's command line parameters&lt;br /&gt;  int debuglevel = 0;&lt;br /&gt;  //Don't know what this is...&lt;br /&gt;  int j =1;&lt;br /&gt;  HprofReader hprofreader = new HprofReader(s, positiondatainputstream,&lt;br /&gt;j, true, debuglevel);&lt;br /&gt;  snapshot = hprofreader.read();&lt;br /&gt;  positiondatainputstream.close();&lt;br /&gt;  //resolve references&lt;br /&gt;  snapshot.resolve(true);&lt;br /&gt;  engine = new OQLEngine(snapshot);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void query(String query) throws Exception {&lt;br /&gt;  engine.executeQuery(query, new MyQueryVisitor(engine) );&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;And the Visitor code:&lt;/span&gt;&lt;br /&gt;&lt;pre style="color: rgb(0, 0, 0);"&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;import java.util.Enumeration;&lt;br /&gt;&lt;br /&gt;import com.sun.tools.hat.internal.model.JavaHeapObject;&lt;br /&gt;import com.sun.tools.hat.internal.oql.OQLEngine;&lt;br /&gt;import com.sun.tools.hat.internal.oql.ObjectVisitor;&lt;br /&gt;&lt;br /&gt;public class MyQueryVisitor implements ObjectVisitor {&lt;br /&gt;private OQLEngine engine;&lt;br /&gt;&lt;br /&gt;public MyQueryVisitor(OQLEngine engine) {&lt;br /&gt; this.engine = engine;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public boolean visit(Object obj) {&lt;br /&gt; try {&lt;br /&gt;  Object iterator = engine.call("wrapIterator",new Object[]{obj});&lt;br /&gt;  //Handles result items that are instance of enumeration. Ex: select referrers(x) from java.io.File x&lt;br /&gt;  if (iterator instanceof Enumeration) {&lt;br /&gt;   System.out.println("enum");&lt;br /&gt;   handleEnumeration((Enumeration)iterator);&lt;br /&gt;  } else {&lt;br /&gt;   //handles single result items. Ex: select x from java.io.File x&lt;br /&gt;   JavaHeapObject javaObj = (JavaHeapObject)engine.call("unwrapJavaObject",new Object[]{obj});&lt;br /&gt;   handleEnumeration(javaObj.getReferers());&lt;br /&gt;  }&lt;br /&gt; } catch (Exception e) {&lt;br /&gt;  e.printStackTrace();&lt;br /&gt; }&lt;br /&gt; return false;&lt;br /&gt;}&lt;br /&gt;void handleEnumeration(Enumeration en) {&lt;br /&gt; while (en.hasMoreElements()) {&lt;br /&gt;  try {&lt;br /&gt;   Object obj = en.nextElement();&lt;br /&gt;   JavaHeapObject unwrapped = (JavaHeapObject)engine.call("unwrapJavaObject",new Object[]{obj});&lt;br /&gt;   System.out.println(unwrapped);&lt;br /&gt;  } catch (Exception e) {&lt;br /&gt;   e.printStackTrace();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-894551937159530968?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/894551937159530968/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=894551937159530968' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/894551937159530968'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/894551937159530968'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/04/hacking-jhat-api-to-integrate-it-to-my.html' title='&quot;Hacking&quot; JHat API to integrate it to my application'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_RRFIUjuwzn4/R_SjXUOiNpI/AAAAAAAAAJA/Y_WeGkO3HIY/s72-c/jhatwrapper.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7414681341906437667.post-7289946150212100746</id><published>2008-04-02T15:50:00.000-07:00</published><updated>2008-04-02T16:05:01.303-07:00</updated><title type='text'>Yet another Java blog</title><content type='html'>Ok, one grain of sand in the desert of blogs that talk about Java...&lt;br /&gt;My intention is to leave some (useful) contribution. I frequently google for things to help me when I develop.&lt;br /&gt;Sometimes I go to forums and mailing lists to make questions but usually I never contribute back helping other people. What a leech!&lt;br /&gt;I hope my posts can help somebody.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7414681341906437667-7289946150212100746?l=ordinaryjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ordinaryjava.blogspot.com/feeds/7289946150212100746/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7414681341906437667&amp;postID=7289946150212100746' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/7289946150212100746'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7414681341906437667/posts/default/7289946150212100746'/><link rel='alternate' type='text/html' href='http://ordinaryjava.blogspot.com/2008/04/yet-another-java-blog.html' title='Yet another Java blog'/><author><name>kiev gama</name><uri>http://www.blogger.com/profile/17229100175885523440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
