tag:blogger.com,1999:blog-190435282024-03-07T15:16:50.988-08:00Tech TalkAshishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-19043528.post-64185276982027063762010-04-21T02:30:00.000-07:002010-04-21T03:58:46.073-07:00GIDS 2010This was the third season of the Great Indian Developer Summit and like the previous conferences, this one too saw developers, technologists, evangelists and motivation speakers come from all parts. Yes motivation speaker! Priya Kumar, a dynamic motivational speaker and author of the best selling book "I am another you" was here and spoke on Possibilities and becoming a hero in what you are doing. The talk was refreshing and a welcome break. Being post lunch it was well timed and brought energy back into the dozing audience.<br /><br />I personally like this conference for the great array of speakers that it calls upon. Being a Java and Web App enthusiast, I attended the GIDS.Web track of the conference. The day started with a keynote by the great Marty Hall from coreservlets. He compared the various approaches to building Rich internet applications with Ajax. He spoke about Javascript libraries like dojo, jQuery available for adding Ajax support to an existing web application vs building Ajax rich applications from scratch using frameworks like JSF. In another session later in the day he juxtaposed the different javascript libraries like jQuery, dojo, prototype, scriptaculous, google closure, and YUI. He rated them against their support for Ajax, UI controls, DOM manipulation, ease of use, javascript features and popularity.<br /><br />Scott Davis delivered an engaging talk on Deconstructing Web2.0. He impressed upon the audience that Web2.0 is not a thing but a state of mind. It's a dynamic, interactive, collaborative and componentized view of the web. He provided many examples and built a web application using grails there and then to drive the point on dynamic nature of Web2.0, short delivery cycles where applications are always in beta.<br /><br />There were a couple of sessions on cloud computing by Amazon and Adobe. But they just scraped the surface. We have heard enough about it. Some practical exercises would have been really useful.<br /><br />The presentations will be up on the <a href="http://www.developermarch.com/developersummit/">devsummit </a>website.<br /><br />~Ashish.Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com0tag:blogger.com,1999:blog-19043528.post-85761458729670042862009-04-23T20:48:00.000-07:002009-04-24T22:54:58.751-07:00GIDS.JavaDay 3 of the Great Indian Developer Summit had its key focus on Java, and Enterprise applications. The conference saw a sea of delegates from the major IT companies all around Bangalore. The usually quaint and quiet premises of IISc was today beaming with techies and nerds noisily discussing their favorite programming language or tool. Age was no bar here. The gray haired were as much (if not more!) geeky as the college pass-outs (or drop-outs!). Organized by <a href="http://www.devmarch.com/index.html">Devmarch</a>, the conference had the likes of Microsoft, Yahoo!, IBM, Adobe, Red Hat, Intel for its sponsors.<br /><br />The attendees had various things to choose from. There were sessions conducted by leading speakers in the industry. There were expos hosted by the sponsors. There were workshops; after all what's programming without some hands-on! And of course there was a lot of opportunity and scope for networking with the speakers and attendees. <br /><br />Sessions for the day were grouped in five parallel tracks. They dealt with the key technologies like cloud computing, RESTful web services, Ruby on Rails, Groovy, Agile development and Ajax in addition to Java of course.<br /><br />Craig McClanahan, the creator of Struts started off the morning session with an insightful talk on Cloud Computing. It means different things for different people. For some it is Software as a service, for some it's virtualization, for a few it is utility computing, grid computing, and for others it is application hosting platform. Truth is that it is a combination of all these and more and has created a lot of buzz amongst the enterprises and developers alike. What's driving their interest is the low cost and agile business model that the cloud promises to achieve. The pay as you go economic model, the rapid, self provisioning and API driven development model and the flexibility offered through standard, elastic, on-demand services is attractive to one and all. There are many clouds out there and Craig spoke about what they all share and what they don't. He also highlighted the three layers in cloud computing - Software as a service (SaaS), Platform as a service (PaaS) and Infrastructure as a service (IaaS) from top to bottom. These are the primary areas where the vendors are focusing be it Amazon Web services and EC2 or Google App Engine or Salesforce.com. At closing he introduced the upcoming cloud platform of Sun (or Oracle!) and hinted on the announcement of the Sun storage and compute services at JavaOne (shhhh!).<br /><br />Jim Webber, author of "Developing Enterprise Applications - Architect's guide" conducted an engaging session on Introducing REST - the Starbucks example. He used the Starbucks coffee shop example to drive home the RESTful paradigm of web services. He started off with the Richardson Maturity Model - a model of technologies stacked up based on the level to which they embrace the web. The stack has the traditional RPC at its peak and then moves down to technologies that use URIs, web services and finally to REST that completely embraces web. REST is all about resources, their states and how they can be accessed with URIs. It's quite hard to believe that what was always there around us (meaning the web) eluded us all with it's power and scalability. While we focused all the energies on building middleware to support the integration, scalability, security and other "abilities", it was all already there in the form of the web. Jim talked about the HTTP implementation of REST, the CRUD operations using the POST, GET, PUT and DELETE verbs, and how HTTP supports metadata in its header. He also stressed on the microformats and media types that are again intrinsic to a RESTful implementation. Jim's humor, the informal style of presentation and animated hand waving was very well taken by the audience. Needless to say that it kept them all engaged and on the edge of their seats!<br /><br />Last session for the day was one on testing Java with JRuby. It was delivered by another Thoughtworker Ola Bini [<a href="http://olabini.com/blog/">Ola Bini blogs</a>]. Now this was a very interesting topic. All the more for me as I had been thinking about this for some time now. Since the dynamic languages are known and used for stitching components, using them for testing is a natural extension. Especially when one has to come up with the test code quickly (which is usually the case), JRuby can be of great help. And its many gems provide added capability for avoiding repetition, and for writing plain text stories and scenarios. Bini kept shuffling between the presentation and demos and did complete justice to the topic.<br /><br />Kudos to the organizing team. With over 3000 attendees at the conference, the logistics was well handled. The sessions were well timed and but for a couple of changes to the agenda, all the others started and got over on time. The only grouse was the long queues and crowd at the dining area; some arrangement there would have helped. And did I say that the food was awesome! :)<br /><br />~AshishAshishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com7tag:blogger.com,1999:blog-19043528.post-3424496944289618612009-04-12T02:22:00.000-07:002009-04-12T02:24:45.547-07:00REST explainedCame across this funny yet revealing post of this guy explaining REST to his wife. It's simplistic and comprehensive starter on all that is REST.<br /><br /><a href="http://tomayko.com/writings/rest-to-my-wife">REST to my wife</a><br /><br />~AshishAshishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com0tag:blogger.com,1999:blog-19043528.post-24889923365115035062009-03-31T01:09:00.000-07:002009-03-31T01:10:16.149-07:00XML generation using SAXTransformer in Java JDKXML generation is a common found requirement in applications. Typical way to address it in java is to manually append the XML string in a StringBuffer. Firstly this can be quite tedious. Secondly it is susceptible to manual errors while writing the XML. Also, the developer needs to take care of the escape characters etc. Clearly this is not the best way of XML generation in Java.<br />A better way of achieving this is to use the classes in javax.xml.transform package of JDK. These are traditionally used for XML parsing and transformations. Their use of XML generation is uncommon and unobvious. here's a code snippet that shows how these classes can be used for XML generation:<br /><br /> SAXTransformerFactory saxFactory = (SAXTransformerFactory) TransformerFactory.newInstance();<br /> StringWriter writer = new StringWriter();<br /> try {<br /> TransformerHandler handler = saxFactory.newTransformerHandler();<br /> Result result = new StreamResult(writer);<br /> handler.setResult(result);<br /> handler.startDocument();<br /> AttributesImpl atts = new AttributesImpl();<br /> atts.addAttribute("", "", "name", "CDATA", "");<br /> atts.addAttribute("", "", "version", "CDATA", "6.2");<br /> handler.startElement("http://wbe.ibm.com/6.2/Event/connect", "","connector", atts);<br /> atts.clear();<br /> atts.addAttribute("", "", "name", "CDATA", "connect");<br /> atts.addAttribute("", "", "type", "CDATA", "Event");<br /> handler.startElement("", "", "connector-bundle", atts);<br /> atts.clear();<br /> handler.startElement("", "", "connect", atts);<br /> String paramValue = null;<br /> for (ScenarioParameter param : scenarioParams) {<br /> atts.clear();<br /> atts.addAttribute("", "", "type", "CDATA", param.getType());<br /> handler.startElement("", "", param.getName(), atts);<br /> paramValue = getParamValue(param.getParamId(), params);<br /> handler.characters(paramValue.toCharArray(), 0, paramValue.length());<br /> handler.endElement("", "", param.getName());<br /> }<br /> handler.endElement("", "", "connect");<br /> handler.endElement("", "", "connector-bundle");<br /> atts.clear();<br /> handler.startElement("", "", "system", atts);<br /> String systemName = InetAddress.getLocalHost().getHostName();<br /> handler.characters(systemName.toCharArray(), 0, systemName.length());<br /> handler.endElement("", "", "system");<br /> handler.startElement("", "", "timestamp", atts);<br /> String timestamp = new Date().toString();<br /> handler.characters(timestamp.toCharArray(), 0, timestamp.length());<br /> handler.endElement("", "", "timestamp");<br /> handler.startElement("", "", "loginfo", atts);<br /> String logMsg = "Sending values at runtime";<br /> handler.characters(logMsg.toCharArray(), 0, logMsg.length());<br /> handler.endElement("", "", "loginfo");<br /> handler.endElement("", "", "connector");<br /> handler.endDocument();<br /><br /> System.out.println(writer.toString());<br /><br />TransformerHandler listens for XML parse events and transforms them to Result. Since we are not using it for parsing, here the handler generates those events like startDocument, startElement and transforms them into Result. The Result thus contains the XML that we wanted to generate. Note that it is the developer's responsibility to take care of the well formedness of the XML. A startElement has to have a matching endElement and a startDocument has to have a matching endDocument.<br /><br />~Ashish.Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com23tag:blogger.com,1999:blog-19043528.post-88278389292430638232009-03-30T04:24:00.000-07:002009-03-30T04:30:06.910-07:00Dynamic EJB lookup using Java ReflectionApplications often need to lookup resources based on their JNDI names. The lookup code can be made short and dynamic using Java reflection.<br />In my application there was a need to lookup an EJB. The JNDI name was dependent on the value of a constant (called cepengine). This is how I implemented the lookup.<br />I wrote a constants file (constants.properties) with these entries:<br /><br />cepengine=wbe<br />eventdefinition.bean.jndi=ejb/com/ibm/eventmanagement/eventdefinition/EventDefinitionServiceHome<br />eventdefinition.wbe.bean.jndi=ejb/com/ibm/eventmanagement/eventdefinition/wbe/WBEEventDefinitionServiceHome<br />eventdefinition.bean.home.wbe=com.ibm.eventmanagement.eventdefinition.wbe.WBEEventDefinitionServiceHome<br />eventdefinition.bean.home=com.ibm.eventmanagement.eventdefinition.EventDefinitionServiceHome<br /><br />I then wrapped this up with a java class (PropertyLoader.java) with methods to return the various values in the properties file. For instance here is the method that returns the JNDI name:<br /><br /> public String getEventDefinitionServiceJNDI() {<br /> String cepEngine = getCEPEngine();<br /> String constStr = null;<br /> if (cepEngine != null && !cepEngine.equalsIgnoreCase("")) {<br /> constStr = "eventdefinition." + getCEPEngine() + ".bean.jndi";<br /> } else {<br /> constStr = "eventdefinition.bean.jndi";<br /> }<br /> return bundle.getString(constStr);<br /> }<br /><br />Similarly there is a method that returns the name of the home interface class.<br /><br />Next I implemented the lookup code using the ServiceLocator pattern in a class aptly named ServiceLocator.java. Here's the code snippet that looks up the home interface object and creates the bean object:<br /><br /> private Object locateEJBHome(String jndi, Class homeClass)<br /> throws ClassCastException, NamingException {<br /> Object ejbHome = ejbHomeObjects.get(homeClass);<br /> if (ejbHome == null) {<br /> ejbHome = PortableRemoteObject.narrow(getInitialContext().lookup(jndi), homeClass);<br /> ejbHomeObjects.put(homeClass, ejbHome);<br /> }<br /> return ejbHome;<br /> }<br /><br /> public EventDefinitionService getEventDefinitionService() {<br /> EventDefinitionService facade = null;<br /> Object facadeHome = null;<br /> PropertyLoader propLoader = new PropertyLoader();<br /> String eventDefHomeName = propLoader.getEventDefinitionServiceHome();<br /><br /> try {<br /> facadeHome = locateEJBHome(propLoader.getEventDefinitionServiceJNDI(), Class.forName(eventDefHomeName));<br /><br /> if (facadeHome != null) {<br /> facadeHome = Class.forName(eventDefHomeName).cast(facadeHome);<br /> Method createMethod = facadeHome.getClass().getMethod("create",new Class[] {});<br /> facade = (EventDefinitionService) createMethod.invoke(facadeHome, new Object[] {});<br /><br /> m_log.info("Received the Event Definition service bean handle");<br /> }<br /> } catch (NamingException ne) {<br /> m_log.severe("NamingException getting event definition EJB facade home."+ ne);<br /> } catch (Exception e) {<br /> m_log.severe("Exception getting event definition service object."+ e);<br /> }<br /> return facade;<br /> }<br /><br />Let's look at the getEventDefinitionService() method. The method first gets the bean JNDI name and home interface class name using the PropertyLoader. It then uses the generic locateEJBHome() method to look up and return the home object. We then typecast the returned object to actual home class. Using java reflection we get the method object for the method called "create". This is the method that creates the bean object. Note that in my requirement there was a hierarchial relationship between the bean implementations. WBEEventDefinitionService is a subclass of EventDefinitionService. Therefore when I invoke the create method object, I know that the returned object is an instance of either EventDefinitionService or its subclass. However if this is not the case, the same notion of reflection can be extended here as well.<br /><br />Thus you can see that this code makes is extremely short and easy to do look up the EJB what might have otherwise required separate lookup code for each EJB.<br /><br />~AshishAshishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com25tag:blogger.com,1999:blog-19043528.post-72150478248477767822008-11-22T21:00:00.000-08:002008-11-22T21:26:24.333-08:00Women in Web2.0Here's a listing of women entrepreneurs who made it big in Web 2.0 startups<br /><a href="http://www.fastcompany.com/articles/2008/11/influential-women-web.html?page=0,0">Most Influential Women in Web 2.0</a><br /><br />AshishAshishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com24tag:blogger.com,1999:blog-19043528.post-17808474109266795642008-03-22T10:14:00.000-07:002008-03-22T10:35:18.772-07:00Which language should I learn next?I had always looked at programming languages as means of achieving the ends. Probably that's why I was stuck with Java for the last four years. That was until the Ruby bug bit me and I was awed by its features. Really learning a new language can be both fun and a learning experience. This blog on Dobbs tell us which languages to focus on.<br /><a href="http://dobbscodetalk.com/index.php?option=com_myblog&show=Learn-as-Many-Languages-as-You-Can-or-just-learn-Scala-.html&Itemid=29">Learn as many languages as you can</a><br />Slashdot has some interesting comments on it:<br /><a href="http://it.slashdot.org/article.pl?sid=08/03/18/1633229&from=rss">What programming languages should you learn next</a>?<br /><br />-Ashish.Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com26tag:blogger.com,1999:blog-19043528.post-85558111921292129262008-03-05T00:25:00.000-08:002008-03-05T04:39:07.352-08:00Scripting the futureNot until only some time back C, C++ and java pretty much ruled the realm of programming languages. Dynamic scripting languages like Perl, python raised their head at times, but were never so much of a buzz. My first tryst with a scripting language happened when I heard about Ruby and developed a web application on Rails. The ease and speed of development impressed me so much that I instantly fell in love with it. Ever since then, scripting languages have been on a rise. I used to always wonder Why. Why was the potential of dynamic languages nascent all this while? What has changed between then and now?<br />I found answers to these in these wonderful articles:<br /><a href="http://www.oreillynet.com/pub/wlg/3190">Why Scripting Languages Matter?</a><br /><a href="http://home.pacbell.net/ouster/scripting.html">Scripting: Higher Level Programming for the 21st Century</a><br /><br />The points look appealing. I had always been taught to do a low level design before getting on with writing code. I always found it disconcerting. I mean who has the patience to design to the lowest level! I was more comfortable with designing while coding and coding while designing. I ran into issues some times that required so much recoding that I used to momentarily regret not following the elders' advice! Scripting languages claim to be more dynamic and malleable. Am sure developers love them for what they have on offer, but do they match up with the static languages on performance and other fronts? Need to see...<br /><br />-Ashish.Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com24tag:blogger.com,1999:blog-19043528.post-4659628875034259002008-03-03T21:57:00.000-08:002008-03-03T22:06:29.056-08:00Who owns the Internet?Bumped on this interesting blog on CIO. The author has created a color coded map of all the routers in North America. Curious to see if something similar exists for India/Asia or create one.<br /><br /><a href="http://advice.cio.com/who-owns-the-internet-we-have-a-map-that-shows-you?page=0%2C0">Who Owns the Internet? We have a Map that shows you.</a><br /><br />-Ashish.Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com0tag:blogger.com,1999:blog-19043528.post-91078113755954781732008-01-02T22:13:00.000-08:002008-01-07T00:54:56.365-08:00Merb - A new Ruby frameworkMerb (Mongrel+ERB) seems to be a new addition to the Ruby based frameworks. Like Rails, it complies to the MVC architecture. But instead of having all the components as part of the core, it relies more on plugins. It therefore claims to have a lighter footprint which can be extended through plugins. This makes it ORM agnostic, template language agnostic. Plugins are available for ActiveRecord, DataMapper, Sequel ORMs.<br /><br />In short Merb has all the good features of Rails and more and is lighter and faster.<br /><br />Learn more about it <a href="http://merbivore.com/">here</a> or on <a href="http://merb.devjavu.com/">DevjaVu</a>.<br /><br />-Ashish.<br /><a href="http://digg.com/submit?url=http%3A%2F%2Ftechielane.blogspot.com/2008/01/merb-new-ruby-framework.html&title=<br />Merb%20-%20A%20new%20Ruby%20framework&bodytext=A%20ruby%20based%20framework%20that%20is%20lighter%20and %20faster%20than%20Rails&media=&topic="><br /><img src="http://digg.com/img/badges/80x15-digg-badge.gif" width="80" height="15" alt="Digg!" /><br /></a>Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com0tag:blogger.com,1999:blog-19043528.post-88285263907358167082007-04-12T02:23:00.000-07:002008-01-07T00:52:37.071-08:00Go OpenGrok<span style="font-size:85%;">To me, browsing a codebase until now always required downloading it and setting it up in an IDE. But as good as they are as a development environment, they are quite cumbersome (some might prefer to say they are an overkill) when it comes to browsing code, especially one that you are not familiar with. Add to this the need to have them and the codebase everywhere and everytime you want to browse... and all I wanted was to browse a set of code!<br /><br />The idea of a web based source browser instantly appealed to me. I heard about <a href="http://www.opensolaris.org/os/project/opengrok/">OpenGrok</a> in one of the sessions at the Sun Techdays and tried it out right away. OpenGrok is a web based source browser with cross referencing and freetext search. All that I need to do is to configure the path of the codebase and run OpenGrok. OpenGrok generates a war that I dump into tomcat and that's all! I can now search the code, click on the variables and methods to check their definitions and do all that's in the scope of code browsing. Moreover, I can just set it up on one box and access it from anywhere on the network.<br /><br />OpenGrok uses <a href="http://ctags.sourceforge.net/">exuberant Ctags</a> and <a href="http://lucene.apache.org/">lucene</a>, the java based search and indexing library to get the job done. It's an easy-to-use code browsing tool... try it out!<br /><br />-Ashish.<br /></span><br /><a href="http://digg.com/submit?url=http%3A%2F%2Ftechielane.blogspot.com/2007/04/go-opengrok.html&title=<br />Merb%20-%20A%20new%20Ruby%20framework&bodytext=a%20web%20based%20source%20browser%20with%20cross%20referencing%20and%20freetext%20search&media=&topic="><br /><img src="http://digg.com/img/badges/80x15-digg-badge.gif" width="80" height="15" alt="Digg!" /><br /></a>Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com0tag:blogger.com,1999:blog-19043528.post-68468152278514375042007-03-21T02:52:00.000-07:002007-07-02T23:05:26.103-07:00Rails vs Struts<span style="font-size:85%;">I had done a study on the size and effort metrics and performance of an application developed on Rails vs that on Struts. Here are the observations:<br /><br /></span><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1KI2YXBI1B7Ay-Sk8Qlrt67rXOmMTXpZVljBYYBKPCTAj-82nWFurZqwtbgM9hIo5e_lz0gbO1KE5sRguceMBo7Af_uQnP4kghJftJx6xFxMICiDmhYpcI2mciZypcu_UYUeIcA/s1600-h/Rails.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 365px; height: 202px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1KI2YXBI1B7Ay-Sk8Qlrt67rXOmMTXpZVljBYYBKPCTAj-82nWFurZqwtbgM9hIo5e_lz0gbO1KE5sRguceMBo7Af_uQnP4kghJftJx6xFxMICiDmhYpcI2mciZypcu_UYUeIcA/s200/Rails.JPG" alt="" id="BLOGGER_PHOTO_ID_5044334294170594098" border="0" /></a><br /><span style="font-size:85%;">Please note that the performance figures are not an exact measure and need to be considered with these points in perspective. There might be scope for improving the performance of the application, as there was no performance tuning performed for the application. In addition, following points also need to be taken into account.<br /><ol><li>Ruby VM: Ruby is right now an interpreted language. But a project (code name Rite) plans to make it byte compiled. This would improve the execution speed of Ruby based programs.</li><li>Framework method tuning: The Rails framework has been around only for a little more than a year. Development is on profile various components especially Active Record and Helper methods. The tuning effort would further improve the performance of applications using Rails.</li><li>Choice of web server: WebRick was used as the web server for this application. Apache and Lighttpd are the suggested web servers for better performance.<br /></li></ol>-Ashish.<br /></span>Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com0tag:blogger.com,1999:blog-19043528.post-78218331959200382632007-02-28T21:49:00.000-08:002007-02-28T23:00:47.271-08:00Sun 'Tech'-aways<span style="font-size:85%;">Last week saw techies from all around the country and outside flocking at the International Convention Center in Hyderabad. It was the Sun Tech Days symposium, a worldwide developer event organized by Sun Microsystems and touted as the mini Sun One conference! With 3000+ attendees, it almost seemed like all roads led to Novotel,Hitex. Although far from the heart of the city, the venue was aptly located very close to the Hi-Tech City thus gaining a lot of visibility from the various IT companies. Both the ICC and Sun representatives did a commendable job of managing the crowd, time, booths, technical sessions and the whole event as such. To top it all, there was good food and gifts galore! Event of this scale can of course not do without sponsors and the list included some of the big names from the industry like AMD, Oracle, VmWare, Accenture, SAS, and NIIT.<br /><br />The technical sessions were divided into multiple tracks alligned with the technologies - J2SE, J2EE, J2ME and open solaris. While on the first two days the attendees were free to choose between any of the sessions going parallaly in these tracks, on the third day, they had to choose between one of - Netbeans, J2ME and Open solaris - tracks. The sessions on ‘Java scripting’ and ‘JRuby’ in the J2SE track were quite interesting and having worked on Ruby, were quite appealing. It was interesting to know that the Java platform was no longer restricted to the Java language alone but supported various scripting languages like JRuby, Javascript, Groovy and Jython. The session on ‘JMX and concurrency’ talked about the new concurrency API in JDK 5.0 and its rich features that address the issues with the old Thread support. The JMX API which was already a part of J2EE 1.4 has now been adopted into the core java platform.<br /><br />Among the more interesting sessions (and among the ones that I attended!) in the J2EE track, was the one on J2EE 5 and Glassfish. Apart from the technical talk on the new EJB 3.0, persistence API, JAX-WS and JAXB, the speaker encouraged the attendees to be a part of the Glassfish community and contribute to the development of the reference implementation.<br /><br />The booth on Java DB, an Apache Derby based project, introduced the java based database. It is best suited for small and medium scale applications and can be bundled along with the application! An ideal solution for sharing database backed applications. The session on SPOTs was very impressive. The Small Programmable Object Technology aims at using Java for programming devices having embedded chips… something that was in the domain of C all this while. The demo showing three robots trying to chase each other recieved a loud applause from the audience. VmWare gave a presentation on their virtualization technology, which apparently is receiving a lot of attention and popularity. The technology evolved trying to explore solutions to the under utilization of the hardware. The presentation introduced the idea of treating one physical system as multiple virtual machines and then focused on its impact on cost, n/w maintenance, and availability. Their VMotion technology that allows runtime movement of virtual machines (and therefore the appliations running on them) from one system to another without requiring the systems to be down indeed has a lot of potential.<br /><br />On the third day, as part of the Open Solaris track, there was an interesting talk on Opengrok. Opengrok is a tool that indexes a given code allowing developers to browse and search the codebase. Although the intent behind its development was to enable quick and easy browsing of the proliferating open source code on the internet without having to set up a development environment, it can be used for any application codebase in our day to day projects. What more, it also has support for dropping the ‘opengrok’ed code into a web server and browsing the code over the network!<br /><br />I must say that it was a good learning experience and a forum to meet other developers and exchange ideas with them. And did I mention about the discounts in technical books and journals! :)<br /><br />The sessions can be downloaded from the Sun Tech Days page on the Sun website:<br /><a href="http://developers.sun.com/events/techdays/index.jsp"><span style="text-decoration: underline;">http://developers.sun.com/events/techdays/index.jsp</span></a><br /><br />- Ashish<br /></span>Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com0tag:blogger.com,1999:blog-19043528.post-1167127886442104952006-12-26T02:07:00.000-08:002006-12-29T01:41:55.088-08:00Closures in Java<span style="font-size:85%;">I hit upon closures first (well at least I thought so until I knew what they were and realized that I had used them before) when coding in Ruby. Closures are blocks of code that can be passed as arguments to other methods. In this sense they are similar to function pointers in C. But closures are a tad more powerful in that they also extend the scope of variables in the lexical scope of where they are used. Refer <a href="http://www.eclipsezone.com/eclipse/forums/t86911.html">http://www.eclipsezone.com/eclipse/forums/t86911.html</a> for a precise definition.<br /><br /></span><span style="font-size:85%;">I recently completed a project involving Ruby on Rails. Having worked with Java for the last three years, I could not help but compare it with Java. I was wondering if any of the language and framework features could be implemented in Java and the numerous frameworks based on it. Blocks and closures are impressive language constructs that allow customization and extension of other language constructs (like the looping constructs) and APIs.<br /><br />Gafter, Gosling et al's proposal to add closures in Java seems to be a good bet. This would put an end to the addition of more new statements like 'for each' that was added in J2SE 5.0.<br /><br />Am keeping an eye on the numerous forums and blogs abuzz with discussions on Java and Ruby. It's interesting how Ruby and more importantly the Rails framework is causing so much flutter.<br /><br />Pointer:<br /><a href="http://www.javac.info/closures-v04.html">http://www.javac.info/closures-v04.html</a><br /><br />-Ashish.<br /></span>Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com0tag:blogger.com,1999:blog-19043528.post-1151498944033922082006-06-28T05:05:00.000-07:002007-03-01T00:12:39.633-08:00Ruby on Rails<span style="font-size:85%;">I got hold of this stone when I attended a presentation organized in the geeknight at <a href="http://www.thoughtworks.com/">ThoughtWorks</a>. The presenters (ThoughtWorkers) were highly enthuisiastic about this project that they had just developmed using the Rails framework. I had only vaguely heard about this new opensource framework and had put it aside as another addition to the slurry of web frameworks that are already in use. The claim that it achieves ten times faster development appeared fantastic - a conclusion drawn from one-off occurence! It was only when I attended this presentation that I got to appreciate the beauty of this precious framework (read stone :)) and how it gets near zero turnaround time.<br /><br />So what is Ruby and what is Rails? And what then is Ruby on Rails!<br /><br />Ruby is a dynamically typed object oriented programming language inspired by other languages like Perl and Smalltalk. And Rails is an open source web framework developed in Ruby. Within a short period, it has gained in popularity for its reduced development time and higher productivity. It is known to be one of the most well thought-out frameworks in existence today.<br /><br />Rails’ support for agile web development can be attributed to various features and its guiding principles - Do not Repeat Yourself (DRY) and Convention over Configuration. Database backed enterprise applications developed today have quite a few things in common. A UI component, a controller component a model component, and an ORM layer. Frameworks like Struts, Spring while providing these components, leave the configuration part to the developers. The developers have to do the menial task of building the configurations and the bunch of XMLs that are common in any application. This leads to a copy paste mentality and repeatative code across applications. It is precisely this that Rails tries to eliminate.<br /><br />Ruby by its very design makes it easy to create domain-specific languages and metaprograms leaving the developers to just focus on the business logic. Also, Rails has its self defined convention for integrating the various components that form part of this full stack framework (ohh yes, its a full stack framework so no need to manage the idiosyncracies of different frameworks at different layers). Thus no more XML configuration files! Talking of the full stack support, Rails has various components that map to the M, V and C. Active Record maps to the model. The programmer is only required to subclass the ActiveRecord: : Base class; and the program by itself determines the table and column details! View is implemented by Embedded Ruby with syntax close to JSP. Controller is taken care of by the Action Pack classes.<br /><br />What more but new technologies like Ajax and Web Services have been integrated with Rails making it convenient to implement applications requiring their use. Among its other features, good programming practices forming a part of this framework result into easily maintainable code.<br /><br />All this might sound like I am painting a rosy picture but try it out now... get your hands dirty and you will see that they don't get all that dirty after all :-). Of course RoR can't be without its drawbacks; nevertheless its promising features were convincing enough for me to choose it as the topic of my final year MS dissertation!<br /><br />Pointers-<br /><a href="http://www.rubyonrails.org/">http://www.rubyonrails.org/</a><br /><a href="http://wiki.rubyonrails.com/rails">http://wiki.rubyonrails.com/rails</a><br /><br />-Ashish.</span>Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com0tag:blogger.com,1999:blog-19043528.post-1137665385136588162006-01-19T02:05:00.000-08:002007-03-01T00:07:39.499-08:00Sudoku<span style="font-size:85%;">Sudoku has become the buzz word around. Small or big, everyone seems to have been enchanted by this apparently simple number game. Like most of us, I stumbled upon this game a few days back in the Times, and have become its avid fan ever since. The only game that had driven me nuts like this before was the Rubik's cube! Basically of Japanese origin (or is it US!) the aim of the game is pretty straight forward. You have to arrange numbers from 1 - 9 in a 9 x 9 sqaure such that each number appears exactly once in every row, column and every 3 x 3 block. [Something similar to Euler's magic quare but not quite same]. It involves no luck, no math, but sheer logic, and there lies the beauty of this game.<br /><br />Solving it requires patience, and with practice one can crack it in a few minutes. Well, to be frank it's not just the matter of practice, but about applying your mind, and learning with every game - a neat test of your logical skills. Try it out right away - <a href="http://www.sudoku.com/">http://www.sudoku.com/</a> - and you would know what I mean!<br /><br />For all those programmers out there, this could be a challenging coding problem. Simple as it might seem, this in fact belongs to one of the tuffest class of problems. By that I don't mean that it cannot be solved, but just that it might not be solvable in polynomial time, so to speak. Those with a little background in algorithmics would have guessed that it has non-polynomial complexity. It is actually NP-complete and thus belongs to the league of Knapsack, graph coloring and 8-queens problem! A trivial approach to it would of course be the good old backtracking! Starting with the first blank sqaure, fill it up with a 1, move on to the next blank... continue in a similar fashion, until you break one of the constraints. As soon as you do, backtrack and fill up the last sqaure with the next possible number. Wait for a sufficiently long time and you will eventually have a solution for sure. <br /><br />There are better approaches. Every blank sqaure can be associated with a list of possible values. This list will be finite and could be set to the universal set [1-9 here] to start with. Now scan the matrix, apply the contraints to each row, column and 3 x 3 block and keep reducing the set of possible values for each blank square until you are left with just one value. This approach would require many scans and updates to the lists before we have a solution. However it can be made faster if we carefully observe the pain points. Those of you who have solved a few sudoku's would be able to relate this approach to how a human mind would solve it. Note how you scan the matrix and you would soon realize that if you scan it for maximally occuring number, the count of subsequent scans would be less. In other words, if you store the frequency of occurence of numbers (currently on board), and scan the matrix for the number with max. frequency, not only would the updates be less, but so would be the required scans. I believe that applying backtracking for sufficiently small sizes of the lists would also be faster. This is so, as we would be saving on the time spent on scanning. Note also, that there's a significant time spent searching for blank squares. This could easily be eliminated by storing references to the neighboring blank squares!<br /><br />It might interest you that this problem belongs to a class of problems called the Exact Cover problem. Knuth gives an elegant algorithm (which he calls the X algorithm) and an equally elegant implementation approach called Dancing Links (so called because of the way in which the doubly linked lists change links as the solution proceeds). For details, here's Knuth's paper on the Dancing Links solution - <a href="http://xxx.lanl.gov/PS_cache/cs/pdf/0011/0011047.pdf">http://xxx.lanl.gov/PS_cache/cs/pdf/0011/0011047.pdf</a><br />It's implementation in java can be found in this <a href="http://www.bluechromis.com:8080/stan/sudoku.html">Sudoku solver</a>.<br /><br />Keep Sudoking!<br />-Ashish.</span>Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com1tag:blogger.com,1999:blog-19043528.post-1137573840978569202006-01-18T00:40:00.000-08:002007-03-01T00:01:24.540-08:00Escape Analysis<span style="font-size:85%;">The idea of implementing Escape Analysis in Mustang (J2SE 6) seems to be an impressive bet and finds a mention in this developerworks article -<br /><a href="http://www-128.ibm.com/developerworks/java/library/j-jtp09275.html?ca=dgr-jw22JavaUrbanLegends">http://www-128.ibm.com/developerworks/java/library/j-jtp09275.html?ca=dgr-jw22JavaUrbanLegends</a><br />Escape analysis refers to the analysis done on a program to determine those dynamically allocated objects and their references that "escape" or are likely to escape the method or thread scope. This has many applications with potential implications on the program performance. The knowledge of objects being bound by the method scope opens up the possibility of allocating them in the method stack frame rather than on the heap as is typically done for any dynamically allocated objects. Dynamic memory allocation (& deallocation) comes at a price. It comes with the associated problems of fragmentation, data locality and overcoming these is costly both in terms of time and space. Talking within the Java perspective, the garbage collector takes care of reclaiming the dead object space, but even the most recent generational copying collectors can "stop-the-world" for significant amount of time. Stack allocation is not only free of these idiosyncrasies but also the deallocation happens implicitly on method return. Moreover, better data locality means that there would be less cache misses.<br /><br />Knowledge of local objects also gives the compiler/optimizer a chance to get rid of the object altogether in some cases. The link above has a code snippet justifying the same.<br /><br />If an object does not escape the thread, the overhead associated with its synchronization can be eliminated. This is significant because forgetting to synchronize objects being accessed by multiple threads can pose serious issues like race condition, spurious and unexpected results etc. Compilers and optimizers often reorder instructions for efficient execution. While this is acceptable in a typical sequential execution, this might cause unexpected results in a multithreaded multiprocessor environment. To add to this, the java memory model does little to ensure the data atomicity, visibility and ordering in such cases. And it is not to blame... with new environments coming up every other day, it is next to impossible to ensure correct execution. Needless to say, thread local objects are desirable and anything that can be done to identify them in a multi threaded program is worth the effort.<br /><br />Okay, so escape analysis seems to be desirable. How do we go about implementing it? The short answer could be - Do it however you like! :)<br />Basically, what this would require is an understanding of the relationship between the various dynamically allocated objects and references... something similar to what a compiler would do in the dataflow analysis. We need to track the object right from it's inception to how it is accessed in a method to how it gets passed to other methods to whether it would be accessed by other threads until it is reclaimed by GC. There are ample articles to peruse varying in details on escape analysis in general, it's application in Java and various implementation strategies. Here's a pointer -<br /><a href="http://citeseer.ist.psu.edu/choi99escape.html">http://citeseer.ist.psu.edu/choi99escape.html</a><br /><br />Whether or not escape analysis is implemented in Mustang is still being debated and you will find many forums dedicated to this topic. But then nothing stops us from delving into the code and contributing to the build!<br /><br />Happy Coding :)<br /> - Ashish.<br /></span>Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com0tag:blogger.com,1999:blog-19043528.post-1132186154309468292005-11-16T15:38:00.000-08:002007-02-28T23:55:42.633-08:00Sticky Stale connections<span style="font-size:85%;">My first encounter with the stale connections was when we first launched an interactive J2EE application on the Websphere Application Server 3.5.6 on a SUN Solaris box. The application frequently received StaleConnectionException (com.ibm.ejs.cm.portability.StaleConnectionException), an exception that became a potential showstopper for us. In spite of frantic googling and research and changes varying from implementation of retry logic in the application to changing the connection pool settings to changing the zparams values on the Db2 server, the sticky issue continued to haunt us. Frustrated with the results, we finally had to do away with the connection pooling support of WAS and obtain the connections directly from the Driver Manager instead. Now as we migrate the application from WAS 3.5.6 to WAS 5.1.1, we were again challenged by the same issue, but this time we finally seem to have got a solution. What follows is an account of the steps we took to combat this "sticky" exception.<br /><br />Well before I forget, the package structure for the exception has changed since WAS 4, and it is now qualified as <strong>com.ibm.websphere.ce.cm.StaleConnectionException</strong>.<br />The first thing we did was to google on StaleConnectionException. Sure enough, there is enough documentation on the net on the possible causes of this exception. And any of these could cause the managed connection objects in the connection pool to become "stale". Any statement executed on this stale connection would cause the driver implementation to throw a SQLException with some SQL state and error code. The WAS implementation maps a set of these error codes to a sub class of the SQLException - StaleConnectionException - and throws this exception to the requesting application. What it also does is that it clears the connection pool off all the unusable connection objects from the datasource in question. So ideally, the application should receive a good connection object the next time it requests for one. This prompted us to implement a <strong>retry logic</strong> something like this:<br />do {<br />try {<br />get connection object;<br />execute statement;<br />...<br />break;<br />}catch(StaleConnectionException se) {<br />retryCount++;<br />}<br />}while(retryCount < MaxTtries);<br />Unfortunately, this did not help. Thinking that the pool implementation might be taking some time to refresh the connection pool, we tried putting delay between the tries... but to no avail.<br />Meanwhile, we were in touch with contacts from other projects. We got all the data access code reviewed to confirm that we were <strong>closing all the connection objects, and closing all the cursurs and statements explicitly</strong>. Thus there was no chance of spurious connection objects becoming stale.<br /><br />We also tried <strong>changing the driver implementation</strong> from the type 2 db2java to type2/4 UDB driver but the exception continued to recur.<br /><br />Sometime in the middle of all this, we also tinkered with a few connection pool parameters but without success. If only we had been a little more careful [:(] 'coz we ultimately found the solution in one of those parameters! Well, before that... by now we were almost certain that there was something going awry in the WAS connection pool implementation but influenced by the statement <br /><br /><blockquote>Recovering from stale connections is a joint effort between the application<br />server run time and the application developer.</blockquote> in the IBM infocenter for WAS 5.1 <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www-306.ibm.com/software/webservers/appserv/was/library/library51.html" target="_blank">http://www-306.ibm.com/software/webservers/appserv/was/library/library51.html</a> we implemented a solution to redirect the users to an error page with a friendly error message asking them to retry the operation. Just when we had given up the hope and were thinking that this was the best we could do, we stumbled upon a link that suggested that applications running behind a firewall might be affected by connection timeout setting at the firewall. This could inturn surface as StaleConnectionException for the application. They also suggested that the "<strong>unused connection timeout</strong>" - one of the connection pool parameters - be set to a value smaller than the firewall setting. It was then that we realized that the connections might be getting closed lower in the network stack, WAS runtime at the application layer being unaware of it. Please note that the pool implementation does not do any check on the validity of the managed connection object before returning one to the requesting application. We set the connection timeout value to 300 seconds and sure enough... we have not seen the exception post this change. Note that the unused connection timeout value should still be greater than the reap time (default 180 sec.) for it to make sense.<br /><br />One more suggestion or rather a best practice to add to this "list" is to <strong>localize the data access</strong> as much as possible. While the DAO pattern helps to a certain extent, what it does not suggest is the localization of the code that uses the connection object. Have a single place where you open the database connection, make the backend call, and close the connection. (Avoid replicating the same in every data access method for instance).<br /><br />Causes for the stale connections are many. Although we found our solution in the connection pool parameter setting, it's equally likely that some other application would find theirs in connection objects being left open in the code. What I am heading at is that if you are a victim of StaleConnectionException, you might want to try <strong>all</strong> the above options... and this might not even be an exhaustive list!Ashishhttp://www.blogger.com/profile/04524393884746220577noreply@blogger.com0